teaching.vue 3.1 KB

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