DataTimingRange.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. // TODO: voir si c'est indispensable de reload la page entière
  60. window.location.reload()
  61. }
  62. /**
  63. * Emit event when component is hidden / shown
  64. */
  65. const emit = defineEmits(['showDateTimeRange'])
  66. const unwatch: WatchStopHandle = watch(show, (newValue) => {
  67. emit('showDateTimeRange', newValue)
  68. })
  69. onUnmounted(() => {
  70. unwatch()
  71. })
  72. // Show by default if a date range is defined in store
  73. if (accessProfileStore.historical.dateStart || accessProfileStore.historical.dateEnd) {
  74. show.value = true
  75. emit('showDateTimeRange', true)
  76. }
  77. </script>
  78. <style scoped lang="scss">
  79. .v-btn--active .v-icon {
  80. color: #FFF !important;
  81. }
  82. .time-btn {
  83. border-width: 1px 1px 1px 0;
  84. border-style: solid;
  85. border-color: rgba(0, 0, 0, 0.12) !important;
  86. }
  87. .data-timing-range {
  88. max-height: 22px;
  89. :deep(.v-text-field) {
  90. padding-top: 0 !important;
  91. margin-top: 0 !important;
  92. }
  93. :deep(.v-input) {
  94. max-height: 22px;
  95. min-height: 22px;
  96. height: 22px;
  97. }
  98. :deep(.v-icon) {
  99. max-height: 22px;
  100. }
  101. :deep(.v-field__input) {
  102. font-size: 14px;
  103. width: 400px !important;
  104. padding: 0;
  105. max-height: 22px;
  106. min-height: 22px;
  107. height: 22px;
  108. }
  109. :deep(.v-field-label) {
  110. top: 0;
  111. font-size: 14px;
  112. max-height: 22px;
  113. min-height: 22px;
  114. height: 22px;
  115. }
  116. :deep(.v-input__prepend) {
  117. padding-top: 0;
  118. font-size: 14px;
  119. }
  120. }
  121. </style>