admin2iosMenu.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 Admin2iosMenu
  7. * Classe pour la construction du Menu Admin 2IOS
  8. */
  9. class Admin2iosMenu extends BaseMenu implements Menu {
  10. /**
  11. * @constructor
  12. * Initialisation des services issus du context
  13. */
  14. constructor () {
  15. const {$config} = useNuxtApp()
  16. super($config)
  17. }
  18. /**
  19. * Construit le menu Administration 2ios 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', 'all_accesses_page')) {
  26. children.push(this.constructMenu('all_accesses', {name: 'fa-users'}, '/all_accesses/list/', true))
  27. }
  28. if (can('display', 'all_organizations_page')) {
  29. children.push(this.constructMenu('all_organizations', {name: 'fa-building'}, '/organization_params/list/', true))
  30. }
  31. if (can('display', 'tips_page')) {
  32. children.push(this.constructMenu('tips', {name: 'fa-info-circle'}, '/tips/list/', true))
  33. }
  34. if (can('display', 'dgv_page')) {
  35. children.push(this.constructMenu('dgv', {name: 'fa-house-damage'}, '/admin2ios/dgv', true))
  36. }
  37. if (can('display', 'cmf_cotisation_page')) {
  38. children.push(this.constructMenu('cmf_cotisation', {name: 'fa-info-circle'}, '/admin2ios/cotisationcmf', true))
  39. }
  40. if (can('display', 'right_page')) {
  41. children.push(this.constructMenu('right_menu', {name: 'fa-balance-scale-right'}, '/admin2ios/right', true))
  42. }
  43. if (can('display', 'tree_page')) {
  44. children.push(this.constructMenu('tree_menu', {name: 'fa-sitemap'}, '/admin2ios/tree', true))
  45. }
  46. if (children.length === 1) {
  47. return children[0]
  48. } else if (children.length > 0) {
  49. return this.constructMenu('admin2ios', {name: 'fa-sitemap'}, undefined, undefined, children)
  50. } else {
  51. return null
  52. }
  53. }
  54. }
  55. export const getAdmin2iosMenu = () => new Admin2iosMenu().getMenu()