DataTiming.vue 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. const accessId = accessProfileStore.currentAccessId
  52. accessProfileStore.setHistorical(
  53. historicalValue.value.includes('past'),
  54. historicalValue.value.includes('present'),
  55. historicalValue.value.includes('future')
  56. )
  57. setDirty(false)
  58. pageStore.loading = true
  59. await em.patch(Access, accessId, {'historical': accessProfileStore.historical})
  60. if (process.server) {
  61. // Force profile refresh server side to avoid a bug where server and client stores diverge on profile refresh
  62. await refreshProfile()
  63. }
  64. window.location.reload()
  65. }
  66. </script>
  67. <style scoped lang="scss">
  68. .v-btn-group {
  69. max-height: 22px;
  70. }
  71. .v-btn {
  72. padding: 0 8px;
  73. }
  74. .v-btn.btn-selected {
  75. background-color: rgb(var(--v-theme-primary)) !important;
  76. }
  77. </style>