DataTiming.vue 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <template>
  2. <main class="d-flex align-baseline">
  3. <span class="mr-2 ot_dark_grey--text font-weight-bold">{{ $t('display_data') }} : </span>
  4. <v-btn-toggle
  5. v-model="historicalBtn"
  6. dense
  7. class="ot_light_grey toggle-btn"
  8. active-class="ot_green ot_white--text"
  9. multiple
  10. >
  11. <v-btn max-height="25" class="font-weight-normal text-caption">
  12. {{ $t('past') }}
  13. </v-btn>
  14. <v-btn max-height="25" class="font-weight-normal text-caption">
  15. {{ $t('present') }}
  16. </v-btn>
  17. <v-btn max-height="25" class="font-weight-normal text-caption">
  18. {{ $t('future') }}
  19. </v-btn>
  20. </v-btn-toggle>
  21. </main>
  22. </template>
  23. <script lang="ts">
  24. import { defineComponent, onUnmounted, ref, useContext, watch, Ref } from '@nuxtjs/composition-api'
  25. import { WatchStopHandle } from '@vue/composition-api'
  26. import { $useDirtyForm } from '~/use/form/useDirtyForm'
  27. import { $useMyProfileUpdater } from '~/use/updater/useMyProfileUpdater'
  28. export default defineComponent({
  29. setup () {
  30. const { store, $dataPersister } = useContext()
  31. const { markFormAsNotDirty } = $useDirtyForm(store)
  32. const { updateMyProfile, setHistorical, historical } = $useMyProfileUpdater(store, $dataPersister)
  33. const historicalBtn:Ref<Array<number>> = initHistoricalBtn(historical.value)
  34. const unwatch:WatchStopHandle = watch(historicalBtn, async (newValue) => {
  35. const historicalChoice:Array<string> = initHistoricalChoice(newValue)
  36. setHistorical(historicalChoice)
  37. markFormAsNotDirty()
  38. await updateMyProfile()
  39. window.location.reload()
  40. })
  41. onUnmounted(() => {
  42. unwatch()
  43. })
  44. return {
  45. historicalBtn
  46. }
  47. }
  48. })
  49. /**
  50. * Prépare le tableau de valeur numéraire devant être passé au component v-btn-toggle
  51. * @param historical
  52. */
  53. function initHistoricalBtn (historical:Array<any>) {
  54. const timeChoice:Ref<Array<number>> = ref(Array<number>())
  55. const historicalArray:Array<any> = ['past', 'present', 'future']
  56. for (const key in historicalArray) {
  57. if (historical[historicalArray[key]]) { timeChoice.value.push(parseInt(key)) }
  58. }
  59. return timeChoice
  60. }
  61. /**
  62. * Transforme le résultat renvoyé par le component v-btn-toggle pour l'enregistrer coté AccessProfile
  63. * @param historical
  64. */
  65. function initHistoricalChoice (historical:Array<any>) {
  66. const historicalArray:Array<any> = ['past', 'present', 'future']
  67. const historicalChoice:Array<string> = []
  68. for (const key in historical) {
  69. historicalChoice.push(historicalArray[historical[key]])
  70. }
  71. return historicalChoice
  72. }
  73. </script>
  74. <style scoped lang="scss">
  75. .toggle-btn{
  76. z-index: 1;
  77. border-radius: 4px 0px 0px 4px;
  78. }
  79. </style>