teaching.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <template>
  2. <LayoutContainer>
  3. <LayoutCommonSection>
  4. <h4>{{ $t('configuration') }}</h4>
  5. <UiFormEdition :id="organizationProfile.parametersId" :model="Parameters">
  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. definePageMeta({
  47. name: 'parameters_teaching_page',
  48. })
  49. const organizationProfile = useOrganizationProfileStore()
  50. if (organizationProfile.parametersId === null) {
  51. throw new Error('Missing organization parameters id')
  52. }
  53. const { fetchCollection } = useEntityFetch()
  54. const { fetch: fetchEnum } = useEnumFetch()
  55. const { data: cycleEnum, status: enumStatus } = fetchEnum('education_cycle')
  56. const { data: cycles, status: cyclesStatus } = fetchCollection(Cycle)
  57. const pending: ComputedRef<boolean> = computed(
  58. () =>
  59. enumStatus.value == FETCHING_STATUS.PENDING ||
  60. cyclesStatus.value == FETCHING_STATUS.PENDING,
  61. )
  62. const orderedCycles: ComputedRef<AnyJson> = computed(() => {
  63. if (pending.value || cycleEnum.value === null || cycles.value === null) {
  64. return []
  65. }
  66. const orderedCycles: AnyJson = {}
  67. for (const enumItem of cycleEnum.value) {
  68. orderedCycles[enumItem.value] = null
  69. }
  70. for (const cycle of cycles.value.items) {
  71. if (!Object.prototype.hasOwnProperty.call(orderedCycles, cycle.cycleEnum)) {
  72. console.error('Unknown cycle enum : ' + cycle.cycleEnum)
  73. continue
  74. }
  75. orderedCycles[cycle.cycleEnum] = cycle
  76. }
  77. return orderedCycles
  78. })
  79. const tableItems = computed(() => {
  80. return (
  81. cycleEnum.value?.map((item) => {
  82. return {
  83. value: item.value,
  84. originalLabel: item.label,
  85. effectiveLabel: (orderedCycles.value[item.value] ?? item).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 (import.meta.client) {
  98. clearNuxtData('/^' + Cycle.entity + '_many_/')
  99. useRepo(Cycle).flush()
  100. }
  101. })
  102. </script>
  103. <style scoped lang="scss"></style>