accountMenu.ts 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 '~/use/layout/Menus/baseMenu'
  5. /**
  6. * @category Use/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. children.push(this.constructMenu('logout', undefined, `/logout`, true))
  74. return children.length > 0 ? this.constructMenu('my_account', 'fa-user', undefined, undefined, children) : null;
  75. }
  76. }
  77. export const getAccountMenu = ($config: NuxtConfig, $ability: Ability, $store: AnyStore) => new AccountMenu($config, $ability, $store).getHeaderMenu()