From cd33a3a0b53ff726ab9c617c24e19f3aaef91a9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-=C3=89tienne=20Lord?= <7397743+pelord@users.noreply.github.com> Date: Tue, 10 Oct 2023 11:44:55 -0400 Subject: [PATCH] feat(*): add types for app environment and config * refactor(portal): subtitute authconfig by authservice check. * refactor(environment): now based on env from igo2-lib * feat(app): add function to compute app version * feat(*): substitute default value calculation to the getConfig method * refactor(*): minor interface changes * feat(app): adding environnement for app extending the lib * refactor(portal): simplify config handling --- src/app/app.component.ts | 28 ++--- src/app/app.module.ts | 2 +- src/app/app.utils.ts | 9 ++ .../map-overlay/map-overlay.component.ts | 6 +- src/app/pages/portal/portal.component.html | 18 +-- src/app/pages/portal/portal.component.ts | 114 +++++++----------- .../pages/portal/sidenav/sidenav.component.ts | 3 +- .../toast-panel/toast-panel.component.ts | 6 +- .../welcome-window.component.ts | 14 +-- .../welcome-window/welcome-window.service.ts | 17 +-- src/config/config.json | 8 +- src/environments/environment.github.ts | 39 +----- src/environments/environment.prod.ts | 42 +------ src/environments/environment.ts | 91 ++++---------- src/environments/environnement.interface.ts | 46 ++++--- 15 files changed, 156 insertions(+), 287 deletions(-) create mode 100644 src/app/app.utils.ts diff --git a/src/app/app.component.ts b/src/app/app.component.ts index b308a6366..1b78dd387 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -4,7 +4,7 @@ import { Title, Meta } from '@angular/platform-browser'; import { DomUtils, userAgent } from '@igo2/utils'; import { LanguageService, ConfigService, MessageService } from '@igo2/core'; import { AuthOptions } from '@igo2/auth'; -import { AnalyticsListenerService } from '@igo2/integration'; +import { AnalyticsListenerService, AppOptions } from '@igo2/integration'; import { PwaService } from './services/pwa.service'; import { NavigationEnd, Router } from '@angular/router'; import { delay, first } from 'rxjs'; @@ -31,7 +31,7 @@ export class AppComponent implements OnInit { private pwaService: PwaService, private router: Router ) { - this.authConfig = this.configService.getConfig('auth'); + this.authConfig = this.configService.getConfig('auth', {}); this.readTitleConfig(); this.readDescriptionConfig(); @@ -40,15 +40,8 @@ export class AppComponent implements OnInit { this.detectOldBrowser(); - this.hasHeader = - this.configService.getConfig('header.hasHeader') === undefined - ? false - : this.configService.getConfig('header.hasHeader'); - - this.hasFooter = - this.configService.getConfig('hasFooter') === undefined - ? false - : this.configService.getConfig('hasFooter'); + this.hasHeader = this.configService.getConfig('header.hasHeader', false); + this.hasFooter = this.configService.getConfig('hasFooter', false); this.setManifest(); this.installPrompt(); @@ -88,7 +81,7 @@ export class AppComponent implements OnInit { private readTitleConfig() { this.languageService.translate - .get(this.configService.getConfig('title')) + .get(this.configService.getConfig('title', '')) .subscribe((title) => { if (title) { this.titleService.setTitle(title); @@ -98,10 +91,11 @@ export class AppComponent implements OnInit { } private setManifest() { - const appConfig = this.configService.getConfig('app'); - if (appConfig?.install?.enabled) { - const manifestPath = - appConfig.install.manifestPath || 'manifest.webmanifest'; + if (this.configService.getConfig('app.install.enabled')) { + const manifestPath = this.configService.getConfig( + 'app.install.manifestPath', + 'manifest.webmanifest' + ); document .querySelector('#igoManifestByConfig') .setAttribute('href', manifestPath); @@ -109,7 +103,7 @@ export class AppComponent implements OnInit { } private installPrompt() { - const appConfig = this.configService.getConfig('app'); + const appConfig: AppOptions = this.configService.getConfig('app'); if (appConfig?.install?.enabled && appConfig?.install?.promote) { if (userAgent.getOSName() !== 'iOS') { window.addEventListener( diff --git a/src/app/app.module.ts b/src/app/app.module.ts index ac8eb2001..ba2f1c9b2 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -133,7 +133,7 @@ function appInitializerFactory( languageService.translate.setTranslation(lang, translations); const configService = injector.get(ConfigService); - const theme = configService.getConfig('theme') || DEFAULT_THEME; + const theme = configService.getConfig('theme', DEFAULT_THEME); loadTheme(document, theme); const titleKey = configService.getConfig('title'); diff --git a/src/app/app.utils.ts b/src/app/app.utils.ts new file mode 100644 index 000000000..1d1870c9a --- /dev/null +++ b/src/app/app.utils.ts @@ -0,0 +1,9 @@ +import { ConfigService, version } from '@igo2/core'; + +export function getAppVersion(configService: ConfigService): string { + return ( + configService.getConfig('version.app') || + configService.getConfig('version.lib') || + version.lib + ); +} diff --git a/src/app/pages/portal/map-overlay/map-overlay.component.ts b/src/app/pages/portal/map-overlay/map-overlay.component.ts index ff12b322a..35fa3be30 100644 --- a/src/app/pages/portal/map-overlay/map-overlay.component.ts +++ b/src/app/pages/portal/map-overlay/map-overlay.component.ts @@ -37,14 +37,14 @@ export class MapOverlayComponent implements AfterViewInit, OnDestroy { } private handleContextChange(context: Context) { - let mapOverlay = []; + let mapOverlay: MapOverlay[] = []; if (context !== undefined) { this.mapOverlay = []; if (context['mapOverlay']) { mapOverlay = context['mapOverlay']; - } else if (this.configService.getConfig('mapOverlay')) { - mapOverlay = this.configService.getConfig('mapOverlay'); + } else { + mapOverlay = this.configService.getConfig('mapOverlay', []); } for (const overlay of mapOverlay) { // If no media define use default to desktop, display only if current media is on context definition diff --git a/src/app/pages/portal/portal.component.html b/src/app/pages/portal/portal.component.html index aa29faf2f..ecdfbd6ef 100644 --- a/src/app/pages/portal/portal.component.html +++ b/src/app/pages/portal/portal.component.html @@ -20,7 +20,7 @@ [termSplitter]="termSplitter" [minLength]="minSearchTermLength" [searchSettings]="true" - [forceNA]="forceCoordsNA" + [forceNA]="appConfig.app?.forceCoordsNA" [store]="searchStore" (searchTermChange)="onSearchTermChange($event)" [pointerSummaryEnabled]="igoSearchPointerSummaryEnabled" @@ -89,13 +89,13 @@ >