DataTiming.vue 2.9 KB

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