DataTiming.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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, watch, Ref, WatchStopHandle, useContext} from '@nuxtjs/composition-api'
  25. import {useForm} from "~/composables/form/useForm";
  26. import { useMyProfile } from '~/composables/data/useMyProfile'
  27. export default defineComponent({
  28. setup () {
  29. const { store, $dataPersister } = useContext()
  30. const { markAsNotDirty } = useForm(store)
  31. const { updateMyProfile, setHistorical, historical } = useMyProfile($dataPersister, store)
  32. const historicalBtn: Ref<Array<number>> = initHistoricalBtn(historical.value as Array<any>)
  33. const unwatch: WatchStopHandle = watch(historicalBtn, async (newValue) => {
  34. const historicalChoice: Array<string> = initHistoricalChoice(newValue)
  35. setHistorical(historicalChoice)
  36. markAsNotDirty()
  37. await updateMyProfile()
  38. window.location.reload()
  39. })
  40. onUnmounted(() => {
  41. unwatch()
  42. })
  43. return {
  44. historicalBtn
  45. }
  46. }
  47. })
  48. /**
  49. * Prépare le tableau de valeur numéraire devant être passé au component v-btn-toggle
  50. * @param historical
  51. */
  52. function initHistoricalBtn (historical: Array<any>) {
  53. const timeChoice:Ref<Array<number>> = ref(Array<number>())
  54. const historicalArray:Array<any> = ['past', 'present', 'future']
  55. for (const key in historicalArray) {
  56. if (historical[historicalArray[key]]) { timeChoice.value.push(parseInt(key)) }
  57. }
  58. return timeChoice
  59. }
  60. /**
  61. * Transforme le résultat renvoyé par le component v-btn-toggle pour l'enregistrer coté AccessProfile
  62. * @param historical
  63. */
  64. function initHistoricalChoice (historical:Array<any>) {
  65. const historicalArray:Array<any> = ['past', 'present', 'future']
  66. const historicalChoice:Array<string> = []
  67. for (const key in historical) {
  68. historicalChoice.push(historicalArray[historical[key]])
  69. }
  70. return historicalChoice
  71. }
  72. </script>
  73. <style scoped lang="scss">
  74. .toggle-btn{
  75. z-index: 1;
  76. border-radius: 4px 0px 0px 4px;
  77. }
  78. </style>