@dative-gpi/foundation-shared-services 0.0.48 → 0.0.50
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.
- package/composables/app/index.ts +2 -0
- package/composables/app/useAppLanguageCode.ts +17 -0
- package/composables/{useTimeZone.ts → app/useAppTimeZone.ts} +13 -27
- package/composables/index.ts +3 -3
- package/composables/services/index.ts +1 -0
- package/composables/services/useLanguages.ts +11 -0
- package/composables/useFoundationShared.ts +14 -0
- package/config/urls/index.ts +1 -0
- package/config/urls/languages.ts +3 -0
- package/package.json +3 -4
- package/composables/useLanguageCode.ts +0 -28
- package/composables/useShared.ts +0 -39
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { computed, ref, watch } from "vue";
|
|
2
|
+
|
|
3
|
+
const languageCode = ref<string | null>(null);
|
|
4
|
+
|
|
5
|
+
export const useAppLanguageCode = () => {
|
|
6
|
+
const setLanguageCode = (payload: string) => {
|
|
7
|
+
languageCode.value = payload;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const ready = computed(() => languageCode.value !== null);
|
|
11
|
+
|
|
12
|
+
return {
|
|
13
|
+
ready,
|
|
14
|
+
languageCode,
|
|
15
|
+
setLanguageCode
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ref, watch } from "vue";
|
|
1
|
+
import { computed, ref, watch } 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";
|
|
@@ -6,14 +6,11 @@ import { format, subDays } from "date-fns";
|
|
|
6
6
|
import { useTranslations as useTranslationsProvider } from "@dative-gpi/bones-ui/composables";
|
|
7
7
|
import { TimeZoneInfos } from "@dative-gpi/foundation-shared-domain/models";
|
|
8
8
|
|
|
9
|
-
import {
|
|
9
|
+
import { useAppLanguageCode } from "./useAppLanguageCode";
|
|
10
10
|
|
|
11
|
-
const timeZone = ref<TimeZoneInfos | null>(
|
|
12
|
-
id: "Europe/Paris",
|
|
13
|
-
offset: "UTC +02:00:00"
|
|
14
|
-
});
|
|
11
|
+
const timeZone = ref<TimeZoneInfos | null>(null);
|
|
15
12
|
|
|
16
|
-
export const
|
|
13
|
+
export const useAppTimeZone = () => {
|
|
17
14
|
const setTimeZone = (payload: TimeZoneInfos) => {
|
|
18
15
|
timeZone.value = payload;
|
|
19
16
|
};
|
|
@@ -25,7 +22,7 @@ export const useTimeZone = () => {
|
|
|
25
22
|
const getUserOffsetMillis = (): number => {
|
|
26
23
|
const offset = timeZone?.value?.offset.slice(3) ?? "";
|
|
27
24
|
const matchData = offset.match(/([+-])(\d+)(?::(\d+))?/);
|
|
28
|
-
if (matchData)
|
|
25
|
+
if (matchData) {
|
|
29
26
|
const [_, sign, hour, minute] = matchData;
|
|
30
27
|
return parseInt(sign + "1") * ((hour ? parseInt(hour) : 0) * 60 + (minute ? parseInt(minute) : 0)) * 60 * 1000;
|
|
31
28
|
}
|
|
@@ -37,13 +34,13 @@ export const useTimeZone = () => {
|
|
|
37
34
|
timeZoneName: "short",
|
|
38
35
|
timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
39
36
|
}).formatToParts().find((i) => i.type === "timeZoneName")?.value ?? "";
|
|
40
|
-
|
|
37
|
+
|
|
41
38
|
const offset = timeZoneName.slice(3);
|
|
42
39
|
if (!offset) {
|
|
43
40
|
return "UTC +00:00:00";
|
|
44
41
|
}
|
|
45
42
|
const matchData = offset.match(/([+-])(\d+)(?::(\d+))?/);
|
|
46
|
-
if (matchData)
|
|
43
|
+
if (matchData) {
|
|
47
44
|
const [_, sign, hour, minute] = matchData;
|
|
48
45
|
return `UTC ${sign}${hour.padStart(2, "0")}:${(minute ?? "").padStart(2, "0")}:00`;
|
|
49
46
|
}
|
|
@@ -55,13 +52,13 @@ export const useTimeZone = () => {
|
|
|
55
52
|
timeZoneName: "short",
|
|
56
53
|
timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
57
54
|
}).formatToParts().find((i) => i.type === "timeZoneName")?.value ?? "";
|
|
58
|
-
|
|
55
|
+
|
|
59
56
|
const offset = timeZoneName.slice(3);
|
|
60
57
|
if (!offset) {
|
|
61
58
|
return 0;
|
|
62
59
|
}
|
|
63
60
|
const matchData = offset.match(/([+-])(\d+)(?::(\d+))?/);
|
|
64
|
-
if (matchData)
|
|
61
|
+
if (matchData) {
|
|
65
62
|
const [_, sign, hour, minute] = matchData;
|
|
66
63
|
return parseInt(sign + "1") * ((hour ? parseInt(hour) : 0) * 60 + (minute ? parseInt(minute) : 0)) * 60 * 1000;
|
|
67
64
|
}
|
|
@@ -147,11 +144,11 @@ export const useTimeZone = () => {
|
|
|
147
144
|
const todayTimeFormat = (): string => {
|
|
148
145
|
return `'${useTranslationsProvider().$tr("ui.time-zone.today-at", "Today at").replaceAll("'", "''")}' HH:mm:ss`;
|
|
149
146
|
}
|
|
150
|
-
|
|
147
|
+
|
|
151
148
|
const yesterdayTimeFormat = (): string => {
|
|
152
149
|
return `'${useTranslationsProvider().$tr("ui.time-zone.yesterday-at", "Yesterday at").replaceAll("'", "''")}' HH:mm:ss`;
|
|
153
150
|
}
|
|
154
|
-
|
|
151
|
+
|
|
155
152
|
const overrideFormat = (date: Date, askedFormat: string): string => {
|
|
156
153
|
let now = new Date();
|
|
157
154
|
if (date.toDateString() === now.toDateString()) {
|
|
@@ -164,7 +161,7 @@ export const useTimeZone = () => {
|
|
|
164
161
|
}
|
|
165
162
|
|
|
166
163
|
const getLocale = (): Locale => {
|
|
167
|
-
switch (
|
|
164
|
+
switch (useAppLanguageCode().languageCode.value) {
|
|
168
165
|
case "fr-FR": return fr;
|
|
169
166
|
case "es-ES": return es;
|
|
170
167
|
case "it-IT": return it;
|
|
@@ -174,18 +171,7 @@ export const useTimeZone = () => {
|
|
|
174
171
|
}
|
|
175
172
|
}
|
|
176
173
|
|
|
177
|
-
const ready =
|
|
178
|
-
if (timeZone.value) {
|
|
179
|
-
resolve(timeZone.value);
|
|
180
|
-
}
|
|
181
|
-
else {
|
|
182
|
-
watch(timeZone, () => {
|
|
183
|
-
if (timeZone.value) {
|
|
184
|
-
resolve(timeZone.value);
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
});
|
|
174
|
+
const ready = computed(() => timeZone.value !== null);
|
|
189
175
|
|
|
190
176
|
return {
|
|
191
177
|
ready,
|
package/composables/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export * from "./services";
|
|
2
|
-
export * from "./
|
|
3
|
-
|
|
4
|
-
export * from "./
|
|
2
|
+
export * from "./app";
|
|
3
|
+
|
|
4
|
+
export * from "./useFoundationShared";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { LanguageDetails, LanguageDetailsDTO, LanguageFilters, LanguageInfos, LanguageInfosDTO } from "@dative-gpi/foundation-shared-domain/models";
|
|
2
|
+
import { ComposableFactory, ServiceFactory } from "@dative-gpi/bones-ui";
|
|
3
|
+
|
|
4
|
+
import { LANGUAGES_URL } from "../../config/urls";
|
|
5
|
+
|
|
6
|
+
const LanguageServiceFactory = new ServiceFactory<LanguageDetailsDTO, LanguageDetails>("language", LanguageDetails).create(factory => factory.build(
|
|
7
|
+
factory.addGetMany<LanguageInfosDTO, LanguageInfos, LanguageFilters>(LANGUAGES_URL, LanguageInfos),
|
|
8
|
+
factory.addNotify()
|
|
9
|
+
));
|
|
10
|
+
|
|
11
|
+
export const useLanguages = ComposableFactory.getMany(LanguageServiceFactory);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { computed } from "vue";
|
|
2
|
+
|
|
3
|
+
import { useAppLanguageCode, useAppTimeZone } from "./app";
|
|
4
|
+
|
|
5
|
+
export function useFoundationShared() {
|
|
6
|
+
const { ready: languageCodeReady } = useAppLanguageCode();
|
|
7
|
+
const { ready: timeZoneReady } = useAppTimeZone();
|
|
8
|
+
|
|
9
|
+
const ready = computed(() => timeZoneReady.value && languageCodeReady.value);
|
|
10
|
+
|
|
11
|
+
return {
|
|
12
|
+
ready,
|
|
13
|
+
};
|
|
14
|
+
}
|
package/config/urls/index.ts
CHANGED
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.
|
|
4
|
+
"version": "0.0.50",
|
|
5
5
|
"description": "",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -11,11 +11,10 @@
|
|
|
11
11
|
"license": "ISC",
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@dative-gpi/bones-ui": "^0.0.61",
|
|
14
|
-
"@dative-gpi/foundation-shared-domain": "0.0.
|
|
14
|
+
"@dative-gpi/foundation-shared-domain": "0.0.50",
|
|
15
15
|
"@microsoft/signalr": "^8.0.0",
|
|
16
|
-
"date-fns": "^3.2.0",
|
|
17
16
|
"vue": "^3.2.0",
|
|
18
17
|
"vue-router": "^4.2.5"
|
|
19
18
|
},
|
|
20
|
-
"gitHead": "
|
|
19
|
+
"gitHead": "be18a14ae47c91c1f3ccd22a196593050f06aae8"
|
|
21
20
|
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { ref, watch } from "vue";
|
|
2
|
-
|
|
3
|
-
const languageCode = ref<string | null>("fr-FR");
|
|
4
|
-
|
|
5
|
-
export const useLanguageCode = () => {
|
|
6
|
-
const setLanguageCode = (payload: string) => {
|
|
7
|
-
languageCode.value = payload;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
const ready = new Promise((resolve) => {
|
|
11
|
-
if (languageCode.value) {
|
|
12
|
-
resolve(languageCode.value);
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
watch(languageCode, () => {
|
|
16
|
-
if (languageCode.value) {
|
|
17
|
-
resolve(languageCode.value);
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
return {
|
|
24
|
-
ready,
|
|
25
|
-
languageCode,
|
|
26
|
-
setLanguageCode
|
|
27
|
-
};
|
|
28
|
-
}
|
package/composables/useShared.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { ref } from "vue";
|
|
2
|
-
|
|
3
|
-
import { useTranslations as useTranslationsProvider } from "@dative-gpi/bones-ui";
|
|
4
|
-
|
|
5
|
-
import { useTranslations } from "./services/useTranslations";
|
|
6
|
-
import { useLanguageCode } from "./useLanguageCode";
|
|
7
|
-
import { useTimeZone } from "./useTimeZone";
|
|
8
|
-
|
|
9
|
-
let called = false;
|
|
10
|
-
|
|
11
|
-
const ready = ref(false);
|
|
12
|
-
|
|
13
|
-
export async function useShared() {
|
|
14
|
-
if (called) {
|
|
15
|
-
return {
|
|
16
|
-
ready
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
called = true;
|
|
21
|
-
|
|
22
|
-
const { ready: languageCodeReady, languageCode } = useLanguageCode();
|
|
23
|
-
const { ready: timeZoneReady } = useTimeZone();
|
|
24
|
-
const { getMany, entities } = useTranslations();
|
|
25
|
-
const { set } = useTranslationsProvider();
|
|
26
|
-
|
|
27
|
-
await languageCodeReady;
|
|
28
|
-
await timeZoneReady;
|
|
29
|
-
|
|
30
|
-
if (languageCode.value) {
|
|
31
|
-
await getMany(languageCode.value);
|
|
32
|
-
set(entities.value.map(t => ({ code: t.code, value: t.value })));
|
|
33
|
-
}
|
|
34
|
-
ready.value = true;
|
|
35
|
-
|
|
36
|
-
return {
|
|
37
|
-
ready
|
|
38
|
-
};
|
|
39
|
-
}
|