diff --git a/@uportal/extended-uportal-header/samples/api/api.json b/@uportal/extended-uportal-header/samples/api/api.json index 1777c1264..4ce4e0953 100644 --- a/@uportal/extended-uportal-header/samples/api/api.json +++ b/@uportal/extended-uportal-header/samples/api/api.json @@ -18247,7 +18247,8 @@ "show-favorites-in-slider": true, "return-home-title": "retour à l'accueil", "return-home-target": "_self", - "icon-type": "nine-square" + "icon-type": "nine-square", + "portlet-info-api-url": "/portlet" } }, "session": { @@ -18259,5 +18260,10 @@ "userName": "Fxxxxxx", "version": "5.12.0" } + }, + "portlet": { + "portlet": { + "title": "Demo Prolongation ENT" + } } } diff --git a/@uportal/extended-uportal-header/samples/api/routes.json b/@uportal/extended-uportal-header/samples/api/routes.json index aabb095cf..e5bc62f91 100644 --- a/@uportal/extended-uportal-header/samples/api/routes.json +++ b/@uportal/extended-uportal-header/samples/api/routes.json @@ -4,5 +4,6 @@ "/uPortal/api/v4-3/dlm/portletRegistry.json": "/portletRegistry", "/uPortal/api/v5-1/userinfo": "/userinfo", "/commun/portal_template_api.tpl.json": "/portal_template", - "/uPortal/api/session.json": "/session" + "/uPortal/api/session.json": "/session", + "/portlet/demo.json": "/portlet" } diff --git a/@uportal/extended-uportal-header/samples/extended-uportal-header.html b/@uportal/extended-uportal-header/samples/extended-uportal-header.html index 9cdf7194e..a22422827 100644 --- a/@uportal/extended-uportal-header/samples/extended-uportal-header.html +++ b/@uportal/extended-uportal-header/samples/extended-uportal-header.html @@ -21,6 +21,7 @@
NOT LOADED
diff --git a/@uportal/extended-uportal-header/src/extended-uportal-header.ts b/@uportal/extended-uportal-header/src/extended-uportal-header.ts index 200188cf0..cd1749cf8 100644 --- a/@uportal/extended-uportal-header/src/extended-uportal-header.ts +++ b/@uportal/extended-uportal-header/src/extended-uportal-header.ts @@ -42,6 +42,7 @@ import defaultAvatar from '@images/default-avatar.svg'; /** Icons */ import { icon } from '@fortawesome/fontawesome-svg-core'; import { faRightToBracket } from '@fortawesome/free-solid-svg-icons/faRightToBracket'; +import portletService from '@services/portletService'; interface properties { messages: unknown; @@ -90,6 +91,8 @@ interface properties { returnHomeTitle: string | null; height: string; sessionRenewDisable: boolean; + portletInfoApiUrl: string; + fname: string; debug: boolean; } @@ -231,6 +234,10 @@ export class ExtendedUportalHeader extends LitElement { sessionRenewDisable = false; @property({ type: Object, attribute: 'dont-override' }) dontOverride: Array | null = null; + @property({ type: String, attribute: 'portlet-info-api-url' }) + portletInfoApiUrl = ''; + @property({ type: String }) + fname = ''; @property({ type: Boolean }) debug = false; @@ -315,6 +322,7 @@ export class ExtendedUportalHeader extends LitElement { private async _firstLoad() { await this._getTemplate(); + this._loadPortletInformations(); this._debounceLoad(); } @@ -431,6 +439,8 @@ export class ExtendedUportalHeader extends LitElement { returnHomeTitle: null, height: 'auto', sessionRenewDisable: false, + portletInfoApiUrl: '', + fname: '', debug: false, }; @@ -490,6 +500,20 @@ export class ExtendedUportalHeader extends LitElement { } } + private async _loadPortletInformations() { + if ( + this.portletInfoApiUrl === '' || + this.fname === '' || + this.serviceName !== '' + ) + return; + const data = await portletService.get( + this._makeUrl(this.portletInfoApiUrl), + this.fname + ); + if (data) this.serviceName = data.title; + } + private _handleUserAction() { if (this._loaded) { this._debounceRenewToken(); @@ -498,6 +522,7 @@ export class ExtendedUportalHeader extends LitElement { } private _makeUrl(path: string, domain = ''): string { + if (path.startsWith('http')) return path; const protocol = this.debug ? 'http' : 'https'; return `${protocol}://${domain == '' ? this.domain : domain}${path}`; } diff --git a/@uportal/extended-uportal-header/src/services/portletService.ts b/@uportal/extended-uportal-header/src/services/portletService.ts new file mode 100644 index 000000000..c9c35e910 --- /dev/null +++ b/@uportal/extended-uportal-header/src/services/portletService.ts @@ -0,0 +1,36 @@ +export interface portlet { + title: string; +} +export default class portletService { + static async get( + portletApiUrl: string, + fname: string + ): Promise { + portletApiUrl = portletApiUrl.endsWith('/') + ? portletApiUrl + : `${portletApiUrl}/`; + + try { + const options = { + method: 'GET', + }; + + const response = await fetch(`${portletApiUrl}${fname}.json`, options); + + if (!response.ok) { + throw new Error(response.statusText); + } + + const portlet = await response.json(); + + return { + title: portlet?.portlet?.title ?? '', + }; + } catch (err) { + // eslint-disable-next-line + console.error(err, portletApiUrl); + return null; + } + return null; + } +}