teaching.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. definePageMeta({
  46. name: 'parameters_teaching_page',
  47. })
  48. const organizationProfile = useOrganizationProfileStore()
  49. if (organizationProfile.parametersId === null) {
  50. throw new Error('Missing organization parameters id')
  51. }
  52. const { fetchCollection } = useEntityFetch()
  53. const { fetch: fetchEnum } = useEnumFetch()
  54. const { data: cycleEnum, status: enumStatus } = fetchEnum('education_cycle')
  55. const { data: cycles, status: cyclesStatus } = fetchCollection(Cycle)
  56. const pending: ComputedRef<boolean> = computed(
  57. () => enumStatus.value == 'pending' || cyclesStatus.value == 'pending',
  58. )
  59. const orderedCycles: ComputedRef<AnyJson> = computed(() => {
  60. if (pending.value || cycleEnum.value === null || cycles.value === null) {
  61. return []
  62. }
  63. const orderedCycles: AnyJson = {}
  64. for (const enumItem of cycleEnum.value) {
  65. orderedCycles[enumItem.value] = null
  66. }
  67. for (const cycle of cycles.value.items) {
  68. if (!Object.prototype.hasOwnProperty.call(orderedCycles, cycle.cycleEnum)) {
  69. console.error('Unknown cycle enum : ' + cycle.cycleEnum)
  70. continue
  71. }
  72. orderedCycles[cycle.cycleEnum] = cycle
  73. }
  74. return orderedCycles
  75. })
  76. const tableItems = computed(() => {
  77. return (
  78. cycleEnum.value?.map((item) => {
  79. return {
  80. value: item.value,
  81. originalLabel: item.label,
  82. effectiveLabel: (orderedCycles.value[item.value] ?? item).label,
  83. }
  84. }) || []
  85. )
  86. })
  87. const goToCycleEditPage = (item: object) => {
  88. const cycle = orderedCycles.value[item.value]
  89. navigateTo(`/parameters/cycles/${cycle.id}`)
  90. }
  91. // Nettoyer les données lors du démontage du composant
  92. onBeforeUnmount(() => {
  93. // Nettoyer les références du store si nécessaire
  94. if (process.client) {
  95. clearNuxtData('/^' + Cycle.entity + '_many_/')
  96. useRepo(Cycle).flush()
  97. }
  98. })
  99. </script>
  100. <style scoped lang="scss"></style>