@dative-gpi/foundation-core-components 1.1.11 → 1.1.12-dashboards-explorer-02

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -41,7 +41,7 @@ import { defineComponent, ref, type PropType, computed } from "vue";
41
41
 
42
42
  import { EntityType } from "@dative-gpi/foundation-shared-domain/enums";
43
43
 
44
- import type { DashboardOrganisationFilters, DashboardOrganisationTypeFilters, DashboardShallowFilters, DeviceOrganisationFilters, FolderFilters, GroupFilters, GroupingFilters, LocationFilters, ModelFilters, SubgroupingFilters, UserOrganisationFilters } from "@dative-gpi/foundation-core-domain/models";
44
+ import type { DashboardExplorerElementFilters, DeviceOrganisationFilters, FolderFilters, GroupFilters, GroupingFilters, LocationFilters, ModelFilters, SubgroupingFilters, UserOrganisationFilters } from "@dative-gpi/foundation-core-domain/models";
45
45
 
46
46
  import FSEntityFieldUI from "@dative-gpi/foundation-shared-components/components/fields/FSEntityFieldUI.vue";
47
47
 
@@ -138,10 +138,8 @@ export default defineComponent({
138
138
  } satisfies DeviceOrganisationFilters;
139
139
  case EntityType.Dashboard:
140
140
  return {
141
- dashboardOrganisationsIds: props.modelValue,
142
- dashboardOrganisationTypesIds: props.modelValue,
143
- dashboardShallowsIds: props.modelValue
144
- } satisfies DashboardOrganisationFilters & DashboardOrganisationTypeFilters & DashboardShallowFilters;
141
+ dashboardExplorerElementsIds: props.modelValue,
142
+ } satisfies DashboardExplorerElementFilters;
145
143
  case EntityType.Group:
146
144
  return {
147
145
  groupsIds: props.modelValue
@@ -65,7 +65,7 @@
65
65
  import { defineComponent, type PropType, computed } from "vue";
66
66
 
67
67
  import { EntityType } from "@dative-gpi/foundation-shared-domain/enums";
68
- import type { DashboardOrganisationFilters, DashboardOrganisationTypeFilters, DashboardShallowFilters, DeviceOrganisationFilters, FolderFilters, GroupFilters, GroupingFilters, LocationFilters, ModelFilters, SubgroupingFilters, UserOrganisationFilters } from "@dative-gpi/foundation-core-domain/models";
68
+ import type { DashboardExplorerElementFilters, DeviceOrganisationFilters, FolderFilters, GroupFilters, GroupingFilters, LocationFilters, ModelFilters, SubgroupingFilters, UserOrganisationFilters } from "@dative-gpi/foundation-core-domain/models";
69
69
 
70
70
  import { TABLES as T } from "../../utils";
71
71
 
@@ -124,10 +124,8 @@ export default defineComponent({
124
124
  } satisfies DeviceOrganisationFilters;
125
125
  case EntityType.Dashboard:
126
126
  return {
127
- dashboardOrganisationsIds: props.modelValue,
128
- dashboardOrganisationTypesIds: props.modelValue,
129
- dashboardShallowsIds: props.modelValue
130
- } satisfies DashboardOrganisationFilters & DashboardOrganisationTypeFilters & DashboardShallowFilters;
127
+ dashboardExplorerElementsIds: props.modelValue,
128
+ } satisfies DashboardExplorerElementFilters;
131
129
  case EntityType.Group:
132
130
  return {
133
131
  groupsIds: props.modelValue
@@ -191,9 +189,7 @@ export default defineComponent({
191
189
  };
192
190
  case EntityType.Dashboard:
193
191
  return {
194
- dashboardShallowsFilters: props.filters,
195
- dashboardOrganisationsFilters: props.filters,
196
- dashboardOrganisationTypeFetchFilter: props.filters,
192
+ dashboardExplorerElementsFilters: props.filters,
197
193
  ...attrs
198
194
  };
199
195
  case EntityType.Group:
@@ -62,9 +62,7 @@ export default defineComponent({
62
62
  case EntityType.Dashboard:
63
63
  return {
64
64
  ...attrs,
65
- dashboardOrganisationFilters : props.filters,
66
- dashboardOrganisationTypeFilters : props.filters,
67
- dashboardShallowFilters : props.filters
65
+ dashboardExplorerElementsFilters: props.filters
68
66
  };
69
67
  case EntityType.Folder:
70
68
  return {
@@ -55,9 +55,7 @@ export default defineComponent({
55
55
  case EntityType.Dashboard:
56
56
  return {
57
57
  ...attrs,
58
- dashboardOrganisationFilters : props.filters,
59
- dashboardOrganisationTypeFilters : props.filters,
60
- dashboardShallowFilters : props.filters
58
+ dashboardExplorerElementsFilters: props.filters
61
59
  };
62
60
  case EntityType.Folder:
63
61
  return {
@@ -0,0 +1,345 @@
1
+ <template>
2
+ <FSDataTable
3
+ defaultMode="iterator"
4
+ :loading="fetchingDashboardExplorerElements"
5
+ :singleSelect="$props.singleSelect"
6
+ :items="dashboardExplorerElements"
7
+ :selectable="$props.selectable"
8
+ :tableCode="$props.tableCode"
9
+ :itemTo="$props.itemTo"
10
+ :noSearch="$props.recursiveSearch"
11
+ :headersOptions="headersOptions"
12
+ :modelValue="$props.modelValue"
13
+ @update:modelValue="onUpdate"
14
+ v-model:search="search"
15
+ v-bind="$attrs"
16
+ >
17
+ <template
18
+ v-for="(_, name) in $slots"
19
+ v-slot:[name]="slotData"
20
+ >
21
+ <slot
22
+ :name="name"
23
+ v-bind="slotData"
24
+ />
25
+ </template>
26
+ <template
27
+ #header.imageId-title
28
+ >
29
+ <FSIcon>
30
+ mdi-panorama-variant-outline
31
+ </FSIcon>
32
+ </template>
33
+ <template
34
+ #item.imageId="{ item }"
35
+ >
36
+ <FSImage
37
+ v-if="item.imageId"
38
+ height="32px"
39
+ width="32px"
40
+ :imageId="item.imageId"
41
+ :thumbnail="true"
42
+ />
43
+ </template>
44
+ <template
45
+ #item.tags="{ item }"
46
+ >
47
+ <FSTagGroup
48
+ variant="slide"
49
+ :showRemove="false"
50
+ :tags="item.tags"
51
+ />
52
+ </template>
53
+ <template
54
+ #item.type="{ item }"
55
+ >
56
+ <FSDashboardExplorerElementChip
57
+ :type="item.type"
58
+ />
59
+ </template>
60
+ <template
61
+ #item.icon="{ item }"
62
+ >
63
+ <FSIcon>
64
+ {{ item.icon }}
65
+ </FSIcon>
66
+ </template>
67
+ <template
68
+ #item.main="{ item }"
69
+ >
70
+ <FSIcon
71
+ v-if="item.id === mainOrganisationDashboardId"
72
+ >
73
+ mdi-account-group-outline
74
+ </FSIcon>
75
+ <FSIcon
76
+ v-if="item.id === mainUserDashboardId"
77
+ >
78
+ mdi-home
79
+ </FSIcon>
80
+ </template>
81
+ <template
82
+ #item.locked="{ item }"
83
+ >
84
+ <FSIconCheck
85
+ v-if="item.locked != null"
86
+ :value="item.locked"
87
+ />
88
+ </template>
89
+ <template
90
+ #item.tile="{ index, item, toggleSelect }"
91
+ >
92
+ <FSFolderTileUI
93
+ v-if="item.type === DashboardExplorerElementType.Folder"
94
+ :key="index"
95
+ :to="$props.itemTo && $props.itemTo(item)"
96
+ :imageId="item.imageId"
97
+ :icon="item.icon"
98
+ :label="item.label"
99
+ :code="item.code"
100
+ :bottomColor="item.colors"
101
+ :recursiveFoldersIds="item.recursiveFoldersIds"
102
+ :recursiveDashboardOrganisationsIds="item.recursiveDashboardOrganisationsIds"
103
+ :recursiveDashboardShallowsIds="item.recursiveDashboardShallowsIds"
104
+ :modelValue="isSelected(item.id)"
105
+ :selectable="$props.selectable"
106
+ @update:modelValue="toggleSelect(item)"
107
+ />
108
+ <FSDashboardOrganisationTileUI
109
+ v-if="item.type === DashboardExplorerElementType.DashboardOrganisation"
110
+ :key="index"
111
+ :to="$props.itemTo && $props.itemTo(item)"
112
+ :bottomColor="item.colors"
113
+ :imageId="item.imageId"
114
+ :icon="item.icon"
115
+ :label="item.label"
116
+ :code="item.code"
117
+ :modelValue="isSelected(item.id)"
118
+ :selectable="$props.selectable"
119
+ @update:modelValue="toggleSelect(item)"
120
+ />
121
+ <FSDashboardShallowTileUI
122
+ v-if="item.type === DashboardExplorerElementType.DashboardShallow"
123
+ :key="index"
124
+ :to="$props.itemTo && $props.itemTo(item)"
125
+ :bottomColor="item.colors"
126
+ :imageId="item.imageId"
127
+ :icon="item.icon"
128
+ :label="item.label"
129
+ :code="item.code"
130
+ :modelValue="isSelected(item.id)"
131
+ :selectable="$props.selectable"
132
+ @update:modelValue="toggleSelect(item)"
133
+ />
134
+ <FSDashboardOrganisationTypeTileUI
135
+ v-if="item.type === DashboardExplorerElementType.DashboardOrganisationType"
136
+ :key="index"
137
+ :to="$props.itemTo && $props.itemTo(item)"
138
+ :bottomColor="item.colors"
139
+ :imageId="item.imageId"
140
+ :icon="item.icon"
141
+ :label="item.label"
142
+ :code="item.code"
143
+ :modelValue="isSelected(item.id)"
144
+ :selectable="$props.selectable"
145
+ @update:modelValue="toggleSelect(item)"
146
+ />
147
+ </template>
148
+ </FSDataTable>
149
+ </template>
150
+
151
+ <script lang="ts">
152
+ import { computed, defineComponent, onMounted, type PropType, ref, watch } from "vue";
153
+ import { type RouteLocation } from "vue-router";
154
+ import _ from "lodash";
155
+
156
+ import { DashboardExplorerElementType } from "@dative-gpi/foundation-shared-domain/enums";
157
+ import { useDashboardExplorerElements, useAppOrganisationId, useCurrentUserOrganisation } from "@dative-gpi/foundation-core-services/composables";
158
+ import { type DashboardExplorerElementInfos, type DashboardExplorerElementFilters } from "@dative-gpi/foundation-core-domain/models";
159
+ import { dashboardExplorerElementTypeLabel } from "@dative-gpi/foundation-core-components/utils";
160
+ import { useDebounce } from "@dative-gpi/foundation-shared-components/composables";
161
+ import { useOrganisation } from "@dative-gpi/foundation-shared-services/composables";
162
+
163
+ import FSDashboardOrganisationTypeTileUI from "@dative-gpi/foundation-shared-components/components/tiles/FSDashboardOrganisationTypeTileUI.vue";
164
+ import FSDashboardOrganisationTileUI from "@dative-gpi/foundation-shared-components/components/tiles/FSDashboardOrganisationTileUI.vue";
165
+ import FSDashboardShallowTileUI from "@dative-gpi/foundation-shared-components/components/tiles/FSDashboardShallowTileUI.vue";
166
+ import FSFolderTileUI from "@dative-gpi/foundation-shared-components/components/tiles/FSFolderTileUI.vue";
167
+ import FSIconCheck from "@dative-gpi/foundation-shared-components/components/FSIconCheck.vue";
168
+ import FSTagGroup from "@dative-gpi/foundation-shared-components/components/FSTagGroup.vue";
169
+ import FSImage from "@dative-gpi/foundation-shared-components/components/FSImage.vue";
170
+ import FSIcon from "@dative-gpi/foundation-shared-components/components/FSIcon.vue";
171
+
172
+ import FSDashboardExplorerElementChip from "./FSDashboardExplorerElementChip.vue";
173
+ import FSDataTable from "../lists/FSDataTable.vue";
174
+
175
+ export default defineComponent({
176
+ name: "FSBaseDashboardsExplorer",
177
+ components: {
178
+ FSDashboardExplorerElementChip,
179
+ FSDashboardOrganisationTypeTileUI,
180
+ FSDashboardOrganisationTileUI,
181
+ FSDashboardShallowTileUI,
182
+ FSFolderTileUI,
183
+ FSDataTable,
184
+ FSIconCheck,
185
+ FSTagGroup,
186
+ FSImage,
187
+ FSIcon
188
+ },
189
+ props: {
190
+ tableCode: {
191
+ type: String as PropType<string | null>,
192
+ required: false,
193
+ default: null
194
+ },
195
+ recursiveSearch: {
196
+ type: Boolean,
197
+ required: false,
198
+ default: true
199
+ },
200
+ parentId: {
201
+ type: String as PropType<string | null>,
202
+ required: false,
203
+ default: null
204
+ },
205
+ root: {
206
+ type: Boolean,
207
+ required: false,
208
+ default: true
209
+ },
210
+ allowedTypes: {
211
+ type: Array as PropType<DashboardExplorerElementType[]>,
212
+ required: false,
213
+ default: () => [
214
+ DashboardExplorerElementType.Folder,
215
+ DashboardExplorerElementType.DashboardOrganisation,
216
+ DashboardExplorerElementType.DashboardShallow,
217
+ DashboardExplorerElementType.DashboardOrganisationType
218
+ ]
219
+ },
220
+ itemTo: {
221
+ type: Function as PropType<(item: DashboardExplorerElementInfos) => Partial<RouteLocation>>,
222
+ required: false
223
+ },
224
+ selectable: {
225
+ type: Boolean,
226
+ required: false,
227
+ default: true
228
+ },
229
+ singleSelect: {
230
+ type: Boolean,
231
+ required: false,
232
+ default: false
233
+ },
234
+ modelValue: {
235
+ type: Array as PropType<string[]>,
236
+ default: () => [],
237
+ required: false
238
+ },
239
+ dashboardExplorerElementsFilters: {
240
+ type: Object as PropType<DashboardExplorerElementFilters>,
241
+ required: false,
242
+ default: () => ({})
243
+ }
244
+ },
245
+ emits: ["update:modelValue", "update:types"],
246
+ setup(props, { emit }) {
247
+ const { entities, fetching: fetchingDashboardExplorerElements, getMany: getManyDashboardExplorerElements } = useDashboardExplorerElements();
248
+ const { fetch: fetchUserOrganisation, entity: userOrganisation } = useCurrentUserOrganisation();
249
+ const { entity: organisation, get: getOrganisation } = useOrganisation();
250
+ const { organisationId } = useAppOrganisationId();
251
+ const { debounce } = useDebounce();
252
+
253
+ const search = ref("");
254
+
255
+ const mainUserDashboardId = computed(() => userOrganisation.value?.mainDashboardId);
256
+ const mainOrganisationDashboardId = computed(() => organisation.value?.mainDashboardId);
257
+
258
+ const dashboardExplorerElements = computed((): DashboardExplorerElementInfos[] => {
259
+ return entities.value
260
+ .filter(e => props.allowedTypes.includes(e.type))
261
+ .slice()
262
+ .sort((a, b) => a.type - b.type);
263
+ });
264
+
265
+ const headersOptions = computed(() => ({
266
+ type: {
267
+ fixedFilters: props.allowedTypes.map(t => ({
268
+ value: t,
269
+ text: dashboardExplorerElementTypeLabel(t)
270
+ })),
271
+ methodFilter: (value: DashboardExplorerElementType, type: DashboardExplorerElementType) => {
272
+ return value === type;
273
+ }
274
+ }
275
+ }));
276
+
277
+ const isSelected = (id: string): boolean => {
278
+ return props.modelValue.includes(id);
279
+ };
280
+
281
+ const onUpdate = (value: string[]): void => {
282
+ const types = value.map(id => entities.value.find(dee => dee.id === id)?.type);
283
+ emit("update:types", types);
284
+
285
+ emit("update:modelValue", value);
286
+ }
287
+
288
+ const fetch = () => {
289
+ if (props.recursiveSearch && search.value) {
290
+ getManyDashboardExplorerElements({
291
+ parentId: props.parentId,
292
+ search: search.value,
293
+ types: props.allowedTypes,
294
+ ...props.dashboardExplorerElementsFilters
295
+ });
296
+ }
297
+ else {
298
+ getManyDashboardExplorerElements({
299
+ parentId: props.parentId,
300
+ root: props.root,
301
+ types: props.allowedTypes,
302
+ ...props.dashboardExplorerElementsFilters
303
+ });
304
+ }
305
+ }
306
+
307
+ // Delay to wait before fetching after a search change
308
+ const debounceFetch = (): void => debounce(fetch, 1000);
309
+
310
+ onMounted(() => {
311
+ fetchUserOrganisation();
312
+ });
313
+
314
+ watch(() => organisationId.value, () => {
315
+ if (organisationId.value) {
316
+ getOrganisation(organisationId.value);
317
+ }
318
+ }, { immediate: true });
319
+
320
+ watch([() => props.parentId, () => props.root, () => props.allowedTypes, () => props.dashboardExplorerElementsFilters], (next, previous) => {
321
+ if ((!next && !previous) || !_.isEqual(next, previous)) {
322
+ fetch();
323
+ }
324
+ }, { immediate: true });
325
+
326
+ watch(search, (next, previous) => {
327
+ if (props.recursiveSearch && next !== previous) {
328
+ debounceFetch();
329
+ }
330
+ });
331
+
332
+ return {
333
+ fetchingDashboardExplorerElements,
334
+ DashboardExplorerElementType,
335
+ dashboardExplorerElements,
336
+ mainOrganisationDashboardId,
337
+ mainUserDashboardId,
338
+ headersOptions,
339
+ search,
340
+ isSelected,
341
+ onUpdate
342
+ };
343
+ }
344
+ });
345
+ </script>
@@ -0,0 +1,37 @@
1
+ <template>
2
+ <FSChip
3
+ :label="chipLabel"
4
+ :color="ColorEnum.Light"
5
+ />
6
+ </template>
7
+
8
+ <script lang="ts">
9
+ import { computed, defineComponent, type PropType } from "vue";
10
+
11
+ import type { DashboardExplorerElementType } from "@dative-gpi/foundation-shared-domain/enums";
12
+ import { dashboardExplorerElementTypeLabel } from "@dative-gpi/foundation-core-components/utils";
13
+
14
+ import FSChip from "@dative-gpi/foundation-shared-components/components/FSChip.vue";
15
+ import { ColorEnum } from "@dative-gpi/foundation-shared-components/models";
16
+
17
+ export default defineComponent({
18
+ name: "FSDashboardExplorerElementChip",
19
+ components: {
20
+ FSChip
21
+ },
22
+ props: {
23
+ type: {
24
+ type: Number as PropType<DashboardExplorerElementType>,
25
+ required: true
26
+ }
27
+ },
28
+ setup(props) {
29
+ const chipLabel = computed(() => dashboardExplorerElementTypeLabel(props.type));
30
+
31
+ return {
32
+ chipLabel,
33
+ ColorEnum
34
+ };
35
+ }
36
+ });
37
+ </script>