DataTiming.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <template>
  2. <main class="d-flex align-baseline">
  3. <span v-show="mdAndUp" class="mr-2 font-weight-bold on-neutral"
  4. >{{ $t('display_data') }} :
  5. </span>
  6. <v-btn-toggle
  7. ref="toggle"
  8. :model-value="historicalValue"
  9. density="compact"
  10. :color="color"
  11. multiple
  12. divider
  13. border
  14. :rounded="true"
  15. class="toggle-btn"
  16. @update:model-value="onUpdate"
  17. >
  18. <v-btn
  19. v-for="(choice, index) in historicalChoices"
  20. :key="index"
  21. :value="choice"
  22. max-height="25"
  23. :class="
  24. 'font-weight-normal text-caption ' +
  25. (historicalValue.includes(choice)
  26. ? 'theme-primary'
  27. : 'theme-neutral-soft')
  28. "
  29. >
  30. <!-- TODO: on ne devrait pas avoir besoin du if et de la classe 'btn-selected' dans v-btn, mais à l'heure
  31. qu'il est, le component ne fonctionne pas comme attendu. A revoir quand vuetify 3 sera plus stable -->
  32. {{ $t(choice) }}
  33. </v-btn>
  34. </v-btn-toggle>
  35. </main>
  36. </template>
  37. <script setup lang="ts">
  38. import type { Ref } from 'vue'
  39. import { useDisplay, useTheme } from 'vuetify'
  40. import { useFormStore } from '~/stores/form'
  41. import { useAccessProfileStore } from '~/stores/accessProfile'
  42. import { useEntityManager } from '~/composables/data/useEntityManager'
  43. import Access from '~/models/Access/Access'
  44. import { usePageStore } from '~/stores/page'
  45. import { useRefreshProfile } from '~/composables/data/useRefreshProfile'
  46. // TODO: en v3.0.5, pas de solution documentée pour renseigner directement la couleur dans le template, à revoir
  47. const color = useTheme().current.value.colors.primary
  48. const { setDirty } = useFormStore()
  49. const accessProfileStore = useAccessProfileStore()
  50. const { em } = useEntityManager()
  51. const { mdAndUp } = useDisplay()
  52. const pageStore = usePageStore()
  53. const { refreshProfile } = useRefreshProfile()
  54. const toggle = ref(null)
  55. const historicalChoices: Array<'past' | 'present' | 'future'> = [
  56. 'past',
  57. 'present',
  58. 'future',
  59. ]
  60. const historicalValue: Ref<Array<string>> = ref(
  61. historicalChoices.filter((item) => accessProfileStore.historical[item]),
  62. )
  63. const onUpdate = async (newValue: Array<string>) => {
  64. historicalValue.value = newValue
  65. const accessId = accessProfileStore.currentAccessId
  66. accessProfileStore.setHistorical(
  67. historicalValue.value.includes('past'),
  68. historicalValue.value.includes('present'),
  69. historicalValue.value.includes('future'),
  70. )
  71. setDirty(false)
  72. pageStore.loading = true
  73. await em.patch(Access, accessId, {
  74. historical: accessProfileStore.historical,
  75. })
  76. if (import.meta.server) {
  77. // Force profile refresh server side to avoid a bug where server and client stores diverge on profile refresh
  78. await refreshProfile()
  79. }
  80. window.location.reload()
  81. }
  82. </script>
  83. <style scoped lang="scss">
  84. .v-btn-group {
  85. max-height: 22px;
  86. }
  87. .v-btn {
  88. padding: 0 8px;
  89. }
  90. .v-btn.btn-selected {
  91. background-color: rgb(var(--v-theme-primary)) !important;
  92. }
  93. </style>