configurationMenu.ts 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import { Ability } from '@casl/ability'
  2. import { NuxtConfig } from '@nuxt/types/config'
  3. import { AnyStore, ItemMenu, ItemsMenu, Menu } from '~/types/interfaces'
  4. import BaseMenu from '~/use/layout/Menus/baseMenu'
  5. /**
  6. * @category Use/layout/Menus
  7. * @class ConfigurationMenu
  8. * Classe pour la construction du Menu Paramètres
  9. */
  10. class ConfigurationMenu extends BaseMenu implements Menu {
  11. private $ability: Ability;
  12. private $store: AnyStore;
  13. /**
  14. * @constructor
  15. * Initialisation des services issues du context
  16. */
  17. constructor ($config: NuxtConfig, $ability: Ability, $store: AnyStore) {
  18. super($config)
  19. this.$ability = $ability
  20. this.$store = $store
  21. }
  22. /**
  23. * Construit le menu Header Configuration ou null si aucune page accessible
  24. * @return {ItemMenu | null}
  25. */
  26. getHeaderMenu (): ItemMenu | null {
  27. const children: ItemsMenu = []
  28. if (this.$ability.can('display', 'organization_page')) {
  29. children.push(this.constructMenu('organization_page', undefined, `/main/organizations/${this.$store.state.profile.organization.id}/dashboard`, true))
  30. }
  31. if (this.$ability.can('display', 'cmf_licence_page')) {
  32. children.push(this.constructMenu('cmf_licence_generate', undefined, '/licence_cmf/organization', true))
  33. }
  34. if (this.$ability.can('display', 'parameters_page')) {
  35. children.push(this.constructMenu('parameters', undefined,`/main/edit/parameters/${this.$store.state.profile.organization.id}`))
  36. }
  37. if (this.$ability.can('display', 'place_page')) {
  38. children.push(this.constructMenu('place', undefined, '/places/list/', true))
  39. }
  40. if (this.$ability.can('display', 'education_page')) {
  41. children.push(this.constructMenu('education', undefined, '/educations/list/', true))
  42. }
  43. if (this.$ability.can('display', 'tag_page')) {
  44. children.push(this.constructMenu('tag', undefined, '/taggs/list/', true))
  45. }
  46. if (this.$ability.can('display', 'activities_page')) {
  47. children.push(this.constructMenu('activities', undefined, '/activities/list/', true))
  48. }
  49. if (this.$ability.can('display', 'template_systems_page')) {
  50. children.push(this.constructMenu('template_systems', undefined,'/template_systems/list/', true))
  51. }
  52. if (this.$ability.can('display', 'billing_settings_page')) {
  53. children.push(this.constructMenu('billing_settings', undefined, '/billing_settings/' + this.$store.state.profile.organization.id, true))
  54. }
  55. if (this.$ability.can('display', 'online_registration_settings_page')) {
  56. children.push(this.constructMenu('online_registration_settings', undefined, '/online_registration_settings/' + this.$store.state.profile.organization.id, true))
  57. }
  58. if (this.$ability.can('display', 'transition_next_year_page')) {
  59. children.push(this.constructMenu('transition_next_year', undefined, '/transition_next_year', true))
  60. }
  61. if (this.$ability.can('display', 'course_duplication_page')) {
  62. children.push(this.constructMenu('course_duplication', undefined, '/duplicate_courses', true))
  63. }
  64. if (this.$ability.can('display', 'import_page')) {
  65. children.push(this.constructMenu('import', undefined, '/import/all', true))
  66. }
  67. if (children.length === 1) {
  68. return children[0]
  69. } else if (children.length > 0) {
  70. return this.constructMenu('configuration', 'fa-cogs', undefined, undefined, children)
  71. } else {
  72. return null
  73. }
  74. }
  75. }
  76. export const getConfigurationMenu = ($config: NuxtConfig, $ability: Ability, $store: AnyStore) => new ConfigurationMenu($config, $ability, $store).getHeaderMenu()