|
| 1 | +<!-- |
| 2 | +// Copyright © 2025 Hardcore Engineering Inc. |
| 3 | +// |
| 4 | +// Licensed under the Eclipse Public License, Version 2.0 (the "License"); |
| 5 | +// you may not use this file except in compliance with the License. You may |
| 6 | +// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0 |
| 7 | +// |
| 8 | +// Unless required by applicable law or agreed to in writing, software |
| 9 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | +// |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | +--> |
| 15 | +<script lang="ts"> |
| 16 | + import { Class, Doc, Ref } from '@hcengineering/core' |
| 17 | + import { createQuery } from '@hcengineering/presentation' |
| 18 | + import { getCurrentLocation, navigate, location as locationStore } from '@hcengineering/ui' |
| 19 | + import { MasterTag } from '@hcengineering/card' |
| 20 | + import { TreeNode } from '@hcengineering/view-resources' |
| 21 | + import { GroupsNavModel } from '@hcengineering/workbench' |
| 22 | + import TagHierarchy from './TagHierarchy.svelte' |
| 23 | + import card from '../../plugin' |
| 24 | +
|
| 25 | + export let model: GroupsNavModel |
| 26 | +
|
| 27 | + let classes: MasterTag[] = [] |
| 28 | + let _class: Ref<Class<Doc>> | undefined |
| 29 | +
|
| 30 | + const query = createQuery() |
| 31 | + query.query(card.class.MasterTag, {}, (res) => { |
| 32 | + classes = res.filter((it) => it.removed !== true).sort((a, b) => a.label.localeCompare(b.label)) |
| 33 | + }) |
| 34 | +
|
| 35 | + function getRootClasses (_classes: MasterTag[]): MasterTag[] { |
| 36 | + return _classes.filter((it) => it.extends === card.class.Card) |
| 37 | + } |
| 38 | +
|
| 39 | + function buildTypePath (currentPath: any[], type: Ref<MasterTag>): any[] { |
| 40 | + return [...currentPath.slice(0, 3), 'type', type] |
| 41 | + } |
| 42 | +
|
| 43 | + function selectType (type: Ref<MasterTag>): void { |
| 44 | + const loc = getCurrentLocation() |
| 45 | + loc.path = buildTypePath(loc.path, type) |
| 46 | + navigate(loc) |
| 47 | + } |
| 48 | +
|
| 49 | + $: _class = $locationStore.path[4] as Ref<Class<Doc>> |
| 50 | + $: selectedClass = classes.find((it) => it._id === _class) |
| 51 | + $: rootClasses = getRootClasses(classes) |
| 52 | + $: empty = rootClasses === undefined || rootClasses.length === 0 |
| 53 | +</script> |
| 54 | + |
| 55 | +<div class="flex-col w-full"> |
| 56 | + <TreeNode |
| 57 | + _id={'tree-' + model.id} |
| 58 | + label={model.label} |
| 59 | + highlighted={selectedClass !== undefined} |
| 60 | + isFold={!empty} |
| 61 | + {empty} |
| 62 | + > |
| 63 | + <TagHierarchy |
| 64 | + classes={rootClasses} |
| 65 | + allClasses={classes} |
| 66 | + {_class} |
| 67 | + space={undefined} |
| 68 | + currentSpace={undefined} |
| 69 | + on:select={(e) => { |
| 70 | + selectType(e.detail) |
| 71 | + }} |
| 72 | + /> |
| 73 | + </TreeNode> |
| 74 | +</div> |
0 commit comments