teaching.vue 2.9 KB

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