websiteMenu.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. if (!this.$store.state.profile.organization.website && this.$store.state.profile.access.isAdminAccess) {
  29. return this.constructMenu('advanced_modification', {name: 'fa-globe-americas'}, this.getWebsite(this.$store.state.profile.organization) + '/typo3', false, undefined, true)
  30. }
  31. return null
  32. }
  33. /**
  34. * Construit le menu Header des Sites internet ou null si aucune page accessible
  35. * @return {ItemMenu | null}
  36. */
  37. getHeaderMenu (): ItemMenu | null {
  38. const children: ItemsMenu = []
  39. children.push(this.constructMenu(this.$store.state.profile.organization.name, undefined, this.getWebsite(this.$store.state.profile.organization), false, undefined, true))
  40. _.each(this.$store.state.profile.organization.parents, (parent) => {
  41. if(parent.id != process.env.OPENTALENT_MANAGER_ID){
  42. children.push(this.constructMenu(parent.name, undefined, this.getWebsite(parent), false, undefined, true))
  43. }
  44. })
  45. return children.length > 0 ? this.constructMenu('website', {name: 'fa-globe-americas'}, undefined, undefined, children) : null
  46. }
  47. getWebsite (organization: organizationState): string {
  48. return organization.website ? organization.website : this.$config.baseURL_typo3.replace('###subDomain###', organization.subDomain)
  49. }
  50. }
  51. export const getWebsiteMenu = ($config: NuxtConfig, $ability: Ability, $store: AnyStore) => new WebsiteMenu($config, $ability, $store)