2020-07-11 17:55:47 +00:00
|
|
|
<template>
|
2021-05-24 09:34:48 +00:00
|
|
|
<div>
|
2022-12-11 09:24:04 +00:00
|
|
|
<div class="d-flex justify-content-center">
|
|
|
|
<div>
|
|
|
|
<label for="dateFrom">Start Date</label>
|
|
|
|
<Datepicker
|
|
|
|
id="dateFrom"
|
|
|
|
v-model="dateFrom"
|
|
|
|
:dark="settingsStore.isDarkTheme"
|
|
|
|
:max-date="now"
|
|
|
|
model-type="yyyy-MM-dd"
|
|
|
|
format="yyyy-MM-dd"
|
|
|
|
text-input
|
|
|
|
auto-apply
|
|
|
|
:enable-time-picker="false"
|
|
|
|
></Datepicker>
|
|
|
|
</div>
|
|
|
|
<div class="ms-2">
|
|
|
|
<label for="dateTo">End Date</label>
|
|
|
|
<Datepicker
|
|
|
|
v-model="dateTo"
|
|
|
|
:dark="settingsStore.isDarkTheme"
|
|
|
|
:max-date="now"
|
|
|
|
model-type="yyyy-MM-dd"
|
|
|
|
format="yyyy-MM-dd"
|
|
|
|
text-input
|
|
|
|
auto-apply
|
|
|
|
:enable-time-picker="false"
|
|
|
|
></Datepicker>
|
|
|
|
</div>
|
2021-05-24 09:34:48 +00:00
|
|
|
</div>
|
2022-12-11 09:24:04 +00:00
|
|
|
|
|
|
|
<label class="mt-1 text-start">
|
2021-05-24 09:34:48 +00:00
|
|
|
Timerange: <b>{{ timeRange }}</b>
|
|
|
|
</label>
|
|
|
|
</div>
|
2020-07-11 17:55:47 +00:00
|
|
|
</template>
|
|
|
|
|
2022-12-10 12:39:53 +00:00
|
|
|
<script setup lang="ts">
|
2020-12-05 18:32:37 +00:00
|
|
|
import { dateFromString, dateStringToTimeRange, timestampToDateString } from '@/shared/formatters';
|
2022-12-10 12:39:53 +00:00
|
|
|
import { ref, computed, onMounted, watch } from 'vue';
|
2022-12-11 09:24:04 +00:00
|
|
|
import Datepicker from '@vuepic/vue-datepicker';
|
|
|
|
import '@vuepic/vue-datepicker/dist/main.css';
|
|
|
|
import { useSettingsStore } from '@/stores/settings';
|
|
|
|
|
|
|
|
const settingsStore = useSettingsStore();
|
2020-07-11 17:55:47 +00:00
|
|
|
|
|
|
|
const now = new Date();
|
2023-04-10 16:17:55 +00:00
|
|
|
const dateFrom = ref<string>('');
|
|
|
|
const dateTo = ref<string>('');
|
2020-07-11 17:55:47 +00:00
|
|
|
|
2022-12-10 12:39:53 +00:00
|
|
|
const props = defineProps({
|
|
|
|
modelValue: { required: true, type: String },
|
|
|
|
});
|
|
|
|
const emit = defineEmits(['update:modelValue']);
|
2020-12-05 18:32:37 +00:00
|
|
|
|
2022-12-10 12:39:53 +00:00
|
|
|
const timeRange = computed(() => {
|
|
|
|
if (dateFrom.value !== '' || dateTo.value !== '') {
|
|
|
|
return `${dateStringToTimeRange(dateFrom.value)}-${dateStringToTimeRange(dateTo.value)}`;
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
});
|
2020-07-11 17:55:47 +00:00
|
|
|
|
2022-12-10 12:39:53 +00:00
|
|
|
const updateInput = () => {
|
|
|
|
const tr = props.modelValue.split('-');
|
|
|
|
if (tr[0]) {
|
|
|
|
dateFrom.value = timestampToDateString(dateFromString(tr[0], 'yyyyMMdd'));
|
2023-04-10 16:17:55 +00:00
|
|
|
} else {
|
|
|
|
dateFrom.value = '';
|
2022-12-10 12:39:53 +00:00
|
|
|
}
|
|
|
|
if (tr.length > 1 && tr[1]) {
|
|
|
|
dateTo.value = timestampToDateString(dateFromString(tr[1], 'yyyyMMdd'));
|
2023-04-10 16:17:55 +00:00
|
|
|
} else {
|
|
|
|
dateTo.value = '';
|
2022-12-10 12:39:53 +00:00
|
|
|
}
|
2023-04-10 16:17:55 +00:00
|
|
|
emit('update:modelValue', timeRange.value);
|
2022-12-10 12:39:53 +00:00
|
|
|
};
|
2021-07-04 14:25:41 +00:00
|
|
|
|
2022-12-10 12:39:53 +00:00
|
|
|
watch(
|
|
|
|
() => timeRange.value,
|
2023-04-10 16:17:55 +00:00
|
|
|
() => emit('update:modelValue', timeRange.value),
|
|
|
|
);
|
|
|
|
watch(
|
|
|
|
() => props.modelValue,
|
|
|
|
() => {
|
|
|
|
updateInput();
|
|
|
|
},
|
2022-12-10 12:39:53 +00:00
|
|
|
);
|
2020-07-11 17:55:47 +00:00
|
|
|
|
2022-12-10 12:39:53 +00:00
|
|
|
onMounted(() => {
|
|
|
|
if (!props.modelValue) {
|
|
|
|
dateFrom.value = timestampToDateString(new Date(now.getFullYear(), now.getMonth() - 1, 1));
|
|
|
|
} else {
|
|
|
|
updateInput();
|
|
|
|
}
|
|
|
|
emit('update:modelValue', timeRange.value);
|
2022-04-21 04:37:57 +00:00
|
|
|
});
|
2020-07-11 17:55:47 +00:00
|
|
|
</script>
|
|
|
|
|
2021-05-24 09:03:36 +00:00
|
|
|
<style scoped></style>
|