DataTimingRange.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <template>
  2. <main class="d-flex align-center data-timing-range">
  3. <div class="d-flex align-center" style="max-height: 100%">
  4. <span class="label pl-2 mr-2 font-weight-bold on-neutral">
  5. {{ $t('period_choose') }}
  6. </span>
  7. <UiDateRangePicker
  8. :model-value="datesRange"
  9. :max-height="28"
  10. @update:model-value="updateDateTimeRange"
  11. />
  12. </div>
  13. </main>
  14. </template>
  15. <script setup lang="ts">
  16. import type {Ref} from "@vue/reactivity";
  17. import {useAccessProfileStore} from "~/stores/accessProfile";
  18. import {useFormStore} from "~/stores/form";
  19. import {useEntityManager} from "~/composables/data/useEntityManager";
  20. import Access from "~/models/Access/Access";
  21. import DateUtils from "~/services/utils/dateUtils";
  22. import {usePageStore} from "~/stores/page";
  23. import {useRefreshProfile} from "~/composables/data/useRefreshProfile";
  24. const { setDirty } = useFormStore()
  25. const accessProfileStore = useAccessProfileStore()
  26. const { em } = useEntityManager()
  27. const pageStore = usePageStore()
  28. const { refreshProfile } = useRefreshProfile()
  29. const start = accessProfileStore.historical.dateStart
  30. const end = accessProfileStore.historical.dateEnd
  31. const datesRange: Ref<Array<Date> | null> = ref((start && end) ? [new Date(start), new Date(end)] : null)
  32. const updateDateTimeRange = async (dates: Array<Date>): Promise<any> => {
  33. const accessId = accessProfileStore.currentAccessId
  34. datesRange.value = dates
  35. if (datesRange.value !== null && datesRange.value[0] !== null && datesRange.value[1] !== null) {
  36. accessProfileStore.setHistoricalRange(
  37. DateUtils.formatIsoShortDate(datesRange.value[0]),
  38. DateUtils.formatIsoShortDate(datesRange.value[1])
  39. )
  40. } else {
  41. accessProfileStore.setHistorical(false, true, false)
  42. }
  43. setDirty(false)
  44. pageStore.loading = true
  45. await em.patch(Access, accessId, {'historical': accessProfileStore.historical})
  46. if (process.server) {
  47. // Force profile refresh server side to avoid a bug where server and client stores diverge on profile refresh
  48. await refreshProfile()
  49. }
  50. window.location.reload()
  51. }
  52. </script>
  53. <style scoped lang="scss">
  54. .label {
  55. min-width: 150px;
  56. }
  57. </style>