src/lib/external-apps.service.ts
Properties |
|
Methods |
|
| Public getApp | ||||||
getApp(appId: string)
|
||||||
|
Defined in src/lib/external-apps.service.ts:41
|
||||||
|
Parameters :
Returns :
ExternalApp | null
|
| Public Async getAppList |
getAppList()
|
|
Defined in src/lib/external-apps.service.ts:101
|
|
Returns :
Promise<Array<ExternalApp>>
|
| Public getAppRouterLink |
getAppRouterLink(appId: string, path: string)
|
|
Defined in src/lib/external-apps.service.ts:64
|
|
Returns :
[] | null
|
| Public getAppRouterLinkOrThrow |
getAppRouterLinkOrThrow(appId: string, path: string)
|
|
Defined in src/lib/external-apps.service.ts:83
|
|
Returns :
string[]
|
| Public getAppUrl | ||||||||||||||||
getAppUrl(appId: string, path: string, infix: string | null)
|
||||||||||||||||
|
Defined in src/lib/external-apps.service.ts:52
|
||||||||||||||||
|
Parameters :
Returns :
string | null
|
| Public getAppUrlOrThrow |
getAppUrlOrThrow(appId: string, path: string)
|
|
Defined in src/lib/external-apps.service.ts:75
|
|
Returns :
string
|
| Protected getPathPrefix |
getPathPrefix()
|
|
Defined in src/lib/external-apps.service.ts:123
|
|
Returns :
string
|
| Public hasApp | ||||||
hasApp(appId: string)
|
||||||
|
Defined in src/lib/external-apps.service.ts:37
|
||||||
|
Parameters :
Returns :
boolean
|
| Public navigate |
navigate(appId: string, path: string)
|
|
Defined in src/lib/external-apps.service.ts:91
|
|
Returns :
void
|
| Public Readonly activeAppList |
Default value : signal<Array<ExternalApp>>([])
|
|
Defined in src/lib/external-apps.service.ts:35
|
|
The list of active apps that is processed by the getAppList method |
| Protected Readonly appFilterList |
Default value : coerceArray(inject(RXAP_EXTERNAL_APP_FILTER, { optional: true }))
|
|
Defined in src/lib/external-apps.service.ts:25
|
| Protected Readonly apps |
Type : Array<ExternalApp>
|
Default value : this.config.get('navigation.apps', [])
|
|
Defined in src/lib/external-apps.service.ts:29
|
| Protected Readonly config |
Default value : inject(ConfigService)
|
|
Defined in src/lib/external-apps.service.ts:26
|
| Protected Readonly environment |
Default value : inject(RXAP_ENVIRONMENT)
|
|
Defined in src/lib/external-apps.service.ts:28
|
| Protected Readonly externalApps |
Default value : coerceArray(inject(RXAP_EXTERNAL_APP, { optional: true }))
|
|
Defined in src/lib/external-apps.service.ts:30
|
| Protected Readonly localeId |
Default value : inject(LOCALE_ID)
|
|
Defined in src/lib/external-apps.service.ts:27
|
import {
inject,
Injectable,
LOCALE_ID,
signal,
} from '@angular/core';
// eslint-disable-next-line @nx/enforce-module-boundaries
import { ClickOnLink } from '@rxap/browser-utilities';
import { ConfigService } from '@rxap/config';
import { RXAP_ENVIRONMENT } from '@rxap/environment';
import {
clone,
coerceArray,
JoinPath,
} from '@rxap/utilities';
import {
RXAP_EXTERNAL_APP,
RXAP_EXTERNAL_APP_FILTER,
} from './tokens';
import { ExternalApp } from './types';
@Injectable()
export class ExternalAppsService {
protected readonly appFilterList = coerceArray(inject(RXAP_EXTERNAL_APP_FILTER, { optional: true }));
protected readonly config = inject(ConfigService);
protected readonly localeId = inject(LOCALE_ID);
protected readonly environment = inject(RXAP_ENVIRONMENT);
protected readonly apps: Array<ExternalApp> = this.config.get('navigation.apps', []);
protected readonly externalApps = coerceArray(inject(RXAP_EXTERNAL_APP, { optional: true }));
/**
* The list of active apps that is processed by the getAppList method
*/
public readonly activeAppList = signal<Array<ExternalApp>>([]);
public hasApp(appId: string): boolean {
return this.apps.some(app => app.id === appId);
}
public getApp(appId: string): ExternalApp | null {
if (!this.hasApp(appId)) {
return null;
}
const app = this.apps.find(app => app.id === appId);
if (!app) {
throw new Error(`FATAL: App with id "${ appId }" not found!`);
}
return clone(app);
}
public getAppUrl(appId: string, path: string, infix: string | null = this.getPathPrefix()): string | null {
const app = this.getApp(appId);
if (!app || !app.href) {
return null;
}
return JoinPath(app.href, infix, path);
}
public getAppRouterLink(appId: string, path: string): string[] | null {
const app = this.getApp(appId);
if (!app || !app.routerLink) {
return null;
}
return [ ...app.routerLink, path ];
}
public getAppUrlOrThrow(appId: string, path: string): string {
const url = this.getAppUrl(appId, path);
if (url) {
return url;
}
throw new Error(`Could not find url for app with id "${ appId }"`);
}
public getAppRouterLinkOrThrow(appId: string, path: string): string[] {
const routerLink = this.getAppRouterLink(appId, path);
if (routerLink) {
return routerLink;
}
throw new Error(`Could not find router link for app with id "${ appId }"`);
}
public navigate(appId: string, path: string): void {
const url = this.getAppUrl(appId, path);
if (url) {
ClickOnLink(url);
}
}
public async getAppList(): Promise<Array<ExternalApp>> {
let appList: ExternalApp[] = [
...this.externalApps,
...this.apps,
].filter(app => !app.hidden)
.map(app => clone(app));
appList.forEach(app => {
if (app.href) {
app.href = JoinPath(app.href, this.getPathPrefix());
}
});
for (const appFilter of this.appFilterList) {
appList = await appFilter.call(clone(appList));
}
appList = clone(appList);
this.activeAppList.set(appList);
return appList;
}
protected getPathPrefix(): string {
if (this.environment.production && this.localeId) {
return this.localeId.replace(/-.+$/, '');
}
return '';
}
}