teaching.vue 3.0 KB

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