Add action for changing request type (#2668)

Signed-off-by: Vyacheslav Tumanov <me@slavatumanov.me>
This commit is contained in:
Vyacheslav Tumanov 2023-02-21 11:47:39 +05:00 committed by GitHub
parent af09bb3ead
commit 0280677f03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 122 additions and 4 deletions

View File

@ -332,6 +332,21 @@ export function createModel (builder: Builder): void {
hr.action.EditRequest
)
createAction(
builder,
{
action: hr.actionImpl.EditRequestType,
actionProps: {},
label: hr.string.EditRequestType,
icon: view.icon.Open,
input: 'any',
category: hr.category.HR,
target: hr.class.Request,
context: { mode: 'context', application: hr.app.HR, group: 'edit' }
},
hr.action.EditRequestType
)
builder.createDoc(
view.class.Viewlet,
core.space.Model,

View File

@ -18,7 +18,7 @@ import { hrId } from '@hcengineering/hr'
import hr from '@hcengineering/hr-resources/src/plugin'
import { IntlString, mergeIds } from '@hcengineering/platform'
import { AnyComponent } from '@hcengineering/ui'
import { Action, ActionCategory } from '@hcengineering/view'
import { Action, ActionCategory, ViewAction } from '@hcengineering/view'
export default mergeIds(hrId, hr, {
string: {
@ -51,6 +51,10 @@ export default mergeIds(hrId, hr, {
EditDepartment: '' as Ref<Action>,
DeleteDepartment: '' as Ref<Action>,
EditRequest: '' as Ref<Action>,
EditRequestType: '' as Ref<Action>,
DeleteRequest: '' as Ref<Action>
},
actionImpl: {
EditRequestType: '' as ViewAction
}
})

View File

@ -32,6 +32,9 @@
"PTO2": "PTO/2",
"Overtime2": "Overtime/2",
"EditRequest": "Edit {type}",
"EditRequestType": "Edit type",
"ChooseNewType": "Choose new type:",
"UnchangeableType": "This type cannot be changed",
"Request": "Request",
"Staff": "Worker",
"Member": "Member",
@ -39,4 +42,4 @@
"NoMembers": "No members added",
"AddMember": "Add member"
}
}
}

View File

@ -32,6 +32,9 @@
"PTO2": "PTO/2",
"Overtime2": "Переработка/2",
"EditRequest": "Редактировать {type}",
"EditRequestType": "Редактировать тип",
"ChooseNewType": "Выберите новый тип:",
"UnchangeableType": "Этот тип нельзя поменять",
"Request": "Запрос",
"Staff": "Работник",
"Member": "Сотрудник",
@ -39,4 +42,4 @@
"NoMembers": "Нет добавленных сотрудников",
"AddMember": "Добавить сотрудника"
}
}
}

View File

@ -0,0 +1,79 @@
<script lang="ts">
import presentation, { Card, createQuery, getClient } from '@hcengineering/presentation'
import hr from '../plugin'
import { createEventDispatcher } from 'svelte'
import { DropdownLabelsIntl, Label } from '@hcengineering/ui'
import { RequestType } from '@hcengineering/hr'
import { Ref } from '@hcengineering/core'
const dispatch = createEventDispatcher()
export let object: Request
let types: RequestType[] = []
let type: RequestType | undefined
let newType: RequestType | undefined
let typesToChange: (RequestType | undefined)[] | undefined
const typesQuery = createQuery()
const client = getClient()
$: typesQuery.query(hr.class.RequestType, {}, (res) => {
types = res
if (object !== undefined && object.type !== undefined) {
type = types.find((t) => t._id === object.type)
typesToChange = requestPairMap.get(type?._id)?.map((t) => types.find((x) => t === x._id))
if (typesToChange !== undefined) {
newType = typesToChange[0]
}
}
})
const requestPairMap: Map<Ref<RequestType>, Array<Ref<RequestType>>> = new Map([
[hr.ids.PTO, [hr.ids.PTO2, hr.ids.Sick, hr.ids.Vacation]],
[hr.ids.PTO2, [hr.ids.PTO]],
[hr.ids.Overtime, [hr.ids.Overtime2]],
[hr.ids.Overtime2, [hr.ids.Overtime]]
])
function typeSelected (_id: Ref<RequestType>): void {
newType = types.find((p) => p._id === _id)
}
async function changeType () {
await client.updateCollection(
hr.class.Request,
object.space,
object._id,
object.attachedTo,
object.attachedToClass,
object.collecttion,
{
type: newType._id
}
)
}
</script>
{#if object && type && type.label}
<Card
label={hr.string.EditRequestType}
labelProps={{ type: type.label }}
canSave={typesToChange !== undefined}
okAction={changeType}
okLabel={presentation.string.Save}
on:close={() => {
dispatch('close')
}}
>
<div class="mr-3">
{#if typesToChange !== undefined}
<Label label={hr.string.ChooseNewType} />
<DropdownLabelsIntl
items={typesToChange.map((p) => {
return { id: p._id, label: p.label }
})}
label={hr.string.RequestType}
on:selected={(e) => typeSelected(e.detail)}
/>
{:else}
<Label label={hr.string.UnchangeableType} />
{/if}
</div>
</Card>
{/if}

View File

@ -23,6 +23,13 @@ import Structure from './components/Structure.svelte'
import TzDatePresenter from './components/TzDatePresenter.svelte'
import TzDateEditor from './components/TzDateEditor.svelte'
import RequestPresenter from './components/RequestPresenter.svelte'
import { showPopup } from '@hcengineering/ui'
import { Request } from '@hcengineering/hr'
import EditRequestType from './components/EditRequestType.svelte'
async function editRequestType (object: Request): Promise<void> {
showPopup(EditRequestType, { object })
}
export default async (): Promise<Resources> => ({
component: {
@ -34,6 +41,10 @@ export default async (): Promise<Resources> => ({
EditRequest,
TzDatePresenter,
TzDateEditor,
RequestPresenter
RequestPresenter,
EditRequestType
},
actionImpl: {
EditRequestType: editRequestType
}
})

View File

@ -36,6 +36,9 @@ export default mergeIds(hrId, hr, {
RequestType: '' as IntlString,
Schedule: '' as IntlString,
EditRequest: '' as IntlString,
EditRequestType: '' as IntlString,
ChooseNewType: '' as IntlString,
UnchangeableType: '' as IntlString,
CreateRequest: '' as IntlString,
Today: '' as IntlString,
NoEmployeesInDepartment: '' as IntlString,