Skip to content

feat: configurable main page #1903

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jun 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"watch": "ng build --watch --configuration default",
"test": "ng test --watch=false --source-map=false",
"lint": "ng lint",
"lint:errors": "ng lint --quiet",
"lint:fix": "ng lint --fix",
"betterer": "betterer",
"cypress:open": "cypress open",
Expand Down
4 changes: 4 additions & 0 deletions src/app/app-config.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import { of } from "rxjs";
import { MockHttp } from "shared/MockStubs";

const appConfig: AppConfigInterface = {
defaultMainPage: {
nonAuthenticatedUser: "DATASETS",
authenticatedUser: "DATASETS",
},
skipSciCatLoginPageEnabled: false,
accessTokenPrefix: "",
addDatasetEnabled: true,
Expand Down
47 changes: 47 additions & 0 deletions src/app/app-config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@
}
}

export enum MainPageOptions {
DATASETS = "/datasets",
PROPOSALS = "/proposals",
INSTRUMENTS = "/instruments",
SAMPLES = "/samples",
}

export class MainPageConfiguration {
nonAuthenticatedUser: keyof typeof MainPageOptions;
authenticatedUser: keyof typeof MainPageOptions;
}

export interface AppConfigInterface {
skipSciCatLoginPageEnabled?: boolean;
accessTokenPrefix: string;
Expand All @@ -44,7 +56,7 @@
datasetReduceEnabled: boolean;
datasetDetailsShowMissingProposalId: boolean;
datafilesActionsEnabled: boolean;
datafilesActions: any[];

Check warning on line 59 in src/app/app-config.service.ts

View workflow job for this annotation

GitHub Actions / eslint

Unexpected any. Specify a different type
editDatasetSampleEnabled: boolean;
editMetadataEnabled: boolean;
editPublishedData: boolean;
Expand Down Expand Up @@ -106,6 +118,17 @@
datasetDetailComponent?: DatasetDetailComponentConfig;
labelsLocalization?: LabelsLocalization;
dateFormat?: string;
defaultMainPage?: MainPageConfiguration;
}

function isMainPageConfiguration(obj: any): obj is MainPageConfiguration {

Check warning on line 124 in src/app/app-config.service.ts

View workflow job for this annotation

GitHub Actions / eslint

Unexpected any. Specify a different type
const validKeys = Object.keys(MainPageOptions);
return (
obj &&
typeof obj === "object" &&
validKeys.includes(obj.nonAuthenticatedUser) &&
validKeys.includes(obj.authenticatedUser)
);
}

@Injectable({
Expand All @@ -123,15 +146,39 @@
.pipe(timeout(2000))
.toPromise();
this.appConfig = Object.assign({}, this.appConfig, config);
} catch (err) {

Check warning on line 149 in src/app/app-config.service.ts

View workflow job for this annotation

GitHub Actions / eslint

'err' is defined but never used
console.log("No config available in backend, trying with local config.");
try {
const config = await this.http.get("/assets/config.json").toPromise();
this.appConfig = Object.assign({}, this.appConfig, config);
} catch (err) {

Check warning on line 154 in src/app/app-config.service.ts

View workflow job for this annotation

GitHub Actions / eslint

'err' is defined but never used
console.error("No config provided.");
}
}

const config: AppConfigInterface = this.appConfig as AppConfigInterface;
if (
"defaultMainPage" in config &&
isMainPageConfiguration(config.defaultMainPage)
) {
config.defaultMainPage.nonAuthenticatedUser = Object.keys(
MainPageOptions,
).includes(config.defaultMainPage.nonAuthenticatedUser)
? config.defaultMainPage.nonAuthenticatedUser
: "DATASETS";
config.defaultMainPage.authenticatedUser = Object.keys(
MainPageOptions,
).includes(config.defaultMainPage.authenticatedUser)
? config.defaultMainPage.authenticatedUser
: "DATASETS";
} else {
config.defaultMainPage = {
nonAuthenticatedUser: "DATASETS",
authenticatedUser: "DATASETS",
} as MainPageConfiguration;
}

this.appConfig = config;
}

getConfig(): AppConfigInterface {
Expand Down
5 changes: 4 additions & 1 deletion src/app/app-routing/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { ErrorPageComponent } from "shared/modules/error-page/error-page.compone
import { AppLayoutComponent } from "_layout/app-layout/app-layout.component";
import { AppMainLayoutComponent } from "_layout/app-main-layout/app-main-layout.component";
import { ServiceGuard } from "./service.guard";
import { MainPageGuard } from "./main-page";
import { RedirectingComponent } from "./redirecting.component";

export const routes: Routes = [
{
Expand All @@ -13,7 +15,8 @@ export const routes: Routes = [
children: [
{
path: "",
redirectTo: "/datasets",
canActivate: [MainPageGuard],
component: RedirectingComponent,
pathMatch: "full",
},
{
Expand Down
33 changes: 33 additions & 0 deletions src/app/app-routing/main-page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Injectable } from "@angular/core";
import { CanActivate, Router } from "@angular/router";
import {
AppConfigService,
MainPageConfiguration,
MainPageOptions,
} from "app-config.service";
import { AuthService } from "shared/services/auth/auth.service";

@Injectable({ providedIn: "root" })
export class MainPageGuard implements CanActivate {
constructor(
private router: Router,
private appConfigService: AppConfigService,
private authService: AuthService,
) {}

canActivate(): boolean {
const defaultMainPage: MainPageConfiguration =
this.appConfigService.getConfig().defaultMainPage;

const userLoggedIn = this.authService.isAuthenticated();

this.router.navigate([
MainPageOptions[
userLoggedIn
? defaultMainPage.authenticatedUser
: defaultMainPage.nonAuthenticatedUser
],
]);
return false;
}
}
46 changes: 46 additions & 0 deletions src/app/app-routing/redirecting.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// dummy.component.ts
import { Component } from "@angular/core";

@Component({
selector: "app-redirecting",
template: `
<div class="redirecting-wrapper">
<div class="redirecting-logo"></div>
<div class="spinner"></div>
<p>Redirecting, please wait...</p>
</div>
`,
styles: [
`
.redirecting-wrapper {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
font-family: Arial, sans-serif;
color: #444;
}

.spinner {
border: 4px solid #f3f3f3;
border-top: 4px solid #3f51b5;
border-radius: 50%;
width: 40px;
height: 40px;
animation: spin 1s linear infinite;
margin-bottom: 10px;
}

@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
`,
],
})
export class RedirectingComponent {}
6 changes: 5 additions & 1 deletion src/assets/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -248,5 +248,9 @@
}
}
}
}
},
"defaultMainPage": {
"nonAuthenticatedUser": "DATASETS",
"authenticatedUser": "DATASETS"
},
}
Loading