teaching.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <template>
  2. <LayoutContainer>
  3. <UiLoadingPanel v-if="pending" />
  4. <UiForm
  5. v-else-if="parameters !== null"
  6. v-model="parameters"
  7. >
  8. <LayoutParametersTable
  9. :items="tableItems"
  10. :title="$t('teaching_cycles')"
  11. :columns-definitions="[{ property: 'originalLabel' }, { property: 'effectiveLabel' }]"
  12. identifier="value"
  13. :actions="[TABLE_ACTION.EDIT]"
  14. @editClicked="goToCycleEditPage"
  15. />
  16. <UiInputCheckbox
  17. v-model="parameters.showEducationIsACollectivePractice"
  18. field="showEducationIsACollectivePractice"
  19. label="allow_to_configure_teachings_with_played_instrument_choice"
  20. />
  21. </UiForm>
  22. </LayoutContainer>
  23. </template>
  24. <script setup lang="ts">
  25. import type { AsyncData } from '#app'
  26. import type { ComputedRef } from 'vue'
  27. import Parameters from '~/models/Organization/Parameters'
  28. import { useEntityFetch } from '~/composables/data/useEntityFetch'
  29. import Cycle from '~/models/Education/Cycle'
  30. import { useOrganizationProfileStore } from '~/stores/organizationProfile'
  31. import type { AnyJson } from '~/types/data'
  32. import { useEnumFetch } from '~/composables/data/useEnumFetch'
  33. import ApiResource from '~/models/ApiResource'
  34. import {TABLE_ACTION} from '~/types/enum/enums';
  35. definePageMeta({
  36. name: 'parameters_teaching_page',
  37. })
  38. const organizationProfile = useOrganizationProfileStore()
  39. if (organizationProfile.parametersId === null) {
  40. throw new Error('Missing organization parameters id')
  41. }
  42. const { fetch, fetchCollection } = useEntityFetch()
  43. const { fetch: fetchEnum } = useEnumFetch()
  44. const { data: cycleEnum, pending: enumPending } = fetchEnum('education_cycle')
  45. const { data: parameters, pending: parametersPending } = fetch(
  46. Parameters,
  47. organizationProfile.parametersId,
  48. ) as AsyncData<ApiResource | null, Error | null>
  49. const { data: cycles, pending: cyclesPending } = fetchCollection(Cycle)
  50. const pending: ComputedRef<boolean> = computed(
  51. () => enumPending.value || parametersPending.value || cyclesPending.value,
  52. )
  53. const orderedCycles: ComputedRef<AnyJson> = computed(() => {
  54. if (pending.value || cycleEnum.value === null || cycles.value === null) {
  55. return []
  56. }
  57. const orderedCycles: AnyJson = {}
  58. for (const enumItem of cycleEnum.value) {
  59. orderedCycles[enumItem.value] = null
  60. }
  61. for (const cycle of cycles.value.items) {
  62. if (!Object.prototype.hasOwnProperty.call(orderedCycles, cycle.cycleEnum)) {
  63. console.error('Unknown cycle enum : ' + cycle.cycleEnum)
  64. continue
  65. }
  66. orderedCycles[cycle.cycleEnum] = cycle
  67. }
  68. return orderedCycles
  69. })
  70. const tableItems = computed(() => {
  71. return cycleEnum.value?.map((item) => {
  72. return {
  73. value: item.value,
  74. originalLabel: item.label,
  75. effectiveLabel: (orderedCycles.value[item.value] ?? item).label,
  76. }
  77. }) || []
  78. })
  79. const goToCycleEditPage = (item: object) => {
  80. const cycle = orderedCycles.value[item.value]
  81. navigateTo(`/parameters/cycles/${cycle.id}`)
  82. }
  83. </script>
  84. <style scoped lang="scss">
  85. </style>