DataTimingRange.vue 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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(
  32. start && end ? [new Date(start), new Date(end)] : null,
  33. )
  34. const updateDateTimeRange = async (dates: Array<Date>): Promise<any> => {
  35. const accessId = accessProfileStore.currentAccessId
  36. datesRange.value = dates
  37. if (
  38. datesRange.value !== null &&
  39. datesRange.value[0] !== null &&
  40. datesRange.value[1] !== null
  41. ) {
  42. accessProfileStore.setHistoricalRange(
  43. DateUtils.formatIsoShortDate(datesRange.value[0]),
  44. DateUtils.formatIsoShortDate(datesRange.value[1]),
  45. )
  46. } else {
  47. accessProfileStore.setHistorical(false, true, false)
  48. }
  49. setDirty(false)
  50. pageStore.loading = true
  51. await em.patch(Access, accessId, {
  52. historical: accessProfileStore.historical,
  53. })
  54. if (process.server) {
  55. // Force profile refresh server side to avoid a bug where server and client stores diverge on profile refresh
  56. await refreshProfile()
  57. }
  58. window.location.reload()
  59. }
  60. </script>
  61. <style scoped lang="scss">
  62. .label {
  63. min-width: 150px;
  64. }
  65. </style>