0
0
Fork 0

Merge branch 'dev' into 6772_reload_sections

This commit is contained in:
Javier Segarra 2024-03-07 11:44:20 +00:00
commit f017069039
3 changed files with 42 additions and 16 deletions

View File

@ -1,6 +1,7 @@
<script setup> <script setup>
import { computed, ref } from 'vue'; import { computed, ref } from 'vue';
import { toDate } from 'src/filters'; import VnInput from 'components/common/VnInput.vue';
import isValidDate from "filters/isValidDate";
const props = defineProps({ const props = defineProps({
modelValue: { modelValue: {
@ -17,12 +18,25 @@ const props = defineProps({
}, },
}); });
const emit = defineEmits(['update:modelValue']); const emit = defineEmits(['update:modelValue']);
const joinDateAndTime = (date, time) => {
if (!date) {
return null;
}
if (!time) {
return new Date(date).toISOString();
}
const [year, month, day] = date.split('/');
return new Date(`${year}-${month}-${day}T${time}`).toISOString();
};
const time = computed(() => (props.modelValue ? props.modelValue.split('T')?.[1] : null));
const value = computed({ const value = computed({
get() { get() {
return props.modelValue; return props.modelValue;
}, },
set(value) { set(value) {
emit('update:modelValue', value ? new Date(value).toISOString() : null); emit('update:modelValue', joinDateAndTime(value, time.value));
}, },
}); });
@ -40,6 +54,16 @@ const formatDate = (dateString) => {
date.getDate() date.getDate()
)}`; )}`;
}; };
const displayDate = (dateString) => {
if (!dateString || !isValidDate(dateString)) {
return '';
}
return new Date(dateString).toLocaleDateString([], {
year: 'numeric',
month: '2-digit',
day: '2-digit',
});
};
const styleAttrs = computed(() => { const styleAttrs = computed(() => {
return props.isOutlined return props.isOutlined
@ -53,12 +77,12 @@ const styleAttrs = computed(() => {
</script> </script>
<template> <template>
<QInput <VnInput
class="vn-input-date" class="vn-input-date"
rounded :model-value="displayDate(value)"
readonly
:model-value="toDate(value)"
v-bind="{ ...$attrs, ...styleAttrs }" v-bind="{ ...$attrs, ...styleAttrs }"
readonly
@click="isPopupOpen = true"
> >
<template #append> <template #append>
<QIcon name="event" class="cursor-pointer"> <QIcon name="event" class="cursor-pointer">
@ -76,7 +100,7 @@ const styleAttrs = computed(() => {
</QPopupProxy> </QPopupProxy>
</QIcon> </QIcon>
</template> </template>
</QInput> </VnInput>
</template> </template>
<style lang="scss"> <style lang="scss">

View File

@ -1,8 +1,8 @@
<script setup> <script setup>
import { computed, ref } from 'vue'; import { computed, ref } from 'vue';
import { toHour } from 'src/filters';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import isValidDate from 'filters/isValidDate'; import isValidDate from 'filters/isValidDate';
import VnInput from "components/common/VnInput.vue";
const props = defineProps({ const props = defineProps({
modelValue: { modelValue: {
@ -26,8 +26,8 @@ const value = computed({
}, },
set(value) { set(value) {
const [hours, minutes] = value.split(':'); const [hours, minutes] = value.split(':');
const date = new Date(); const date = new Date(props.modelValue);
date.setUTCHours( date.setHours(
Number.parseInt(hours) || 0, Number.parseInt(hours) || 0,
Number.parseInt(minutes) || 0, Number.parseInt(minutes) || 0,
0, 0,
@ -37,6 +37,7 @@ const value = computed({
}, },
}); });
const isPopupOpen = ref(false);
const onDateUpdate = (date) => { const onDateUpdate = (date) => {
internalValue.value = date; internalValue.value = date;
}; };
@ -45,7 +46,7 @@ const save = () => {
value.value = internalValue.value; value.value = internalValue.value;
}; };
const formatTime = (dateString) => { const formatTime = (dateString) => {
if (!isValidDate(dateString)) { if (!dateString || !isValidDate(dateString)) {
return ''; return '';
} }
@ -70,16 +71,17 @@ const styleAttrs = computed(() => {
</script> </script>
<template> <template>
<QInput <VnInput
class="vn-input-time" class="vn-input-time"
rounded
readonly readonly
:model-value="toHour(value)" :model-value="formatTime(value)"
v-bind="{ ...$attrs, ...styleAttrs }" v-bind="{ ...$attrs, ...styleAttrs }"
@click="isPopupOpen = true"
> >
<template #append> <template #append>
<QIcon name="event" class="cursor-pointer"> <QIcon name="event" class="cursor-pointer">
<QPopupProxy <QPopupProxy
v-model="isPopupOpen"
cover cover
transition-show="scale" transition-show="scale"
transition-hide="scale" transition-hide="scale"
@ -109,7 +111,7 @@ const styleAttrs = computed(() => {
</QPopupProxy> </QPopupProxy>
</QIcon> </QIcon>
</template> </template>
</QInput> </VnInput>
</template> </template>
<style lang="scss"> <style lang="scss">

View File

@ -142,7 +142,7 @@ watch(props, async () => {
display: flex; display: flex;
margin-bottom: 9px; margin-bottom: 9px;
& .q-checkbox__label { & .q-checkbox__label {
margin-left: 25px; margin-left: 31px;
color: var(--vn-text); color: var(--vn-text);
} }
& .q-checkbox__inner { & .q-checkbox__inner {