websiteListMenuBuilder.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 override readonly menuName = 'WebsiteList'
  11. static OPENTALENT_MANAGER_ID = 93931
  12. /**
  13. * Construit le menu Site internet, ou null si aucune page accessible
  14. */
  15. build(): MenuGroup | null {
  16. const children: MenuItems = []
  17. // Add organization website
  18. if (this.organizationProfile.website) {
  19. children.push(
  20. this.createItem(
  21. this.organizationProfile.name as string,
  22. undefined,
  23. this.organizationProfile.website,
  24. MENU_LINK_TYPE.EXTERNAL,
  25. ),
  26. )
  27. }
  28. // Add parents websites
  29. _.each(
  30. this.organizationProfile.parents,
  31. (parent: BaseOrganizationProfile) => {
  32. if (
  33. parent.id &&
  34. parent.name &&
  35. parent.website &&
  36. parent.id !== WebsiteListMenuBuilder.OPENTALENT_MANAGER_ID
  37. ) {
  38. children.push(
  39. this.createItem(
  40. parent.name,
  41. undefined,
  42. parent.website,
  43. MENU_LINK_TYPE.EXTERNAL,
  44. ),
  45. )
  46. }
  47. },
  48. )
  49. if (children.length > 0) {
  50. return this.createGroup(
  51. 'websiteList',
  52. { name: 'fas fa-globe-americas' },
  53. children,
  54. )
  55. }
  56. return null
  57. }
  58. }