teaching.vue 3.2 KB

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