menu.ts 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. import {ref, useContext} from "@nuxtjs/composition-api";
  2. import {ItemMenu, ItemsMenu} from "~/types/types";
  3. import {organizationProfile} from "~/services/profile/organizationProfile";
  4. export default class Menu{
  5. private $ability:any;
  6. private $config:any;
  7. private $store:any;
  8. constructor() {
  9. const {$ability, $config, store} = useContext();
  10. this.$ability = $ability;
  11. this.$config = $config;
  12. this.$store = store;
  13. }
  14. useMenuConstruct(){
  15. let menu:ItemsMenu = [ this.constructMenu('fa-home', 'welcome', '/dashboard', true) ]
  16. const accessMenu = this.accessMenu()
  17. if(accessMenu) menu.push(accessMenu)
  18. const agendaMenu = this.agendaMenu()
  19. if(agendaMenu) menu.push(agendaMenu)
  20. const equipmentMenu = this.equipmentMenu()
  21. if(equipmentMenu) menu.push(equipmentMenu)
  22. const educationalMenu = this.educationalMenu()
  23. if(educationalMenu) menu.push(educationalMenu)
  24. return ref(menu)
  25. }
  26. /**
  27. * Menu Répertoire
  28. */
  29. accessMenu():ItemMenu | null {
  30. const children:ItemsMenu = [];
  31. if (this.$ability().can('display', 'accesses_page')) {
  32. const organization = organizationProfile(this.$store)
  33. let to = organization.isSchool() ? `/students/list/` : `/adherent/list/`
  34. children.push(this.constructMenu('fa-user', 'person', to, true))
  35. }
  36. if (this.$ability().can('display', 'student_registration_page')) {
  37. children.push(this.constructMenu('fa-users', 'family_view', '/student_registration/new', true))
  38. }
  39. if (this.$ability().can('display', 'education_student_next_year_page')) {
  40. children.push(this.constructMenu('fa-list-alt', 'education_student_next_year', '/education_student_next_year/list/', true))
  41. }
  42. if (this.$ability().can('display', 'commissions_page')) {
  43. children.push(this.constructMenu('fa-street-view', 'commissions', '/commissions/list/', true))
  44. }
  45. if (this.$ability().can('display', 'network_children_page')) {
  46. children.push(this.constructMenu('fa-sitemap', 'network', 'networks/list/', true))
  47. }
  48. if (this.$ability().can('display', 'network_parents_page')) {
  49. children.push(this.constructMenu('fa-sitemap', 'my_network', '/network_artist_schools/list/', true))
  50. }
  51. if(children.length === 1){
  52. return children[0];
  53. }
  54. return children.length > 0 ? this.constructMenu('fa-address-book', 'address_book', undefined, undefined, children) : null;
  55. }
  56. /**
  57. * Menu agenda
  58. */
  59. agendaMenu():ItemMenu | null {
  60. const children:ItemsMenu = [];
  61. if (this.$ability().can('display', 'agenda_page')) {
  62. children.push(this.constructMenu('fa-calendar-alt', 'schedule', '/calendar', true))
  63. }
  64. if (this.$ability().can('display', 'attendance_page')) {
  65. children.push(this.constructMenu('fa-calendar-check', 'attendances', '/attendances/list/', true))
  66. }
  67. if(children.length === 1){
  68. return children[0];
  69. }
  70. return children.length > 0 ? this.constructMenu('fa-calendar-alt', 'schedule', undefined, undefined, children) : null;
  71. }
  72. /**
  73. * Menu equipment
  74. */
  75. equipmentMenu():ItemMenu | null {
  76. return this.constructMenu('fa-cube', 'equipment', '/equipment/list', true)
  77. }
  78. /**
  79. * Menu suivi pédagogique
  80. */
  81. educationalMenu():ItemMenu | null {
  82. const children:ItemsMenu = [];
  83. if (this.$ability().can('display', 'criteria_notations_page')) {
  84. children.push(this.constructMenu('fa-bars', 'criteria_notations', '/criteria_notations/list/', true))
  85. }
  86. if (this.$ability().can('display', 'seizure_period_page')) {
  87. children.push(this.constructMenu('fa-calendar-alt', 'seizure_period', '/education_teachers/list/', true))
  88. }
  89. if (this.$ability().can('display', 'test_seizure_page')) {
  90. children.push(this.constructMenu('fa-pencil-alt', 'test_seizure', '/education_input/list/', true))
  91. }
  92. if (this.$ability().can('display', 'test_validation_page')) {
  93. children.push(this.constructMenu('fa-check', 'test_validation', '/education_notations/list/', true))
  94. }
  95. if (this.$ability().can('display', 'examen_results_page')) {
  96. children.push(this.constructMenu('fa-graduation-cap', 'examen_results', '/examen_convocations/list/', true))
  97. }
  98. if (this.$ability().can('display', 'education_by_student_validation_page')) {
  99. children.push(this.constructMenu('fa-check-square', 'education_by_student_validation', '/education_by_student/list/', true))
  100. }
  101. if(children.length === 1){
  102. return children[0];
  103. }
  104. return children.length > 0 ? this.constructMenu('fa-graduation-cap', 'education_state', undefined, undefined, children) : null;
  105. }
  106. /**
  107. * Construit un ItemMenu
  108. * @param icon
  109. * @param title
  110. * @param link
  111. * @param isOldLink
  112. * @param children
  113. */
  114. constructMenu(icon: string, title: string, link?: string, isOldLink?: boolean, children?: Array<ItemMenu>): ItemMenu{
  115. return children ? {
  116. icon: icon,
  117. title: title,
  118. children: children,
  119. } : {
  120. icon: icon,
  121. title: title,
  122. to: `${isOldLink ? this.$config.baseURL_adminLegacy : ''}${link}`,
  123. old: isOldLink,
  124. }
  125. }
  126. }