teaching.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <template>
  2. <LayoutContainer>
  3. <LayoutCommonSection>
  4. <h4>{{ $t('configuration') }}</h4>
  5. <UiFormEdition :model="Parameters" :id="organizationProfile.parametersId">
  6. <template #default="{ entity : parameters }">
  7. <div v-if="parameters">
  8. <v-row>
  9. <v-col cols="12">
  10. <UiInputCheckbox
  11. v-model="parameters.showEducationIsACollectivePractice"
  12. field="showEducationIsACollectivePractice"
  13. label="allow_to_configure_teachings_with_played_instrument_choice"
  14. />
  15. </v-col>
  16. </v-row>
  17. </div>
  18. </template>
  19. </UiFormEdition>
  20. </LayoutCommonSection>
  21. <LayoutCommonSection>
  22. <LayoutParametersTable
  23. :items="tableItems"
  24. :title="$t('teaching_cycles')"
  25. :columns-definitions="[
  26. { property: 'originalLabel' },
  27. { property: 'effectiveLabel' },
  28. ]"
  29. identifier="value"
  30. :actions="[TABLE_ACTION.EDIT]"
  31. @edit-clicked="goToCycleEditPage"
  32. />
  33. </LayoutCommonSection>
  34. </LayoutContainer>
  35. </template>
  36. <script setup lang="ts">
  37. import type { ComputedRef } from 'vue'
  38. import Parameters from '~/models/Organization/Parameters'
  39. import { useEntityFetch } from '~/composables/data/useEntityFetch'
  40. import Cycle from '~/models/Education/Cycle'
  41. import { useOrganizationProfileStore } from '~/stores/organizationProfile'
  42. import type { AnyJson } from '~/types/data'
  43. import { useEnumFetch } from '~/composables/data/useEnumFetch'
  44. import { TABLE_ACTION } from '~/types/enum/enums'
  45. import {FETCHING_STATUS} from "~/types/enum/data";
  46. import { type EnumChoice } from '~/types/enum/interface'
  47. definePageMeta({
  48. name: 'parameters_teaching_page',
  49. })
  50. const organizationProfile = useOrganizationProfileStore()
  51. if (organizationProfile.parametersId === null) {
  52. throw new Error('Missing organization parameters id')
  53. }
  54. const { fetchCollection } = useEntityFetch()
  55. const { fetch: fetchEnum } = useEnumFetch()
  56. const { data: cycleEnum, status: enumStatus } = fetchEnum('education_cycle')
  57. const { data: cycles, status: cyclesStatus } = fetchCollection(Cycle)
  58. const pending: ComputedRef<boolean> = computed(
  59. () => enumStatus.value == FETCHING_STATUS.PENDING || cyclesStatus.value == FETCHING_STATUS.PENDING,
  60. )
  61. const orderedCycles: ComputedRef<AnyJson> = computed(() => {
  62. if (pending.value || cycleEnum.value === null || cycles.value === null) {
  63. return {}
  64. }
  65. const orderedCycles: AnyJson = {}
  66. for (const enumItem of cycleEnum.value) {
  67. orderedCycles[enumItem.value] = null
  68. }
  69. for (const cycle of cycles.value.items) {
  70. if (!Object.prototype.hasOwnProperty.call(orderedCycles, cycle.cycleEnum)) {
  71. console.error('Unknown cycle enum : ' + cycle.cycleEnum)
  72. continue
  73. }
  74. orderedCycles[cycle.cycleEnum] = cycle
  75. }
  76. return orderedCycles
  77. })
  78. const tableItems = computed(() => {
  79. return (
  80. cycleEnum.value?.map((item) => {
  81. const effectiveItem: EnumChoice = orderedCycles.value[item.value] ?? item
  82. return {
  83. value: item.value,
  84. originalLabel: item.label,
  85. effectiveLabel: effectiveItem.label,
  86. }
  87. }) || []
  88. )
  89. })
  90. const goToCycleEditPage = (item: object) => {
  91. const cycle = orderedCycles.value[item.value]
  92. navigateTo(`/parameters/cycles/${cycle.id}`)
  93. }
  94. // Nettoyer les données lors du démontage du composant
  95. onBeforeUnmount(() => {
  96. // Nettoyer les références du store si nécessaire
  97. if (process.client) {
  98. clearNuxtData('/^' + Cycle.entity + '_many_/')
  99. useRepo(Cycle).flush()
  100. }
  101. })
  102. </script>
  103. <style scoped lang="scss"></style>