From ce54262513586d9295921e80e4841a830d798792 Mon Sep 17 00:00:00 2001
From: Florent Poittevin <florent.poittevin@unige.ch>
Date: Wed, 5 Feb 2020 16:44:10 +0100
Subject: [PATCH] feat: 1110 Override base href dynamically

---
 src/app/app.component.ts                            | 7 +++----
 src/assets/configurations/environment.dlcmtest.json | 1 +
 src/assets/configurations/environment.sandbox.json  | 1 +
 src/environments/environment.defaults.model.ts      | 1 +
 src/environments/environment.defaults.ts            | 1 +
 5 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/src/app/app.component.ts b/src/app/app.component.ts
index 3445f9c8d..7b9122c7a 100644
--- a/src/app/app.component.ts
+++ b/src/app/app.component.ts
@@ -62,7 +62,6 @@ export class AppComponent extends SharedAbstractPresentational {
   private static readonly _themeAttributeName: string = "theme";
   currentModule: string;
   logo: string;
-  baseHref: string;
 
   @Select((state: LocalStateModel) => state.router.state) urlStateObs: Observable<RouterStateSnapshot>;
   @Select((state: LocalStateModel) => state.application.appLanguage) appLanguageObs: Observable<LanguagesEnum>;
@@ -103,7 +102,7 @@ export class AppComponent extends SharedAbstractPresentational {
               private readonly _dialog: MatDialog) {
     super();
     this.store.dispatch(new AppAction.InitApplication());
-    this.getBaseHref();
+    this.setBaseHref();
     this.setTitle();
     this._setOverrideCssStyleSheet();
     this.listenCurrentModule();
@@ -267,8 +266,8 @@ export class AppComponent extends SharedAbstractPresentational {
     this._renderer.appendChild(header, link);
   }
 
-  private getBaseHref(): void {
+  private setBaseHref(): void {
     const base = this._document.querySelector("head > base");
-    this.baseHref = base.attributes["href"].value;
+    this._renderer.setAttribute(base, "href", environment.baseHref);
   }
 }
diff --git a/src/assets/configurations/environment.dlcmtest.json b/src/assets/configurations/environment.dlcmtest.json
index 67022aa8a..93bb6498c 100644
--- a/src/assets/configurations/environment.dlcmtest.json
+++ b/src/assets/configurations/environment.dlcmtest.json
@@ -1,4 +1,5 @@
 {
+  "baseHref": "/portal",
   "theme": "dlcm",
   "production": true,
   "isDemoMode": true,
diff --git a/src/assets/configurations/environment.sandbox.json b/src/assets/configurations/environment.sandbox.json
index a66d427f1..52f3b018f 100644
--- a/src/assets/configurations/environment.sandbox.json
+++ b/src/assets/configurations/environment.sandbox.json
@@ -1,4 +1,5 @@
 {
+  "baseHref": "/portal",
   "theme": "dlcm",
   "production": true,
   "ADMIN_APPLICATION": "https://sandbox.dlcm.ch/administration/",
diff --git a/src/environments/environment.defaults.model.ts b/src/environments/environment.defaults.model.ts
index 2de2873a2..a484ee6c8 100644
--- a/src/environments/environment.defaults.model.ts
+++ b/src/environments/environment.defaults.model.ts
@@ -4,6 +4,7 @@ import {Storage} from "@app/shared/models/storage.model";
 import {DefaultSolidifyEnvironment} from "solidify-frontend";
 
 export interface DlcmEnvironment extends DefaultSolidifyEnvironment {
+  baseHref: string;
   appTitle: string;
   isDemoMode: boolean;
   theme: ThemeEnum;
diff --git a/src/environments/environment.defaults.ts b/src/environments/environment.defaults.ts
index f3118807d..48a218ff7 100644
--- a/src/environments/environment.defaults.ts
+++ b/src/environments/environment.defaults.ts
@@ -9,6 +9,7 @@ import {TRANSLATE} from "solidify-frontend";
 import {DlcmEnvironment} from "./environment.defaults.model";
 
 export const defaultEnvironment: DlcmEnvironment = {
+  baseHref: "/",
   appTitle: "DLCM - Portal",
   production: false,
   forceRuntimeOverrideSetting: false,
-- 
GitLab