DataTimingRange.vue 2.2 KB

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