accountMenu.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import { ItemMenu, ItemsMenu, Menu } from '~/types/interfaces'
  2. import BaseMenu from '~/composables/layout/Menus/baseMenu'
  3. import {useProfileAccessStore} from "~/store/profile/access";
  4. import {useAbility} from "@casl/vue";
  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. /**
  12. * @constructor
  13. * Initialisation des services issues du context
  14. */
  15. constructor () {
  16. const {$config} = useNuxtApp()
  17. super($config)
  18. }
  19. /**
  20. * Construit le menu Header Configuration ou null si aucune page accessible
  21. * @return {ItemMenu | null}
  22. */
  23. getHeaderMenu (): ItemMenu | null {
  24. const profileAccessStore = useProfileAccessStore();
  25. const {can} = useAbility()
  26. const children: ItemsMenu = []
  27. if (can('display', 'my_schedule_page')) {
  28. children.push(this.constructMenu('my_schedule_page', undefined, '/my_calendar', true))
  29. }
  30. if (can('display', 'attendance_bookings_page')) {
  31. children.push(this.constructMenu('attendance_bookings_menu', undefined, '/own_attendance', true))
  32. }
  33. if (can('display', 'my_attendance_page')) {
  34. children.push(this.constructMenu('my_attendance', undefined, '/my_attendances/list/', true))
  35. }
  36. if (can('display', 'my_invitation_page')) {
  37. children.push(this.constructMenu('my_invitation', undefined, '/my_invitations/list/', true))
  38. }
  39. if (can('display', 'my_students_page')) {
  40. children.push(this.constructMenu('my_students', undefined, '/my_students/list/', true))
  41. }
  42. if (can('display', 'my_students_education_students_page')) {
  43. children.push(this.constructMenu('my_students_education_students', undefined, '/my_students_education_students/list/', true))
  44. }
  45. if (can('display', 'criteria_notations_page') || can('display', 'criteria_notations_page_from_account_menu')) {
  46. children.push(this.constructMenu('criteria_notations', undefined, '/criteria_notations/list/', true))
  47. }
  48. if (can('display', 'my_education_students_page')) {
  49. children.push(this.constructMenu('my_education_students', undefined, `/main/my_profile/${profileAccessStore.id}/dashboard/my_education_students/list/`, true))
  50. }
  51. if (can('display', 'send_an_email_page')) {
  52. children.push(this.constructMenu('send_an_email', undefined, `/list/create/emails`, true))
  53. }
  54. if (can('display', 'my_documents_page')) {
  55. children.push(this.constructMenu('my_documents', undefined, `/main/my_profile/${profileAccessStore.id}/dashboard/show/my_access_file`, true))
  56. }
  57. if (can('display', 'my_profile_page')) {
  58. children.push(this.constructMenu('my_profile', undefined, `/main/my_profile/${profileAccessStore.id}/dashboard`, true))
  59. }
  60. if (can('display', 'adherent_list_page')) {
  61. children.push(this.constructMenu('adherent_list', undefined, `/adherent_contacts/list/`, true))
  62. }
  63. if (can('display', 'subscription_page')) {
  64. children.push(this.constructMenu('my_subscription', undefined, `/subscription`))
  65. }
  66. if (can('display', 'my_bills_page')) {
  67. children.push(this.constructMenu('my_bills', undefined, `/main/my_profile/${profileAccessStore.id}/dashboard/show/my_bills`, true))
  68. }
  69. if (can('display', 'cmf_licence_person_page')) {
  70. children.push(this.constructMenu('print_my_licence', undefined, `/licence_cmf/user`, true))
  71. }
  72. const accountMenu = this.constructMenu('my_account', {
  73. avatarId: profileAccessStore.avatarId,
  74. avatarByDefault: profileAccessStore.gender == 'MISTER' ? 'men-1.png' : 'women-1.png'
  75. }, undefined, undefined, children, false)
  76. const actions: ItemsMenu = [];
  77. actions.push(this.constructMenu('logout', undefined, `/logout`, true))
  78. accountMenu.actions = actions
  79. return accountMenu
  80. }
  81. }
  82. export const getAccountMenu = () => new AccountMenu().getHeaderMenu()