accountMenu.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import { Ability } from '@casl/ability'
  2. import { NuxtConfig } from '@nuxt/types/config'
  3. import { AnyStore, ItemMenu, ItemsMenu, Menu } from '~/types/interfaces'
  4. import BaseMenu from '~/composables/layout/Menus/baseMenu'
  5. /**
  6. * @category composables/layout/Menus
  7. * @class AccountMenu
  8. * Classe pour la construction du Menu Mon compte
  9. */
  10. class AccountMenu extends BaseMenu implements Menu {
  11. private $ability: Ability;
  12. private $store: AnyStore;
  13. /**
  14. * @constructor
  15. * Initialisation des services issues du context
  16. */
  17. constructor ($config: NuxtConfig, $ability: Ability, $store: AnyStore) {
  18. super($config)
  19. this.$ability = $ability
  20. this.$store = $store
  21. }
  22. /**
  23. * Construit le menu Header Configuration ou null si aucune page accessible
  24. * @return {ItemMenu | null}
  25. */
  26. getHeaderMenu (): ItemMenu | null {
  27. const children: ItemsMenu = []
  28. if (this.$ability.can('display', 'my_schedule_page')) {
  29. children.push(this.constructMenu('my_schedule_page', undefined, '/my_calendar', true))
  30. }
  31. if (this.$ability.can('display', 'attendance_bookings_page')) {
  32. children.push(this.constructMenu('attendance_bookings_menu', undefined, '/attendance_bookings', true))
  33. }
  34. if (this.$ability.can('display', 'my_attendance_page')) {
  35. children.push(this.constructMenu('my_attendance', undefined, '/my_attendances/list', true))
  36. }
  37. if (this.$ability.can('display', 'my_invitation_page')) {
  38. children.push(this.constructMenu('my_invitation', undefined, '/my_invitations/list', true))
  39. }
  40. if (this.$ability.can('display', 'my_students_page')) {
  41. children.push(this.constructMenu('my_students', undefined, '/my_students/list', true))
  42. }
  43. if (this.$ability.can('display', 'my_students_education_students_page')) {
  44. children.push(this.constructMenu('my_students_education_students', undefined, '/my_students_education_students/list', true))
  45. }
  46. if (this.$ability.can('display', 'criteria_notations_page') || this.$ability.can('display', 'criteria_notations_page_from_account_menu')) {
  47. children.push(this.constructMenu('criteria_notations', undefined, '/criteria_notations/list', true))
  48. }
  49. if (this.$ability.can('display', 'my_education_students_page')) {
  50. children.push(this.constructMenu('my_education_students', undefined, `/main/my_profile/${this.$store.state.profile.access.id}/dashboard/my_education_students/list`, true))
  51. }
  52. if (this.$ability.can('display', 'send_an_email_page')) {
  53. children.push(this.constructMenu('send_an_email', undefined, `/list/create/emails`, true))
  54. }
  55. if (this.$ability.can('display', 'my_documents_page')) {
  56. children.push(this.constructMenu('my_documents', undefined, `/main/my_profile/${this.$store.state.profile.access.id}/dashboard/show/my_access_file`, true))
  57. }
  58. if (this.$ability.can('display', 'my_profile_page')) {
  59. children.push(this.constructMenu('my_profile', undefined, `/main/my_profile/${this.$store.state.profile.access.id}/dashboard`, true))
  60. }
  61. if (this.$ability.can('display', 'adherent_list_page')) {
  62. children.push(this.constructMenu('adherent_list', undefined, `/adherent_contacts/list/`, true))
  63. }
  64. if (this.$ability.can('display', 'subscription_page')) {
  65. children.push(this.constructMenu('my_subscription', undefined, `/subscription`))
  66. }
  67. if (this.$ability.can('display', 'my_bills_page')) {
  68. children.push(this.constructMenu('my_bills', undefined, `/main/my_profile/${this.$store.state.profile.access.id}/dashboard/show/my_bills`, true))
  69. }
  70. if (this.$ability.can('display', 'cmf_licence_page')) {
  71. children.push(this.constructMenu('print_my_licence', undefined, `/licence-cmf`, true))
  72. }
  73. const accountMenu = this.constructMenu('my_account', 'fa-user', undefined, undefined, children, false)
  74. const actions: ItemsMenu = [];
  75. actions.push(this.constructMenu('logout', undefined, `/logout`, true))
  76. accountMenu.actions = actions
  77. return accountMenu
  78. }
  79. }
  80. export const getAccountMenu = ($config: NuxtConfig, $ability: Ability, $store: AnyStore) => new AccountMenu($config, $ability, $store).getHeaderMenu()