@dative-gpi/foundation-core-services 1.1.12 → 1.1.13

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.
@@ -14,6 +14,7 @@ export * from "./useCustomPropertyValues";
14
14
  export * from "./useDashboardOrganisations";
15
15
  export * from "./useDashboardOrganisationTypes";
16
16
  export * from "./useDashboards";
17
+ export * from "./useDashboardExplorerElements";
17
18
  export * from "./useDashboardShallows";
18
19
  export * from "./useDataCategories";
19
20
  export * from "./useDataDefinitions";
@@ -0,0 +1,92 @@
1
+ import { ref } from "vue";
2
+
3
+ import { DashboardExplorerElementDetails, type DashboardExplorerElementDetailsDTO, type DashboardExplorerElementFilters, DashboardExplorerElementInfos, type DashboardExplorerElementInfosDTO } from "@dative-gpi/foundation-core-domain/models";
4
+ import { onCollectionChanged } from "@dative-gpi/bones-ui";
5
+ import { ServiceFactory } from "@dative-gpi/bones-ui/core";
6
+ import { createCollectionHandler } from "@dative-gpi/foundation-shared-services/tools";
7
+ import { containsSearchTerm } from "@dative-gpi/foundation-shared-components/utils";
8
+
9
+ import { DASHBOARD_EXPLORER_ELEMENTS_URL } from "../../config/urls";
10
+
11
+ import { useSubscribeToDashboardOrganisations } from "./useDashboardOrganisations";
12
+ import { useSubscribeToDashboardShallows } from "./useDashboardShallows";
13
+ import { useSubscribeToDashboardOrganisationTypes } from "./useDashboardOrganisationTypes";
14
+ import { useSubscribeToFolders } from "./useFolders";
15
+
16
+ const DashboardExplorerElementServiceFactory = new ServiceFactory<DashboardExplorerElementDetailsDTO, DashboardExplorerElementDetails>("dashboardExplorerElement", DashboardExplorerElementDetails).create(factory => factory.build(
17
+ factory.addGetMany<DashboardExplorerElementInfosDTO, DashboardExplorerElementInfos, DashboardExplorerElementFilters>(DASHBOARD_EXPLORER_ELEMENTS_URL, DashboardExplorerElementInfos),
18
+ factory.addNotify()
19
+ ));
20
+
21
+ export const useDashboardExplorerElements = () => {
22
+ const { subscribe: subscribeToDashboardOrganisations } = useSubscribeToDashboardOrganisations();
23
+ const { subscribe: subscribeToDashboardShallows } = useSubscribeToDashboardShallows();
24
+ const { subscribe: subscribeToDashboardOrganisationTypes } = useSubscribeToDashboardOrganisationTypes();
25
+ const { subscribe: subscribeToFolders } = useSubscribeToFolders();
26
+
27
+ const fetching = ref(false);
28
+ const entities = ref<DashboardExplorerElementInfos[]>([]);
29
+ const filters = ref<DashboardExplorerElementFilters>();
30
+
31
+ const getMany = async (filter?: DashboardExplorerElementFilters) => {
32
+ fetching.value = true;
33
+ filters.value = filter;
34
+
35
+ const filterMethod = (el: DashboardExplorerElementInfos): boolean => {
36
+ if (!filters.value) {
37
+ return true;
38
+ }
39
+ if (filters.value.types && !filters.value.types.includes(el.type)) {
40
+ return false;
41
+ }
42
+ if (filters.value.dashboardExplorerElementsIds) {
43
+ return filters.value.dashboardExplorerElementsIds.includes(el.id);
44
+ }
45
+ if (!filters.value.search) {
46
+ return (!!filters.value.root && !el.parentId) || (!!filters.value.parentId && filters.value.parentId === el.parentId);
47
+ }
48
+ return (!filters.value.parentId || el.path.some(p => p.id === filters.value!.parentId)) &&
49
+ containsSearchTerm({ label: el.label, code: el.code, tags: el.tags }, filters.value.search.toLowerCase());
50
+ };
51
+
52
+ const onCollectionChangedCustom = onCollectionChanged(entities, filterMethod);
53
+
54
+ try {
55
+ entities.value = await DashboardExplorerElementServiceFactory.getMany(filters.value);
56
+
57
+ subscribeToDashboardOrganisations("all",
58
+ createCollectionHandler(
59
+ onCollectionChangedCustom,
60
+ DashboardExplorerElementInfos.fromDashboardOrganisation
61
+ )
62
+ );
63
+ subscribeToDashboardShallows("all",
64
+ createCollectionHandler(
65
+ onCollectionChangedCustom,
66
+ DashboardExplorerElementInfos.fromDashboardShallow
67
+ )
68
+ );
69
+ subscribeToDashboardOrganisationTypes("all",
70
+ createCollectionHandler(
71
+ onCollectionChangedCustom,
72
+ DashboardExplorerElementInfos.fromDashboardOrganisationType
73
+ )
74
+ );
75
+ subscribeToFolders("all",
76
+ createCollectionHandler(
77
+ onCollectionChangedCustom,
78
+ DashboardExplorerElementInfos.fromFolder
79
+ )
80
+ );
81
+ }
82
+ finally {
83
+ fetching.value = false;
84
+ }
85
+ };
86
+
87
+ return {
88
+ fetching,
89
+ getMany,
90
+ entities
91
+ };
92
+ };
@@ -29,6 +29,7 @@ const DashboardOrganisationTypeServiceFactory = new ServiceFactory<DashboardOrga
29
29
 
30
30
  export const useDashboardOrganisationType = ComposableFactory.get(DashboardOrganisationTypeServiceFactory);
31
31
  export const useDashboardOrganisationTypes = ComposableFactory.getMany(DashboardOrganisationTypeServiceFactory);
32
+ export const useSubscribeToDashboardOrganisationTypes = ComposableFactory.subscribe(DashboardOrganisationTypeServiceFactory);
32
33
  export const useUpdateDashboardOrganisationType = ComposableFactory.update(DashboardOrganisationTypeServiceFactory);
33
34
  export const useRemoveDashboardOrganisationType = ComposableFactory.remove(DashboardOrganisationTypeServiceFactory);
34
35
  export const usePublishDashboardOrganisationType = ComposableFactory.custom(DashboardOrganisationTypeServiceFactory.publish);
@@ -28,6 +28,7 @@ const DashboardOrganisationServiceFactoryIncomplete = new ServiceFactory("dashbo
28
28
 
29
29
  export const useDashboardOrganisation = ComposableFactory.get(DashboardOrganisationServiceFactory);
30
30
  export const useDashboardOrganisations = ComposableFactory.getMany(DashboardOrganisationServiceFactory);
31
+ export const useSubscribeToDashboardOrganisations = ComposableFactory.subscribe(DashboardOrganisationServiceFactory);
31
32
  export const useCreateDashboardOrganisation = ComposableFactory.create(DashboardOrganisationServiceFactory);
32
33
  export const useUpdateDashboardOrganisation = ComposableFactory.update(DashboardOrganisationServiceFactory);
33
34
  export const useRemoveDashboardOrganisation = ComposableFactory.remove(DashboardOrganisationServiceFactory);
@@ -23,6 +23,7 @@ const DashboardShallowServiceFactoryIncomplete = new ServiceFactory("dashboardSh
23
23
 
24
24
  export const useDashboardShallow = ComposableFactory.get(DashboardShallowServiceFactory);
25
25
  export const useDashboardShallows = ComposableFactory.getMany(DashboardShallowServiceFactory);
26
+ export const useSubscribeToDashboardShallows = ComposableFactory.subscribe(DashboardShallowServiceFactory);
26
27
  export const useCreateDashboardShallow = ComposableFactory.create(DashboardShallowServiceFactory);
27
28
  export const useUpdateDashboardShallow = ComposableFactory.update(DashboardShallowServiceFactory);
28
29
  export const useRemoveDashboardShallow = ComposableFactory.remove(DashboardShallowServiceFactory);
@@ -1,9 +1,12 @@
1
1
  import { ref } from "vue";
2
2
 
3
- import { DeviceExplorerElementDetails, type DeviceExplorerElementDetailsDTO, type DeviceExplorerElementFilters, DeviceExplorerElementInfos, type DeviceExplorerElementInfosDTO, type DeviceOrganisationDetails, type GroupDetails } from "@dative-gpi/foundation-core-domain/models";
4
- import { type AddOrUpdateCallback, type DeleteCallback, type NotifyEvent, onCollectionChanged } from "@dative-gpi/bones-ui";
3
+ import { DeviceExplorerElementDetails, type DeviceExplorerElementDetailsDTO, type DeviceExplorerElementFilters, DeviceExplorerElementInfos, type DeviceExplorerElementInfosDTO } from "@dative-gpi/foundation-core-domain/models";
4
+ import { onCollectionChanged } from "@dative-gpi/bones-ui";
5
5
  import { ServiceFactory } from "@dative-gpi/bones-ui/core";
6
6
 
7
+ import { createCollectionHandler } from "@dative-gpi/foundation-shared-services/tools";
8
+ import { containsSearchTerm } from "@dative-gpi/foundation-shared-components/utils";
9
+
7
10
  import { DEVICE_EXPLORER_ELEMENTS_URL } from "../../config/urls";
8
11
 
9
12
  import { useTrackDeviceConnectivity, useWatchDeviceConnectivity } from "./useDeviceConnectivities";
@@ -42,9 +45,8 @@ export const useDeviceExplorerElements = () => {
42
45
  return (filters.value.root && !el.parentId) || (!!filters.value.parentId && filters.value.parentId == el.parentId);
43
46
  }
44
47
 
45
- const fullText = `${el.label} ${el.code} ${el.tags.join(" ")}`;
46
48
  return (!filters.value.parentId || el.path.some(p => p.id === filters.value!.parentId)) &&
47
- (fullText.toLowerCase().includes(filters.value.search.toLowerCase()));
49
+ containsSearchTerm({ label: el.label, code: el.code, tags: el.tags }, filters.value.search.toLowerCase());
48
50
  };
49
51
 
50
52
  const onCollectionChangedCustom = onCollectionChanged(entities, filterMethod);
@@ -52,29 +54,19 @@ export const useDeviceExplorerElements = () => {
52
54
  try {
53
55
  entities.value = await DeviceExplorerElementServiceFactory.getMany(filters.value);
54
56
 
55
- subscribeToDeviceOrganisations("all", (ev: NotifyEvent, el: DeviceOrganisationDetails | any) => {
56
- switch(ev) {
57
- case "add":
58
- case "update":
59
- (onCollectionChangedCustom as AddOrUpdateCallback<DeviceExplorerElementInfos>)(ev, DeviceExplorerElementInfos.fromDeviceOrganisation(el));
60
- break;
61
- case "delete":
62
- (onCollectionChangedCustom as DeleteCallback)(ev, el);
63
- break;
64
- }
65
- });
66
-
67
- subscribeToGroups("all", (ev: NotifyEvent, el: GroupDetails | any) => {
68
- switch(ev) {
69
- case "add":
70
- case "update":
71
- (onCollectionChangedCustom as AddOrUpdateCallback<DeviceExplorerElementInfos>)(ev, DeviceExplorerElementInfos.fromGroup(el));
72
- break;
73
- case "delete":
74
- (onCollectionChangedCustom as DeleteCallback)(ev, el);
75
- break;
76
- }
77
- });
57
+ subscribeToDeviceOrganisations("all",
58
+ createCollectionHandler(
59
+ onCollectionChangedCustom,
60
+ DeviceExplorerElementInfos.fromDeviceOrganisation
61
+ )
62
+ );
63
+
64
+ subscribeToGroups("all",
65
+ createCollectionHandler(
66
+ onCollectionChangedCustom,
67
+ DeviceExplorerElementInfos.fromGroup
68
+ )
69
+ );
78
70
 
79
71
  watchDevicesStatuses();
80
72
  watchDevicesConnectivity();
@@ -14,6 +14,7 @@ const FolderServiceFactory = new ServiceFactory<FolderDetailsDTO, FolderDetails>
14
14
 
15
15
  export const useFolder = ComposableFactory.get(FolderServiceFactory);
16
16
  export const useFolders = ComposableFactory.getMany(FolderServiceFactory);
17
+ export const useSubscribeToFolders = ComposableFactory.subscribe(FolderServiceFactory);
17
18
  export const useCreateFolder = ComposableFactory.create(FolderServiceFactory);
18
19
  export const useUpdateFolder = ComposableFactory.update(FolderServiceFactory);
19
20
  export const useRemoveFolder = ComposableFactory.remove(FolderServiceFactory);
@@ -0,0 +1,3 @@
1
+ import { CORE_URL } from "./base";
2
+
3
+ export const DASHBOARD_EXPLORER_ELEMENTS_URL = () => `${CORE_URL()}/dashboard-explorer-elements`;
@@ -13,6 +13,7 @@ export * from "./customPropertyValues";
13
13
  export * from "./dashboardOrganisations";
14
14
  export * from "./dashboardOrganisationTypes";
15
15
  export * from "./dashboards";
16
+ export * from "./dashboardExplorerElements";
16
17
  export * from "./data";
17
18
  export * from "./dataCategories";
18
19
  export * from "./dataDefinitions";
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "url": "https://github.com/Dative-GPI/foundation-shared-ui.git"
5
5
  },
6
6
  "sideEffects": false,
7
- "version": "1.1.12",
7
+ "version": "1.1.13",
8
8
  "description": "",
9
9
  "publishConfig": {
10
10
  "access": "public"
@@ -13,7 +13,7 @@
13
13
  "author": "",
14
14
  "license": "ISC",
15
15
  "dependencies": {
16
- "@dative-gpi/foundation-core-domain": "1.1.12"
16
+ "@dative-gpi/foundation-core-domain": "1.1.13"
17
17
  },
18
18
  "peerDependencies": {
19
19
  "@dative-gpi/bones-ui": "^1.0.0",
@@ -21,5 +21,5 @@
21
21
  "vue": "3.5.26",
22
22
  "vue-router": "^4.3.0"
23
23
  },
24
- "gitHead": "9ad6a2732e79fef8289b5c606efaf027ea0cd5ba"
24
+ "gitHead": "808ff91c2715ee0c9201227529471b0a428861c1"
25
25
  }