websiteMenu.ts 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import * as _ from 'lodash'
  2. import { Ability } from '@casl/ability'
  3. import { NuxtConfig } from '@nuxt/types/config'
  4. import BaseMenu from '~/composables/layout/Menus/baseMenu'
  5. import { AnyStore, ItemMenu, ItemsMenu, Menu, organizationState } from '~/types/interfaces'
  6. /**
  7. * @category composables/layout/Menus
  8. * @class WebsiteMenu
  9. * Classe pour la construction du Menu Sites internet
  10. */
  11. class WebsiteMenu extends BaseMenu implements Menu {
  12. private $ability: Ability;
  13. private $store: AnyStore;
  14. /**
  15. * @constructor
  16. * Initialisation des services issues du context
  17. */
  18. constructor ($config: NuxtConfig, $ability: Ability, $store: AnyStore) {
  19. super($config)
  20. this.$ability = $ability
  21. this.$store = $store
  22. }
  23. /**
  24. * Construit le menu Site internet ou null si aucune page accessible
  25. * @return {ItemMenu | null}
  26. */
  27. getMenu (): ItemMenu | null {
  28. const children: ItemsMenu = []
  29. if (!this.$store.state.profile.organization.website && this.$store.state.profile.access.isAdminAccess) {
  30. children.push(this.constructMenu(this.$store.state.profile.organization.name, undefined, this.getWebsite(this.$store.state.profile.organization), false, undefined, true))
  31. children.push(this.constructMenu('simple_modification', 'fa-globe-europe', this.getWebsite(this.$store.state.profile.organization), false, undefined, true))
  32. children.push(this.constructMenu('advanced_modification', 'fa-globe-europe', this.getWebsite(this.$store.state.profile.organization) + '/typo3', false, undefined, true))
  33. }
  34. return children.length > 0 ? this.constructMenu('website','fa-globe-europe', undefined, undefined, children) : null
  35. }
  36. /**
  37. * Construit le menu Header des Sites internet ou null si aucune page accessible
  38. * @return {ItemMenu | null}
  39. */
  40. getHeaderMenu (): ItemMenu | null {
  41. const children: ItemsMenu = []
  42. children.push(this.constructMenu(this.$store.state.profile.organization.name, undefined, this.getWebsite(this.$store.state.profile.organization), false, undefined, true))
  43. _.each(this.$store.state.profile.organization.parents, (parent) => {
  44. if(parent.id != process.env.OPENTALENT_MANAGER_ID){
  45. children.push(this.constructMenu(parent.name, undefined, this.getWebsite(parent), false, undefined, true))
  46. }
  47. })
  48. return children.length > 0 ? this.constructMenu('website', 'fa-globe-europe', undefined, undefined, children) : null
  49. }
  50. getWebsite (organization: organizationState): string {
  51. return organization.website ? organization.website : this.$config.baseURL_typo3.replace('###subDomain###', organization.subDomain)
  52. }
  53. }
  54. export const getWebsiteMenu = ($config: NuxtConfig, $ability: Ability, $store: AnyStore) => new WebsiteMenu($config, $ability, $store)