communicationMenu.ts 1.6 KB

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