configurationMenu.ts 3.9 KB

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