@dative-gpi/foundation-shared-services 0.0.51 → 0.0.53

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.
@@ -3,7 +3,7 @@ import { computed, ref } from "vue";
3
3
  const languageCode = ref<string | undefined>(undefined);
4
4
 
5
5
  export const useAppLanguageCode = () => {
6
- const setLanguageCode = (payload: string) => {
6
+ const setAppLanguageCode = (payload: string) => {
7
7
  languageCode.value = payload;
8
8
  };
9
9
 
@@ -12,6 +12,6 @@ export const useAppLanguageCode = () => {
12
12
  return {
13
13
  ready,
14
14
  languageCode,
15
- setLanguageCode
15
+ setAppLanguageCode
16
16
  };
17
17
  }
@@ -1,4 +1,4 @@
1
- import { computed, ref, watch } from "vue";
1
+ import { computed, ref } from "vue";
2
2
 
3
3
  import { enUS, enGB, fr, it, es, de, Locale } from "date-fns/locale";
4
4
  import { format, subDays } from "date-fns";
@@ -11,7 +11,7 @@ import { useAppLanguageCode } from "./useAppLanguageCode";
11
11
  const timeZone = ref<TimeZoneInfos | null>(null);
12
12
 
13
13
  export const useAppTimeZone = () => {
14
- const setTimeZone = (payload: TimeZoneInfos) => {
14
+ const setAppTimeZone = (payload: TimeZoneInfos) => {
15
15
  timeZone.value = payload;
16
16
  };
17
17
 
@@ -183,7 +183,7 @@ export const useAppTimeZone = () => {
183
183
  return {
184
184
  ready,
185
185
  timeZone,
186
- setTimeZone,
186
+ setAppTimeZone,
187
187
  getUserOffset,
188
188
  getMachineOffset,
189
189
  getUserOffsetMillis,
@@ -1,4 +1,5 @@
1
1
  export * from "./services";
2
2
  export * from "./app";
3
3
 
4
+ export * from "./useFiles";
4
5
  export * from "./useFoundationShared";
@@ -1,50 +1,11 @@
1
- import { onUnmounted, ref } from "vue";
2
-
3
1
  import { ApplicationDetails, ApplicationDetailsDTO } from "@dative-gpi/foundation-shared-domain/models";
4
- import { onEntityChanged, ServiceFactory } from "@dative-gpi/bones-ui";
2
+ import { ComposableFactory, ServiceFactory } from "@dative-gpi/bones-ui";
5
3
 
6
4
  import { APPLICATION_CURRENT_URL } from "../../config/urls";
7
5
 
8
6
  const ApplicationServiceFactory = new ServiceFactory<ApplicationDetailsDTO, ApplicationDetails>("application", ApplicationDetails).create(factory => factory.build(
9
- factory.addNotify((notifyService) => ({
10
- getCurrent: async (): Promise<ApplicationDetails> => {
11
- const response = await ServiceFactory.http.get(APPLICATION_CURRENT_URL());
12
- const result = new ApplicationDetails(response.data);
13
-
14
- notifyService.notify("update", result);
15
-
16
- return result;
17
- }
18
- }))
7
+ factory.addCustom("getCurrent", (axios) => axios.get(APPLICATION_CURRENT_URL())),
8
+ factory.addNotify()
19
9
  ));
20
10
 
21
- export const useCurrentApplication = () => {
22
- const service = ApplicationServiceFactory();
23
- const subscribersIds: number[] = [];
24
-
25
- const getting = ref(false);
26
- const entity = ref<ApplicationDetails | null>(null);
27
-
28
- onUnmounted(() => {
29
- subscribersIds.forEach(id => service.unsubscribe(id));
30
- subscribersIds.length = 0;
31
- });
32
-
33
- const get = async () => {
34
- getting.value = true;
35
- try {
36
- entity.value = await service.getCurrent();
37
- }
38
- finally {
39
- getting.value = false;
40
- }
41
- subscribersIds.push(service.subscribe("all", onEntityChanged(entity)));
42
- return entity;
43
- }
44
-
45
- return {
46
- getting,
47
- get,
48
- entity
49
- }
50
- }
11
+ export const useCurrentApplication = ComposableFactory.custom(ApplicationServiceFactory, ApplicationServiceFactory.getCurrent);
@@ -1,41 +1,11 @@
1
- import { ref } from "vue";
2
-
1
+ import { ComposableFactory, ServiceFactory } from "@dative-gpi/bones-ui";
3
2
  import { BlurHash } from "@dative-gpi/foundation-shared-domain/models";
4
- import { ServiceFactory } from "@dative-gpi/bones-ui";
5
3
 
6
4
  import { IMAGE_BLURHASH_URL } from "../../config/urls";
7
5
 
8
6
  const ImageServiceFactory = new ServiceFactory("image", BlurHash).create(factory => factory.build(
9
- factory.addNotify(() => ({
10
- getBlurHash: async (imageId: string): Promise<BlurHash> => {
11
- const response = await ServiceFactory.http.get(IMAGE_BLURHASH_URL(imageId));
12
- const result = new BlurHash(response.data);
13
-
14
- return result;
15
- }
16
- }))
7
+ factory.addCustom("getBlurHash", (axios, imageId: string) => axios.get(IMAGE_BLURHASH_URL(imageId))),
8
+ factory.addNotify()
17
9
  ));
18
10
 
19
- export const useImageBlurHash = () => {
20
- const service = ImageServiceFactory();
21
-
22
- const getting = ref(false);
23
- const entity = ref<BlurHash | null>(null);
24
-
25
- const get = async (imageId: string) => {
26
- getting.value = true;
27
- try {
28
- entity.value = await service.getBlurHash(imageId);
29
- }
30
- finally {
31
- getting.value = false;
32
- }
33
- return entity;
34
- }
35
-
36
- return {
37
- getting,
38
- get,
39
- entity
40
- }
41
- }
11
+ export const useImageBlurHash = ComposableFactory.custom(ImageServiceFactory, ImageServiceFactory.getBlurHash);
@@ -1,88 +1,13 @@
1
- import { onUnmounted, ref } from "vue";
2
-
3
1
  import { UpdateUserDTO, UserDetails, UserDetailsDTO } from "@dative-gpi/foundation-shared-domain/models";
4
- import { onEntityChanged, ServiceFactory } from "@dative-gpi/bones-ui";
2
+ import { ComposableFactory, ServiceFactory } from "@dative-gpi/bones-ui";
5
3
 
6
4
  import { USER_CURRENT_URL } from "../../config/urls";
7
5
 
8
6
  const UserServiceFactory = new ServiceFactory<UserDetailsDTO, UserDetails>("user", UserDetails).create(factory => factory.build(
9
- factory.addNotify((notifyService) => ({
10
- getCurrent: async (): Promise<UserDetails> => {
11
- const response = await ServiceFactory.http.get(USER_CURRENT_URL());
12
- const result = new UserDetails(response.data);
13
-
14
- notifyService.notify("update", result);
15
-
16
- return result;
17
- },
18
- updateCurrent: async (payload: UpdateUserDTO): Promise<UserDetails> => {
19
- const response = await ServiceFactory.http.post(USER_CURRENT_URL(), payload);
20
- const result = new UserDetails(response.data);
21
-
22
- notifyService.notify("update", result);
23
-
24
- return result;
25
- }
26
- }))
7
+ factory.addCustom("getCurrent", (axios) => axios.get(USER_CURRENT_URL())),
8
+ factory.addCustom("updateCurrent", (axios, payload: UpdateUserDTO) => axios.post(USER_CURRENT_URL(), payload)),
9
+ factory.addNotify()
27
10
  ));
28
11
 
29
- export const useCurrentUser = () => {
30
- const service = UserServiceFactory();
31
- const subscribersIds: number[] = [];
32
-
33
- const getting = ref(false);
34
- const entity = ref<UserDetails | null>(null);
35
-
36
- onUnmounted(() => {
37
- subscribersIds.forEach(id => service.unsubscribe(id));
38
- subscribersIds.length = 0;
39
- });
40
-
41
- const get = async () => {
42
- getting.value = true;
43
- try {
44
- entity.value = await service.getCurrent();
45
- }
46
- finally {
47
- getting.value = false;
48
- }
49
- subscribersIds.push(service.subscribe("all", onEntityChanged(entity)));
50
- return entity;
51
- }
52
-
53
- return {
54
- getting,
55
- get,
56
- entity
57
- }
58
- }
59
- export const useUpdateCurrentUser = () => {
60
- const service = UserServiceFactory();
61
- const subscribersIds: number[] = [];
62
-
63
- const updating = ref(false);
64
- const updated = ref<UserDetails | null>(null);
65
-
66
- onUnmounted(() => {
67
- subscribersIds.forEach(id => service.unsubscribe(id));
68
- subscribersIds.length = 0;
69
- });
70
-
71
- const update = async (payload: UpdateUserDTO) => {
72
- updating.value = true;
73
- try {
74
- updated.value = await service.updateCurrent(payload);
75
- }
76
- finally {
77
- updating.value = false;
78
- }
79
- subscribersIds.push(service.subscribe("all", onEntityChanged(updated)));
80
- return updated;
81
- }
82
-
83
- return {
84
- updating,
85
- update,
86
- updated
87
- }
88
- }
12
+ export const useCurrentUser = ComposableFactory.custom(UserServiceFactory, UserServiceFactory.getCurrent);
13
+ export const useUpdateCurrentUser = ComposableFactory.custom(UserServiceFactory, UserServiceFactory.updateCurrent);
@@ -0,0 +1,25 @@
1
+ import { FILE_URL } from "../config/urls";
2
+
3
+ export const useFiles = () => {
4
+ const downloadFile = (id: string): void => {
5
+ window.open(FILE_URL(id), "_blank");
6
+ };
7
+
8
+ const readFile = (file: File): Promise<string | ArrayBuffer | null> => {
9
+ return new Promise((resolve, reject) => {
10
+ const reader = new FileReader();
11
+ reader.addEventListener("load", (fileEv) => {
12
+ resolve(fileEv.target && fileEv.target.result);
13
+ });
14
+ reader.addEventListener("error", (fileEv) => {
15
+ reject(fileEv);
16
+ });
17
+ reader.readAsDataURL(file);
18
+ });
19
+ };
20
+
21
+ return {
22
+ downloadFile,
23
+ readFile
24
+ };
25
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dative-gpi/foundation-shared-services",
3
3
  "sideEffects": false,
4
- "version": "0.0.51",
4
+ "version": "0.0.53",
5
5
  "description": "",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -10,11 +10,11 @@
10
10
  "author": "",
11
11
  "license": "ISC",
12
12
  "dependencies": {
13
- "@dative-gpi/bones-ui": "^0.0.61",
14
- "@dative-gpi/foundation-shared-domain": "0.0.51",
13
+ "@dative-gpi/bones-ui": "^0.0.67",
14
+ "@dative-gpi/foundation-shared-domain": "0.0.53",
15
15
  "@microsoft/signalr": "^8.0.0",
16
16
  "vue": "^3.2.0",
17
17
  "vue-router": "^4.2.5"
18
18
  },
19
- "gitHead": "13a8e0d4bd10a05a35c570412fa2024d33b0c115"
19
+ "gitHead": "4ecd4c47590cb49ab9f480e12202cde9af5396e1"
20
20
  }