mirror of
https://github.com/hcengineering/platform.git
synced 2024-11-22 03:14:40 +03:00
parent
509952de4e
commit
30c08f494b
@ -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'
|
||||||
|
@ -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
|
||||||
|
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user