DataTiming.vue 2.8 KB

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