|
4 | 4 | import { createQuery, getClient, ObjectCreate } from '@hcengineering/presentation' |
5 | 5 | import { Button, IconAdd, Label, Scroller, Section, showPopup } from '@hcengineering/ui' |
6 | 6 | import { showMenu } from '../actions' |
7 | | - import { Viewlet, ViewletPreference } from '@hcengineering/view' |
| 7 | + import { Viewlet, ViewletPreference, ViewOptions } from '@hcengineering/view' |
8 | 8 | import DocTable from './DocTable.svelte' |
9 | 9 | import ObjectBoxPopup from './ObjectBoxPopup.svelte' |
10 | 10 | import view from '../plugin' |
| 11 | + import ViewletsSettingButton from './ViewletsSettingButton.svelte' |
11 | 12 |
|
12 | 13 | export let object: Doc |
13 | 14 | export let docs: Doc[] |
|
62 | 63 | let viewlet: WithLookup<Viewlet> | undefined |
63 | 64 | let preference: ViewletPreference | undefined = undefined |
64 | 65 |
|
65 | | - const query = createQuery() |
66 | | -
|
67 | | - $: query.query( |
68 | | - view.class.Viewlet, |
69 | | - { |
70 | | - attachTo: client.getHierarchy().getBaseClass(_class) |
71 | | - }, |
72 | | - (res) => { |
73 | | - viewlet = res[0] |
74 | | - }, |
75 | | - { |
76 | | - lookup: { |
77 | | - descriptor: view.class.ViewletDescriptor |
78 | | - } |
79 | | - } |
80 | | - ) |
81 | | -
|
82 | | - const preferenceQuery = createQuery() |
83 | | -
|
84 | | - $: if (viewlet != null) { |
85 | | - preferenceQuery.query( |
86 | | - view.class.ViewletPreference, |
87 | | - { |
88 | | - space: core.space.Workspace, |
89 | | - attachedTo: viewlet._id |
90 | | - }, |
91 | | - (res) => { |
92 | | - preference = res[0] |
93 | | - }, |
94 | | - { limit: 1 } |
95 | | - ) |
96 | | - } else { |
97 | | - preferenceQuery.unsubscribe() |
98 | | - preference = undefined |
99 | | - } |
| 66 | + $: baseClass = client.getHierarchy().getBaseClass(_class) |
100 | 67 |
|
101 | 68 | $: selectedConfig = preference?.config ?? viewlet?.config |
102 | 69 | $: config = selectedConfig?.filter((p) => |
|
133 | 100 | {#if classLabel} |
134 | 101 | <Label label={classLabel} /> |
135 | 102 | {/if} |
| 103 | + <ViewletsSettingButton viewletQuery={{ attachTo: baseClass }} kind={'tertiary'} bind:viewlet bind:preference /> |
136 | 104 | {#if !readonly && allowToCreate} |
137 | 105 | <Button id={core.string.AddRelation} icon={IconAdd} kind={'ghost'} on:click={add} /> |
138 | 106 | {/if} |
|
0 commit comments