teaching.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 { useEnumFetch } from '~/composables/data/useEnumFetch'
  43. import { TABLE_ACTION } from '~/types/enum/enums'
  44. import { FETCHING_STATUS } from "~/types/enum/data";
  45. import type { EnumChoice } from '~/types/interfaces'
  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. () => enumStatus.value == FETCHING_STATUS.PENDING || cyclesStatus.value == FETCHING_STATUS.PENDING,
  59. )
  60. const orderedCycles: ComputedRef<Record<string, Cycle>> = computed(() => {
  61. if (pending.value || cycleEnum.value === null || cycles.value === null) {
  62. return {}
  63. }
  64. const orderedCycles: Record<string, Cycle> = {}
  65. for (const enumItem of cycleEnum.value) {
  66. orderedCycles[enumItem.value] = null
  67. }
  68. for (const cycle of cycles.value.items) {
  69. if (!Object.prototype.hasOwnProperty.call(orderedCycles, cycle.cycleEnum)) {
  70. console.error('Unknown cycle enum : ' + cycle.cycleEnum)
  71. continue
  72. }
  73. orderedCycles[cycle.cycleEnum] = cycle
  74. }
  75. return orderedCycles
  76. })
  77. interface CycleTableItem {
  78. value: string
  79. originalLabel: string
  80. effectiveLabel: string
  81. }
  82. const tableItems: Ref<CycleTableItem[]> = computed(() => {
  83. if (pending.value || cycleEnum.value === null || cycles.value === null) {
  84. return []
  85. }
  86. return cycleEnum.value?.map((item) => {
  87. const effectiveItem: Cycle = orderedCycles.value[item.value]
  88. return {
  89. value: item.value,
  90. originalLabel: item.label,
  91. effectiveLabel: effectiveItem.label,
  92. }
  93. }) || []
  94. })
  95. const goToCycleEditPage = (item: CycleTableItem) => {
  96. const cycle = orderedCycles.value[item.value]
  97. navigateTo(`/parameters/cycles/${cycle.id}`)
  98. }
  99. // Nettoyer les données lors du démontage du composant
  100. onBeforeUnmount(() => {
  101. // Nettoyer les références du store si nécessaire
  102. if (import.meta.client) {
  103. clearNuxtData('/^' + Cycle.entity + '_many_/')
  104. useRepo(Cycle).flush()
  105. }
  106. })
  107. </script>
  108. <style scoped lang="scss"></style>