DataTimingRange.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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">
  5. {{ $t('period_choose') }}
  6. </span>
  7. <UiInputDatePicker
  8. label="date_choose"
  9. :data="datesRange"
  10. range
  11. dense
  12. single-line
  13. height="22"
  14. @update="updateDateTimeRange"
  15. />
  16. </div>
  17. <v-btn
  18. ref="btn"
  19. class="time-btn ml-1"
  20. height="22" min-height="22" max-height="22"
  21. width="25" min-width="25" max-width="25"
  22. elevation="0"
  23. @click="show = !show"
  24. >
  25. <v-icon icon="fas fa-history" color="ot-grey" class="font-weight-normal" style="font-size: 14px;" />
  26. </v-btn>
  27. <v-tooltip location="bottom" :activator="btn">
  28. <span>{{ $t('history_help') }}</span>
  29. </v-tooltip>
  30. </main>
  31. </template>
  32. <script setup lang="ts">
  33. import {Ref} from "@vue/reactivity";
  34. import {useAccessProfileStore} from "~/stores/accessProfile";
  35. import {useFormStore} from "~/stores/form";
  36. import {WatchStopHandle} from "@vue/runtime-core";
  37. import {useEntityManager} from "~/composables/data/useEntityManager";
  38. import {Access} from "~/models/Access/Access";
  39. const btn: Ref = ref(null)
  40. const show: Ref<boolean> = ref(false)
  41. const { setDirty } = useFormStore()
  42. const accessProfileStore = useAccessProfileStore()
  43. const { em } = useEntityManager()
  44. const datesRange: Ref<Array<string | null | undefined>> = ref([
  45. accessProfileStore.historical.dateStart,
  46. accessProfileStore.historical.dateEnd
  47. ])
  48. const updateDateTimeRange = async (dates:Array<string>): Promise<any> => {
  49. if (accessProfileStore.id === null) {
  50. throw new Error('Invalid profile id')
  51. }
  52. accessProfileStore.setHistoricalRange(dates[0], dates[1])
  53. setDirty(false)
  54. await em.patch(
  55. Access,
  56. accessProfileStore.id,
  57. {'historical': accessProfileStore.historical}
  58. )
  59. window.location.reload()
  60. }
  61. /**
  62. * Emit event when component is hidden / shown
  63. */
  64. const emit = defineEmits(['showDateTimeRange'])
  65. const unwatch: WatchStopHandle = watch(show, (newValue) => {
  66. emit('showDateTimeRange', newValue)
  67. })
  68. onUnmounted(() => {
  69. unwatch()
  70. })
  71. // Show by default if a date range is defined in store
  72. if (accessProfileStore.historical.dateStart || accessProfileStore.historical.dateEnd) {
  73. show.value = true
  74. emit('showDateTimeRange', true)
  75. }
  76. </script>
  77. <style scoped lang="scss">
  78. .v-btn--active .v-icon {
  79. color: #FFF !important;
  80. }
  81. .time-btn {
  82. border-width: 1px 1px 1px 0;
  83. border-style: solid;
  84. border-color: rgba(0, 0, 0, 0.12) !important;
  85. }
  86. .data-timing-range {
  87. max-height: 22px;
  88. :deep(.v-text-field) {
  89. padding-top: 0 !important;
  90. margin-top: 0 !important;
  91. }
  92. :deep(.v-input) {
  93. max-height: 22px;
  94. min-height: 22px;
  95. height: 22px;
  96. }
  97. :deep(.v-icon) {
  98. max-height: 22px;
  99. }
  100. :deep(.v-field__input) {
  101. font-size: 14px;
  102. width: 400px !important;
  103. padding: 0;
  104. max-height: 22px;
  105. min-height: 22px;
  106. height: 22px;
  107. }
  108. :deep(.v-field-label) {
  109. top: 0;
  110. font-size: 14px;
  111. max-height: 22px;
  112. min-height: 22px;
  113. height: 22px;
  114. }
  115. :deep(.v-input__prepend) {
  116. padding-top: 0;
  117. font-size: 14px;
  118. }
  119. }
  120. </style>