teaching.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. const organizationProfile = useOrganizationProfileStore()
  58. if (organizationProfile.parametersId === null) {
  59. throw new Error('Missing organization parameters id')
  60. }
  61. const { fetch, fetchCollection } = useEntityFetch()
  62. const { fetch: fetchEnum } = useEnumFetch()
  63. const { data: cycleEnum, pending: enumPending } = fetchEnum('education_cycle')
  64. const { data: parameters, pending: parametersPending } = fetch(
  65. Parameters,
  66. organizationProfile.parametersId,
  67. ) as AsyncData<ApiResource | null, Error | null>
  68. const { data: cycles, pending: cyclesPending } = fetchCollection(Cycle)
  69. const pending: ComputedRef<boolean> = computed(
  70. () => enumPending.value || parametersPending.value || cyclesPending.value,
  71. )
  72. const orderedCycles: ComputedRef<AnyJson> = computed(() => {
  73. if (pending.value || cycleEnum.value === null || cycles.value === null) {
  74. return []
  75. }
  76. const orderedCycles: AnyJson = {}
  77. for (const enumItem of cycleEnum.value) {
  78. orderedCycles[enumItem.value] = null
  79. }
  80. for (const cycle of cycles.value.items) {
  81. if (!Object.prototype.hasOwnProperty.call(orderedCycles, cycle.cycleEnum)) {
  82. console.error('Unknown cycle enum : ' + cycle.cycleEnum)
  83. continue
  84. }
  85. orderedCycles[cycle.cycleEnum] = cycle
  86. }
  87. return orderedCycles
  88. })
  89. const goToCycleEditPage = (id: number) => {
  90. navigateTo(`/parameters/cycles/${id}`)
  91. }
  92. </script>
  93. <style scoped lang="scss">
  94. .v-table {
  95. width: 100%;
  96. max-width: 800px;
  97. }
  98. .cycle-edit-icon {
  99. color: rgb(var(--v-theme-primary));
  100. }
  101. :deep(.cycle-edit-icon .v-icon) {
  102. font-size: 18px;
  103. }
  104. </style>