DataTimingRange.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 {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. const { setDirty } = useFormStore()
  24. const accessProfileStore = useAccessProfileStore()
  25. const { em } = useEntityManager()
  26. const pageStore = usePageStore()
  27. const start = accessProfileStore.historical.dateStart
  28. const end = accessProfileStore.historical.dateEnd
  29. const datesRange: Ref<Array<Date> | null> = ref((start && end) ? [new Date(start), new Date(end)] : null)
  30. const updateDateTimeRange = async (dates: Array<Date>): Promise<any> => {
  31. if (accessProfileStore.id === null) {
  32. throw new Error('Invalid profile id')
  33. }
  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, accessProfileStore.id, {'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 em.refreshProfile()
  49. }
  50. window.location.reload()
  51. }
  52. </script>
  53. <style scoped lang="scss">
  54. .label {
  55. min-width: 150px;
  56. }
  57. </style>