teaching.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. <v-table>
  11. <thead>
  12. <tr>
  13. <td>{{ $t('originalLabel') }}</td>
  14. <td>{{ $t('effectiveLabel') }}</td>
  15. </tr>
  16. </thead>
  17. <tbody>
  18. <tr v-for="enumItem in cycleEnum" :key="enumItem.value">
  19. <td>{{ $t(enumItem.value) }}</td>
  20. <td class="cycle-editable-cell">
  21. {{
  22. orderedCycles[enumItem.value]
  23. ? orderedCycles[enumItem.value].label
  24. : $t(enumItem.value)
  25. }}
  26. </td>
  27. <td style="max-width: 24px">
  28. <v-btn
  29. v-if="orderedCycles[enumItem.value]"
  30. :flat="true"
  31. icon="fa fa-pen"
  32. class="cycle-edit-icon"
  33. @click="goToCycleEditPage(orderedCycles[enumItem.value].id)"
  34. />
  35. </td>
  36. </tr>
  37. </tbody>
  38. </v-table>
  39. <UiInputCheckbox
  40. v-model="parameters.showEducationIsACollectivePractice"
  41. field="showEducationIsACollectivePractice"
  42. label="allow_to_configure_teachings_with_played_instrument_choice"
  43. />
  44. </UiForm>
  45. </LayoutContainer>
  46. </template>
  47. <script setup lang="ts">
  48. import type { AsyncData } from '#app'
  49. import type { ComputedRef } from 'vue'
  50. import Parameters from '~/models/Organization/Parameters'
  51. import { useEntityFetch } from '~/composables/data/useEntityFetch'
  52. import Cycle from '~/models/Education/Cycle'
  53. import { useOrganizationProfileStore } from '~/stores/organizationProfile'
  54. import type { AnyJson } from '~/types/data'
  55. import { useEnumFetch } from '~/composables/data/useEnumFetch'
  56. import ApiResource from '~/models/ApiResource'
  57. definePageMeta({
  58. name: 'parameters_teaching_page',
  59. })
  60. const organizationProfile = useOrganizationProfileStore()
  61. if (organizationProfile.parametersId === null) {
  62. throw new Error('Missing organization parameters id')
  63. }
  64. const { fetch, fetchCollection } = useEntityFetch()
  65. const { fetch: fetchEnum } = useEnumFetch()
  66. const { data: cycleEnum, pending: enumPending } = fetchEnum('education_cycle')
  67. const { data: parameters, pending: parametersPending } = fetch(
  68. Parameters,
  69. organizationProfile.parametersId,
  70. ) as AsyncData<ApiResource | null, Error | null>
  71. const { data: cycles, pending: cyclesPending } = fetchCollection(Cycle)
  72. const pending: ComputedRef<boolean> = computed(
  73. () => enumPending.value || parametersPending.value || cyclesPending.value,
  74. )
  75. const orderedCycles: ComputedRef<AnyJson> = computed(() => {
  76. if (pending.value || cycleEnum.value === null || cycles.value === null) {
  77. return []
  78. }
  79. const orderedCycles: AnyJson = {}
  80. for (const enumItem of cycleEnum.value) {
  81. orderedCycles[enumItem.value] = null
  82. }
  83. for (const cycle of cycles.value.items) {
  84. if (!Object.prototype.hasOwnProperty.call(orderedCycles, cycle.cycleEnum)) {
  85. console.error('Unknown cycle enum : ' + cycle.cycleEnum)
  86. continue
  87. }
  88. orderedCycles[cycle.cycleEnum] = cycle
  89. }
  90. return orderedCycles
  91. })
  92. const goToCycleEditPage = (id: number) => {
  93. navigateTo(`/parameters/cycles/${id}`)
  94. }
  95. </script>
  96. <style scoped lang="scss">
  97. .v-table {
  98. width: 100%;
  99. max-width: 800px;
  100. }
  101. .cycle-edit-icon {
  102. color: rgb(var(--v-theme-primary));
  103. }
  104. :deep(.cycle-edit-icon .v-icon) {
  105. font-size: 18px;
  106. }
  107. </style>