@dative-gpi/foundation-shared-services 0.1.120 → 1.0.1
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 +1 -0
- package/composables/app/useAppLanguages.ts +19 -0
- package/composables/app/useAppTimeZone.ts +269 -250
- package/composables/services/index.ts +1 -0
- package/composables/services/useAuthTokens.ts +7 -3
- package/composables/services/useImages.ts +2 -1
- package/composables/services/useLanguages.ts +2 -1
- package/composables/services/useOrganisations.ts +2 -1
- package/composables/services/useTerminals.ts +17 -0
- package/composables/services/useTimeZones.ts +2 -1
- package/composables/services/useTranslations.ts +2 -1
- package/composables/services/useUsers.ts +3 -2
- package/config/urls/authTokens.ts +2 -1
- package/config/urls/base.ts +1 -2
- package/config/urls/images.ts +2 -2
- package/config/urls/index.ts +1 -0
- package/config/urls/terminals.ts +4 -0
- package/package.json +8 -6
- package/tools/hubFactory.ts +3 -3
package/composables/app/index.ts
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { computed, ref } from "vue";
|
|
2
|
+
|
|
3
|
+
import { type LanguageInfos } from "@dative-gpi/foundation-shared-domain/models";
|
|
4
|
+
|
|
5
|
+
const languages = ref<LanguageInfos[] | undefined>(undefined);
|
|
6
|
+
|
|
7
|
+
export const useAppLanguages = () => {
|
|
8
|
+
const sepAppLanguages = (payload: LanguageInfos[]) => {
|
|
9
|
+
languages.value = payload;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const ready = computed(() => languages.value !== null);
|
|
13
|
+
|
|
14
|
+
return {
|
|
15
|
+
ready,
|
|
16
|
+
languages,
|
|
17
|
+
sepAppLanguages
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { format, subDays, addDays, addMilliseconds, parse } from "date-fns";
|
|
2
|
-
import {
|
|
2
|
+
import type { Locale } from "date-fns/locale";
|
|
3
|
+
import { enUS, enGB, fr, it, es, de } from "date-fns/locale";
|
|
3
4
|
import { computed, ref } from "vue";
|
|
4
5
|
|
|
5
6
|
import { useTranslations as useTranslationsProvider } from "@dative-gpi/bones-ui/composables";
|
|
6
|
-
import { TimeZoneInfos } from "@dative-gpi/foundation-shared-domain/models";
|
|
7
|
+
import type { TimeZoneInfos } from "@dative-gpi/foundation-shared-domain/models";
|
|
7
8
|
import { isoTimeFormat } from "@dative-gpi/foundation-shared-domain/tools";
|
|
8
9
|
|
|
9
10
|
import { useAppLanguageCode } from "./useAppLanguageCode";
|
|
@@ -11,260 +12,278 @@ import { useAppLanguageCode } from "./useAppLanguageCode";
|
|
|
11
12
|
const timeZone = ref<TimeZoneInfos | null>(null);
|
|
12
13
|
|
|
13
14
|
export const useAppTimeZone = () => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
15
|
+
const setAppTimeZone = (payload: TimeZoneInfos) => {
|
|
16
|
+
timeZone.value = payload;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const getOffsetNumber = (offsetString: string, hours: boolean = false): number => {
|
|
20
|
+
let offset = 0;
|
|
21
|
+
switch (offsetString.toLowerCase().replaceAll(" ", "")) {
|
|
22
|
+
case "utc-11:00:00": offset = -11; break;
|
|
23
|
+
case "utc-10:00:00": offset = -10; break;
|
|
24
|
+
case "utc-09:00:00": offset = -9; break;
|
|
25
|
+
case "utc-08:00:00": offset = -8; break;
|
|
26
|
+
case "utc-07:00:00": offset = -7; break;
|
|
27
|
+
case "utc-06:00:00": offset = -6; break;
|
|
28
|
+
case "utc-05:00:00": offset = -5; break;
|
|
29
|
+
case "utc-04:00:00": offset = -4; break;
|
|
30
|
+
case "utc-03:00:00": offset = -3; break;
|
|
31
|
+
case "utc-02:00:00": offset = -2; break;
|
|
32
|
+
case "utc-01:00:00": offset = -1; break;
|
|
33
|
+
case "utc+01:00:00": offset = +1; break;
|
|
34
|
+
case "utc+02:00:00": offset = +2; break;
|
|
35
|
+
case "utc+03:00:00": offset = +3; break;
|
|
36
|
+
case "utc+04:00:00": offset = +4; break;
|
|
37
|
+
case "utc+05:00:00": offset = +5; break;
|
|
38
|
+
case "utc+06:00:00": offset = +6; break;
|
|
39
|
+
case "utc+07:00:00": offset = +7; break;
|
|
40
|
+
case "utc+08:00:00": offset = +8; break;
|
|
41
|
+
case "utc+09:00:00": offset = +9; break;
|
|
42
|
+
case "utc+10:00:00": offset = +10; break;
|
|
43
|
+
case "utc+11:00:00": offset = +11; break;
|
|
44
|
+
case "utc+12:00:00": offset = +12; break;
|
|
45
|
+
case "utc+13:00:00": offset = +13; break;
|
|
46
|
+
case "utc+14:00:00": offset = +14; break;
|
|
47
|
+
}
|
|
48
|
+
return hours ? offset : offset * 60 * 60 * 1000;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const userOffset = (): number => {
|
|
52
|
+
return getOffsetNumber(getUserOffset());
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const machineOffset = (): number => {
|
|
56
|
+
return getOffsetNumber(getMachineOffset());
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const getUserOffset = (): string => {
|
|
60
|
+
return timeZone?.value?.offset ?? "UTC +00:00:00";
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const getUserOffsetMillis = (): number => {
|
|
64
|
+
const offset = timeZone?.value?.offset.slice(3) ?? "";
|
|
65
|
+
const matchData = offset.match(/([+-])(\d+)(?::(\d+))?/);
|
|
66
|
+
if (matchData) {
|
|
67
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
68
|
+
const [_, sign, hour, minute] = matchData;
|
|
69
|
+
return parseInt(sign + "1") * ((hour ? parseInt(hour) : 0) * 60 + (minute ? parseInt(minute) : 0)) * 60 * 1000;
|
|
70
|
+
}
|
|
71
|
+
return 0;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const getMachineOffset = (): string => {
|
|
75
|
+
const timeZoneName = Intl.DateTimeFormat("ia", {
|
|
76
|
+
timeZoneName: "short",
|
|
77
|
+
timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
78
|
+
}).formatToParts().find((i) => i.type === "timeZoneName")?.value ?? "";
|
|
79
|
+
|
|
80
|
+
const offset = timeZoneName.slice(3);
|
|
81
|
+
if (!offset) {
|
|
82
|
+
return "UTC +00:00:00";
|
|
83
|
+
}
|
|
84
|
+
const matchData = offset.match(/([+-])(\d+)(?::(\d+))?/);
|
|
85
|
+
if (matchData) {
|
|
86
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
87
|
+
const [_, sign, hour, minute] = matchData;
|
|
88
|
+
return `UTC ${sign}${hour.padStart(2, "0")}:${(minute ?? "").padStart(2, "0")}:00`;
|
|
89
|
+
}
|
|
90
|
+
return "UTC +00:00:00";
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const getMachineOffsetMillis = (): number => {
|
|
94
|
+
const timeZoneName = Intl.DateTimeFormat("ia", {
|
|
95
|
+
timeZoneName: "short",
|
|
96
|
+
timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
97
|
+
}).formatToParts().find((i) => i.type === "timeZoneName")?.value ?? "";
|
|
98
|
+
|
|
99
|
+
const offset = timeZoneName.slice(3);
|
|
100
|
+
if (!offset) {
|
|
101
|
+
return 0;
|
|
102
|
+
}
|
|
103
|
+
const matchData = offset.match(/([+-])(\d+)(?::(\d+))?/);
|
|
104
|
+
if (matchData) {
|
|
105
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
106
|
+
const [_, sign, hour, minute] = matchData;
|
|
107
|
+
return parseInt(sign + "1") * ((hour ? parseInt(hour) : 0) * 60 + (minute ? parseInt(minute) : 0)) * 60 * 1000;
|
|
108
|
+
}
|
|
109
|
+
return 0;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const todayToEpoch = (resetHours: boolean): number => {
|
|
113
|
+
const today = new Date();
|
|
114
|
+
if (resetHours) {
|
|
115
|
+
today.setHours(0, 0, 0, 0);
|
|
116
|
+
}
|
|
117
|
+
return today.getTime() + getMachineOffsetMillis() - getUserOffsetMillis();
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const pickerToEpoch = (value: Date | null | undefined): number => {
|
|
121
|
+
if (value != null) {
|
|
122
|
+
// FSCalendar is always in machine time zone, so we need to convert it to user time zone
|
|
123
|
+
return value.getTime() + getMachineOffsetMillis() - getUserOffsetMillis();
|
|
124
|
+
}
|
|
125
|
+
return 0;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const epochToPicker = (value: number | null | undefined): Date => {
|
|
129
|
+
const date = new Date(0);
|
|
130
|
+
if (value != null) {
|
|
131
|
+
// Epoch is always without time zone, so we need to convert it to user time zone
|
|
132
|
+
date.setUTCMilliseconds(value - getMachineOffsetMillis() + getUserOffsetMillis());
|
|
133
|
+
}
|
|
134
|
+
return date;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const epochToPickerHeader = (value: number): { d: number, m: number, y: number } => {
|
|
138
|
+
const date = new Date(0);
|
|
139
|
+
if (value != null) {
|
|
140
|
+
date.setUTCMilliseconds(value - getMachineOffsetMillis() + getUserOffsetMillis());
|
|
48
141
|
}
|
|
142
|
+
return { d: date.getDate(), m: date.getMonth(), y: date.getFullYear() };
|
|
143
|
+
};
|
|
49
144
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const machineOffset = (): number => {
|
|
55
|
-
return getOffsetNumber(getMachineOffset());
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
const getUserOffset = (): string => {
|
|
59
|
-
return timeZone?.value?.offset ?? "UTC +00:00:00";
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
const getUserOffsetMillis = (): number => {
|
|
63
|
-
const offset = timeZone?.value?.offset.slice(3) ?? "";
|
|
64
|
-
const matchData = offset.match(/([+-])(\d+)(?::(\d+))?/);
|
|
65
|
-
if (matchData) {
|
|
66
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
67
|
-
const [_, sign, hour, minute] = matchData;
|
|
68
|
-
return parseInt(sign + "1") * ((hour ? parseInt(hour) : 0) * 60 + (minute ? parseInt(minute) : 0)) * 60 * 1000;
|
|
69
|
-
}
|
|
70
|
-
return 0;
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
const getMachineOffset = (): string => {
|
|
74
|
-
const timeZoneName = Intl.DateTimeFormat("ia", {
|
|
75
|
-
timeZoneName: "short",
|
|
76
|
-
timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
77
|
-
}).formatToParts().find((i) => i.type === "timeZoneName")?.value ?? "";
|
|
78
|
-
|
|
79
|
-
const offset = timeZoneName.slice(3);
|
|
80
|
-
if (!offset) {
|
|
81
|
-
return "UTC +00:00:00";
|
|
82
|
-
}
|
|
83
|
-
const matchData = offset.match(/([+-])(\d+)(?::(\d+))?/);
|
|
84
|
-
if (matchData) {
|
|
85
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
86
|
-
const [_, sign, hour, minute] = matchData;
|
|
87
|
-
return `UTC ${sign}${hour.padStart(2, "0")}:${(minute ?? "").padStart(2, "0")}:00`;
|
|
88
|
-
}
|
|
89
|
-
return "UTC +00:00:00";
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
const getMachineOffsetMillis = (): number => {
|
|
93
|
-
const timeZoneName = Intl.DateTimeFormat("ia", {
|
|
94
|
-
timeZoneName: "short",
|
|
95
|
-
timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
96
|
-
}).formatToParts().find((i) => i.type === "timeZoneName")?.value ?? "";
|
|
97
|
-
|
|
98
|
-
const offset = timeZoneName.slice(3);
|
|
99
|
-
if (!offset) {
|
|
100
|
-
return 0;
|
|
101
|
-
}
|
|
102
|
-
const matchData = offset.match(/([+-])(\d+)(?::(\d+))?/);
|
|
103
|
-
if (matchData) {
|
|
104
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
105
|
-
const [_, sign, hour, minute] = matchData;
|
|
106
|
-
return parseInt(sign + "1") * ((hour ? parseInt(hour) : 0) * 60 + (minute ? parseInt(minute) : 0)) * 60 * 1000;
|
|
107
|
-
}
|
|
108
|
-
return 0;
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
const todayToEpoch = (resetHours: boolean): number => {
|
|
112
|
-
const today = new Date();
|
|
113
|
-
if (resetHours) {
|
|
114
|
-
today.setHours(0, 0, 0, 0);
|
|
115
|
-
}
|
|
116
|
-
return today.getTime() + getMachineOffsetMillis() - getUserOffsetMillis();
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
const pickerToEpoch = (value: Date | null | undefined): number => {
|
|
120
|
-
if (value != null) {
|
|
121
|
-
// FSCalendar is always in machine time zone, so we need to convert it to user time zone
|
|
122
|
-
return value.getTime() + getMachineOffsetMillis() - getUserOffsetMillis();
|
|
123
|
-
}
|
|
124
|
-
return 0;
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
const epochToPicker = (value: number | null | undefined): Date => {
|
|
128
|
-
const date = new Date(0);
|
|
129
|
-
if (value != null) {
|
|
130
|
-
// Epoch is always without time zone, so we need to convert it to user time zone
|
|
131
|
-
date.setUTCMilliseconds(value - getMachineOffsetMillis() + getUserOffsetMillis());
|
|
132
|
-
}
|
|
133
|
-
return date;
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
const epochToPickerHeader = (value: number): { d: number, m: number, y: number } => {
|
|
137
|
-
const date = new Date(0);
|
|
138
|
-
if (value != null) {
|
|
139
|
-
date.setUTCMilliseconds(value - getMachineOffsetMillis() + getUserOffsetMillis());
|
|
140
|
-
}
|
|
141
|
-
return { d: date.getDate(), m: date.getMonth(), y: date.getFullYear() };
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
const epochToLongDateFormat = (value: number | null | undefined): string => {
|
|
145
|
-
if (value == null || !isFinite(value)) {
|
|
146
|
-
return "";
|
|
147
|
-
}
|
|
148
|
-
const date = new Date(0);
|
|
149
|
-
date.setUTCMilliseconds(value - getMachineOffsetMillis() + getUserOffsetMillis());
|
|
150
|
-
return format(date, "EEEE dd LLLL yyyy", { locale: getLocale() });
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
const epochToLongTimeFormat = (value: number | null | undefined): string => {
|
|
154
|
-
if (value == null || !isFinite(value)) {
|
|
155
|
-
return "";
|
|
156
|
-
}
|
|
157
|
-
const date = new Date(0);
|
|
158
|
-
date.setUTCMilliseconds(value - getMachineOffsetMillis() + getUserOffsetMillis());
|
|
159
|
-
return format(date, overrideFormat(date, "EEEE dd LLLL yyyy HH:mm"), { locale: getLocale() })
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
const epochToShortDateFormat = (value: number | null | undefined): string => {
|
|
163
|
-
if (value == null || !isFinite(value)) {
|
|
164
|
-
return "";
|
|
165
|
-
}
|
|
166
|
-
const date = new Date(0);
|
|
167
|
-
date.setUTCMilliseconds(value - getMachineOffsetMillis() + getUserOffsetMillis());
|
|
168
|
-
switch (getLocale()) {
|
|
169
|
-
case enUS: {
|
|
170
|
-
return format(date, "MM/dd/yyyy", { locale: getLocale() });
|
|
171
|
-
}
|
|
172
|
-
default: {
|
|
173
|
-
return format(date, "dd/MM/yyyy", { locale: getLocale() });
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
const epochToShortTimeFormat = (value: number | null | undefined): string => {
|
|
179
|
-
if (value == null || !isFinite(value)) {
|
|
180
|
-
return "";
|
|
181
|
-
}
|
|
182
|
-
const date = new Date(0);
|
|
183
|
-
date.setUTCMilliseconds(value - getMachineOffsetMillis() + getUserOffsetMillis());
|
|
184
|
-
switch (getLocale()) {
|
|
185
|
-
case enUS: {
|
|
186
|
-
return format(date, "MM/dd/yyyy HH:mm", { locale: getLocale() });
|
|
187
|
-
}
|
|
188
|
-
default: {
|
|
189
|
-
return format(date, "dd/MM/yyyy HH:mm", { locale: getLocale() });
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
|
|
194
|
-
const todayTimeFormat = (): string => {
|
|
195
|
-
return `'${useTranslationsProvider().$tr("ui.time-zone.today-at", "Today at").replace(/'/g, "''")}' HH:mm:ss`;
|
|
145
|
+
const epochToLongDateFormat = (value: number | null | undefined): string => {
|
|
146
|
+
if (value == null || !isFinite(value)) {
|
|
147
|
+
return "";
|
|
196
148
|
}
|
|
149
|
+
const date = new Date(0);
|
|
150
|
+
date.setUTCMilliseconds(value - getMachineOffsetMillis() + getUserOffsetMillis());
|
|
151
|
+
return format(date, "EEEE dd LLLL yyyy", { locale: getLocale() });
|
|
152
|
+
};
|
|
197
153
|
|
|
198
|
-
|
|
199
|
-
|
|
154
|
+
const epochToLongTimeFormat = (value: number | null | undefined): string => {
|
|
155
|
+
if (value == null || !isFinite(value)) {
|
|
156
|
+
return "";
|
|
200
157
|
}
|
|
158
|
+
const date = new Date(0);
|
|
159
|
+
date.setUTCMilliseconds(value - getMachineOffsetMillis() + getUserOffsetMillis());
|
|
160
|
+
return format(date, overrideFormat(date, "EEEE dd LLLL yyyy HH:mm"), { locale: getLocale() })
|
|
161
|
+
};
|
|
201
162
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
return todayTimeFormat();
|
|
206
|
-
}
|
|
207
|
-
if (date.toDateString() === subDays(now, 1).toDateString()) {
|
|
208
|
-
return yesterdayTimeFormat();
|
|
209
|
-
}
|
|
210
|
-
return askedFormat;
|
|
163
|
+
const epochToShortDateFormat = (value: number | null | undefined): string => {
|
|
164
|
+
if (value == null || !isFinite(value)) {
|
|
165
|
+
return "";
|
|
211
166
|
}
|
|
167
|
+
const date = new Date(0);
|
|
168
|
+
date.setUTCMilliseconds(value - getMachineOffsetMillis() + getUserOffsetMillis());
|
|
169
|
+
switch (getLocale()) {
|
|
170
|
+
case enUS: {
|
|
171
|
+
return format(date, "MM/dd/yyyy", { locale: getLocale() });
|
|
172
|
+
}
|
|
173
|
+
default: {
|
|
174
|
+
return format(date, "dd/MM/yyyy", { locale: getLocale() });
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
const epochToTimeOnlyFormat = (value: number | null | undefined): string => {
|
|
180
|
+
if (value == null || !isFinite(value)) {
|
|
181
|
+
return "";
|
|
182
|
+
}
|
|
183
|
+
const date = new Date(0);
|
|
184
|
+
date.setUTCMilliseconds(value - getMachineOffsetMillis() + getUserOffsetMillis());
|
|
185
|
+
return format(date, "HH:mm:ss", { locale: getLocale() });
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
const epochToShortTimeFormat = (value: number | null | undefined): string => {
|
|
189
|
+
if (value == null || !isFinite(value)) {
|
|
190
|
+
return "";
|
|
191
|
+
}
|
|
192
|
+
const date = new Date(0);
|
|
193
|
+
date.setUTCMilliseconds(value - getMachineOffsetMillis() + getUserOffsetMillis());
|
|
194
|
+
switch (getLocale()) {
|
|
195
|
+
case enUS: {
|
|
196
|
+
return format(date, "MM/dd/yyyy HH:mm", { locale: getLocale() });
|
|
197
|
+
}
|
|
198
|
+
default: {
|
|
199
|
+
return format(date, "dd/MM/yyyy HH:mm", { locale: getLocale() });
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
const todayTimeFormat = (): string => {
|
|
205
|
+
return `'${useTranslationsProvider().$tr("ui.time-zone.today-at", "Today at").replace(/'/g, "''")}' HH:mm:ss`;
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
const yesterdayTimeFormat = (): string => {
|
|
209
|
+
return `'${useTranslationsProvider().$tr("ui.time-zone.yesterday-at", "Yesterday at").replace(/'/g, "''")}' HH:mm:ss`;
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
const overrideFormat = (date: Date, askedFormat: string): string => {
|
|
213
|
+
const now = new Date();
|
|
214
|
+
if (date.toDateString() === now.toDateString()) {
|
|
215
|
+
return todayTimeFormat();
|
|
216
|
+
}
|
|
217
|
+
if (date.toDateString() === subDays(now, 1).toDateString()) {
|
|
218
|
+
return yesterdayTimeFormat();
|
|
219
|
+
}
|
|
220
|
+
return askedFormat;
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
const getLocale = (): Locale => {
|
|
224
|
+
switch (useAppLanguageCode().languageCode.value) {
|
|
225
|
+
case "fr-FR": return fr;
|
|
226
|
+
case "es-ES": return es;
|
|
227
|
+
case "it-IT": return it;
|
|
228
|
+
case "en-GB": return enGB;
|
|
229
|
+
case "de-DE": return de;
|
|
230
|
+
default: return enUS;
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
const parseForPicker = (value: string, dateFormat: string = isoTimeFormat()): number | null => {
|
|
235
|
+
let date = parse(value!, dateFormat, new Date());
|
|
236
|
+
date = addMilliseconds(date, userOffset());
|
|
237
|
+
if (!isFinite(date.getTime())) {
|
|
238
|
+
return null;
|
|
239
|
+
}
|
|
240
|
+
return date.getTime();
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
const formatCurrentForPicker = (daysOffset: number = -1): string => {
|
|
244
|
+
let date = new Date();
|
|
245
|
+
date.setSeconds(0, 0);
|
|
246
|
+
date = addMilliseconds(addDays(date, daysOffset), -machineOffset());
|
|
247
|
+
return format(date, isoTimeFormat());
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
const formatFromPicker = (date: number | null): string => {
|
|
251
|
+
if (date != null) {
|
|
252
|
+
const epoch = date - machineOffset() + (machineOffset() - userOffset());
|
|
253
|
+
return format(epoch, isoTimeFormat());
|
|
254
|
+
}
|
|
255
|
+
return "";
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
const formatEpochToVariable = (epoch: number | undefined): string => {
|
|
259
|
+
if (epoch == null || !isFinite(epoch)) {
|
|
260
|
+
return "";
|
|
261
|
+
}
|
|
262
|
+
return format(epoch - machineOffset(), isoTimeFormat());
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
const ready = computed(() => timeZone.value !== null);
|
|
212
266
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
date.setSeconds(0, 0);
|
|
236
|
-
date = addMilliseconds(addDays(date, daysOffset), -machineOffset());
|
|
237
|
-
return format(date, isoTimeFormat());
|
|
238
|
-
};
|
|
239
|
-
|
|
240
|
-
const formatFromPicker = (date: number | null): string => {
|
|
241
|
-
if (date != null) {
|
|
242
|
-
const epoch = date - machineOffset() + (machineOffset() - userOffset());
|
|
243
|
-
return format(epoch, isoTimeFormat());
|
|
244
|
-
}
|
|
245
|
-
return "";
|
|
246
|
-
};
|
|
247
|
-
|
|
248
|
-
const ready = computed(() => timeZone.value !== null);
|
|
249
|
-
|
|
250
|
-
return {
|
|
251
|
-
ready,
|
|
252
|
-
timeZone,
|
|
253
|
-
setAppTimeZone,
|
|
254
|
-
getUserOffset,
|
|
255
|
-
getMachineOffset,
|
|
256
|
-
getUserOffsetMillis,
|
|
257
|
-
getMachineOffsetMillis,
|
|
258
|
-
todayToEpoch,
|
|
259
|
-
pickerToEpoch,
|
|
260
|
-
epochToPicker,
|
|
261
|
-
epochToPickerHeader,
|
|
262
|
-
epochToLongDateFormat,
|
|
263
|
-
epochToLongTimeFormat,
|
|
264
|
-
epochToShortDateFormat,
|
|
265
|
-
epochToShortTimeFormat,
|
|
266
|
-
parseForPicker,
|
|
267
|
-
formatCurrentForPicker,
|
|
268
|
-
formatFromPicker
|
|
269
|
-
};
|
|
267
|
+
return {
|
|
268
|
+
ready,
|
|
269
|
+
timeZone,
|
|
270
|
+
setAppTimeZone,
|
|
271
|
+
getUserOffset,
|
|
272
|
+
getMachineOffset,
|
|
273
|
+
getUserOffsetMillis,
|
|
274
|
+
getMachineOffsetMillis,
|
|
275
|
+
todayToEpoch,
|
|
276
|
+
pickerToEpoch,
|
|
277
|
+
epochToPicker,
|
|
278
|
+
epochToPickerHeader,
|
|
279
|
+
epochToLongDateFormat,
|
|
280
|
+
epochToLongTimeFormat,
|
|
281
|
+
epochToShortDateFormat,
|
|
282
|
+
epochToShortTimeFormat,
|
|
283
|
+
epochToTimeOnlyFormat,
|
|
284
|
+
parseForPicker,
|
|
285
|
+
formatCurrentForPicker,
|
|
286
|
+
formatFromPicker,
|
|
287
|
+
formatEpochToVariable
|
|
288
|
+
};
|
|
270
289
|
}
|
|
@@ -2,6 +2,7 @@ export * from "./useAuthTokens";
|
|
|
2
2
|
export * from "./useImages";
|
|
3
3
|
export * from "./useLanguages";
|
|
4
4
|
export * from "./useOrganisations";
|
|
5
|
+
export * from "./useTerminals";
|
|
5
6
|
export * from "./useTimeZones";
|
|
6
7
|
export * from "./useTranslations";
|
|
7
8
|
export * from "./useUsers";
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import { AuthTokenDetails, AuthTokenDetailsDTO, CreateAuthTokenDTO } from "@dative-gpi/foundation-shared-domain/models";
|
|
1
|
+
import { AuthTokenDetails, type AuthTokenDetailsDTO, type AuthTokenFilters, AuthTokenInfos, type AuthTokenInfosDTO, type CreateAuthTokenDTO } from "@dative-gpi/foundation-shared-domain/models";
|
|
2
2
|
import { ComposableFactory, ServiceFactory } from "@dative-gpi/bones-ui/core";
|
|
3
3
|
|
|
4
|
-
import { AUTH_TOKENS_URL } from "../../config/urls";
|
|
4
|
+
import { AUTH_TOKENS_URL, AUTH_TOKEN_URL } from "../../config/urls";
|
|
5
5
|
|
|
6
6
|
const AuthTokenServiceFactory = new ServiceFactory<AuthTokenDetailsDTO, AuthTokenDetails>("authToken", AuthTokenDetails).create(factory => factory.build(
|
|
7
|
+
factory.addGetMany<AuthTokenInfosDTO, AuthTokenInfos, AuthTokenFilters>(AUTH_TOKENS_URL, AuthTokenInfos),
|
|
7
8
|
factory.addCreate<CreateAuthTokenDTO>(AUTH_TOKENS_URL),
|
|
9
|
+
factory.addRemove(AUTH_TOKEN_URL),
|
|
8
10
|
factory.addNotify()
|
|
9
11
|
));
|
|
10
12
|
|
|
11
|
-
export const
|
|
13
|
+
export const useAuthTokens = ComposableFactory.getMany(AuthTokenServiceFactory);
|
|
14
|
+
export const useCreateAuthToken = ComposableFactory.create(AuthTokenServiceFactory);
|
|
15
|
+
export const useRemoveAuthToken = ComposableFactory.remove(AuthTokenServiceFactory);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ComposableFactory, ServiceFactory } from "@dative-gpi/bones-ui/core";
|
|
2
|
-
import {
|
|
2
|
+
import type { BlurHashDTO } from "@dative-gpi/foundation-shared-domain/models";
|
|
3
|
+
import { BlurHash } from "@dative-gpi/foundation-shared-domain/models";
|
|
3
4
|
|
|
4
5
|
import { IMAGE_BLURHASH_URL } from "../../config/urls";
|
|
5
6
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { LanguageDetailsDTO, LanguageFilters, LanguageInfosDTO } from "@dative-gpi/foundation-shared-domain/models";
|
|
2
|
+
import { LanguageDetails, LanguageInfos } from "@dative-gpi/foundation-shared-domain/models";
|
|
2
3
|
import { ComposableFactory, ServiceFactory } from "@dative-gpi/bones-ui/core";
|
|
3
4
|
|
|
4
5
|
import { LANGUAGES_URL } from "../../config/urls";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { OrganisationDetailsDTO, OrganisationFilters, OrganisationInfosDTO, UpdateOrganisationDTO } from "@dative-gpi/foundation-shared-domain/models";
|
|
2
|
+
import { OrganisationDetails, OrganisationInfos } from "@dative-gpi/foundation-shared-domain/models";
|
|
2
3
|
import { ComposableFactory, ServiceFactory } from "@dative-gpi/bones-ui/core";
|
|
3
4
|
|
|
4
5
|
import { ORGANISATIONS_URL, ORGANISATION_URL } from "../../config/urls";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type CreateTerminalDTO, TerminalDetails, type TerminalDetailsDTO, type TerminalFilters, TerminalInfos, type TerminalInfosDTO, type UpdateTerminalDTO } from "@dative-gpi/foundation-shared-domain/models";
|
|
2
|
+
import { ComposableFactory, ServiceFactory } from "@dative-gpi/bones-ui/core";
|
|
3
|
+
|
|
4
|
+
import { TERMINALS_URL, TERMINAL_URL } from "../../config/urls";
|
|
5
|
+
|
|
6
|
+
const TerminalServiceFactory = new ServiceFactory<TerminalDetailsDTO, TerminalDetails>("terminal", TerminalDetails).create(factory => factory.build(
|
|
7
|
+
factory.addGetMany<TerminalInfosDTO, TerminalInfos, TerminalFilters>(TERMINALS_URL, TerminalInfos),
|
|
8
|
+
factory.addCreate<CreateTerminalDTO>(TERMINALS_URL),
|
|
9
|
+
factory.addUpdate<UpdateTerminalDTO>(TERMINAL_URL),
|
|
10
|
+
factory.addRemove(TERMINAL_URL),
|
|
11
|
+
factory.addNotify()
|
|
12
|
+
));
|
|
13
|
+
|
|
14
|
+
export const useTerminals = ComposableFactory.getMany(TerminalServiceFactory);
|
|
15
|
+
export const useCreateTerminal = ComposableFactory.create(TerminalServiceFactory);
|
|
16
|
+
export const useUpdateTerminal = ComposableFactory.update(TerminalServiceFactory);
|
|
17
|
+
export const useRemoveTerminal = ComposableFactory.remove(TerminalServiceFactory);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { TimeZoneDetailsDTO, TimeZoneFilters, TimeZoneInfosDTO } from "@dative-gpi/foundation-shared-domain/models";
|
|
2
|
+
import { TimeZoneDetails, TimeZoneInfos } from "@dative-gpi/foundation-shared-domain/models";
|
|
2
3
|
import { ComposableFactory, ServiceFactory } from "@dative-gpi/bones-ui/core";
|
|
3
4
|
|
|
4
5
|
import { TIME_ZONES_URL } from "../../config/urls";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { TranslationInfosDTO } from "@dative-gpi/foundation-shared-domain/models";
|
|
2
|
+
import { TranslationInfos } from "@dative-gpi/foundation-shared-domain/models";
|
|
2
3
|
import { ComposableFactory, ServiceFactory } from "@dative-gpi/bones-ui/core";
|
|
3
4
|
|
|
4
5
|
import { TRANSLATIONS_LANGUAGE_URL } from "../../config/urls";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Ref } from "vue";
|
|
1
|
+
import type { Ref } from "vue";
|
|
2
2
|
|
|
3
|
-
import { UpdateCurrentUserDTO, UpdateCurrentUserEmailDTO,
|
|
3
|
+
import type { UpdateCurrentUserDTO, UpdateCurrentUserEmailDTO, UserDetailsDTO } from "@dative-gpi/foundation-shared-domain/models";
|
|
4
|
+
import { UserDetails } from "@dative-gpi/foundation-shared-domain/models";
|
|
4
5
|
import { ComposableFactory, ServiceFactory } from "@dative-gpi/bones-ui/core";
|
|
5
6
|
|
|
6
7
|
import { USER_CURRENT_URL } from "../../config/urls";
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { GATEWAY_URL } from "./base";
|
|
2
2
|
|
|
3
|
-
export const AUTH_TOKENS_URL = () => `${GATEWAY_URL()}/
|
|
3
|
+
export const AUTH_TOKENS_URL = () => `${GATEWAY_URL()}/pats`;
|
|
4
|
+
export const AUTH_TOKEN_URL = (tokenId: string) => `${AUTH_TOKENS_URL()}/${encodeURIComponent(tokenId)}`;
|
package/config/urls/base.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export const GATEWAY_URL = () => "/api/foundation/shared/v1";
|
|
2
|
-
export const GATEWAY_EXTENSION_URL = () => "/api/shared/v1";
|
|
1
|
+
export const GATEWAY_URL = () => "/api/foundation/shared/v1";
|
package/config/urls/images.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GATEWAY_URL } from "./base";
|
|
2
2
|
|
|
3
|
-
export const IMAGES_URL = () => `${
|
|
3
|
+
export const IMAGES_URL = () => `${GATEWAY_URL()}/images`;
|
|
4
4
|
|
|
5
5
|
export const IMAGES_RAW_URL = () => `${IMAGES_URL()}/raw`;
|
|
6
6
|
export const IMAGE_RAW_URL = (imageId: string) => `${IMAGES_RAW_URL()}/${encodeURIComponent(imageId)}`;
|
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.1
|
|
4
|
+
"version": "1.0.1",
|
|
5
5
|
"description": "",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -10,11 +10,13 @@
|
|
|
10
10
|
"author": "",
|
|
11
11
|
"license": "ISC",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@dative-gpi/
|
|
14
|
-
|
|
13
|
+
"@dative-gpi/foundation-shared-domain": "1.0.1"
|
|
14
|
+
},
|
|
15
|
+
"peerDependencies": {
|
|
16
|
+
"@dative-gpi/bones-ui": "^0.0.75",
|
|
15
17
|
"@microsoft/signalr": "^8.0.0",
|
|
16
|
-
"vue": "^3.4.
|
|
17
|
-
"vue-router": "^4.
|
|
18
|
+
"vue": "^3.4.29",
|
|
19
|
+
"vue-router": "^4.3.0"
|
|
18
20
|
},
|
|
19
|
-
"gitHead": "
|
|
21
|
+
"gitHead": "297a3db2234e01a04a88c111d547656f4d0a74f0"
|
|
20
22
|
}
|
package/tools/hubFactory.ts
CHANGED
|
@@ -11,7 +11,7 @@ export class HubFactory {
|
|
|
11
11
|
let connection: signalR.HubConnection | null = null;
|
|
12
12
|
let subscribed = false;
|
|
13
13
|
let watchManySubscribers = 0;
|
|
14
|
-
|
|
14
|
+
const watcheds = ref<string[]>([]);
|
|
15
15
|
|
|
16
16
|
return () => {
|
|
17
17
|
const connect = async () => {
|
|
@@ -59,7 +59,7 @@ export class HubFactory {
|
|
|
59
59
|
|
|
60
60
|
const unsubscribeFromOne = (alertId: string) => {
|
|
61
61
|
const index = watcheds.value.indexOf(alertId);
|
|
62
|
-
if (index > -1) watcheds.value = watcheds.value.splice(index, 1);
|
|
62
|
+
if (index > -1) {watcheds.value = watcheds.value.splice(index, 1);}
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
const subscribeToMany = () => {
|
|
@@ -90,7 +90,7 @@ export class HubFactory {
|
|
|
90
90
|
if (manySubscriptions.value) {
|
|
91
91
|
unsubscribeFromMany();
|
|
92
92
|
}
|
|
93
|
-
for (
|
|
93
|
+
for (const subscription of oneSubscriptions.value) {
|
|
94
94
|
unsubscribeFromOne(subscription);
|
|
95
95
|
}
|
|
96
96
|
})
|