teaching.vue 3.5 KB

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