DataTiming.vue 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 {$useDirtyForm} from "~/use/form/useDirtyForm";
  26. import {$useMyProfileUpdater} from "~/use/updater/useMyProfileUpdater";
  27. import {WatchStopHandle} from "@vue/composition-api";
  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]])
  58. timeChoice.value.push(parseInt(key))
  59. }
  60. return timeChoice
  61. }
  62. /**
  63. * Transforme le résultat renvoyé par le component v-btn-toggle pour l'enregistrer coté AccessProfile
  64. * @param historical
  65. */
  66. function initHistoricalChoice(historical:Array<any>){
  67. const historicalArray:Array<any> = ['past', 'present', 'future']
  68. const historicalChoice:Array<string> = []
  69. for(const key in historical){
  70. historicalChoice.push(historicalArray[historical[key]])
  71. }
  72. return historicalChoice
  73. }
  74. </script>
  75. <style scoped lang="scss">
  76. .toggle-btn{
  77. z-index: 1;
  78. border-radius: 4px 0px 0px 4px;
  79. }
  80. </style>