Commit 39290c06 authored by Florent Poittevin's avatar Florent Poittevin Committed by Alicia.DeDiosFuente
Browse files

fix: [DLCM-1918] remove routing hash strategy

parent 1f55ffbf
......@@ -46,9 +46,6 @@
{
"glob": "**/*",
"input": "src/assets/",
"ignore": [
"**/configurations/environment.runtime.json"
],
"output": "/assets/"
}
],
......
......@@ -109,7 +109,7 @@ const routes: DlcmRoutes = [
@NgModule({
imports: [RouterModule.forRoot(routes, {
useHash: true,
useHash: false,
relativeLinkResolution: "legacy",
})],
exports: [RouterModule],
......
......@@ -160,7 +160,7 @@
class="link"
>
<mat-label class="disabled">{{labelTranslateEnum.sip | translate}}</mat-label>
<a [href]="getSipPath(model.sipId)">{{model.title}}</a>
<a [routerLink]="getSipPath(model.sipId)">{{model.title}}</a>
</div>
<mat-form-field *ngIf="getFormControl(formDefinition.doi).value !== null"
......
......@@ -402,7 +402,7 @@ export class DepositFormPresentational extends AbstractFormPresentational<Deposi
}
getSipPath(sipId: string): string {
return "#" + SOLIDIFY_CONSTANTS.URL_SEPARATOR + RoutesEnum.preservationPlanningSipDetail + SOLIDIFY_CONSTANTS.URL_SEPARATOR + sipId;
return SOLIDIFY_CONSTANTS.URL_SEPARATOR + RoutesEnum.preservationPlanningSipDetail + SOLIDIFY_CONSTANTS.URL_SEPARATOR + sipId;
}
navigateToPerson(person: Person): void {
......
......@@ -6,7 +6,7 @@
class="status"
>
<ng-container *ngIf="getUrl(copy) as url; else noUrl">
<a [href]="getUrl(copy)">{{getStatusLabel(copy.status) | translate}}</a>
<a [routerLink]="url">{{getStatusLabel(copy.status) | translate}}</a>
</ng-container>
<ng-template #noUrl>
{{getStatusLabel(copy.status) | translate}}
......
......@@ -50,7 +50,7 @@ export class SharedAipStatusSummaryPresentational extends SharedAbstractPresenta
aipCopySorted: AipCopy[] = [];
private readonly PATH_TO_AIP_STORAGION: string = "#" + urlSeparator + AppRoutesEnum.preservationPlanning + urlSeparator + PreservationPlanningRoutesEnum.aip + urlSeparator;
private readonly PATH_TO_AIP_STORAGION: string = urlSeparator + AppRoutesEnum.preservationPlanning + urlSeparator + PreservationPlanningRoutesEnum.aip + urlSeparator;
get packageStatusEnum(): typeof Enums.Package.StatusEnum {
return Enums.Package.StatusEnum;
......
......@@ -8,6 +8,7 @@ import {
ReactiveFormsModule,
} from "@angular/forms";
import {MatSpinner} from "@angular/material/progress-spinner";
import {RouterModule} from "@angular/router";
import {MaterialModule} from "@app/material.module";
import {SharedInstitutionState} from "@app/shared/stores/institution/shared-institution.state";
import {SharedLanguageState} from "@app/shared/stores/language/shared-language.state";
......@@ -151,6 +152,7 @@ const services = [
const modules = [
CommonModule,
FormsModule,
RouterModule,
ReactiveFormsModule,
FormlyModule,
MaterialModule,
......
......@@ -16,6 +16,7 @@ import {
import {DlcmEnvironment} from "./environment.defaults.model";
export const defaultEnvironment: DlcmEnvironment = {
baseHref: "/",
appTitle: "DLCM - Portal",
appDescription: "Platform for archiving research data",
production: false,
......
......@@ -4,16 +4,85 @@
<meta charset="utf-8">
<title>Portal</title>
<base href="/">
<script>
var attributeTempSuffix = "-temp";
<script defer>
function getLocationListSegment() {
let locationListSegment = [window.location.origin];
let locationFragment = window.location.pathname;
if (locationFragment.startsWith("/")) {
locationFragment = locationFragment.substring(1, locationFragment.length);
}
locationListSegment.push(...locationFragment.split("/"));
return locationListSegment;
}
const RUNTIME_CONFIG_FILE_URL = "/assets/configurations/environment.runtime.json";
const DEFAULT_BASE_HREF = "/";
const ATTRIBUTE_TEMP_SUFFIX = "-temp";
const LOCATION_LIST_SEGMENT = getLocationListSegment();
function updateWebmanifestAndColor(runtimeConfig) {
const attributeTempSuffixWebManifest = "-webmanifest-temp"
const attributeTempSuffixColor = "-color-temp"
let theme = runtimeConfig.theme;
if (theme === null || theme === undefined || typeof theme !== "string" || theme.trim() === "") {
theme = "dlcm";
}
var base = document.getElementsByTagName("base")[0];
if (base) {
base.href = window.location.pathname.replace(/\/[^\/]+$/, "/");
base.removeAttribute("href" + attributeTempSuffix);
const pathToWebmanifest = "./assets/themes/" + theme + "/manifest.webmanifest.json";
handleTempAttribute("href", attributeTempSuffixWebManifest, pathToWebmanifest);
fetch(pathToWebmanifest)
.then(response => response.json())
.then(json => {
const color = json.theme_color;
handleTempAttribute("content", attributeTempSuffixColor, color);
});
}
function handleTempAttribute(attributeName, attributeSuffix = attributeTempSuffix, dataErase = null, dataPrefix = "", dataSuffix = "") {
async function getRuntimeConfig(locationListSegment, index) {
const path = locationListSegment.slice(0, index + 1).join("/") + RUNTIME_CONFIG_FILE_URL;
console.info("Search runtime config file on " + path);
var response = await fetch(path);
if (response.status === 200) {
console.info("Runtime config found");
const json = await response.json();
if (json !== null && json !== undefined) {
return json
}
return {};
}
index++;
if (index >= locationListSegment.length) {
console.info("No runtime config found");
return {};
}
return await getRuntimeConfig(locationListSegment, index)
}
function getBaseHref(runtimeConfig) {
if (runtimeConfig === null
|| runtimeConfig.baseHref === null
|| runtimeConfig.baseHref === undefined
|| typeof runtimeConfig.baseHref !== "string"
|| runtimeConfig.baseHref.trim() === "") {
return DEFAULT_BASE_HREF;
}
let baseHref = runtimeConfig.baseHref + "";
if (!baseHref.startsWith("/")) {
baseHref = "/" + baseHref;
}
if (!baseHref.endsWith("/")) {
baseHref = baseHref + "/";
}
return baseHref;
}
function handleTempAttribute(attributeName, attributeSuffix = ATTRIBUTE_TEMP_SUFFIX, dataErase = null, dataPrefix = "", dataSuffix = "") {
const attributeFullName = attributeName + attributeSuffix
document.querySelectorAll("[" + attributeFullName + "]")
.forEach(function (element) {
......@@ -28,6 +97,45 @@
element.removeAttribute(attributeFullName);
});
}
function setTempAttribute(attributeName, attributeOwner = "", attributeSuffix = ATTRIBUTE_TEMP_SUFFIX, dataErase = null, dataPrefix = "", dataSuffix =
"") {
const attributeFullName = attributeName + attributeSuffix
document.querySelectorAll(attributeOwner + "[" + attributeName + "]")
.forEach(function (element) {
let newData = "";
if (dataErase !== null) {
newData = dataErase;
} else {
newData = dataPrefix + element.getAttribute(attributeName) + dataSuffix;
}
element.setAttribute(attributeFullName, newData);
element.removeAttribute(attributeName);
});
}
function bootstrapAppWithBaseHref(resolve) {
var base = document.getElementsByTagName("base")[0];
if (base) {
getRuntimeConfig(LOCATION_LIST_SEGMENT, 0)
.then(runtimeConfig => {
const baseHref = getBaseHref(runtimeConfig);
console.log("Bootstrap app with base href '" + baseHref + "'");
base.href = baseHref;
updateWebmanifestAndColor(runtimeConfig);
base.removeAttribute("href" + ATTRIBUTE_TEMP_SUFFIX);
handleTempAttribute("href");
handleTempAttribute("src");
resolve()
});
}
}
// Promise used in main.ts to bootstrap app
var readyToBootstrap = new Promise((resolve, reject) => {
bootstrapAppWithBaseHref(resolve);
});
</script>
<meta content=""
name="description"
......@@ -41,31 +149,6 @@
<meta content-color-temp="#000000"
name="theme-color"
>
<script>
function updateWebmanifestAndColor(environmentRuntime) {
const attributeTempSuffixWebManifest = "-webmanifest-temp"
const attributeTempSuffixColor = "-color-temp"
let theme = environmentRuntime.theme;
if (theme === null || theme === undefined || theme === "") {
theme = "dlcm";
}
const pathToWebmanifest = "./assets/themes/" + theme + "/manifest.webmanifest.json";
handleTempAttribute("href", attributeTempSuffixWebManifest, pathToWebmanifest);
fetch(pathToWebmanifest)
.then(response => response.json())
.then(json => {
const color = json.theme_color;
handleTempAttribute("content", attributeTempSuffixColor, color);
});
}
fetch("./assets/configurations/environment.runtime.json")
.then(response => response.json())
.then(json => updateWebmanifestAndColor(json));
</script>
</head>
<body>
<dlcm-root></dlcm-root>
......@@ -99,6 +182,18 @@
}
</script>
</body>
<script>
function setScriptAndStyleInjectedInTempMode() {
// Only for dev server because js and style injected by serve process on startup.
// Useless in builded env because js 'src' and link 'href' attributes are suffixed by '-temp' during docker image build (see docker-entrypoint.sh)
// In builded env this code have no effect
setTempAttribute("src");
setTempAttribute("href", "link");
}
setScriptAndStyleInjectedInTempMode();
</script>
<script src-differ="./assets/jsmol/JSmol.min.js"
type="text/javascript"
></script>
......@@ -111,9 +206,6 @@
<!-- Global site tag (gtag.js) - Google Analytics -->
<script src-ga-differ="https://www.googletagmanager.com/gtag/js?id="></script>
<script>
handleTempAttribute("href");
handleTempAttribute("src");
// Google Analytics
window.dataLayer = window.dataLayer || [];
......
......@@ -4,10 +4,14 @@ import {platformBrowserDynamic} from "@angular/platform-browser-dynamic";
import {AppModule} from "./app/app.module";
import {environment} from "./environments/environment";
declare const readyToBootstrap: Promise<void>;
if (environment.production) {
enableProdMode();
}
platformBrowserDynamic().bootstrapModule(AppModule)
// eslint-disable-next-line no-console
.catch(err => console.error(err));
readyToBootstrap.then(() => {
platformBrowserDynamic().bootstrapModule(AppModule)
// eslint-disable-next-line no-console
.catch(err => console.error(err));
});
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment