Skip to content

Commit 63be7c9

Browse files
LRM: add Today button on Date/Time fields
1 parent 9d43c1b commit 63be7c9

2 files changed

Lines changed: 122 additions & 1 deletion

File tree

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<template>
2+
<v-menu v-model="menuOpened" :close-on-content-click="false">
3+
<template #activator="{ props: activatorProps }">
4+
<v-text-field
5+
v-bind="activatorProps"
6+
:model-value="displayValue"
7+
:label="modelValue.layout?.label"
8+
readonly
9+
prepend-inner-icon="mdi-calendar"
10+
/>
11+
</template>
12+
13+
<v-sheet width="328" style="position: relative">
14+
<v-tabs v-model="tab" align-tabs="center">
15+
<v-tab value="date">
16+
<v-icon icon="mdi-calendar" />
17+
</v-tab>
18+
<v-tab value="time" :disabled="!modelValue.data">
19+
<v-icon icon="mdi-clock-outline" />
20+
</v-tab>
21+
</v-tabs>
22+
<v-tabs-window v-model="tab">
23+
<v-tabs-window-item value="date">
24+
<v-date-picker
25+
hide-header
26+
:model-value="localDateObj"
27+
@update:model-value="onDateSelected"
28+
/>
29+
</v-tabs-window-item>
30+
<v-tabs-window-item value="time">
31+
<v-time-picker
32+
hide-title
33+
format="ampm"
34+
density="compact"
35+
class="mt-8"
36+
:model-value="localTimeStr"
37+
@update:model-value="onTimeSelected"
38+
/>
39+
</v-tabs-window-item>
40+
</v-tabs-window>
41+
<v-btn
42+
v-if="tab === 'date'"
43+
size="small"
44+
variant="tonal"
45+
color="primary"
46+
prepend-icon="mdi-clock-check-outline"
47+
style="
48+
position: absolute;
49+
bottom: 10px;
50+
left: 50%;
51+
transform: translateX(-50%);
52+
"
53+
@click="setNow"
54+
>
55+
Aujourd'hui
56+
</v-btn>
57+
</v-sheet>
58+
</v-menu>
59+
</template>
60+
61+
<script setup>
62+
import { ref, computed } from 'vue';
63+
import moment from 'moment';
64+
65+
const props = defineProps({
66+
modelValue: {
67+
type: Object,
68+
required: true,
69+
},
70+
statefulLayout: {
71+
type: Object,
72+
required: true,
73+
},
74+
});
75+
76+
const menuOpened = ref(false);
77+
const tab = ref('date');
78+
79+
const displayValue = computed(() => {
80+
if (!props.modelValue.data) return '';
81+
return moment(props.modelValue.data).format('MMM D, YYYY, h:mm A');
82+
});
83+
84+
const localDateObj = computed(() =>
85+
props.modelValue.data ? new Date(props.modelValue.data) : null
86+
);
87+
88+
const localTimeStr = computed(() =>
89+
props.modelValue.data ? moment(props.modelValue.data).format('HH:mm') : null
90+
);
91+
92+
function onDateSelected(date) {
93+
if (!date) return;
94+
const currentTime = props.modelValue.data
95+
? moment(props.modelValue.data).format('HH:mm:ss')
96+
: moment().format('HH:mm:ss');
97+
const newDateTime = `${moment(date).format('YYYY-MM-DD')}T${currentTime}`;
98+
props.statefulLayout.input(props.modelValue, moment(newDateTime).format());
99+
tab.value = 'time';
100+
}
101+
102+
function onTimeSelected(time) {
103+
if (!time) return;
104+
const datePart = props.modelValue.data
105+
? moment(props.modelValue.data).format('YYYY-MM-DD')
106+
: moment().format('YYYY-MM-DD');
107+
props.statefulLayout.input(
108+
props.modelValue,
109+
moment(`${datePart}T${time}:00`).format()
110+
);
111+
}
112+
113+
function setNow() {
114+
props.statefulLayout.input(props.modelValue, moment().format());
115+
menuOpened.value = false;
116+
}
117+
</script>

web/lrm/client/components/RequestForm.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
</template>
1212

1313
<script setup>
14-
import { ref, computed, toRefs, watch } from 'vue';
14+
import { ref, computed, toRefs, watch, markRaw } from 'vue';
1515
import Vjsf from '@koumoul/vjsf';
1616
import moment from 'moment';
1717
import { useMainStore } from '~/store';
18+
import DateTimePickerWithNow from './DateTimePickerWithNow.vue';
1819
1920
const props = defineProps({
2021
schema: {
@@ -67,6 +68,9 @@ const options = ref({
6768
formats: {
6869
'date-time': (dateTime, _locale) => moment(new Date(dateTime)).format(),
6970
},
71+
nodeComponents: {
72+
'date-time-picker': markRaw(DateTimePickerWithNow),
73+
},
7074
});
7175
7276
const processedSchema = computed(() => {

0 commit comments

Comments
 (0)