websiteListMenuBuilder.ts 1.6 KB

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