| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- import { NuxtConfig } from '@nuxt/types/config'
- import { Ability } from '@casl/ability'
- import { ItemMenu, ItemsMenu, Menu } from '~/types/interfaces'
- import BaseMenu from '~/composables/layout/Menus/baseMenu'
- /**
- * @category composables/layout/Menus
- * @class CommunicationMenu
- * Classe pour la construction du Menu Communication
- */
- class CommunicationMenu extends BaseMenu implements Menu {
- private $ability: Ability;
- /**
- * @constructor
- * Initialisation des services issues du context
- */
- constructor ($config: NuxtConfig, $ability: Ability) {
- super($config)
- this.$ability = $ability
- }
- /**
- * Construit le menu Communication ou null si aucune page accessible
- * @return {ItemMenu | null}
- */
- getMenu (): ItemMenu | null {
- const children: ItemsMenu = []
- if (this.$ability.can('display', 'inbox_page')) {
- children.push(this.constructMenu('inbox', {name: 'fa-inbox'}, '/messages/list/', true))
- }
- if (this.$ability.can('display', 'message_send_page')) {
- children.push(this.constructMenu('message_send', {name: 'fa-paper-plane'}, '/messagessends/list/', true))
- }
- if (this.$ability.can('display', 'message_templates_page')) {
- children.push(this.constructMenu('message_templates', {name: 'fa-edit'}, '/templates/list/', true))
- }
- if (children.length === 1) {
- return children[0]
- } else if (children.length > 0) {
- return this.constructMenu('communication', {name: 'fa-comments'}, undefined, undefined, children)
- } else {
- return null
- }
- }
- }
- export const getCommunicationMenu = ($config: NuxtConfig, $ability: Ability) => new CommunicationMenu($config, $ability).getMenu()
|