DataTimingRange.vue 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <template>
  2. <main class="d-flex align-center data-timing-range">
  3. <div v-if="show" class="d-flex align-center" style="max-height: 100%">
  4. <span class="pl-2 mr-2 font-weight-bold on-neutral" style="min-width: 150px;">
  5. {{ $t('period_choose') }}
  6. </span>
  7. <UiInputDateRangePicker v-model="datesRange" max-height="28" />
  8. </div>
  9. <v-btn
  10. ref="btn"
  11. class="time-btn ml-1 theme-neutral-soft"
  12. height="22" min-height="22" max-height="22"
  13. width="25" min-width="25" max-width="25"
  14. elevation="0"
  15. @click="show = !show"
  16. >
  17. <v-icon icon="fas fa-history" class="font-weight-normal" style="font-size: 14px;" />
  18. </v-btn>
  19. <v-tooltip location="bottom" :activator="btn">
  20. <span>{{ $t('history_help') }}</span>
  21. </v-tooltip>
  22. </main>
  23. </template>
  24. <script setup lang="ts">
  25. import {Ref} from "@vue/reactivity";
  26. import {useAccessProfileStore} from "~/stores/accessProfile";
  27. import {useFormStore} from "~/stores/form";
  28. import {WatchStopHandle} from "@vue/runtime-core";
  29. import {useEntityManager} from "~/composables/data/useEntityManager";
  30. import Access from "~/models/Access/Access";
  31. const btn: Ref = ref(null)
  32. const show: Ref<boolean> = ref(false)
  33. const { setDirty } = useFormStore()
  34. const accessProfileStore = useAccessProfileStore()
  35. const { em } = useEntityManager()
  36. const start = accessProfileStore.historical.dateStart
  37. const end = accessProfileStore.historical.dateStart
  38. const datesRange: Ref<Array<Date | null>> = ref([
  39. start ? new Date(start) : null,
  40. end ? new Date(end) : null
  41. ])
  42. const updateDateTimeRange = async (dates: Array<Date>): Promise<any> => {
  43. if (accessProfileStore.id === null) {
  44. throw new Error('Invalid profile id')
  45. }
  46. accessProfileStore.setHistoricalRange(dates[0], dates[1])
  47. setDirty(false)
  48. await em.patch(
  49. Access,
  50. accessProfileStore.id,
  51. {'historical': accessProfileStore.historical}
  52. )
  53. window.location.reload()
  54. }
  55. /**
  56. * Emit event when component is hidden / shown
  57. */
  58. const emit = defineEmits(['showDateTimeRange'])
  59. const unwatch: WatchStopHandle = watch(show, (newValue) => {
  60. emit('showDateTimeRange', newValue)
  61. })
  62. onUnmounted(() => {
  63. unwatch()
  64. })
  65. // Show by default if a date range is defined in store
  66. if (accessProfileStore.historical.dateStart || accessProfileStore.historical.dateEnd) {
  67. show.value = true
  68. emit('showDateTimeRange', true)
  69. }
  70. </script>
  71. <style scoped lang="scss">
  72. .time-btn {
  73. border-width: 1px 1px 1px 0;
  74. border-style: solid;
  75. }
  76. </style>