From a4b3cb4a44f314f4ccf001539849c6bd54e98933 Mon Sep 17 00:00:00 2001 From: Andrey Sobolev Date: Sat, 2 Jul 2022 23:55:15 +0700 Subject: [PATCH] Allow to do departament d&d (#2194) Signed-off-by: Andrey Sobolev --- models/hr/src/index.ts | 23 ++++++++ .../src/components/MessageBox.svelte | 3 +- .../src/components/DepartmentCard.svelte | 39 ++++++++++++-- .../src/components/DepartmentStaff.svelte | 50 ++--------------- .../src/components/PersonsPresenter.svelte | 51 ++++++++++++++++-- plugins/hr-resources/src/utils.ts | 54 +++++++++++++++++++ .../src/components/ValueSelector.svelte | 16 ++++-- 7 files changed, 175 insertions(+), 61 deletions(-) create mode 100644 plugins/hr-resources/src/utils.ts diff --git a/models/hr/src/index.ts b/models/hr/src/index.ts index d0dd70c791..e61d62c554 100644 --- a/models/hr/src/index.ts +++ b/models/hr/src/index.ts @@ -333,6 +333,29 @@ export function createModel (builder: Builder): void { }, hr.viewlet.TableMember ) + + createAction(builder, { + action: view.actionImpl.ValueSelector, + actionPopup: view.component.ValueSelector, + actionProps: { + attribute: 'department', + _class: hr.class.Department, + query: {}, + searchField: 'name', + placeholder: hr.string.Department + }, + label: hr.string.Department, + icon: hr.icon.Department, + keyBinding: [], + input: 'none', + category: hr.category.HR, + target: hr.mixin.Staff, + context: { + mode: ['context'], + application: hr.app.HR, + group: 'associate' + } + }) } export { hrOperation } from './migration' diff --git a/packages/presentation/src/components/MessageBox.svelte b/packages/presentation/src/components/MessageBox.svelte index 29943fb454..59d0a10c40 100644 --- a/packages/presentation/src/components/MessageBox.svelte +++ b/packages/presentation/src/components/MessageBox.svelte @@ -19,6 +19,7 @@ import presentation from '..' export let label: IntlString + export let labelProps: IntlString export let message: IntlString export let params: Record = {} export let canSubmit = true @@ -27,7 +28,7 @@
-
+
- +
@@ -127,17 +152,21 @@
{#each currentDescendants as nested} - + {/each}
diff --git a/plugins/hr-resources/src/components/DepartmentStaff.svelte b/plugins/hr-resources/src/components/DepartmentStaff.svelte index 805fa64f69..def384dd94 100644 --- a/plugins/hr-resources/src/components/DepartmentStaff.svelte +++ b/plugins/hr-resources/src/components/DepartmentStaff.svelte @@ -13,15 +13,15 @@ // limitations under the License. --> {#if value}
- {#each persons as p} -
+ {#each persons as p (p._id)} +
ondrag(p)} + on:dragend|preventDefault|stopPropagation={() => { + dragPerson = undefined + closeTooltip() + }} + on:contextmenu|stopPropagation|preventDefault={(evt) => showContextMenu(evt, p)} + >
{/each} + {#if showDragPerson && dragPerson !== undefined && persons.find((it) => it._id === dragPerson?._id) === undefined} + + {/if}
{/if} diff --git a/plugins/hr-resources/src/utils.ts b/plugins/hr-resources/src/utils.ts new file mode 100644 index 0000000000..93dd0b9cfb --- /dev/null +++ b/plugins/hr-resources/src/utils.ts @@ -0,0 +1,54 @@ +import { Employee, formatName } from '@anticrm/contact' +import { TxOperations } from '@anticrm/core' +import { Department } from '@anticrm/hr' +import { MessageBox } from '@anticrm/presentation' +import { showPopup } from '@anticrm/ui' +import hr from './plugin' + +export async function addMember (client: TxOperations, employee?: Employee, value?: Department): Promise { + if (employee === null || employee === undefined || value === undefined) { + return + } + + const hierarchy = client.getHierarchy() + if (!hierarchy.hasMixin(employee, hr.mixin.Staff)) { + await client.createMixin(employee._id, employee._class, employee.space, hr.mixin.Staff, { + department: value._id + }) + } else { + const staff = hierarchy.as(employee, hr.mixin.Staff) + if (staff.department === value._id) return + const current = await client.findOne(hr.class.Department, { + _id: staff.department + }) + if (current !== undefined) { + await new Promise((resolve) => { + showPopup( + MessageBox, + { + label: hr.string.MoveStaff, + labelProps: { name: formatName(employee.name) }, + message: hr.string.MoveStaffDescr, + params: { + current: current.name, + department: value.name + } + }, + undefined, + (res?: boolean) => { + if (res === true && value !== undefined) { + void client.updateMixin(employee._id, employee._class, employee.space, hr.mixin.Staff, { + department: value._id + }) + } + resolve(null) + } + ) + }) + } else { + await client.updateMixin(employee._id, employee._class, employee.space, hr.mixin.Staff, { + department: value._id + }) + } + } +} diff --git a/plugins/view-resources/src/components/ValueSelector.svelte b/plugins/view-resources/src/components/ValueSelector.svelte index 88c4ecbd4a..90020b7359 100644 --- a/plugins/view-resources/src/components/ValueSelector.svelte +++ b/plugins/view-resources/src/components/ValueSelector.svelte @@ -1,7 +1,7 @@