mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-20 07:10:02 +00:00
Add action for changing request type (#2668)
Signed-off-by: Vyacheslav Tumanov <me@slavatumanov.me>
This commit is contained in:
parent
af09bb3ead
commit
0280677f03
@ -332,6 +332,21 @@ export function createModel (builder: Builder): void {
|
|||||||
hr.action.EditRequest
|
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(
|
builder.createDoc(
|
||||||
view.class.Viewlet,
|
view.class.Viewlet,
|
||||||
core.space.Model,
|
core.space.Model,
|
||||||
|
@ -18,7 +18,7 @@ import { hrId } from '@hcengineering/hr'
|
|||||||
import hr from '@hcengineering/hr-resources/src/plugin'
|
import hr from '@hcengineering/hr-resources/src/plugin'
|
||||||
import { IntlString, mergeIds } from '@hcengineering/platform'
|
import { IntlString, mergeIds } from '@hcengineering/platform'
|
||||||
import { AnyComponent } from '@hcengineering/ui'
|
import { AnyComponent } from '@hcengineering/ui'
|
||||||
import { Action, ActionCategory } from '@hcengineering/view'
|
import { Action, ActionCategory, ViewAction } from '@hcengineering/view'
|
||||||
|
|
||||||
export default mergeIds(hrId, hr, {
|
export default mergeIds(hrId, hr, {
|
||||||
string: {
|
string: {
|
||||||
@ -51,6 +51,10 @@ export default mergeIds(hrId, hr, {
|
|||||||
EditDepartment: '' as Ref<Action>,
|
EditDepartment: '' as Ref<Action>,
|
||||||
DeleteDepartment: '' as Ref<Action>,
|
DeleteDepartment: '' as Ref<Action>,
|
||||||
EditRequest: '' as Ref<Action>,
|
EditRequest: '' as Ref<Action>,
|
||||||
|
EditRequestType: '' as Ref<Action>,
|
||||||
DeleteRequest: '' as Ref<Action>
|
DeleteRequest: '' as Ref<Action>
|
||||||
|
},
|
||||||
|
actionImpl: {
|
||||||
|
EditRequestType: '' as ViewAction
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -32,6 +32,9 @@
|
|||||||
"PTO2": "PTO/2",
|
"PTO2": "PTO/2",
|
||||||
"Overtime2": "Overtime/2",
|
"Overtime2": "Overtime/2",
|
||||||
"EditRequest": "Edit {type}",
|
"EditRequest": "Edit {type}",
|
||||||
|
"EditRequestType": "Edit type",
|
||||||
|
"ChooseNewType": "Choose new type:",
|
||||||
|
"UnchangeableType": "This type cannot be changed",
|
||||||
"Request": "Request",
|
"Request": "Request",
|
||||||
"Staff": "Worker",
|
"Staff": "Worker",
|
||||||
"Member": "Member",
|
"Member": "Member",
|
||||||
|
@ -32,6 +32,9 @@
|
|||||||
"PTO2": "PTO/2",
|
"PTO2": "PTO/2",
|
||||||
"Overtime2": "Переработка/2",
|
"Overtime2": "Переработка/2",
|
||||||
"EditRequest": "Редактировать {type}",
|
"EditRequest": "Редактировать {type}",
|
||||||
|
"EditRequestType": "Редактировать тип",
|
||||||
|
"ChooseNewType": "Выберите новый тип:",
|
||||||
|
"UnchangeableType": "Этот тип нельзя поменять",
|
||||||
"Request": "Запрос",
|
"Request": "Запрос",
|
||||||
"Staff": "Работник",
|
"Staff": "Работник",
|
||||||
"Member": "Сотрудник",
|
"Member": "Сотрудник",
|
||||||
|
79
plugins/hr-resources/src/components/EditRequestType.svelte
Normal file
79
plugins/hr-resources/src/components/EditRequestType.svelte
Normal 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}
|
@ -23,6 +23,13 @@ import Structure from './components/Structure.svelte'
|
|||||||
import TzDatePresenter from './components/TzDatePresenter.svelte'
|
import TzDatePresenter from './components/TzDatePresenter.svelte'
|
||||||
import TzDateEditor from './components/TzDateEditor.svelte'
|
import TzDateEditor from './components/TzDateEditor.svelte'
|
||||||
import RequestPresenter from './components/RequestPresenter.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> => ({
|
export default async (): Promise<Resources> => ({
|
||||||
component: {
|
component: {
|
||||||
@ -34,6 +41,10 @@ export default async (): Promise<Resources> => ({
|
|||||||
EditRequest,
|
EditRequest,
|
||||||
TzDatePresenter,
|
TzDatePresenter,
|
||||||
TzDateEditor,
|
TzDateEditor,
|
||||||
RequestPresenter
|
RequestPresenter,
|
||||||
|
EditRequestType
|
||||||
|
},
|
||||||
|
actionImpl: {
|
||||||
|
EditRequestType: editRequestType
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -36,6 +36,9 @@ export default mergeIds(hrId, hr, {
|
|||||||
RequestType: '' as IntlString,
|
RequestType: '' as IntlString,
|
||||||
Schedule: '' as IntlString,
|
Schedule: '' as IntlString,
|
||||||
EditRequest: '' as IntlString,
|
EditRequest: '' as IntlString,
|
||||||
|
EditRequestType: '' as IntlString,
|
||||||
|
ChooseNewType: '' as IntlString,
|
||||||
|
UnchangeableType: '' as IntlString,
|
||||||
CreateRequest: '' as IntlString,
|
CreateRequest: '' as IntlString,
|
||||||
Today: '' as IntlString,
|
Today: '' as IntlString,
|
||||||
NoEmployeesInDepartment: '' as IntlString,
|
NoEmployeesInDepartment: '' as IntlString,
|
||||||
|
Loading…
Reference in New Issue
Block a user