adminforth 4.7.5 → 4.8.0
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/dist/modules/styles.js +4 -4
- package/dist/spa/package.json +1 -0
- package/dist/spa/src/afcl/Calendar.vue +211 -0
- package/dist/spa/src/afcl/DateField.vue +257 -0
- package/dist/spa/src/afcl/DatePicker.vue +103 -245
- package/dist/spa/src/afcl/TimeField.vue +52 -0
- package/dist/spa/src/afcl/pickerStyles.ts +25 -0
- package/dist/spa/src/afcl/shadowRoot.ts +1 -2
- package/dist/spa/src/components/ColumnValueInput.vue +9 -7
- package/dist/spa/src/components/ColumnValueInputWrapper.vue +1 -1
- package/dist/spa/src/components/CustomDateRangePicker.vue +47 -165
- package/dist/spa/src/components/Filters.vue +7 -4
- package/dist/spa/src/components/GroupsTable.vue +23 -43
- package/dist/spa/src/components/ShowTable.vue +21 -31
- package/dist/spa/src/utils/dateUtils.ts +33 -21
- package/dist/spa/src/views/CreateEditSkeleton.vue +6 -17
- package/dist/spa/src/views/ShowView.vue +14 -24
- package/dist/spa/tailwind.config.js +1 -1
- package/package.json +1 -1
|
@@ -1,75 +1,34 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div>
|
|
3
|
-
<div
|
|
4
|
-
<
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
</div>
|
|
8
|
-
|
|
9
|
-
<input ref="datepickerStartEl" type="text"
|
|
10
|
-
class="bg-lightDatePickerButtonBackground border border-lightDatePickerButtonBorder text-lightDatePickerButtonText placeholder-lightDatePickerPlaceHolder text-sm rounded-default shadow-customLight focus:outline-none focus:ring-[3px] focus:ring-lightInputFocusRing focus:border-lightInputFocusBorder block w-full px-2.5 py-1.5 leading-5 dark:bg-darkDatePickerButtonBackground dark:border-darkDatePickerButtonBorder dark:placeholder-darkDatePickerPlaceHolder dark:text-darkDatePickerButtonText dark:focus:ring-darkInputFocusRing dark:focus:border-darkInputFocusBorder"
|
|
11
|
-
:placeholder="$t('From')">
|
|
12
|
-
</div>
|
|
13
|
-
|
|
14
|
-
<div class="relative">
|
|
15
|
-
<div class="absolute inset-y-0 end-0 top-0 flex items-center pe-3.5 pointer-events-none">
|
|
16
|
-
<IconCalendar class="w-4 h-4 text-lightDatePickerIcon dark:text-darkDatePickerIcon"/>
|
|
17
|
-
</div>
|
|
18
|
-
|
|
19
|
-
<input ref="datepickerEndEl" type="text"
|
|
20
|
-
class="bg-lightDatePickerButtonBackground border border-lightDatePickerButtonBorder text-lightDatePickerButtonText placeholder-lightDatePickerPlaceHolder text-sm rounded-default shadow-customLight focus:outline-none focus:ring-[3px] focus:ring-lightInputFocusRing focus:border-lightInputFocusBorder block w-full px-2.5 py-1.5 leading-5 dark:bg-darkDatePickerButtonBackground dark:border-darkDatePickerButtonBorder dark:placeholder-darkDatePickerPlaceHolder dark:text-darkDatePickerButtonText dark:focus:ring-darkInputFocusRing dark:focus:border-darkInputFocusBorder"
|
|
21
|
-
:placeholder="$t('To')">
|
|
22
|
-
</div>
|
|
2
|
+
<div class="af-date-range-picker flex flex-col gap-2">
|
|
3
|
+
<div v-if="column.type !== 'time'" class="flex items-center" :class="PICKER_BOX_CLASSES">
|
|
4
|
+
<DateField v-model="startDate" bare class="flex-1 min-w-0 h-full" :placeholder="$t('From')" />
|
|
5
|
+
<IconArrowRight class="w-3.5 h-3.5 shrink-0 text-lightDatePickerIcon dark:text-darkDatePickerIcon rtl:rotate-180" aria-hidden="true" />
|
|
6
|
+
<DateField v-model="endDate" bare class="flex-1 min-w-0 h-full" :placeholder="$t('To')" />
|
|
23
7
|
</div>
|
|
24
8
|
|
|
25
|
-
<div>
|
|
26
|
-
<
|
|
27
|
-
|
|
28
|
-
<div class="relative">
|
|
29
|
-
<div class="absolute inset-y-0 end-0 top-0 flex items-center pe-3.5 pointer-events-none">
|
|
30
|
-
<IconClock class="w-4 h-4 text-lightDatePickerIcon dark:text-darkDatePickerIcon bg-lightDatePickerButtonBackground dark:bg-darkDatePickerButtonBackground"/>
|
|
31
|
-
</div>
|
|
32
|
-
|
|
33
|
-
<input v-model="startTime" type="time" id="start-time"
|
|
34
|
-
class="bg-lightDatePickerButtonBackground border border-lightDatePickerButtonBorder text-lightDatePickerButtonText placeholder-lightDatePickerPlaceHolder text-sm rounded-default shadow-customLight focus:outline-none focus:ring-[3px] focus:ring-lightInputFocusRing focus:border-lightInputFocusBorder block w-full px-2.5 py-1.5 leading-5 dark:bg-darkDatePickerButtonBackground dark:border-darkDatePickerButtonBorder dark:placeholder-darkDatePickerPlaceHolder dark:text-darkDatePickerButtonText dark:focus:ring-darkInputFocusRing dark:focus:border-darkInputFocusBorder"
|
|
35
|
-
value="00:00" required/>
|
|
36
|
-
</div>
|
|
37
|
-
</div>
|
|
38
|
-
|
|
39
|
-
<div>
|
|
40
|
-
<div class="relative">
|
|
41
|
-
<div class="absolute inset-y-0 end-0 top-0 flex items-center pe-3.5 pointer-events-none">
|
|
42
|
-
<IconClock class="w-4 h-4 text-lightDatePickerIcon dark:text-darkDatePickerIcon bg-lightDatePickerButtonBackground dark:bg-darkDatePickerButtonBackground"/>
|
|
43
|
-
</div>
|
|
44
|
-
|
|
45
|
-
<input v-model="endTime" type="time" id="end-time"
|
|
46
|
-
class="bg-lightDatePickerButtonBackground border border-lightDatePickerButtonBorder text-lightDatePickerButtonText placeholder-lightDatePickerPlaceHolder text-sm rounded-default shadow-customLight focus:outline-none focus:ring-[3px] focus:ring-lightInputFocusRing focus:border-lightInputFocusBorder block w-full px-2.5 py-1.5 leading-5 dark:bg-darkDatePickerButtonBackground dark:border-darkDatePickerButtonBorder dark:placeholder-darkDatePickerPlaceHolder dark:text-darkDatePickerButtonText dark:focus:ring-darkInputFocusRing dark:focus:border-darkInputFocusBorder"
|
|
47
|
-
value="00:00" required/>
|
|
48
|
-
</div>
|
|
49
|
-
</div>
|
|
50
|
-
</div>
|
|
51
|
-
|
|
52
|
-
<button type="button"
|
|
53
|
-
class="text-lightPrimary dark:text-darkPrimary text-[13px] font-medium hover:underline p-0 inline-flex items-center gap-0.5 mb-2"
|
|
54
|
-
:class="{hidden: column.type !== 'datetime'}"
|
|
55
|
-
@click="toggleTimeInputs">{{ showTimeInputs ? $t('Hide time') : $t('Show time') }}
|
|
56
|
-
<IconChevronDown class="w-4 h-4" :class="{'rotate-180': showTimeInputs}"/>
|
|
57
|
-
</button>
|
|
9
|
+
<div v-if="showTimeInputs" class="grid grid-cols-2 gap-2">
|
|
10
|
+
<TimeField v-model="startTime" />
|
|
11
|
+
<TimeField v-model="endTime" />
|
|
58
12
|
</div>
|
|
13
|
+
|
|
14
|
+
<button type="button"
|
|
15
|
+
v-if="column.type === 'datetime'"
|
|
16
|
+
class="self-start inline-flex items-center gap-0.5 p-0 rounded-sm text-[13px] font-medium hover:underline focus:outline-none focus-visible:ring-[3px] focus-visible:ring-lightFocusRing dark:focus-visible:ring-darkFocusRing text-lightDatePickerExpandText dark:text-darkDatePickerExpandText"
|
|
17
|
+
@click="showTimeInputs = !showTimeInputs">{{ showTimeInputs ? $t('Hide time') : $t('Show time') }}
|
|
18
|
+
<IconChevronDown class="w-4 h-4" :class="{'rotate-180': showTimeInputs}" aria-hidden="true"/>
|
|
19
|
+
</button>
|
|
59
20
|
</div>
|
|
60
21
|
</template>
|
|
61
22
|
<script setup>
|
|
62
|
-
import {ref, computed,
|
|
23
|
+
import {ref, computed, watch} from 'vue';
|
|
63
24
|
import dayjs from 'dayjs';
|
|
64
|
-
import utc from 'dayjs/plugin/utc';
|
|
65
|
-
|
|
66
|
-
import {useCoreStore} from '@/stores/core';
|
|
67
|
-
import {FLEXIBLE_DATEPICKER_FORMAT} from '@/utils';
|
|
68
25
|
|
|
69
|
-
import {
|
|
26
|
+
import {PICKER_DAY_FORMAT} from '@/utils';
|
|
27
|
+
import DateField from '@/afcl/DateField.vue';
|
|
28
|
+
import TimeField from '@/afcl/TimeField.vue';
|
|
29
|
+
import {PICKER_BOX_CLASSES} from '@/afcl/pickerStyles';
|
|
70
30
|
|
|
71
|
-
|
|
72
|
-
dayjs.extend(utc)
|
|
31
|
+
import { IconArrowRight, IconChevronDown } from '@iconify-prerendered/vue-lucide';
|
|
73
32
|
|
|
74
33
|
const props = defineProps({
|
|
75
34
|
valueStart: {
|
|
@@ -85,20 +44,18 @@ const props = defineProps({
|
|
|
85
44
|
|
|
86
45
|
const emit = defineEmits(['update:valueStart', 'update:valueEnd']);
|
|
87
46
|
|
|
88
|
-
|
|
89
|
-
const
|
|
47
|
+
// a range from the start of a day to its end needs no time, the time fields stay hidden for it
|
|
48
|
+
const DAY_START = '00:00:00';
|
|
49
|
+
const DAY_END = '23:59:59';
|
|
90
50
|
|
|
91
51
|
const showTimeInputs = ref(props.column?.type === 'time');
|
|
92
52
|
|
|
93
|
-
const startDate = ref(
|
|
94
|
-
const endDate = ref(
|
|
53
|
+
const startDate = ref(null);
|
|
54
|
+
const endDate = ref(null);
|
|
95
55
|
|
|
96
56
|
const startTime = ref('');
|
|
97
57
|
const endTime = ref('');
|
|
98
58
|
|
|
99
|
-
const datepickerStartObject = ref('')
|
|
100
|
-
const datepickerEndObject = ref('')
|
|
101
|
-
|
|
102
59
|
const start = computed(() => {
|
|
103
60
|
if (props.column?.type === 'time') {
|
|
104
61
|
return formatTime(startTime.value);
|
|
@@ -136,59 +93,36 @@ const end = computed(() => {
|
|
|
136
93
|
return date.format('YYYY-MM-DD');
|
|
137
94
|
}
|
|
138
95
|
|
|
139
|
-
|
|
140
|
-
date = addTimeToDate(formatTime(endTime.value), date)
|
|
141
|
-
} else {
|
|
142
|
-
date = addTimeToDate('23:59:59', date)
|
|
143
|
-
}
|
|
96
|
+
date = addTimeToDate(endTime.value ? formatTime(endTime.value) : DAY_END, date);
|
|
144
97
|
|
|
145
98
|
return date.utc().toISOString();
|
|
146
99
|
})
|
|
147
100
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
} else if (props.column.type === 'time') {
|
|
153
|
-
startTime.value = props.valueStart;
|
|
154
|
-
} else {
|
|
155
|
-
const date = dayjs(props.valueStart);
|
|
156
|
-
datepickerStartEl.value.value = date.format('DD MMM YYYY');
|
|
157
|
-
if (date.format('HH:mm') !== '00:00') {
|
|
158
|
-
startTime.value = date.format('HH:mm');
|
|
159
|
-
showTimeInputs.value = true;
|
|
160
|
-
} else {
|
|
161
|
-
startTime.value = '';
|
|
162
|
-
}
|
|
163
|
-
startDate.value = date.toString();
|
|
164
|
-
}
|
|
101
|
+
// the time of a datetime bound for the time field, empty when the bound is the start or the end of its day
|
|
102
|
+
function boundTime(date, dayEdge) {
|
|
103
|
+
return props.column.type === 'datetime' && date.format('HH:mm:ss') !== dayEdge ? date.format('HH:mm') : '';
|
|
104
|
+
}
|
|
165
105
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
106
|
+
// shows a bound of the range from its prop. Each bound follows only its own prop: the other one may still wait
|
|
107
|
+
// in the debounce of the filters, resetting it here would drop it
|
|
108
|
+
function showBound(value, dayEdge, date, time) {
|
|
109
|
+
if (!value) {
|
|
110
|
+
date.value = null;
|
|
111
|
+
time.value = '';
|
|
170
112
|
} else if (props.column.type === 'time') {
|
|
171
|
-
|
|
113
|
+
time.value = value;
|
|
172
114
|
} else {
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
endTime.value = '';
|
|
180
|
-
}
|
|
181
|
-
endDate.value = date.toString();
|
|
115
|
+
const parsed = dayjs(value);
|
|
116
|
+
date.value = parsed.format(PICKER_DAY_FORMAT);
|
|
117
|
+
time.value = boundTime(parsed, dayEdge);
|
|
118
|
+
}
|
|
119
|
+
if (time.value) {
|
|
120
|
+
showTimeInputs.value = true;
|
|
182
121
|
}
|
|
183
122
|
}
|
|
184
123
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
watch(() => [props.valueStart, props.valueEnd], (value) => {
|
|
189
|
-
updateFromProps();
|
|
190
|
-
});
|
|
191
|
-
})
|
|
124
|
+
watch(() => props.valueStart, (value) => showBound(value, DAY_START, startDate, startTime), { immediate: true });
|
|
125
|
+
watch(() => props.valueEnd, (value) => showBound(value, DAY_END, endDate, endTime), { immediate: true });
|
|
192
126
|
|
|
193
127
|
watch(start, () => {
|
|
194
128
|
emit('update:valueStart', start.value)
|
|
@@ -198,45 +132,6 @@ watch(end, () => {
|
|
|
198
132
|
emit('update:valueEnd', end.value)
|
|
199
133
|
})
|
|
200
134
|
|
|
201
|
-
async function initDatepickers() {
|
|
202
|
-
const { default: Datepicker } = await import(
|
|
203
|
-
'flowbite-datepicker/Datepicker'
|
|
204
|
-
);
|
|
205
|
-
|
|
206
|
-
if (!datepickerStartEl.value || !datepickerEndEl.value) {
|
|
207
|
-
return;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
const LS_LANG_KEY = `afLanguage`;
|
|
211
|
-
const options = {format: FLEXIBLE_DATEPICKER_FORMAT, language: localStorage.getItem(LS_LANG_KEY)};
|
|
212
|
-
datepickerStartObject.value = new Datepicker(datepickerStartEl.value, options);
|
|
213
|
-
datepickerEndObject.value = new Datepicker(datepickerEndEl.value, options);
|
|
214
|
-
addChangeDateListener();
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
function addChangeDateListener() {
|
|
218
|
-
datepickerStartEl.value.addEventListener('changeDate', setStartDate)
|
|
219
|
-
datepickerEndEl.value.addEventListener('changeDate', setEndDate)
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
function removeChangeDateListener() {
|
|
223
|
-
datepickerStartEl.value.removeEventListener('changeDate', setStartDate);
|
|
224
|
-
datepickerEndEl.value.removeEventListener('changeDate', setEndDate);
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
function destroyDatepickerElement() {
|
|
228
|
-
datepickerStartObject.value?.destroy?.();
|
|
229
|
-
datepickerEndObject.value?.destroy?.();
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
function setStartDate(event) {
|
|
233
|
-
startDate.value = event.detail.date
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
function setEndDate(event) {
|
|
237
|
-
endDate.value = event.detail.date
|
|
238
|
-
}
|
|
239
|
-
|
|
240
135
|
function formatTime(time) {
|
|
241
136
|
return time.split(':').map(Number).length === 2 ? time + ':00' : time;
|
|
242
137
|
}
|
|
@@ -245,17 +140,4 @@ function addTimeToDate(time, date) {
|
|
|
245
140
|
const [hours, minutes, seconds] = time.split(':').map(Number)
|
|
246
141
|
return date.hour(hours).minute(minutes).second(seconds)
|
|
247
142
|
}
|
|
248
|
-
|
|
249
|
-
const toggleTimeInputs = () => {
|
|
250
|
-
showTimeInputs.value = !showTimeInputs.value
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
onMounted(() => {
|
|
254
|
-
initDatepickers();
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
onBeforeUnmount(() => {
|
|
258
|
-
removeChangeDateListener();
|
|
259
|
-
destroyDatepickerElement();
|
|
260
|
-
})
|
|
261
|
-
</script>
|
|
143
|
+
</script>
|
|
@@ -277,12 +277,15 @@ watch(() => props.show, (show) => {
|
|
|
277
277
|
const onFilterInput = computed(() => {
|
|
278
278
|
if (!props.columns) return {} as Record<string, any>;
|
|
279
279
|
|
|
280
|
-
return props.columns.reduce<Record<string,
|
|
280
|
+
return props.columns.reduce<Record<string, (item: Parameters<typeof setFilterItem>[0]) => void>>((acc, c) => {
|
|
281
|
+
// a debounce per operator: both ends of a date range set within the debounce time must not drop the first one
|
|
282
|
+
const byOperator: Partial<Record<AdminForthFilterOperators, ReturnType<typeof debounce>>> = {};
|
|
281
283
|
return {
|
|
282
284
|
...acc,
|
|
283
|
-
[c.name]:
|
|
284
|
-
|
|
285
|
-
|
|
285
|
+
[c.name]: (item: Parameters<typeof setFilterItem>[0]) => {
|
|
286
|
+
byOperator[item.operator] ??= debounce(setFilterItem, c.filterOptions?.debounceTimeMs || 10);
|
|
287
|
+
byOperator[item.operator]!(item);
|
|
288
|
+
},
|
|
286
289
|
};
|
|
287
290
|
}, {});
|
|
288
291
|
});
|
|
@@ -1,49 +1,36 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div class="rounded-lg shadow-resourseFormShadow dark:shadow-darkResourseFormShadow border border-lightFormBorder bg-lightForm dark:bg-darkForm dark:border-darkFormBorder">
|
|
3
|
-
<div v-if="group.groupName && !group.noTitle" class="
|
|
3
|
+
<div v-if="group.groupName && !group.noTitle" class="px-5 pt-4 pb-1 text-sm font-semibold text-lightFormFieldTextColor dark:text-darkFormFieldTextColor">
|
|
4
4
|
{{ group.groupName }}
|
|
5
5
|
</div>
|
|
6
6
|
<table class="w-full text-sm text-left rtl:text-right text-lightFormFieldTextColor dark:text-darkFormFieldTextColor">
|
|
7
|
-
<
|
|
8
|
-
<
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
<th scope="col" :class="{'rounded-tr-lg': !group.groupName}" class="px-5 py-2.5 font-medium hidden md:table-cell">
|
|
13
|
-
{{ $t('Value') }}
|
|
14
|
-
</th>
|
|
15
|
-
</tr>
|
|
16
|
-
</thead>
|
|
17
|
-
<tbody>
|
|
7
|
+
<colgroup>
|
|
8
|
+
<col class="md:w-56">
|
|
9
|
+
<col>
|
|
10
|
+
</colgroup>
|
|
11
|
+
<tbody v-if="currentValues !== null" class="divide-y divide-lightShowTableBodyBorder dark:divide-darkShowTableBodyBorder">
|
|
18
12
|
<tr
|
|
19
|
-
v-for="
|
|
13
|
+
v-for="column in group.columns"
|
|
20
14
|
:key="column.name"
|
|
21
|
-
|
|
22
|
-
class="bg-lightForm dark:bg-darkForm border-lightFormBorder dark:border-darkFormBorder block md:table-row"
|
|
23
|
-
:class="{ 'border-b': i !== group.columns.length - 1}"
|
|
15
|
+
class="block md:table-row"
|
|
24
16
|
>
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
<
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
<Tooltip v-if="column.required[mode]">
|
|
17
|
+
<!-- top-aligned: the label sits on the first line of a tall value, md:pt-5 centers it on a 34px input -->
|
|
18
|
+
<td class="px-5 pt-3 md:pt-5 pb-0 md:pb-3 block md:table-cell align-top">
|
|
19
|
+
<span class="flex items-center gap-1 text-[13px] leading-[18px] font-medium">
|
|
20
|
+
{{ column.label }}
|
|
21
|
+
<Tooltip v-if="column.required[mode]">
|
|
31
22
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
23
|
+
<IconAsterisk v-if="column.required[mode]" class="w-3 h-3"
|
|
24
|
+
:class="(columnsWithErrors[column.name] && validatingMode && !isValidating) ? 'text-lightInputErrorColor dark:text-darkInputErrorColor' : 'text-lightRequiredIconColor dark:text-darkRequiredIconColor'"
|
|
25
|
+
/>
|
|
35
26
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
</div>
|
|
27
|
+
<template #tooltip>
|
|
28
|
+
{{ $t('Required field') }}
|
|
29
|
+
</template>
|
|
30
|
+
</Tooltip>
|
|
31
|
+
</span>
|
|
42
32
|
</td>
|
|
43
|
-
<td
|
|
44
|
-
class="px-5 py-3 whitespace-pre-wrap relative block md:table-cell"
|
|
45
|
-
:class="{'rounded-br-lg': i === group.columns.length - 1}"
|
|
46
|
-
>
|
|
33
|
+
<td class="px-5 pt-1.5 pb-3 md:pt-3 whitespace-pre-wrap relative block md:table-cell">
|
|
47
34
|
<ColumnValueInputWrapper
|
|
48
35
|
:source="source"
|
|
49
36
|
:column="column"
|
|
@@ -70,10 +57,9 @@
|
|
|
70
57
|
<script setup lang="ts">
|
|
71
58
|
import { IconAsterisk } from '@iconify-prerendered/vue-lucide';
|
|
72
59
|
import { Tooltip } from '@/afcl';
|
|
73
|
-
import { ref,
|
|
60
|
+
import { ref, watch, nextTick, type Ref } from 'vue';
|
|
74
61
|
import { useI18n } from 'vue-i18n';
|
|
75
62
|
import ColumnValueInputWrapper from "@/components/ColumnValueInputWrapper.vue";
|
|
76
|
-
import type { AdminForthResourceColumnInputCommon } from '@/types/Common';
|
|
77
63
|
|
|
78
64
|
const { t } = useI18n();
|
|
79
65
|
|
|
@@ -94,12 +80,6 @@
|
|
|
94
80
|
|
|
95
81
|
const customComponentsInValidity: Ref<Record<string, boolean>> = ref({});
|
|
96
82
|
const customComponentsEmptiness: Ref<Record<string, boolean>> = ref({});
|
|
97
|
-
const allColumnsHaveCustomComponent = computed(() => {
|
|
98
|
-
return props.group.columns.every((column: AdminForthResourceColumnInputCommon) => {
|
|
99
|
-
const componentKey = `${props.source}Row` as keyof typeof column.components;
|
|
100
|
-
return column.components?.[componentKey];
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
83
|
|
|
104
84
|
const emit = defineEmits(['update:customComponentsInValidity', 'update:customComponentsEmptiness']);
|
|
105
85
|
|
|
@@ -1,43 +1,34 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div class="overflow-x-auto overscroll-x-contain shadow-resourseFormShadow dark:shadow-darkResourseFormShadow border border-lightFormBorder dark:border-darkFormBorder"
|
|
2
|
+
<div class="overflow-x-auto overscroll-x-contain shadow-resourseFormShadow dark:shadow-darkResourseFormShadow border border-lightFormBorder dark:border-darkFormBorder bg-lightShowTablesBodyBackground dark:bg-darkShowTablesBodyBackground"
|
|
3
3
|
:class="{'rounded-lg' : isRounded}"
|
|
4
4
|
>
|
|
5
|
-
<div v-if="groupName && !noTitle"
|
|
5
|
+
<div v-if="groupName && !noTitle" class="px-5 pt-4 pb-1 text-sm font-semibold text-lightShowTableHeadingText dark:text-darkShowTableHeadingText">
|
|
6
6
|
{{ groupName }}
|
|
7
7
|
</div>
|
|
8
8
|
<table class="w-full text-sm text-left rtl:text-right text-lightShowTableBodyText dark:text-darkShowTableBodyText table-fixed">
|
|
9
|
-
<
|
|
10
|
-
<
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
<th scope="col" class="px-5 py-2.5 text-xs font-medium hidden md:table-cell">
|
|
15
|
-
{{ $t('Value') }}
|
|
16
|
-
</th>
|
|
17
|
-
</tr>
|
|
18
|
-
</thead>
|
|
19
|
-
<tbody>
|
|
9
|
+
<colgroup>
|
|
10
|
+
<col class="md:w-56">
|
|
11
|
+
<col>
|
|
12
|
+
</colgroup>
|
|
13
|
+
<tbody class="divide-y divide-lightShowTableBodyBorder dark:divide-darkShowTableBodyBorder">
|
|
20
14
|
<tr
|
|
21
|
-
v-for="column in
|
|
15
|
+
v-for="column in visibleColumns"
|
|
22
16
|
:key="column.name"
|
|
23
|
-
class="
|
|
24
|
-
dark:bg-darkShowTablesBodyBackground dark:border-darkShowTableBodyBorder block md:table-row"
|
|
17
|
+
class="block md:table-row"
|
|
25
18
|
>
|
|
26
19
|
<component
|
|
27
|
-
v-if="column.components?.showRow
|
|
20
|
+
v-if="column.components?.showRow"
|
|
28
21
|
:is="getCustomComponent(column.components.showRow)"
|
|
29
22
|
:meta="column.components.showRow.meta"
|
|
30
23
|
:column="column"
|
|
31
24
|
:resource="coreStore.resource"
|
|
32
25
|
:record="coreStore.record"
|
|
33
26
|
/>
|
|
34
|
-
<template v-else
|
|
35
|
-
<td class="px-5
|
|
36
|
-
|
|
37
|
-
{{ column.label }}
|
|
38
|
-
</div>
|
|
27
|
+
<template v-else>
|
|
28
|
+
<td class="px-5 pt-2.5 pb-0 md:pb-2.5 block md:table-cell align-top text-[13px] text-lightInputIconColor dark:text-darkInputIconColor">
|
|
29
|
+
{{ column.label }}
|
|
39
30
|
</td>
|
|
40
|
-
<td class="px-5
|
|
31
|
+
<td class="px-5 pt-1 pb-2.5 md:pt-2.5 block md:table-cell whitespace-pre-wrap" :data-af-column="column.name">
|
|
41
32
|
<component
|
|
42
33
|
v-if="column?.components?.show"
|
|
43
34
|
:is="getCustomComponent(column?.components?.show)"
|
|
@@ -58,14 +49,14 @@
|
|
|
58
49
|
</table>
|
|
59
50
|
</div>
|
|
60
51
|
</template>
|
|
61
|
-
|
|
52
|
+
|
|
62
53
|
<script setup lang="ts">
|
|
63
54
|
import ValueRenderer from '@/components/ValueRenderer.vue';
|
|
64
55
|
import { getCustomComponent, checkShowIf } from '@/utils';
|
|
65
56
|
import { useCoreStore } from '@/stores/core';
|
|
66
57
|
import { computed } from 'vue';
|
|
67
58
|
import type { AdminForthResourceFrontend, AdminForthResourceColumnInputCommon } from '@/types/Common';
|
|
68
|
-
const props = withDefaults(defineProps<{
|
|
59
|
+
const props = withDefaults(defineProps<{
|
|
69
60
|
columns: Array<{
|
|
70
61
|
name: string;
|
|
71
62
|
label?: string;
|
|
@@ -89,11 +80,10 @@
|
|
|
89
80
|
}>(), {
|
|
90
81
|
isRounded: true
|
|
91
82
|
});
|
|
92
|
-
|
|
83
|
+
|
|
93
84
|
const coreStore = useCoreStore();
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
});
|
|
85
|
+
// hidden columns render no row, so the dividers between rows never double up
|
|
86
|
+
const visibleColumns = computed(() => {
|
|
87
|
+
return props.columns.filter(column => checkShowIf(column, props.record, props.resource?.columns || []));
|
|
98
88
|
});
|
|
99
|
-
</script>
|
|
89
|
+
</script>
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import dayjs from 'dayjs';
|
|
2
2
|
import utc from 'dayjs/plugin/utc';
|
|
3
3
|
import timezone from 'dayjs/plugin/timezone';
|
|
4
|
+
import localeData from 'dayjs/plugin/localeData';
|
|
4
5
|
import { useCoreStore } from '../stores/core';
|
|
5
6
|
|
|
6
7
|
dayjs.extend(utc);
|
|
7
8
|
dayjs.extend(timezone);
|
|
9
|
+
dayjs.extend(localeData);
|
|
8
10
|
|
|
9
11
|
export const DEFAULT_DATES_FORMAT = 'YYYY-MM-DD';
|
|
10
12
|
export const DEFAULT_TIME_FORMAT = 'HH:mm:ss';
|
|
@@ -50,8 +52,10 @@ export function formatTime(time: string | null | undefined): string {
|
|
|
50
52
|
return dayjs(`0000-00-00 ${time}`).format(getTimeFormat());
|
|
51
53
|
}
|
|
52
54
|
|
|
53
|
-
/**
|
|
54
|
-
|
|
55
|
+
/** A day picked in a date picker: "2026-10-14", without time and timezone. */
|
|
56
|
+
export const PICKER_DAY_FORMAT = 'YYYY-MM-DD';
|
|
57
|
+
/** A picked day in the field of a date picker, the month is a word so the order of the parts is never ambiguous. */
|
|
58
|
+
const PICKER_DISPLAY_FORMAT = 'DD MMM YYYY';
|
|
55
59
|
|
|
56
60
|
/** A run of letters or a run of digits, so "18Aug2003" and "Jun 23, 2022 ·" both tokenize cleanly. */
|
|
57
61
|
const DATE_TOKEN_RE = /\p{L}+|\p{N}+/gu;
|
|
@@ -68,14 +72,29 @@ const CENTURY_PIVOT = 50;
|
|
|
68
72
|
/** Shortest month abbreviation across locales; single letters would match random words. */
|
|
69
73
|
const MIN_MONTH_NAME_LENGTH = 2;
|
|
70
74
|
|
|
71
|
-
|
|
75
|
+
/**
|
|
76
|
+
* Month names of the active dayjs locale (the i18n plugin switches it), full and short. "D MMMM" gives the form
|
|
77
|
+
* a month takes inside a date, in uk and ru it differs from the standalone one ("14 січня", "січень").
|
|
78
|
+
*/
|
|
79
|
+
function localeMonthNames(): string[][] {
|
|
80
|
+
const months = Array.from({ length: 12 }, (_, month) => dayjs().startOf('year').month(month));
|
|
81
|
+
const dayPrefix = months[0].format('D ');
|
|
82
|
+
return [
|
|
83
|
+
months.map(m => m.format('MMM')),
|
|
84
|
+
months.map(m => m.format('MMMM')),
|
|
85
|
+
months.map(m => m.format('D MMM').slice(dayPrefix.length)),
|
|
86
|
+
months.map(m => m.format('D MMMM').slice(dayPrefix.length)),
|
|
87
|
+
];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function findMonthIndex(name: string): number {
|
|
72
91
|
if (name.length < MIN_MONTH_NAME_LENGTH) {
|
|
73
92
|
return -1;
|
|
74
93
|
}
|
|
75
94
|
const lowered = name.toLowerCase();
|
|
76
95
|
const startsWithToken = (monthName: string) => monthName.toLowerCase().startsWith(lowered);
|
|
77
96
|
// both short and full names, in the active language and in English (pasted dates are often English)
|
|
78
|
-
for (const names of [
|
|
97
|
+
for (const names of [...localeMonthNames(), EN_MONTHS_SHORT, EN_MONTHS]) {
|
|
79
98
|
const index = names.findIndex(startsWithToken);
|
|
80
99
|
if (index >= 0) {
|
|
81
100
|
return index;
|
|
@@ -93,10 +112,10 @@ function normalizeYear(year: number, digits: number): number {
|
|
|
93
112
|
|
|
94
113
|
/**
|
|
95
114
|
* Parses a human-typed or pasted date in whatever order the parts came in:
|
|
96
|
-
* "18 Aug 2003", "Aug 18, 2003", "18.08.2003", "2003-08-18", "Jun 23, 2022 ·".
|
|
97
|
-
* Returns
|
|
115
|
+
* "18 Aug 2003", "Aug 18, 2003", "18.08.2003", "2003-08-18", "Jun 23, 2022 ·", "14 січня".
|
|
116
|
+
* Returns the day in PICKER_DAY_FORMAT, or null when the string is not a date.
|
|
98
117
|
*/
|
|
99
|
-
export function parseFlexibleDate(dateStr: string
|
|
118
|
+
export function parseFlexibleDate(dateStr: string): string | null {
|
|
100
119
|
const tokens = dateStr.replace(TIME_PART_RE, ' ').match(DATE_TOKEN_RE) || [];
|
|
101
120
|
|
|
102
121
|
let month = -1;
|
|
@@ -105,7 +124,7 @@ export function parseFlexibleDate(dateStr: string, locale: DatepickerLocale): nu
|
|
|
105
124
|
if (DIGITS_RE.test(token)) {
|
|
106
125
|
numbers.push({ value: parseInt(token, 10), digits: token.length });
|
|
107
126
|
} else if (month < 0) {
|
|
108
|
-
month = findMonthIndex(token
|
|
127
|
+
month = findMonthIndex(token);
|
|
109
128
|
}
|
|
110
129
|
}
|
|
111
130
|
|
|
@@ -128,7 +147,7 @@ export function parseFlexibleDate(dateStr: string, locale: DatepickerLocale): nu
|
|
|
128
147
|
day = numbers.shift()!.value;
|
|
129
148
|
month = new Date().getMonth();
|
|
130
149
|
} else {
|
|
131
|
-
return
|
|
150
|
+
return null;
|
|
132
151
|
}
|
|
133
152
|
|
|
134
153
|
const leftover = numbers.shift();
|
|
@@ -141,17 +160,10 @@ export function parseFlexibleDate(dateStr: string, locale: DatepickerLocale): nu
|
|
|
141
160
|
const date = new Date(year, month, day);
|
|
142
161
|
date.setFullYear(year);
|
|
143
162
|
// rejects impossible dates like "31 Feb" instead of silently rolling them over
|
|
144
|
-
return date.getMonth() === month && date.getDate() === day ? date.
|
|
163
|
+
return date.getMonth() === month && date.getDate() === day ? dayjs(date).format(PICKER_DAY_FORMAT) : null;
|
|
145
164
|
}
|
|
146
165
|
|
|
147
|
-
/**
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
toDisplay(date: Date, format: unknown, locale: DatepickerLocale): string {
|
|
152
|
-
return `${String(date.getDate()).padStart(2, '0')} ${locale.monthsShort[date.getMonth()]} ${date.getFullYear()}`;
|
|
153
|
-
},
|
|
154
|
-
toValue(dateStr: string, format: unknown, locale: DatepickerLocale): number {
|
|
155
|
-
return parseFlexibleDate(dateStr, locale);
|
|
156
|
-
},
|
|
157
|
-
};
|
|
166
|
+
/** A picked day as the field of a date picker shows it: "14 Oct 2026", month names in the active language. */
|
|
167
|
+
export function formatPickerDay(day: string): string {
|
|
168
|
+
return dayjs(day).format(PICKER_DISPLAY_FORMAT);
|
|
169
|
+
}
|
|
@@ -1,34 +1,23 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div class="w-full mt-[36px]">
|
|
3
|
-
<div class="w-full border dark:border-darkFormBorder border-lightFormBorder rounded-lg overflow-hidden shadow-resourseFormShadow dark:shadow-darkResourseFormShadow bg-lightForm dark:bg-darkForm">
|
|
4
|
-
|
|
5
|
-
<div class="flex px-5 items-center border-b border-lightFormBorder dark:border-darkFormBorder bg-lightFormHeading dark:bg-darkFormHeading h-[40px]">
|
|
6
|
-
<div class="w-[208px] flex-shrink-0 pr-6 text-xs text-lightListTableHeadingText uppercase dark:text-darkListTableHeadingText font-bold">
|
|
7
|
-
{{ $t('Field') }}
|
|
8
|
-
</div>
|
|
9
|
-
<div class="flex-1 text-xs text-lightListTableHeadingText uppercase dark:text-darkListTableHeadingText font-bold">
|
|
10
|
-
{{ $t('Value') }}
|
|
11
|
-
</div>
|
|
12
|
-
</div>
|
|
13
|
-
|
|
3
|
+
<div class="w-full border dark:border-darkFormBorder border-lightFormBorder rounded-lg overflow-hidden shadow-resourseFormShadow dark:shadow-darkResourseFormShadow bg-lightForm dark:bg-darkForm divide-y divide-lightShowTableBodyBorder dark:divide-darkShowTableBodyBorder">
|
|
14
4
|
<div
|
|
15
5
|
v-for="i in 10"
|
|
16
6
|
:key="i"
|
|
17
|
-
class="flex items-center
|
|
7
|
+
class="flex items-center h-[58px]"
|
|
18
8
|
>
|
|
19
|
-
<div class="w-
|
|
9
|
+
<div class="w-56 flex-shrink-0 px-5 flex items-center">
|
|
20
10
|
<Skeleton class="w-24 h-[10px]" />
|
|
21
11
|
</div>
|
|
22
12
|
|
|
23
|
-
<div class="flex-1 px-
|
|
24
|
-
<Skeleton
|
|
13
|
+
<div class="flex-1 px-5">
|
|
14
|
+
<Skeleton class="h-[10px] w-full max-w-xl" />
|
|
25
15
|
</div>
|
|
26
16
|
</div>
|
|
27
|
-
|
|
28
17
|
</div>
|
|
29
18
|
</div>
|
|
30
19
|
</template>
|
|
31
20
|
|
|
32
21
|
<script setup lang="ts">
|
|
33
22
|
import { Skeleton } from '@/afcl';
|
|
34
|
-
</script>
|
|
23
|
+
</script>
|