@dative-gpi/foundation-shared-components 1.0.68 → 1.0.70
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/components/fields/FSTimeRangeField.vue +380 -0
- package/package.json +4 -4
- package/tools/index.ts +2 -1
- package/tools/timeRangeTools.ts +66 -0
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<FSBaseField
|
|
3
|
+
:description="$props.description"
|
|
4
|
+
:hideHeader="$props.hideHeader"
|
|
5
|
+
:required="$props.required"
|
|
6
|
+
:editable="$props.editable"
|
|
7
|
+
:label="$props.label"
|
|
8
|
+
:messages="messages"
|
|
9
|
+
>
|
|
10
|
+
<FSRow>
|
|
11
|
+
<FSRow
|
|
12
|
+
:wrap="false"
|
|
13
|
+
>
|
|
14
|
+
<FSSelectField
|
|
15
|
+
:validationValue="$props.modelValue"
|
|
16
|
+
:editable="$props.editable"
|
|
17
|
+
:validateOn="validateOn"
|
|
18
|
+
:rules="$props.rules"
|
|
19
|
+
:items="daysObject"
|
|
20
|
+
:hideHeader="true"
|
|
21
|
+
:clearable="false"
|
|
22
|
+
:style="style"
|
|
23
|
+
:modelValue="realTime?.startDay ?? 0"
|
|
24
|
+
@update:modelValue="onChangeDayStart"
|
|
25
|
+
/>
|
|
26
|
+
<FSClock
|
|
27
|
+
class="fs-time-slot-field-number"
|
|
28
|
+
:editable="$props.editable"
|
|
29
|
+
:color="ColorEnum.Light"
|
|
30
|
+
:slider="false"
|
|
31
|
+
:style="style"
|
|
32
|
+
:modelValue="startTime"
|
|
33
|
+
@update:modelValue="onChangeHourStart"
|
|
34
|
+
/>
|
|
35
|
+
</FSRow>
|
|
36
|
+
<FSRow
|
|
37
|
+
:wrap="false"
|
|
38
|
+
>
|
|
39
|
+
<FSSelectField
|
|
40
|
+
class="fs-time-slot-field-select"
|
|
41
|
+
:editable="$props.editable"
|
|
42
|
+
:items="daysObject"
|
|
43
|
+
:hideHeader="true"
|
|
44
|
+
:clearable="false"
|
|
45
|
+
:style="style"
|
|
46
|
+
:modelValue="realTime?.endDay ?? 0"
|
|
47
|
+
@update:modelValue="onChangeDayEnd"
|
|
48
|
+
/>
|
|
49
|
+
<FSClock
|
|
50
|
+
class="fs-time-slot-field-number"
|
|
51
|
+
:editable="$props.editable"
|
|
52
|
+
:color="ColorEnum.Light"
|
|
53
|
+
:slider="false"
|
|
54
|
+
:style="style"
|
|
55
|
+
:modelValue="endTime"
|
|
56
|
+
@update:modelValue="onChangeHourEnd"
|
|
57
|
+
/>
|
|
58
|
+
</FSRow>
|
|
59
|
+
</FSRow>
|
|
60
|
+
</FSBaseField>
|
|
61
|
+
</template>
|
|
62
|
+
|
|
63
|
+
<script lang="ts">
|
|
64
|
+
import { computed, defineComponent, type PropType, type StyleValue } from "vue";
|
|
65
|
+
|
|
66
|
+
import { useColors, useRules } from "@dative-gpi/foundation-shared-components/composables";
|
|
67
|
+
import { ColorEnum } from "@dative-gpi/foundation-shared-components/models";
|
|
68
|
+
import { Days } from "@dative-gpi/foundation-shared-domain/enums";
|
|
69
|
+
|
|
70
|
+
import FSSelectField from "./FSSelectField.vue";
|
|
71
|
+
import FSBaseField from "./FSBaseField.vue";
|
|
72
|
+
import FSClock from "../FSClock.vue";
|
|
73
|
+
import FSRow from "../FSRow.vue";
|
|
74
|
+
|
|
75
|
+
import { applyOffset, type DateTimeRange } from "../../tools";
|
|
76
|
+
|
|
77
|
+
export default defineComponent({
|
|
78
|
+
name: "FSTimeRangeField",
|
|
79
|
+
components: {
|
|
80
|
+
FSSelectField,
|
|
81
|
+
FSBaseField,
|
|
82
|
+
FSClock,
|
|
83
|
+
FSRow
|
|
84
|
+
},
|
|
85
|
+
props: {
|
|
86
|
+
label: {
|
|
87
|
+
type: String as PropType<string | null>,
|
|
88
|
+
required: false,
|
|
89
|
+
default: null
|
|
90
|
+
},
|
|
91
|
+
description: {
|
|
92
|
+
type: String as PropType<string | null>,
|
|
93
|
+
required: false,
|
|
94
|
+
default: null
|
|
95
|
+
},
|
|
96
|
+
modelValue: {
|
|
97
|
+
type: Object as PropType<DateTimeRange | null>,
|
|
98
|
+
required: true,
|
|
99
|
+
default: null
|
|
100
|
+
},
|
|
101
|
+
hideHeader: {
|
|
102
|
+
type: Boolean,
|
|
103
|
+
required: false,
|
|
104
|
+
default: false
|
|
105
|
+
},
|
|
106
|
+
required: {
|
|
107
|
+
type: Boolean,
|
|
108
|
+
required: false,
|
|
109
|
+
default: false
|
|
110
|
+
},
|
|
111
|
+
rules: {
|
|
112
|
+
type: Array as PropType<any[]>,
|
|
113
|
+
required: false,
|
|
114
|
+
default: () => []
|
|
115
|
+
},
|
|
116
|
+
messages: {
|
|
117
|
+
type: Array as PropType<string[]>,
|
|
118
|
+
required: false,
|
|
119
|
+
default: null
|
|
120
|
+
},
|
|
121
|
+
editable: {
|
|
122
|
+
type: Boolean,
|
|
123
|
+
required: false,
|
|
124
|
+
default: true
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
emits: ["update:modelValue"],
|
|
128
|
+
setup(props, { emit }) {
|
|
129
|
+
const { validateOn, getMessages } = useRules();
|
|
130
|
+
const { getColors } = useColors();
|
|
131
|
+
|
|
132
|
+
const errors = getColors(ColorEnum.Error);
|
|
133
|
+
const lights = getColors(ColorEnum.Light);
|
|
134
|
+
const darks = getColors(ColorEnum.Dark);
|
|
135
|
+
|
|
136
|
+
const daysObject: { id: number; label: string }[] = Object.keys(Days).reduce((acc, key) => {
|
|
137
|
+
if (isNaN(Number(key))) {
|
|
138
|
+
acc.push({
|
|
139
|
+
id: Days[key],
|
|
140
|
+
label: key
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
return acc;
|
|
144
|
+
}, [] as { id: number, label: string }[]);
|
|
145
|
+
|
|
146
|
+
const style = computed((): StyleValue => {
|
|
147
|
+
if (!props.editable) {
|
|
148
|
+
return {
|
|
149
|
+
"--fs-time-slot-field-cursor" : "default",
|
|
150
|
+
"--fs-time-slot-field-border-color" : lights.base,
|
|
151
|
+
"--fs-time-slot-field-color" : lights.dark,
|
|
152
|
+
"--fs-time-slot-field-active-border-color": lights.base
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
return {
|
|
156
|
+
"--fs-time-slot-field-cursor" : "text",
|
|
157
|
+
"--fs-time-slot-field-border-color" : lights.dark,
|
|
158
|
+
"--fs-time-slot-field-color" : darks.base,
|
|
159
|
+
"--fs-time-slot-field-active-border-color": darks.dark,
|
|
160
|
+
"--fs-time-slot-field-error-color" : errors.base,
|
|
161
|
+
"--fs-time-slot-field-error-border-color" : errors.base
|
|
162
|
+
};
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
const realTime = computed(() => {
|
|
166
|
+
if (props.modelValue) {
|
|
167
|
+
return applyOffset(props.modelValue, false);
|
|
168
|
+
}
|
|
169
|
+
return null;
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
const startTime = computed((): number => {
|
|
173
|
+
if (realTime.value) {
|
|
174
|
+
return realTime.value.startHour * 60 * 60 * 1000 + realTime.value.startMinute * 60 * 1000;
|
|
175
|
+
}
|
|
176
|
+
return 0;
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
const endTime = computed((): number => {
|
|
180
|
+
if (realTime.value) {
|
|
181
|
+
return realTime.value.endHour * 60 * 60 * 1000 + realTime.value.endMinute * 60 * 1000;
|
|
182
|
+
}
|
|
183
|
+
return 0;
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
const messages = computed((): string[] => props.messages ?? getMessages(props.modelValue, props.rules));
|
|
187
|
+
|
|
188
|
+
const onChangeDayStart = (value: number) => {
|
|
189
|
+
if (value === 7) {
|
|
190
|
+
if (props.modelValue) {
|
|
191
|
+
emit("update:modelValue",
|
|
192
|
+
{
|
|
193
|
+
startDay: 7,
|
|
194
|
+
startHour: props.modelValue.startHour,
|
|
195
|
+
startMinute: props.modelValue.startMinute,
|
|
196
|
+
endDay: 7,
|
|
197
|
+
endHour: props.modelValue.endHour,
|
|
198
|
+
endMinute: props.modelValue.endMinute
|
|
199
|
+
}
|
|
200
|
+
);
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
emit("update:modelValue",
|
|
204
|
+
{
|
|
205
|
+
startDay: 7,
|
|
206
|
+
startHour: 0,
|
|
207
|
+
startMinute: 0,
|
|
208
|
+
endDay: 7,
|
|
209
|
+
endHour: 0,
|
|
210
|
+
endMinute: 0
|
|
211
|
+
}
|
|
212
|
+
);
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
if (props.modelValue) {
|
|
216
|
+
if (props.modelValue.endDay === 7) {
|
|
217
|
+
emit("update:modelValue",
|
|
218
|
+
{
|
|
219
|
+
startDay: value,
|
|
220
|
+
startHour: props.modelValue.startHour,
|
|
221
|
+
startMinute: props.modelValue.startMinute,
|
|
222
|
+
endDay: value,
|
|
223
|
+
endHour: props.modelValue.endHour,
|
|
224
|
+
endMinute: props.modelValue.endMinute
|
|
225
|
+
}
|
|
226
|
+
);
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
const t = applyOffset({
|
|
230
|
+
startDay: value,
|
|
231
|
+
startHour: props.modelValue.startHour,
|
|
232
|
+
startMinute: props.modelValue.startMinute,
|
|
233
|
+
endDay: props.modelValue.endDay,
|
|
234
|
+
endHour: props.modelValue.endHour,
|
|
235
|
+
endMinute: props.modelValue.endMinute
|
|
236
|
+
}, true);
|
|
237
|
+
emit("update:modelValue", t);
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
emit("update:modelValue",{
|
|
241
|
+
startDay: value,
|
|
242
|
+
startHour: 0,
|
|
243
|
+
startMinute: 0,
|
|
244
|
+
endDay: value,
|
|
245
|
+
endHour: 0,
|
|
246
|
+
endMinute: 0
|
|
247
|
+
});
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
const onChangeHourStart = (value: number) => {
|
|
252
|
+
const innerHours = value ? Math.floor(value / (60 * 60 * 1000)) : 0;
|
|
253
|
+
const innerMinutes = value ? Math.floor((value % (60 * 60 * 1000)) / (60 * 1000)) : 0;
|
|
254
|
+
if (realTime.value) {
|
|
255
|
+
const t = {
|
|
256
|
+
startDay: realTime.value.startDay,
|
|
257
|
+
startHour: innerHours,
|
|
258
|
+
startMinute: innerMinutes,
|
|
259
|
+
endDay: realTime.value.endDay,
|
|
260
|
+
endHour: realTime.value.endHour,
|
|
261
|
+
endMinute: realTime.value.endMinute
|
|
262
|
+
};
|
|
263
|
+
const newTime = applyOffset(t, true);
|
|
264
|
+
emit("update:modelValue", newTime);
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
emit("update:modelValue", {
|
|
268
|
+
startDay: 0,
|
|
269
|
+
startHour: innerHours,
|
|
270
|
+
startMinute: innerMinutes,
|
|
271
|
+
endDay: 0,
|
|
272
|
+
endHour: 0,
|
|
273
|
+
endMinute: 0
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const onChangeDayEnd = (value: number) => {
|
|
278
|
+
if (value === 7) {
|
|
279
|
+
if (props.modelValue) {
|
|
280
|
+
emit("update:modelValue",
|
|
281
|
+
{
|
|
282
|
+
startDay: 7,
|
|
283
|
+
startHour: props.modelValue.startHour,
|
|
284
|
+
startMinute: props.modelValue.startMinute,
|
|
285
|
+
endDay: 7,
|
|
286
|
+
endHour: props.modelValue.endHour,
|
|
287
|
+
endMinute: props.modelValue.endMinute
|
|
288
|
+
}
|
|
289
|
+
);
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
emit("update:modelValue",
|
|
293
|
+
{
|
|
294
|
+
startDay: 7,
|
|
295
|
+
startHour: 0,
|
|
296
|
+
startMinute: 0,
|
|
297
|
+
endDay: 7,
|
|
298
|
+
endHour: 0,
|
|
299
|
+
endMinute: 0
|
|
300
|
+
}
|
|
301
|
+
);
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
if (props.modelValue) {
|
|
305
|
+
if (props.modelValue.startDay === 7) {
|
|
306
|
+
emit("update:modelValue",{
|
|
307
|
+
startDay: value,
|
|
308
|
+
startHour: props.modelValue.startHour,
|
|
309
|
+
startMinute: props.modelValue.startMinute,
|
|
310
|
+
endDay: value,
|
|
311
|
+
endHour: props.modelValue.endHour,
|
|
312
|
+
endMinute: props.modelValue.endMinute
|
|
313
|
+
});
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
const t = applyOffset({
|
|
317
|
+
startDay: props.modelValue.startDay,
|
|
318
|
+
startHour: props.modelValue.startHour,
|
|
319
|
+
startMinute: props.modelValue.startMinute,
|
|
320
|
+
endDay: value,
|
|
321
|
+
endHour: props.modelValue.endHour,
|
|
322
|
+
endMinute: props.modelValue.endMinute
|
|
323
|
+
}, true);
|
|
324
|
+
emit("update:modelValue", t);
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
emit("update:modelValue",{
|
|
328
|
+
startDay: value,
|
|
329
|
+
startHour: 0,
|
|
330
|
+
startMinute: 0,
|
|
331
|
+
endDay: value,
|
|
332
|
+
endHour: 0,
|
|
333
|
+
endMinute: 0
|
|
334
|
+
});
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
const onChangeHourEnd = (value: number) => {
|
|
338
|
+
const innerHours = value ? Math.floor(value / (60 * 60 * 1000)) : 0;
|
|
339
|
+
const innerMinutes = value ? Math.floor((value % (60 * 60 * 1000)) / (60 * 1000)) : 0;
|
|
340
|
+
if (realTime.value) {
|
|
341
|
+
const t = {
|
|
342
|
+
startDay: realTime.value.startDay,
|
|
343
|
+
startHour: realTime.value.startHour,
|
|
344
|
+
startMinute: realTime.value.startMinute,
|
|
345
|
+
endDay: realTime.value.endDay,
|
|
346
|
+
endHour: innerHours,
|
|
347
|
+
endMinute: innerMinutes
|
|
348
|
+
};
|
|
349
|
+
const newTime = applyOffset(t, true);
|
|
350
|
+
|
|
351
|
+
emit("update:modelValue", newTime);
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
emit("update:modelValue",{
|
|
355
|
+
startDay: 0,
|
|
356
|
+
startHour: 0,
|
|
357
|
+
startMinute: 0,
|
|
358
|
+
endDay: 0,
|
|
359
|
+
endHour: innerHours,
|
|
360
|
+
endMinute: innerMinutes
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
return {
|
|
365
|
+
daysObject,
|
|
366
|
+
validateOn,
|
|
367
|
+
ColorEnum,
|
|
368
|
+
startTime,
|
|
369
|
+
realTime,
|
|
370
|
+
messages,
|
|
371
|
+
endTime,
|
|
372
|
+
style,
|
|
373
|
+
onChangeHourStart,
|
|
374
|
+
onChangeDayStart,
|
|
375
|
+
onChangeHourEnd,
|
|
376
|
+
onChangeDayEnd
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
</script>
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dative-gpi/foundation-shared-components",
|
|
3
3
|
"sideEffects": false,
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.70",
|
|
5
5
|
"description": "",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
"author": "",
|
|
11
11
|
"license": "ISC",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@dative-gpi/foundation-shared-domain": "1.0.
|
|
14
|
-
"@dative-gpi/foundation-shared-services": "1.0.
|
|
13
|
+
"@dative-gpi/foundation-shared-domain": "1.0.70",
|
|
14
|
+
"@dative-gpi/foundation-shared-services": "1.0.70"
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {
|
|
17
17
|
"@dative-gpi/bones-ui": "^0.0.75",
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"sass": "1.71.1",
|
|
36
36
|
"sass-loader": "13.3.2"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "6ecedd781dfabf0bf696992e85f35d9ce69037b9"
|
|
39
39
|
}
|
package/tools/index.ts
CHANGED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Days } from "@dative-gpi/foundation-shared-domain/enums";
|
|
2
|
+
import { useAppTimeZone } from "@dative-gpi/foundation-shared-services/composables";
|
|
3
|
+
|
|
4
|
+
const { getUserOffset } = useAppTimeZone();
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
export const applyOffset = (r: DateTimeRange, negative: boolean) => {
|
|
8
|
+
|
|
9
|
+
const range: DateTimeRange = r;
|
|
10
|
+
|
|
11
|
+
if (negative) {
|
|
12
|
+
range.startHour = r.startHour - getUserOffset() / 1000 / 60 / 60;
|
|
13
|
+
range.endHour = r.endHour - getUserOffset() / 1000 / 60 / 60;
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
range.startHour = r.startHour + getUserOffset() / 1000 / 60 / 60;
|
|
17
|
+
range.endHour = r.endHour + getUserOffset() / 1000 / 60 / 60;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
if (![Days.AllDays].includes(r.startDay)) {
|
|
22
|
+
if (r.startHour > 23) {
|
|
23
|
+
|
|
24
|
+
range.startDay = (r.startDay + 1) % 7;
|
|
25
|
+
range.startHour -= 24;
|
|
26
|
+
}
|
|
27
|
+
else if (r.startHour < 0) {
|
|
28
|
+
range.startDay = (r.startDay + 6) % 7;
|
|
29
|
+
range.startHour += 24;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (r.endHour > 23) {
|
|
33
|
+
range.endDay = (r.endDay + 1) % 7;
|
|
34
|
+
range.endHour -= 24;
|
|
35
|
+
}
|
|
36
|
+
else if (r.endHour < 0) {
|
|
37
|
+
range.endDay = (r.endDay + 6) % 7;
|
|
38
|
+
range.endHour += 24;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
if (r.startHour > 23) {
|
|
43
|
+
range.startHour -= 24;
|
|
44
|
+
}
|
|
45
|
+
else if (r.startHour < 0) {
|
|
46
|
+
range.startHour += 24;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (r.endHour > 23) {
|
|
50
|
+
range.endHour -= 24;
|
|
51
|
+
}
|
|
52
|
+
else if (r.endHour < 0) {
|
|
53
|
+
range.endHour += 24;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return range;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface DateTimeRange {
|
|
60
|
+
startDay: Days;
|
|
61
|
+
startHour: number;
|
|
62
|
+
startMinute: number;
|
|
63
|
+
endDay: Days;
|
|
64
|
+
endHour: number;
|
|
65
|
+
endMinute: number;
|
|
66
|
+
}
|