DataTiming.vue 2.9 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 type {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. import {useRefreshProfile} from "~/composables/data/useRefreshProfile";
  38. // TODO: en v3.0.5, pas de solution documentée pour renseigner directement la couleur dans le template, à revoir
  39. const color = useTheme().current.value.colors['primary']
  40. const { setDirty } = useFormStore()
  41. const accessProfileStore = useAccessProfileStore()
  42. const { em } = useEntityManager()
  43. const { mdAndUp } = useDisplay()
  44. const pageStore = usePageStore()
  45. const { refreshProfile } = useRefreshProfile()
  46. const toggle = ref(null)
  47. const historicalChoices: Array<'past' | 'present' | 'future'> = ['past', 'present', 'future']
  48. const historicalValue: Ref<Array<string>> = ref(historicalChoices.filter((item) => accessProfileStore.historical[item]))
  49. const onUpdate = async (newValue: Array<string>) => {
  50. historicalValue.value = newValue
  51. if (accessProfileStore.id === null) {
  52. throw new Error('Invalid profile id')
  53. }
  54. accessProfileStore.setHistorical(
  55. historicalValue.value.includes('past'),
  56. historicalValue.value.includes('present'),
  57. historicalValue.value.includes('future')
  58. )
  59. setDirty(false)
  60. pageStore.loading = true
  61. await em.patch(Access, accessProfileStore.id, {'historical': accessProfileStore.historical})
  62. if (process.server) {
  63. // Force profile refresh server side to avoid a bug where server and client stores diverge on profile refresh
  64. await refreshProfile()
  65. }
  66. window.location.reload()
  67. }
  68. </script>
  69. <style scoped lang="scss">
  70. .v-btn-group {
  71. max-height: 22px;
  72. }
  73. .v-btn {
  74. padding: 0 8px;
  75. }
  76. .v-btn.btn-selected {
  77. background-color: rgb(var(--v-theme-primary)) !important;
  78. }
  79. </style>