DataTiming.vue 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <template>
  2. <main class="d-flex align-baseline">
  3. <span v-show="mdAndUp" class="mr-2 text-ot-dark_grey font-weight-bold">{{ $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="bg-ot-light-grey 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) ? ' btn-selected' : '')"
  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. // TODO: en v3.0.5, pas de solution documentée pour renseigner directement la couleur dans le template, à revoir
  37. const color = useTheme().current.value.colors['ot-green']
  38. const { setDirty } = useFormStore()
  39. const accessProfileStore = useAccessProfileStore()
  40. const { em } = useEntityManager()
  41. const { mdAndUp } = useDisplay()
  42. const toggle = ref(null)
  43. const historicalChoices: Array<'past' | 'present' | 'future'> = ['past', 'present', 'future']
  44. const historicalValue: Ref<Array<string>> = ref(historicalChoices.filter((item) => accessProfileStore.historical[item]))
  45. const onUpdate = async (newValue: Array<string>) => {
  46. historicalValue.value = newValue
  47. if (accessProfileStore.id === null) {
  48. throw new Error('Invalid profile id')
  49. }
  50. accessProfileStore.setHistorical(
  51. historicalValue.value.includes('past'),
  52. historicalValue.value.includes('present'),
  53. historicalValue.value.includes('future')
  54. )
  55. setDirty(false)
  56. await em.patch(
  57. Access,
  58. accessProfileStore.id,
  59. {'historical': accessProfileStore.historical}
  60. )
  61. // TODO: voir si c'est indispensable de reload la page entière
  62. window.location.reload()
  63. }
  64. </script>
  65. <style scoped lang="scss">
  66. .v-btn-group {
  67. max-height: 22px;
  68. }
  69. .v-btn {
  70. padding: 0 8px;
  71. }
  72. .v-btn.btn-selected {
  73. background-color: rgb(var(--v-theme-ot-green)) !important;
  74. }
  75. </style>