mirror of
https://github.com/hcengineering/platform.git
synced 2024-11-21 16:09:12 +03:00
parent
509952de4e
commit
30c08f494b
@ -18,16 +18,8 @@
|
||||
import { Ref, WithLookup } from '@hcengineering/core'
|
||||
import { Department, Staff } from '@hcengineering/hr'
|
||||
import { getClient } from '@hcengineering/presentation'
|
||||
import {
|
||||
Button,
|
||||
IconAdd,
|
||||
Label,
|
||||
closeTooltip,
|
||||
eventToHTMLElement,
|
||||
getEventPositionElement,
|
||||
showPopup
|
||||
} from '@hcengineering/ui'
|
||||
import { Menu, openDoc, showMenu } from '@hcengineering/view-resources'
|
||||
import { Button, IconAdd, Label, closeTooltip, eventToHTMLElement, showPopup } from '@hcengineering/ui'
|
||||
import { openDoc, showMenu } from '@hcengineering/view-resources'
|
||||
import hr from '../plugin'
|
||||
import { addMember } from '../utils'
|
||||
import CreateDepartment from './CreateDepartment.svelte'
|
||||
|
@ -19,6 +19,7 @@
|
||||
import { ButtonKind, ButtonSize } from '@hcengineering/ui'
|
||||
import { ObjectBox } from '@hcengineering/view-resources'
|
||||
import hr from '../plugin'
|
||||
import { createQuery } from '@hcengineering/presentation'
|
||||
|
||||
export let value: Ref<Department> | undefined
|
||||
export let label: IntlString = hr.string.ParentDepartmentLabel
|
||||
@ -27,16 +28,47 @@
|
||||
export let size: ButtonSize = 'small'
|
||||
export let justify: 'left' | 'center' = 'center'
|
||||
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>
|
||||
|
||||
<ObjectBox
|
||||
_class={hr.class.Department}
|
||||
{excluded}
|
||||
{label}
|
||||
{size}
|
||||
{kind}
|
||||
{justify}
|
||||
allowDeselect
|
||||
{width}
|
||||
readonly={value === undefined}
|
||||
showNavigate={false}
|
||||
autoSelect={false}
|
||||
bind:value
|
||||
|
@ -82,7 +82,7 @@
|
||||
departments.clear()
|
||||
descendants.clear()
|
||||
for (const doc of res) {
|
||||
if (doc.parent !== undefined) {
|
||||
if (doc.parent !== undefined && doc._id !== hr.ids.Head) {
|
||||
const current = descendants.get(doc.parent) ?? []
|
||||
current.push(doc)
|
||||
descendants.set(doc.parent, current)
|
||||
|
Loading…
Reference in New Issue
Block a user