@mapomodule/uikit 1.0.0-alpha.40 → 1.0.0-alpha.42
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/CHANGELOG.md +36 -0
- package/components/Detail/Detail.vue +479 -427
- package/components/Form/defaults.js +4 -0
- package/components/Form/fields/DateTimeField.vue +282 -0
- package/components/Form/fields/TimeField.vue +137 -0
- package/components/LogoutButton.vue +1 -0
- package/components/MediaManager/MediaEditor.vue +223 -176
- package/components/layout/Sidebar/SidebarListItem.vue +29 -17
- package/package.json +2 -2
- package/translations/en-US.js +2 -1
- package/translations/it-IT.js +2 -1
|
@@ -19,6 +19,8 @@ const components = {
|
|
|
19
19
|
// customs
|
|
20
20
|
wygEditor: () => import("@mapomodule/uikit/components/Form/fields/wygEditor/wygEditor.vue"),
|
|
21
21
|
DateField: () => import("@mapomodule/uikit/components/Form/fields/DateField.vue"),
|
|
22
|
+
TimeField: () => import("@mapomodule/uikit/components/Form/fields/TimeField.vue"),
|
|
23
|
+
DateTimeField: () => import("@mapomodule/uikit/components/Form/fields/DateTimeField.vue"),
|
|
22
24
|
FksField: () => import("@mapomodule/uikit/components/Form/fields/FksField.vue"),
|
|
23
25
|
MediaM2mField: () => import("@mapomodule/uikit/components/Form/fields/MediaM2mField.vue"),
|
|
24
26
|
MediaField: () => import("@mapomodule/uikit/components/Form/fields/MediaField.vue"),
|
|
@@ -33,6 +35,8 @@ const mapping = {
|
|
|
33
35
|
text: components.vTextField,
|
|
34
36
|
select: components.vSelect,
|
|
35
37
|
date: components.DateField,
|
|
38
|
+
time: components.TimeField,
|
|
39
|
+
datetime: components.DateTimeField,
|
|
36
40
|
textarea: components.vTextarea,
|
|
37
41
|
switch: components.vSwitch,
|
|
38
42
|
slider: components.vSlider,
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div>
|
|
3
|
+
<v-menu ref="menu" v-model="menu" :close-on-content-click="false" max-width="580">
|
|
4
|
+
<template v-slot:activator="{ on, attrs }">
|
|
5
|
+
<v-text-field
|
|
6
|
+
:value="textFieldString"
|
|
7
|
+
prepend-inner-icon="mdi-calendar"
|
|
8
|
+
readonly
|
|
9
|
+
v-bind="{ ...$attrs, ...attrs }"
|
|
10
|
+
v-on="readonly ? undefined : on"
|
|
11
|
+
:clearable="!readonly"
|
|
12
|
+
class="rounded-inherit"
|
|
13
|
+
></v-text-field>
|
|
14
|
+
</template>
|
|
15
|
+
<v-card>
|
|
16
|
+
<div class="d-flex flex-nowrap">
|
|
17
|
+
<v-date-picker
|
|
18
|
+
v-model="dateModel"
|
|
19
|
+
:range="range"
|
|
20
|
+
no-title
|
|
21
|
+
v-bind="datePickerAttrs"
|
|
22
|
+
class="rounded-0"
|
|
23
|
+
ref="datePicker"
|
|
24
|
+
>
|
|
25
|
+
</v-date-picker
|
|
26
|
+
><v-time-picker
|
|
27
|
+
v-model="timeModel"
|
|
28
|
+
no-title
|
|
29
|
+
v-bind="timePickerAttrs"
|
|
30
|
+
ref="timePicker"
|
|
31
|
+
class="rounded-0"
|
|
32
|
+
>
|
|
33
|
+
</v-time-picker>
|
|
34
|
+
</div>
|
|
35
|
+
<v-card-actions class="justify-center">
|
|
36
|
+
<input
|
|
37
|
+
v-model="startRawDateTime"
|
|
38
|
+
type="datetime-local"
|
|
39
|
+
class="primary--text text-h6 raw-input"
|
|
40
|
+
ref="startRawInput"
|
|
41
|
+
autofocus
|
|
42
|
+
@click="disableCalendar"
|
|
43
|
+
@keydown="disableCalendar"
|
|
44
|
+
/>
|
|
45
|
+
<v-divider class="mx-4" v-if="range"></v-divider>
|
|
46
|
+
<input
|
|
47
|
+
v-if="range"
|
|
48
|
+
:disabled="!startDateTime"
|
|
49
|
+
v-model="endRawDateTime"
|
|
50
|
+
type="datetime-local"
|
|
51
|
+
class="primary--text text-h6 raw-input"
|
|
52
|
+
ref="endRawInput"
|
|
53
|
+
autofocus
|
|
54
|
+
@click="disableCalendar"
|
|
55
|
+
@keydown="disableCalendar"
|
|
56
|
+
/>
|
|
57
|
+
</v-card-actions>
|
|
58
|
+
</v-card>
|
|
59
|
+
</v-menu>
|
|
60
|
+
</div>
|
|
61
|
+
</template>
|
|
62
|
+
|
|
63
|
+
<style scoped>
|
|
64
|
+
.rounded-inherit {
|
|
65
|
+
border-radius: inherit;
|
|
66
|
+
}
|
|
67
|
+
.raw-input {
|
|
68
|
+
outline: none;
|
|
69
|
+
}
|
|
70
|
+
</style>
|
|
71
|
+
|
|
72
|
+
<script>
|
|
73
|
+
import dateFormat from "dateformat";
|
|
74
|
+
/**
|
|
75
|
+
* This component is used to edit a datetime in iso format. It is a combination of "v-text-field", "v-date-picker" and "v-time-picker".
|
|
76
|
+
* All dates are emitted using UTC timezone.
|
|
77
|
+
*/
|
|
78
|
+
export default {
|
|
79
|
+
name: "DateTimeField",
|
|
80
|
+
data() {
|
|
81
|
+
return {
|
|
82
|
+
startDateTime: null,
|
|
83
|
+
endDateTime: null,
|
|
84
|
+
menu: null,
|
|
85
|
+
isStartFocused: true,
|
|
86
|
+
focusinFunc: () => {
|
|
87
|
+
this.isStartFocused = document.activeElement !== this.$refs.endRawInput;
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
},
|
|
91
|
+
props: {
|
|
92
|
+
// V-model property. Is the date to be modified. It can be also array in case of date range.
|
|
93
|
+
value: {
|
|
94
|
+
// `String|Array`
|
|
95
|
+
type: String | Array,
|
|
96
|
+
},
|
|
97
|
+
// Determines if we need to work with date ranges.
|
|
98
|
+
range: {
|
|
99
|
+
type: Boolean,
|
|
100
|
+
default: false,
|
|
101
|
+
},
|
|
102
|
+
// This set the component status to readonly, stopping the user interaction.
|
|
103
|
+
readonly: {
|
|
104
|
+
type: Boolean,
|
|
105
|
+
default: false,
|
|
106
|
+
},
|
|
107
|
+
datePickerAttrs: {
|
|
108
|
+
type: Object,
|
|
109
|
+
default: () => {},
|
|
110
|
+
},
|
|
111
|
+
timePickerAttrs: {
|
|
112
|
+
type: Object,
|
|
113
|
+
default: () => {},
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
watch: {
|
|
117
|
+
value(val) {
|
|
118
|
+
this.setupValue();
|
|
119
|
+
},
|
|
120
|
+
model(val) {
|
|
121
|
+
// Fired when the v-model changes
|
|
122
|
+
//@arg Emits the date or the date range edited.
|
|
123
|
+
this.$emit("input", val);
|
|
124
|
+
},
|
|
125
|
+
menu(val) {
|
|
126
|
+
if (val)
|
|
127
|
+
setTimeout(() => {
|
|
128
|
+
this.$refs.startRawInput?.focus();
|
|
129
|
+
this.$refs.timePicker.selecting = 1;
|
|
130
|
+
});
|
|
131
|
+
},
|
|
132
|
+
isStartFocused(val, old) {
|
|
133
|
+
if (val != old) this.$refs.timePicker.selecting = 1;
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
methods: {
|
|
137
|
+
disableCalendar(evt) {
|
|
138
|
+
if (!evt.keyCode || evt.keyCode == 13) {
|
|
139
|
+
evt.preventDefault();
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
selectTimePickerMethod(oldDateTime, newDateTime) {
|
|
144
|
+
const currentValue = oldDateTime?.split("T").splice(-1)[0]?.split(":") || [];
|
|
145
|
+
const nextValue = newDateTime?.split("T").splice(-1)[0].split(":") || [];
|
|
146
|
+
for (
|
|
147
|
+
let index = 0;
|
|
148
|
+
index < Math.min(currentValue.length, nextValue.length);
|
|
149
|
+
index++
|
|
150
|
+
) {
|
|
151
|
+
if (currentValue[index] != nextValue[index]) {
|
|
152
|
+
this.$refs.timePicker.selecting = index + 1;
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
emit() {
|
|
158
|
+
if (this.range) {
|
|
159
|
+
const start = this.startDateTime && new Date(this.startDateTime);
|
|
160
|
+
const end = this.endDateTime && new Date(this.endDateTime);
|
|
161
|
+
if (start && end && start > end)
|
|
162
|
+
[this.startDateTime, this.endDateTime] = [this.endDateTime, this.startDateTime];
|
|
163
|
+
}
|
|
164
|
+
this.$emit(
|
|
165
|
+
"input",
|
|
166
|
+
this.range
|
|
167
|
+
? [this.startDateTime, this.endDateTime].filter((d) => d)
|
|
168
|
+
: this.startDateTime
|
|
169
|
+
);
|
|
170
|
+
},
|
|
171
|
+
setupValue() {
|
|
172
|
+
const dates =
|
|
173
|
+
(typeof this.value == "string" && this.value
|
|
174
|
+
? this.value.split(",").filter((v) => v)
|
|
175
|
+
: this.value) || [];
|
|
176
|
+
this.startDateTime = dates.length > 0 ? dates[0] : null;
|
|
177
|
+
this.endDateTime = dates.length > 1 ? dates[1] : null;
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
computed: {
|
|
181
|
+
timeModel: {
|
|
182
|
+
get() {
|
|
183
|
+
const time = this.isStartFocused ? this.startDateTime : this.endDateTime;
|
|
184
|
+
if (!time) return null;
|
|
185
|
+
return dateFormat(time, "HH:MM:ss");
|
|
186
|
+
},
|
|
187
|
+
set(value) {
|
|
188
|
+
const mergeTime = (dateTime, time) => {
|
|
189
|
+
let newDateTime = new Date(dateTime);
|
|
190
|
+
const [hours, minutes, seconds] = time.split(":").map((n) => parseInt(n));
|
|
191
|
+
if (hours) newDateTime.setHours(hours);
|
|
192
|
+
if (minutes) newDateTime.setMinutes(minutes);
|
|
193
|
+
if (seconds) newDateTime.setSeconds(seconds);
|
|
194
|
+
return newDateTime.toISOString();
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
if (this.isStartFocused)
|
|
198
|
+
this.startDateTime = mergeTime(this.startDateTime, value);
|
|
199
|
+
else this.endDateTime = mergeTime(this.endDateTime, value);
|
|
200
|
+
this.emit();
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
dateModel: {
|
|
204
|
+
get() {
|
|
205
|
+
const d = [this.startDateTime, this.endDateTime]
|
|
206
|
+
.filter((d) => d)
|
|
207
|
+
.map((d) => dateFormat(d, "yyyy-mm-dd"));
|
|
208
|
+
if (this.range) return d;
|
|
209
|
+
else if (d.length > 0) return d[0];
|
|
210
|
+
return null;
|
|
211
|
+
},
|
|
212
|
+
set(value) {
|
|
213
|
+
const mergeDate = (dateTime, date) => {
|
|
214
|
+
let newDateTime = new Date(dateTime);
|
|
215
|
+
const dateObj = new Date(date);
|
|
216
|
+
newDateTime.setFullYear(dateObj.getFullYear());
|
|
217
|
+
newDateTime.setMonth(dateObj.getMonth());
|
|
218
|
+
newDateTime.setDate(dateObj.getDate());
|
|
219
|
+
return newDateTime.toISOString();
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
if (this.range && value.length == 2) {
|
|
223
|
+
this.endDateTime = mergeDate(this.endDateTime || null, value[1]);
|
|
224
|
+
this.startDateTime = mergeDate(this.startDateTime || null, value[0]);
|
|
225
|
+
setTimeout(() => this.$refs.endRawInput?.focus());
|
|
226
|
+
} else {
|
|
227
|
+
this.endDateTime = null;
|
|
228
|
+
this.startDateTime = mergeDate(
|
|
229
|
+
this.startDateTime || null,
|
|
230
|
+
Array.isArray(value) ? value[0] : value
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
this.emit();
|
|
234
|
+
},
|
|
235
|
+
},
|
|
236
|
+
startRawDateTime: {
|
|
237
|
+
get() {
|
|
238
|
+
if (!this.startDateTime) return null;
|
|
239
|
+
return dateFormat(this.startDateTime, "yyyy-mm-dd'T'HH:MM:ss");
|
|
240
|
+
},
|
|
241
|
+
set(value) {
|
|
242
|
+
const oldDateTime = this.startDateTime;
|
|
243
|
+
if (value) this.startDateTime = new Date(value).toISOString();
|
|
244
|
+
this.selectTimePickerMethod(oldDateTime, this.startDateTime);
|
|
245
|
+
this.emit();
|
|
246
|
+
},
|
|
247
|
+
},
|
|
248
|
+
endRawDateTime: {
|
|
249
|
+
get() {
|
|
250
|
+
if (!this.endDateTime) return null;
|
|
251
|
+
return dateFormat(this.endDateTime, "yyyy-mm-dd'T'HH:MM:ss");
|
|
252
|
+
},
|
|
253
|
+
set(value) {
|
|
254
|
+
const oldDateTime = this.endDateTime;
|
|
255
|
+
if (value) this.endDateTime = new Date(value).toISOString();
|
|
256
|
+
this.selectTimePickerMethod(oldDateTime, this.endDateTime);
|
|
257
|
+
setTimeout(() => this.$refs.endRawInput?.focus());
|
|
258
|
+
this.emit();
|
|
259
|
+
},
|
|
260
|
+
},
|
|
261
|
+
textFieldString() {
|
|
262
|
+
return this.range
|
|
263
|
+
? [this.startDateTime, this.endDateTime]
|
|
264
|
+
.filter((d) => d)
|
|
265
|
+
.map((d) => new Date(d).toLocaleString())
|
|
266
|
+
.join(", ")
|
|
267
|
+
: this.startDateTime && new Date(this.startDateTime).toLocaleString();
|
|
268
|
+
},
|
|
269
|
+
},
|
|
270
|
+
mounted() {
|
|
271
|
+
if (process.client) {
|
|
272
|
+
document.addEventListener("focusin", this.focusinFunc);
|
|
273
|
+
}
|
|
274
|
+
this.setupValue();
|
|
275
|
+
},
|
|
276
|
+
destroyed() {
|
|
277
|
+
if (process.client) {
|
|
278
|
+
document.removeEventListener("focusin", this.focusinFunc);
|
|
279
|
+
}
|
|
280
|
+
},
|
|
281
|
+
};
|
|
282
|
+
</script>
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div>
|
|
3
|
+
<v-menu
|
|
4
|
+
ref="menu"
|
|
5
|
+
v-model="menu"
|
|
6
|
+
:close-on-content-click="false"
|
|
7
|
+
transition="scale-transition"
|
|
8
|
+
offset-y
|
|
9
|
+
min-width="auto"
|
|
10
|
+
>
|
|
11
|
+
<template v-slot:activator="{ on, attrs }">
|
|
12
|
+
<v-text-field
|
|
13
|
+
v-model="localModel"
|
|
14
|
+
prepend-inner-icon="mdi-clock"
|
|
15
|
+
v-bind="{ ...$attrs, ...attrs }"
|
|
16
|
+
v-on="readonly ? undefined : on"
|
|
17
|
+
readonly
|
|
18
|
+
:clearable="!readonly"
|
|
19
|
+
class="rounded-inherit"
|
|
20
|
+
></v-text-field>
|
|
21
|
+
</template>
|
|
22
|
+
<v-time-picker v-model="localModel" no-title v-bind="$attrs" ref="timePicker">
|
|
23
|
+
<div class="raw-input-container">
|
|
24
|
+
<input
|
|
25
|
+
:value="localModel"
|
|
26
|
+
type="time"
|
|
27
|
+
class="primary--text text-h6"
|
|
28
|
+
ref="rawInput"
|
|
29
|
+
@input="setModel"
|
|
30
|
+
autofocus
|
|
31
|
+
v-bind="$attrs"
|
|
32
|
+
/>
|
|
33
|
+
</div>
|
|
34
|
+
</v-time-picker>
|
|
35
|
+
</v-menu>
|
|
36
|
+
</div>
|
|
37
|
+
</template>
|
|
38
|
+
|
|
39
|
+
<style scoped>
|
|
40
|
+
.rounded-inherit {
|
|
41
|
+
border-radius: inherit;
|
|
42
|
+
}
|
|
43
|
+
.raw-input-container {
|
|
44
|
+
width: 100%;
|
|
45
|
+
}
|
|
46
|
+
.raw-input-container input {
|
|
47
|
+
width: 100%;
|
|
48
|
+
text-align: center;
|
|
49
|
+
outline: none;
|
|
50
|
+
}
|
|
51
|
+
</style>
|
|
52
|
+
|
|
53
|
+
<script>
|
|
54
|
+
import dateFormat from "dateformat";
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* This component is used to edit a time in iso format. It is a combination of "v-text-field" and "v-time-picker".
|
|
58
|
+
* Can get time from a full ISO date (as string in UTC timezone) or from string in a HH:MM:ss format.
|
|
59
|
+
*/
|
|
60
|
+
export default {
|
|
61
|
+
name: "TimeField",
|
|
62
|
+
data() {
|
|
63
|
+
return {
|
|
64
|
+
model: null,
|
|
65
|
+
menu: null,
|
|
66
|
+
returnDate: false,
|
|
67
|
+
};
|
|
68
|
+
},
|
|
69
|
+
props: {
|
|
70
|
+
// V-model property. Is the time to be modified.
|
|
71
|
+
value: {
|
|
72
|
+
// `String`
|
|
73
|
+
type: String, // TODO: make it work also with arrays for ranges
|
|
74
|
+
},
|
|
75
|
+
// This set the component status to readonly, stopping the user interaction.
|
|
76
|
+
readonly: {
|
|
77
|
+
type: Boolean,
|
|
78
|
+
default: false,
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
watch: {
|
|
82
|
+
value(val) {
|
|
83
|
+
if (this.model !== val) {
|
|
84
|
+
this.setupValue();
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
model(val) {
|
|
88
|
+
// Fired when the v-model changes
|
|
89
|
+
//@arg Emits the time edited.
|
|
90
|
+
if (this.returnDate) this.$emit("input", `${this.value.split("T")[0]}T${val}Z`);
|
|
91
|
+
else this.$emit("input", val);
|
|
92
|
+
},
|
|
93
|
+
menu(val) {
|
|
94
|
+
if (val)
|
|
95
|
+
setTimeout(() => {
|
|
96
|
+
this.$refs.rawInput.focus();
|
|
97
|
+
});
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
computed: {
|
|
101
|
+
localModel: {
|
|
102
|
+
get() {
|
|
103
|
+
return this.model && dateFormat(`2000-01-01T${this.model}Z`, "HH:MM:ss");
|
|
104
|
+
},
|
|
105
|
+
set(value) {
|
|
106
|
+
this.model = dateFormat(`2000-01-01T${value}`, "UTC:HH:MM:ss");
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
methods: {
|
|
111
|
+
setModel(evt) {
|
|
112
|
+
const model = evt.target.value;
|
|
113
|
+
const currentValue = this.localModel?.split(":") || [];
|
|
114
|
+
const nextValue = model?.split(":") || [];
|
|
115
|
+
for (
|
|
116
|
+
let index = 0;
|
|
117
|
+
index < Math.min(currentValue.length, nextValue.length);
|
|
118
|
+
index++
|
|
119
|
+
) {
|
|
120
|
+
if (currentValue[index] != nextValue[index]) {
|
|
121
|
+
this.$refs.timePicker.selecting = index + 1;
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
this.localModel = model;
|
|
126
|
+
},
|
|
127
|
+
setupValue() {
|
|
128
|
+
const d = new Date(this.value);
|
|
129
|
+
this.returnDate = !isNaN(d);
|
|
130
|
+
this.model = !isNaN(d) ? dateFormat(d, "UTC:HH:MM:ss") : this.value;
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
mounted() {
|
|
134
|
+
this.setupValue();
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
</script>
|