communicationMenu.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { ItemMenu, ItemsMenu, Menu } from '~/types/interfaces'
  2. import BaseMenu from '~/composables/layout/Menus/baseMenu'
  3. import {useAbility} from "@casl/vue";
  4. /**
  5. * @category composables/layout/Menus
  6. * @class CommunicationMenu
  7. * Classe pour la construction du Menu Communication
  8. */
  9. class CommunicationMenu extends BaseMenu implements Menu {
  10. /**
  11. * @constructor
  12. * Initialisation des services issues du context
  13. */
  14. constructor () {
  15. const {$config} = useNuxtApp()
  16. super($config)
  17. }
  18. /**
  19. * Construit le menu Communication ou null si aucune page accessible
  20. * @return {ItemMenu | null}
  21. */
  22. getMenu (): ItemMenu | null {
  23. const {can} = useAbility()
  24. const children: ItemsMenu = []
  25. if (can('display', 'inbox_page')) {
  26. children.push(this.constructMenu('inbox', {name: 'fa-inbox'}, '/messages/list/', true))
  27. }
  28. if (can('display', 'message_send_page')) {
  29. children.push(this.constructMenu('message_send', {name: 'fa-paper-plane'}, '/messagessends/list/', true))
  30. }
  31. if (can('display', 'message_templates_page')) {
  32. children.push(this.constructMenu('message_templates', {name: 'fa-edit'}, '/templates/list/', true))
  33. }
  34. if (children.length === 1) {
  35. return children[0]
  36. } else if (children.length > 0) {
  37. return this.constructMenu('communication', {name: 'fa-comments'}, undefined, undefined, children)
  38. } else {
  39. return null
  40. }
  41. }
  42. }
  43. export const getCommunicationMenu = () => new CommunicationMenu().getMenu()