@dative-gpi/foundation-shared-services 0.0.49 → 0.0.51
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} +31 -38
- 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 -3
- package/composables/useLanguageCode.ts +0 -28
- package/composables/useShared.ts +0 -39
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { computed, ref } from "vue";
|
|
2
|
+
|
|
3
|
+
const languageCode = ref<string | undefined>(undefined);
|
|
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
|
}
|
|
@@ -76,25 +73,32 @@ export const useTimeZone = () => {
|
|
|
76
73
|
return today.getTime() + getMachineOffsetMillis() - getUserOffsetMillis();
|
|
77
74
|
}
|
|
78
75
|
|
|
79
|
-
const pickerToEpoch = (value: Date): number => {
|
|
80
|
-
|
|
81
|
-
|
|
76
|
+
const pickerToEpoch = (value: Date | null | undefined): number => {
|
|
77
|
+
if (value != null) {
|
|
78
|
+
// FSCalendar is always in machine time zone, so we need to convert it to user time zone
|
|
79
|
+
return value.getTime() + getMachineOffsetMillis() - getUserOffsetMillis();
|
|
80
|
+
}
|
|
81
|
+
return 0;
|
|
82
82
|
};
|
|
83
83
|
|
|
84
|
-
const epochToPicker = (value: number): Date => {
|
|
85
|
-
// Epoch is always without time zone, so we need to convert it to user time zone
|
|
84
|
+
const epochToPicker = (value: number | null | undefined): Date => {
|
|
86
85
|
const date = new Date(0);
|
|
87
|
-
|
|
86
|
+
if (value != null) {
|
|
87
|
+
// Epoch is always without time zone, so we need to convert it to user time zone
|
|
88
|
+
date.setUTCMilliseconds(value - getMachineOffsetMillis() + getUserOffsetMillis());
|
|
89
|
+
}
|
|
88
90
|
return date;
|
|
89
91
|
};
|
|
90
92
|
|
|
91
93
|
const epochToPickerHeader = (value: number): { d: number, m: number, y: number } => {
|
|
92
94
|
const date = new Date(0);
|
|
93
|
-
|
|
95
|
+
if (value != null) {
|
|
96
|
+
date.setUTCMilliseconds(value - getMachineOffsetMillis() + getUserOffsetMillis());
|
|
97
|
+
}
|
|
94
98
|
return { d: date.getDate(), m: date.getMonth(), y: date.getFullYear() };
|
|
95
99
|
};
|
|
96
100
|
|
|
97
|
-
const epochToLongDateFormat = (value: number): string => {
|
|
101
|
+
const epochToLongDateFormat = (value: number | null | undefined): string => {
|
|
98
102
|
if (value == null || !isFinite(value)) {
|
|
99
103
|
return "";
|
|
100
104
|
}
|
|
@@ -103,7 +107,7 @@ export const useTimeZone = () => {
|
|
|
103
107
|
return format(date, "EEEE dd LLLL yyyy", { locale: getLocale() });
|
|
104
108
|
};
|
|
105
109
|
|
|
106
|
-
const epochToLongTimeFormat = (value: number): string => {
|
|
110
|
+
const epochToLongTimeFormat = (value: number | null | undefined): string => {
|
|
107
111
|
if (value == null || !isFinite(value)) {
|
|
108
112
|
return "";
|
|
109
113
|
}
|
|
@@ -112,7 +116,7 @@ export const useTimeZone = () => {
|
|
|
112
116
|
return format(date, overrideFormat(date, "EEEE dd LLLL yyyy HH:mm"), { locale: getLocale() })
|
|
113
117
|
};
|
|
114
118
|
|
|
115
|
-
const epochToShortDateFormat = (value: number): string => {
|
|
119
|
+
const epochToShortDateFormat = (value: number | null | undefined): string => {
|
|
116
120
|
if (value == null || !isFinite(value)) {
|
|
117
121
|
return "";
|
|
118
122
|
}
|
|
@@ -128,7 +132,7 @@ export const useTimeZone = () => {
|
|
|
128
132
|
}
|
|
129
133
|
};
|
|
130
134
|
|
|
131
|
-
const epochToShortTimeFormat = (value: number): string => {
|
|
135
|
+
const epochToShortTimeFormat = (value: number | null | undefined): string => {
|
|
132
136
|
if (value == null || !isFinite(value)) {
|
|
133
137
|
return "";
|
|
134
138
|
}
|
|
@@ -147,11 +151,11 @@ export const useTimeZone = () => {
|
|
|
147
151
|
const todayTimeFormat = (): string => {
|
|
148
152
|
return `'${useTranslationsProvider().$tr("ui.time-zone.today-at", "Today at").replaceAll("'", "''")}' HH:mm:ss`;
|
|
149
153
|
}
|
|
150
|
-
|
|
154
|
+
|
|
151
155
|
const yesterdayTimeFormat = (): string => {
|
|
152
156
|
return `'${useTranslationsProvider().$tr("ui.time-zone.yesterday-at", "Yesterday at").replaceAll("'", "''")}' HH:mm:ss`;
|
|
153
157
|
}
|
|
154
|
-
|
|
158
|
+
|
|
155
159
|
const overrideFormat = (date: Date, askedFormat: string): string => {
|
|
156
160
|
let now = new Date();
|
|
157
161
|
if (date.toDateString() === now.toDateString()) {
|
|
@@ -164,7 +168,7 @@ export const useTimeZone = () => {
|
|
|
164
168
|
}
|
|
165
169
|
|
|
166
170
|
const getLocale = (): Locale => {
|
|
167
|
-
switch (
|
|
171
|
+
switch (useAppLanguageCode().languageCode.value) {
|
|
168
172
|
case "fr-FR": return fr;
|
|
169
173
|
case "es-ES": return es;
|
|
170
174
|
case "it-IT": return it;
|
|
@@ -174,18 +178,7 @@ export const useTimeZone = () => {
|
|
|
174
178
|
}
|
|
175
179
|
}
|
|
176
180
|
|
|
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
|
-
});
|
|
181
|
+
const ready = computed(() => timeZone.value !== null);
|
|
189
182
|
|
|
190
183
|
return {
|
|
191
184
|
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.51",
|
|
5
5
|
"description": "",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -11,10 +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.51",
|
|
15
15
|
"@microsoft/signalr": "^8.0.0",
|
|
16
16
|
"vue": "^3.2.0",
|
|
17
17
|
"vue-router": "^4.2.5"
|
|
18
18
|
},
|
|
19
|
-
"gitHead": "
|
|
19
|
+
"gitHead": "13a8e0d4bd10a05a35c570412fa2024d33b0c115"
|
|
20
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
|
-
}
|