configurationMenu.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 '~/composables/layout/Menus/baseMenu'
  5. /**
  6. * @category composables/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. children.push(this.constructMenu('organization_page', undefined, `/organization`, false))
  31. }
  32. if (this.$ability.can('display', 'cmf_licence_page')) {
  33. children.push(this.constructMenu('cmf_licence_generate', undefined, '/licence_cmf/organization', true))
  34. }
  35. if (this.$ability.can('display', 'parameters_page')) {
  36. // children.push(this.constructMenu('parameters', undefined,`/main/edit/parameters/${this.$store.state.profile.organization.id}`, true))
  37. children.push(this.constructMenu('parameters', undefined,`/parameters`, false))
  38. }
  39. if (this.$ability.can('display', 'place_page')) {
  40. children.push(this.constructMenu('place', undefined, '/places/list/', true))
  41. }
  42. if (this.$ability.can('display', 'education_page')) {
  43. children.push(this.constructMenu('education', undefined, '/educations/list/', true))
  44. }
  45. if (this.$ability.can('display', 'tag_page')) {
  46. children.push(this.constructMenu('tag', undefined, '/taggs/list/', true))
  47. }
  48. if (this.$ability.can('display', 'activities_page')) {
  49. children.push(this.constructMenu('activities', undefined, '/activities/list/', true))
  50. }
  51. if (this.$ability.can('display', 'template_systems_page')) {
  52. children.push(this.constructMenu('template_systems', undefined,'/template_systems/list/', true))
  53. }
  54. if (this.$ability.can('display', 'billing_settings_page')) {
  55. children.push(this.constructMenu('billing_settings', undefined, '/main/edit/billing_settings/' + this.$store.state.profile.organization.id, true))
  56. }
  57. if (this.$ability.can('display', 'online_registration_settings_page')) {
  58. children.push(this.constructMenu('online_registration_settings', undefined, '/main/edit/online_registration_settings/' + this.$store.state.profile.organization.id, true))
  59. }
  60. if (this.$ability.can('display', 'transition_next_year_page')) {
  61. children.push(this.constructMenu('transition_next_year', undefined, '/transition_next_year', true))
  62. }
  63. if (this.$ability.can('display', 'course_duplication_page')) {
  64. children.push(this.constructMenu('course_duplication', undefined, '/duplicate_courses', true))
  65. }
  66. if (this.$ability.can('display', 'import_page')) {
  67. children.push(this.constructMenu('import', undefined, '/import/all', true))
  68. }
  69. if (children.length === 1) {
  70. return children[0]
  71. } else if (children.length > 0) {
  72. return this.constructMenu('configuration', {name: 'fa-cogs'}, undefined, undefined, children)
  73. } else {
  74. return null
  75. }
  76. }
  77. }
  78. export const getConfigurationMenu = ($config: NuxtConfig, $ability: Ability, $store: AnyStore) => new ConfigurationMenu($config, $ability, $store).getHeaderMenu()