Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov 2024-10-08 22:15:11 +05:00 committed by GitHub
parent 509952de4e
commit 30c08f494b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 36 additions and 12 deletions

View File

@ -18,16 +18,8 @@
import { Ref, WithLookup } from '@hcengineering/core' import { Ref, WithLookup } from '@hcengineering/core'
import { Department, Staff } from '@hcengineering/hr' import { Department, Staff } from '@hcengineering/hr'
import { getClient } from '@hcengineering/presentation' import { getClient } from '@hcengineering/presentation'
import { import { Button, IconAdd, Label, closeTooltip, eventToHTMLElement, showPopup } from '@hcengineering/ui'
Button, import { openDoc, showMenu } from '@hcengineering/view-resources'
IconAdd,
Label,
closeTooltip,
eventToHTMLElement,
getEventPositionElement,
showPopup
} from '@hcengineering/ui'
import { Menu, openDoc, showMenu } from '@hcengineering/view-resources'
import hr from '../plugin' import hr from '../plugin'
import { addMember } from '../utils' import { addMember } from '../utils'
import CreateDepartment from './CreateDepartment.svelte' import CreateDepartment from './CreateDepartment.svelte'

View File

@ -19,6 +19,7 @@
import { ButtonKind, ButtonSize } from '@hcengineering/ui' import { ButtonKind, ButtonSize } from '@hcengineering/ui'
import { ObjectBox } from '@hcengineering/view-resources' import { ObjectBox } from '@hcengineering/view-resources'
import hr from '../plugin' import hr from '../plugin'
import { createQuery } from '@hcengineering/presentation'
export let value: Ref<Department> | undefined export let value: Ref<Department> | undefined
export let label: IntlString = hr.string.ParentDepartmentLabel export let label: IntlString = hr.string.ParentDepartmentLabel
@ -27,16 +28,47 @@
export let size: ButtonSize = 'small' export let size: ButtonSize = 'small'
export let justify: 'left' | 'center' = 'center' export let justify: 'left' | 'center' = 'center'
export let width: string | undefined = undefined export let width: string | undefined = undefined
export let object: Department | undefined
let excluded: Ref<Department>[] = []
let descendants: Map<Ref<Department>, Department[]> = new Map<Ref<Department>, Department[]>()
$: excluded =
object !== undefined
? descendants
.get(object._id)
?.map((p) => p._id)
.concat(object._id) ?? [object._id]
: []
const q = createQuery()
$: if (object !== undefined) {
q.query(hr.class.Department, {}, (res) => {
descendants.clear()
for (const doc of res) {
if (doc.parent !== undefined && doc._id !== hr.ids.Head) {
const current = descendants.get(doc.parent) ?? []
current.push(doc)
descendants.set(doc.parent, current)
}
}
descendants = descendants
})
} else {
q.unsubscribe()
excluded = []
}
</script> </script>
<ObjectBox <ObjectBox
_class={hr.class.Department} _class={hr.class.Department}
{excluded}
{label} {label}
{size} {size}
{kind} {kind}
{justify} {justify}
allowDeselect
{width} {width}
readonly={value === undefined}
showNavigate={false} showNavigate={false}
autoSelect={false} autoSelect={false}
bind:value bind:value

View File

@ -82,7 +82,7 @@
departments.clear() departments.clear()
descendants.clear() descendants.clear()
for (const doc of res) { for (const doc of res) {
if (doc.parent !== undefined) { if (doc.parent !== undefined && doc._id !== hr.ids.Head) {
const current = descendants.get(doc.parent) ?? [] const current = descendants.get(doc.parent) ?? []
current.push(doc) current.push(doc)
descendants.set(doc.parent, current) descendants.set(doc.parent, current)