websiteListMenuBuilder.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import AbstractMenuBuilder from '~/services/layout/menuBuilder/abstractMenuBuilder'
  2. import type { MenuGroup, MenuItems } from '~/types/layout'
  3. import { MENU_LINK_TYPE } from '~/types/enum/layout'
  4. import type { BaseOrganizationProfile } from '~/types/interfaces'
  5. /**
  6. * Menu : Liste des sites internet de la structure et de ses structures parentes
  7. */
  8. export default class WebsiteListMenuBuilder extends AbstractMenuBuilder {
  9. static readonly menuName = 'WebsiteList'
  10. /**
  11. * Construit le menu Site internet, ou null si aucune page accessible
  12. */
  13. build(): MenuGroup | null {
  14. const children: MenuItems = []
  15. // Add organization website
  16. if (this.organizationProfile.website) {
  17. children.push(
  18. this.createItem(
  19. this.organizationProfile.name as string,
  20. undefined,
  21. this.organizationProfile.website,
  22. MENU_LINK_TYPE.EXTERNAL,
  23. ),
  24. )
  25. }
  26. // Add parents websites
  27. Object.entries(this.organizationProfile.parents).forEach(
  28. (parent: BaseOrganizationProfile) => {
  29. if (
  30. parent.id &&
  31. parent.name &&
  32. parent.website &&
  33. parent.id !== this.runtimeConfig.OPENTALENT_MANAGER_ID
  34. ) {
  35. children.push(
  36. this.createItem(
  37. parent.name,
  38. undefined,
  39. parent.website,
  40. MENU_LINK_TYPE.EXTERNAL,
  41. ),
  42. )
  43. }
  44. },
  45. )
  46. if (children.length > 0) {
  47. return this.createGroup(
  48. 'websiteList',
  49. { name: 'fas fa-globe-americas' },
  50. children,
  51. )
  52. }
  53. return null
  54. }
  55. }