From 4b537b6e58ac1ce86504b8e70f61c6b974d1df25 Mon Sep 17 00:00:00 2001
From: Simon
Date: Thu, 23 Jun 2022 22:51:23 +0200
Subject: [PATCH 01/36] removed usage of remote_url
---
src/app/core/app-config/app-config.ts | 1 +
.../session/session-service/remote-session.ts | 16 +++++++++++++---
.../session-service/synced-session.service.ts | 2 +-
3 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/src/app/core/app-config/app-config.ts b/src/app/core/app-config/app-config.ts
index 11d94cd813..68cf79d68c 100644
--- a/src/app/core/app-config/app-config.ts
+++ b/src/app/core/app-config/app-config.ts
@@ -34,6 +34,7 @@ import { IAppConfig } from "./app-config.model";
* // no need for dependency injection here
*/
export class AppConfig {
+ static DB_PROXY_PREFIX = "/db";
/** settings for the app */
static settings: IAppConfig;
diff --git a/src/app/core/session/session-service/remote-session.ts b/src/app/core/session/session-service/remote-session.ts
index 672d74cec3..d257f83036 100644
--- a/src/app/core/session/session-service/remote-session.ts
+++ b/src/app/core/session/session-service/remote-session.ts
@@ -22,6 +22,7 @@ import { SessionService } from "./session.service";
import { LoginState } from "../session-states/login-state.enum";
import { PouchDatabase } from "../../database/pouch-database";
import { LoggingService } from "../../logging/logging.service";
+import PouchDB from "pouchdb-browser";
/**
* Responsibilities:
@@ -47,9 +48,18 @@ export class RemoteSession extends SessionService {
) {
super();
this.database = new PouchDatabase(this.loggingService).initIndexedDB(
- AppConfig.settings.database.remote_url + AppConfig.settings.database.name,
+ `${AppConfig.DB_PROXY_PREFIX}/${AppConfig.settings.database.name}`,
{
+ adapter: "http",
skip_setup: true,
+ fetch: (url, opts) => {
+ if (typeof url === "string") {
+ return PouchDB.fetch(
+ AppConfig.DB_PROXY_PREFIX + url.split(AppConfig.DB_PROXY_PREFIX)[1],
+ opts
+ );
+ }
+ },
}
);
}
@@ -63,7 +73,7 @@ export class RemoteSession extends SessionService {
try {
const response = await this.httpClient
.post(
- `${AppConfig.settings.database.remote_url}_session`,
+ `${AppConfig.DB_PROXY_PREFIX}/_session`,
{ name: username, password: password },
{ withCredentials: true }
)
@@ -103,7 +113,7 @@ export class RemoteSession extends SessionService {
*/
public async logout(): Promise {
await this.httpClient
- .delete(`${AppConfig.settings.database.remote_url}_session`, {
+ .delete(`${AppConfig.DB_PROXY_PREFIX}/_session`, {
withCredentials: true,
})
.toPromise()
diff --git a/src/app/core/session/session-service/synced-session.service.ts b/src/app/core/session/session-service/synced-session.service.ts
index ba353ae5d9..8848339c43 100644
--- a/src/app/core/session/session-service/synced-session.service.ts
+++ b/src/app/core/session/session-service/synced-session.service.ts
@@ -75,7 +75,7 @@ export class SyncedSessionService extends SessionService {
*/
checkForValidSession() {
this.httpClient
- .get(`${AppConfig.settings.database.remote_url}_session`, {
+ .get(`${AppConfig.DB_PROXY_PREFIX}/_session`, {
withCredentials: true,
})
.subscribe((res: any) => {
From 3a12b4cb22715e0342a7315dfdafd31f80b0fce5 Mon Sep 17 00:00:00 2001
From: Simon
Date: Thu, 23 Jun 2022 23:13:15 +0200
Subject: [PATCH 02/36] removed database name from config
---
src/app/core/app-config/app-config.model.ts | 7 -------
1 file changed, 7 deletions(-)
diff --git a/src/app/core/app-config/app-config.model.ts b/src/app/core/app-config/app-config.model.ts
index dade0d20b5..74a6eec9bf 100644
--- a/src/app/core/app-config/app-config.model.ts
+++ b/src/app/core/app-config/app-config.model.ts
@@ -43,13 +43,6 @@ export interface IAppConfig {
database: {
/** name of the database - both remote and local */
name: string;
-
- /**
- * URL to the database server to be synced with
- *
- * Beware of CORS issues if this is on a different domain than the app is served from.
- */
- remote_url: string;
};
/**
From 39dd063c7a531d4b307fc681eae164ea84c46966 Mon Sep 17 00:00:00 2001
From: Simon
Date: Fri, 24 Jun 2022 09:46:59 +0200
Subject: [PATCH 03/36] added comments for proxy url
---
build/default.conf | 1 +
src/app/core/app-config/app-config.ts | 1 +
2 files changed, 2 insertions(+)
diff --git a/build/default.conf b/build/default.conf
index f6ed30b008..6840fcce02 100644
--- a/build/default.conf
+++ b/build/default.conf
@@ -48,6 +48,7 @@ server {
root /usr/share/nginx/html;
}
+ # The proxy path should be the same as in AppConfig.DB_PROXY_PREFIX
location /db {
rewrite /db/(.*) /$1 break;
proxy_pass ${COUCHDB_URL};
diff --git a/src/app/core/app-config/app-config.ts b/src/app/core/app-config/app-config.ts
index 68cf79d68c..4d00811cca 100644
--- a/src/app/core/app-config/app-config.ts
+++ b/src/app/core/app-config/app-config.ts
@@ -34,6 +34,7 @@ import { IAppConfig } from "./app-config.model";
* // no need for dependency injection here
*/
export class AppConfig {
+ /** Path for the reverse proxy that forwards to the database - configured in `proxy.conf.json` and `default.conf` */
static DB_PROXY_PREFIX = "/db";
/** settings for the app */
static settings: IAppConfig;
From 031ee25c62859c15998e2b800ab0d07ee07a38c3 Mon Sep 17 00:00:00 2001
From: Simon
Date: Fri, 24 Jun 2022 09:58:56 +0200
Subject: [PATCH 04/36] removed usages of remote_url for database
---
src/app/app.component.spec.ts | 2 +-
src/app/core/admin/admin/admin.component.spec.ts | 5 +----
src/app/core/session/session-service/local-session.spec.ts | 5 +----
src/app/core/session/session-service/remote-session.spec.ts | 5 +----
.../session/session-service/synced-session.service.spec.ts | 5 +----
src/app/core/webdav/cloud-file-service.service.spec.ts | 5 +----
src/app/utils/mocked-testing.module.ts | 5 +----
src/app/utils/performance-tests.spec.ts | 5 +----
8 files changed, 8 insertions(+), 29 deletions(-)
diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts
index 857f692546..be70b1e10b 100644
--- a/src/app/app.component.spec.ts
+++ b/src/app/app.component.spec.ts
@@ -48,7 +48,7 @@ describe("AppComponent", () => {
let entityUpdates: Subject>;
const mockAppSettings: IAppConfig = {
- database: { name: "", remote_url: "" },
+ database: { name: "" },
session_type: SessionType.local,
demo_mode: false,
site_name: "",
diff --git a/src/app/core/admin/admin/admin.component.spec.ts b/src/app/core/admin/admin/admin.component.spec.ts
index 2e3e6c0a70..a3ccaab64b 100644
--- a/src/app/core/admin/admin/admin.component.spec.ts
+++ b/src/app/core/admin/admin/admin.component.spec.ts
@@ -58,10 +58,7 @@ describe("AdminComponent", () => {
AppConfig.settings = {
site_name: "",
session_type: SessionType.mock,
- database: {
- name: "unit-tests",
- remote_url: "",
- },
+ database: { name: "unit-tests" },
};
TestBed.configureTestingModule({
diff --git a/src/app/core/session/session-service/local-session.spec.ts b/src/app/core/session/session-service/local-session.spec.ts
index 38cd66c4c0..d2944c4eec 100644
--- a/src/app/core/session/session-service/local-session.spec.ts
+++ b/src/app/core/session/session-service/local-session.spec.ts
@@ -33,10 +33,7 @@ describe("LocalSessionService", () => {
AppConfig.settings = {
site_name: "Aam Digital - DEV",
session_type: SessionType.mock,
- database: {
- name: "test-db-name",
- remote_url: "https://demo.aam-digital.com/db/",
- },
+ database: { name: "test-db-name" },
};
database = jasmine.createSpyObj([
"initInMemoryDB",
diff --git a/src/app/core/session/session-service/remote-session.spec.ts b/src/app/core/session/session-service/remote-session.spec.ts
index 7dd3d53d35..7bb30a3134 100644
--- a/src/app/core/session/session-service/remote-session.spec.ts
+++ b/src/app/core/session/session-service/remote-session.spec.ts
@@ -19,10 +19,7 @@ describe("RemoteSessionService", () => {
AppConfig.settings = {
site_name: "test",
session_type: SessionType.mock,
- database: {
- name: "database",
- remote_url: "database_url",
- },
+ database: { name: "database" },
};
mockHttpClient = jasmine.createSpyObj(["post", "delete"]);
mockHttpClient.delete.and.returnValue(of());
diff --git a/src/app/core/session/session-service/synced-session.service.spec.ts b/src/app/core/session/session-service/synced-session.service.spec.ts
index 6a21796a46..063ffa6d73 100644
--- a/src/app/core/session/session-service/synced-session.service.spec.ts
+++ b/src/app/core/session/session-service/synced-session.service.spec.ts
@@ -65,10 +65,7 @@ describe("SyncedSessionService", () => {
AppConfig.settings = {
site_name: "Aam Digital - DEV",
session_type: SessionType.mock,
- database: {
- name: "integration_tests",
- remote_url: "https://demo.aam-digital.com/db/",
- },
+ database: { name: "integration_tests" },
webdav: { remote_url: "" },
};
sessionService = TestBed.inject(SyncedSessionService);
diff --git a/src/app/core/webdav/cloud-file-service.service.spec.ts b/src/app/core/webdav/cloud-file-service.service.spec.ts
index 066690ec40..b48c3a9383 100644
--- a/src/app/core/webdav/cloud-file-service.service.spec.ts
+++ b/src/app/core/webdav/cloud-file-service.service.spec.ts
@@ -26,10 +26,7 @@ describe("CloudFileService", () => {
AppConfig.settings = {
site_name: "",
session_type: SessionType.mock,
- database: {
- name: "unit-tests",
- remote_url: "",
- },
+ database: { name: "unit-tests" },
webdav: { remote_url: "test-url" },
};
diff --git a/src/app/utils/mocked-testing.module.ts b/src/app/utils/mocked-testing.module.ts
index fa0c092247..fc9b0cf730 100644
--- a/src/app/utils/mocked-testing.module.ts
+++ b/src/app/utils/mocked-testing.module.ts
@@ -90,10 +90,7 @@ export class MockedTestingModule {
AppConfig.settings = {
site_name: "Aam Digital - DEV",
session_type: SessionType.mock,
- database: {
- name: "test-db-name",
- remote_url: "https://demo.aam-digital.com/db/",
- },
+ database: { name: "test-db-name" },
};
const mockedEntityMapper = mockEntityMapper([new User(TEST_USER), ...data]);
const session = createLocalSession(loginState === LoginState.LOGGED_IN);
diff --git a/src/app/utils/performance-tests.spec.ts b/src/app/utils/performance-tests.spec.ts
index 449be9fda6..07759f7b11 100644
--- a/src/app/utils/performance-tests.spec.ts
+++ b/src/app/utils/performance-tests.spec.ts
@@ -14,10 +14,7 @@ xdescribe("Performance Tests", () => {
AppConfig.settings = {
site_name: "Aam Digital - DEV",
session_type: SessionType.mock, // change to SessionType.local to run performance tests with the InBrowser database
- database: {
- name: "test-db-name",
- remote_url: "https://demo.aam-digital.com/db/",
- },
+ database: { name: "test-db-name" },
};
await TestBed.configureTestingModule({
From 3e8e55afac16c294efbabc4cb9dacd92f8b4c03f Mon Sep 17 00:00:00 2001
From: Simon
Date: Fri, 24 Jun 2022 11:20:20 +0200
Subject: [PATCH 05/36] fixed lint error
---
src/app/core/session/session-service/remote-session.ts | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/app/core/session/session-service/remote-session.ts b/src/app/core/session/session-service/remote-session.ts
index d257f83036..03ea1546e8 100644
--- a/src/app/core/session/session-service/remote-session.ts
+++ b/src/app/core/session/session-service/remote-session.ts
@@ -55,7 +55,8 @@ export class RemoteSession extends SessionService {
fetch: (url, opts) => {
if (typeof url === "string") {
return PouchDB.fetch(
- AppConfig.DB_PROXY_PREFIX + url.split(AppConfig.DB_PROXY_PREFIX)[1],
+ AppConfig.DB_PROXY_PREFIX +
+ url.split(AppConfig.DB_PROXY_PREFIX)[1],
opts
);
}
From 6b5b98131f21a3809d8bc6153c91ef3d23bc75bb Mon Sep 17 00:00:00 2001
From: Simon
Date: Wed, 6 Jul 2022 09:55:51 +0200
Subject: [PATCH 06/36] removed remote_url from default config
---
src/assets/config.default.json | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/src/assets/config.default.json b/src/assets/config.default.json
index 726dd76062..e81807178b 100644
--- a/src/assets/config.default.json
+++ b/src/assets/config.default.json
@@ -4,8 +4,7 @@
"session_type": "mock",
"demo_mode": true,
"database": {
- "name": "app",
- "remote_url": "http://localhost:4200/db/"
+ "name": "app"
},
"debug": false
From 93974ceb3bf55f09562a9f66d7a41226857bfe18 Mon Sep 17 00:00:00 2001
From: Simon
Date: Wed, 6 Jul 2022 10:54:19 +0200
Subject: [PATCH 07/36] removed database name and replaced it by a static value
---
src/app/core/app-config/app-config.ts | 4 +++-
.../core/demo-data/demo-data-initializer.service.spec.ts | 4 ++--
src/app/core/demo-data/demo-data-initializer.service.ts | 4 ++--
src/app/core/session/session-service/local-session.spec.ts | 6 +++---
src/app/core/session/session-service/local-session.ts | 6 +++---
src/app/core/session/session-service/remote-session.ts | 2 +-
src/assets/config.default.json | 3 ---
7 files changed, 14 insertions(+), 15 deletions(-)
diff --git a/src/app/core/app-config/app-config.ts b/src/app/core/app-config/app-config.ts
index 4d00811cca..004db4e7a6 100644
--- a/src/app/core/app-config/app-config.ts
+++ b/src/app/core/app-config/app-config.ts
@@ -35,7 +35,9 @@ import { IAppConfig } from "./app-config.model";
*/
export class AppConfig {
/** Path for the reverse proxy that forwards to the database - configured in `proxy.conf.json` and `default.conf` */
- static DB_PROXY_PREFIX = "/db";
+ static readonly DB_PROXY_PREFIX = "/db";
+ /** Name of the database that is used */
+ static readonly DB_NAME = "app";
/** settings for the app */
static settings: IAppConfig;
diff --git a/src/app/core/demo-data/demo-data-initializer.service.spec.ts b/src/app/core/demo-data/demo-data-initializer.service.spec.ts
index 6cfe6f83c8..2cce870282 100644
--- a/src/app/core/demo-data/demo-data-initializer.service.spec.ts
+++ b/src/app/core/demo-data/demo-data-initializer.service.spec.ts
@@ -29,8 +29,8 @@ describe("DemoDataInitializerService", () => {
database: { name: "test-db" },
session_type: SessionType.mock,
} as IAppConfig;
- demoUserDBName = `${DemoUserGeneratorService.DEFAULT_USERNAME}-${AppConfig.settings.database.name}`;
- adminDBName = `${DemoUserGeneratorService.ADMIN_USERNAME}-${AppConfig.settings.database.name}`;
+ demoUserDBName = `${DemoUserGeneratorService.DEFAULT_USERNAME}-${AppConfig.DB_NAME}`;
+ adminDBName = `${DemoUserGeneratorService.ADMIN_USERNAME}-${AppConfig.DB_NAME}`;
mockDemoDataService = jasmine.createSpyObj(["publishDemoData"]);
mockDemoDataService.publishDemoData.and.resolveTo();
mockDialog = jasmine.createSpyObj(["open"]);
diff --git a/src/app/core/demo-data/demo-data-initializer.service.ts b/src/app/core/demo-data/demo-data-initializer.service.ts
index e4d5d3a78c..50bd44f7e6 100644
--- a/src/app/core/demo-data/demo-data-initializer.service.ts
+++ b/src/app/core/demo-data/demo-data-initializer.service.ts
@@ -95,7 +95,7 @@ export class DemoDataInitializerService {
}
private async syncWithDemoUserDB() {
- const dbName = `${DemoUserGeneratorService.DEFAULT_USERNAME}-${AppConfig.settings.database.name}`;
+ const dbName = `${DemoUserGeneratorService.DEFAULT_USERNAME}-${AppConfig.DB_NAME}`;
let demoUserDB: PouchDB.Database;
if (AppConfig.settings.session_type === SessionType.mock) {
PouchDB.plugin(memory);
@@ -119,7 +119,7 @@ export class DemoDataInitializerService {
}
private initializeDefaultDatabase() {
- const dbName = `${DemoUserGeneratorService.DEFAULT_USERNAME}-${AppConfig.settings.database.name}`;
+ const dbName = `${DemoUserGeneratorService.DEFAULT_USERNAME}-${AppConfig.DB_NAME}`;
if (AppConfig.settings.session_type === SessionType.mock) {
this.pouchDatabase.initInMemoryDB(dbName);
} else {
diff --git a/src/app/core/session/session-service/local-session.spec.ts b/src/app/core/session/session-service/local-session.spec.ts
index 267998ccf0..8494a86a4c 100644
--- a/src/app/core/session/session-service/local-session.spec.ts
+++ b/src/app/core/session/session-service/local-session.spec.ts
@@ -37,8 +37,8 @@ describe("LocalSessionService", () => {
session_type: SessionType.mock,
database: { name: "test-db-name" },
};
- userDBName = `${TEST_USER}-${AppConfig.settings.database.name}`;
- deprecatedDBName = AppConfig.settings.database.name;
+ userDBName = `${TEST_USER}-${AppConfig.DB_NAME}`;
+ deprecatedDBName = AppConfig.DB_NAME;
database = jasmine.createSpyObj([
"initInMemoryDB",
"initIndexedDB",
@@ -120,7 +120,7 @@ describe("LocalSessionService", () => {
await localSession.login(TEST_USER, TEST_PASSWORD);
expect(database.initInMemoryDB).toHaveBeenCalledWith(
- TEST_USER + "-" + AppConfig.settings.database.name
+ TEST_USER + "-" + AppConfig.DB_NAME
);
expect(localSession.getDatabase()).toBe(database);
});
diff --git a/src/app/core/session/session-service/local-session.ts b/src/app/core/session/session-service/local-session.ts
index d226420fd3..f312f9a9a6 100644
--- a/src/app/core/session/session-service/local-session.ts
+++ b/src/app/core/session/session-service/local-session.ts
@@ -69,7 +69,7 @@ export class LocalSession extends SessionService {
}
private async initializeDatabaseForCurrentUser() {
- const userDBName = `${this.currentDBUser.name}-${AppConfig.settings.database.name}`;
+ const userDBName = `${this.currentDBUser.name}-${AppConfig.DB_NAME}`;
// Work on a temporary database before initializing the real one
const tmpDB = new PouchDatabase(undefined);
this.initDatabase(userDBName, tmpDB);
@@ -79,7 +79,7 @@ export class LocalSession extends SessionService {
return;
}
- this.initDatabase(AppConfig.settings.database.name, tmpDB);
+ this.initDatabase(AppConfig.DB_NAME, tmpDB);
const dbFallback = window.localStorage.getItem(
LocalSession.DEPRECATED_DB_KEY
);
@@ -90,7 +90,7 @@ export class LocalSession extends SessionService {
LocalSession.DEPRECATED_DB_KEY,
this.currentDBUser.name
);
- this.initDatabase(AppConfig.settings.database.name);
+ this.initDatabase(AppConfig.DB_NAME);
return;
}
diff --git a/src/app/core/session/session-service/remote-session.ts b/src/app/core/session/session-service/remote-session.ts
index 03ea1546e8..d173d44fc9 100644
--- a/src/app/core/session/session-service/remote-session.ts
+++ b/src/app/core/session/session-service/remote-session.ts
@@ -48,7 +48,7 @@ export class RemoteSession extends SessionService {
) {
super();
this.database = new PouchDatabase(this.loggingService).initIndexedDB(
- `${AppConfig.DB_PROXY_PREFIX}/${AppConfig.settings.database.name}`,
+ `${AppConfig.DB_PROXY_PREFIX}/${AppConfig.DB_NAME}`,
{
adapter: "http",
skip_setup: true,
diff --git a/src/assets/config.default.json b/src/assets/config.default.json
index e81807178b..223ed4fe6b 100644
--- a/src/assets/config.default.json
+++ b/src/assets/config.default.json
@@ -3,9 +3,6 @@
"session_type": "mock",
"demo_mode": true,
- "database": {
- "name": "app"
- },
"debug": false
}
From faeca3424cc07ddbdb22255ec4ffad9617156918 Mon Sep 17 00:00:00 2001
From: Simon
Date: Wed, 6 Jul 2022 12:02:49 +0200
Subject: [PATCH 08/36] removed site_name from config.json and moved it to db
config
---
src/app/app.component.spec.ts | 2 --
.../core/admin/admin/admin.component.spec.ts | 2 --
.../core/analytics/analytics.service.spec.ts | 3 ---
src/app/core/analytics/analytics.service.ts | 21 +++++++++++--------
src/app/core/app-config/app-config.model.ts | 4 ++--
src/app/core/config/config-fix.ts | 3 ++-
.../session-service/local-session.spec.ts | 2 --
.../session-service/remote-session.spec.ts | 2 --
.../synced-session.service.spec.ts | 3 ---
src/app/core/ui/ui-config.ts | 5 +++++
src/app/core/ui/ui/ui.component.ts | 14 +++++--------
src/app/utils/mocked-testing.module.ts | 2 --
src/app/utils/performance-tests.spec.ts | 2 --
13 files changed, 26 insertions(+), 39 deletions(-)
diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts
index cab529e864..ac6d198590 100644
--- a/src/app/app.component.spec.ts
+++ b/src/app/app.component.spec.ts
@@ -48,10 +48,8 @@ describe("AppComponent", () => {
let entityUpdates: Subject>;
const mockAppSettings: IAppConfig = {
- database: { name: "" },
session_type: SessionType.local,
demo_mode: false,
- site_name: "",
};
beforeEach(
diff --git a/src/app/core/admin/admin/admin.component.spec.ts b/src/app/core/admin/admin/admin.component.spec.ts
index a3ccaab64b..a5b9aecfe2 100644
--- a/src/app/core/admin/admin/admin.component.spec.ts
+++ b/src/app/core/admin/admin/admin.component.spec.ts
@@ -56,9 +56,7 @@ describe("AdminComponent", () => {
beforeEach(
waitForAsync(() => {
AppConfig.settings = {
- site_name: "",
session_type: SessionType.mock,
- database: { name: "unit-tests" },
};
TestBed.configureTestingModule({
diff --git a/src/app/core/analytics/analytics.service.spec.ts b/src/app/core/analytics/analytics.service.spec.ts
index e6a002f34d..1277e55655 100644
--- a/src/app/core/analytics/analytics.service.spec.ts
+++ b/src/app/core/analytics/analytics.service.spec.ts
@@ -5,8 +5,6 @@ import { Angulartics2Matomo, Angulartics2Module } from "angulartics2";
import { RouterTestingModule } from "@angular/router/testing";
import { ConfigService } from "../config/config.service";
import { UsageAnalyticsConfig } from "./usage-analytics-config";
-import { AppConfig } from "../app-config/app-config";
-import { IAppConfig } from "../app-config/app-config.model";
import { Subject } from "rxjs";
import { Config } from "../config/config";
@@ -18,7 +16,6 @@ describe("AnalyticsService", () => {
let mockMatomo: jasmine.SpyObj;
beforeEach(() => {
- AppConfig.settings = { site_name: "unit-testing" } as IAppConfig;
mockConfigService = jasmine.createSpyObj(
"mockConfigService",
["getConfig"],
diff --git a/src/app/core/analytics/analytics.service.ts b/src/app/core/analytics/analytics.service.ts
index b3cfc3801a..673a47569f 100644
--- a/src/app/core/analytics/analytics.service.ts
+++ b/src/app/core/analytics/analytics.service.ts
@@ -1,6 +1,5 @@
import { Injectable } from "@angular/core";
import { environment } from "../../../environments/environment";
-import { AppConfig } from "../app-config/app-config";
import { ConfigService } from "../config/config.service";
import {
USAGE_ANALYTICS_CONFIG_ID,
@@ -8,6 +7,7 @@ import {
} from "./usage-analytics-config";
import { Angulartics2, Angulartics2Matomo } from "angulartics2";
import md5 from "md5";
+import { UiConfig } from "../ui/ui-config";
/**
* Track usage analytics data and report it to a backend server like Matomo.
@@ -18,10 +18,6 @@ import md5 from "md5";
providedIn: "root",
})
export class AnalyticsService {
- private static getUserHash(username: string): string {
- return md5(AppConfig.settings?.site_name + username);
- }
-
private isInitialized = false;
constructor(
@@ -30,10 +26,14 @@ export class AnalyticsService {
private configService: ConfigService
) {}
+ /**
+ * Sets a unique user hash which is always for the same user but does not expose the username.
+ * This improves the logging behavior.
+ * @param username actual username
+ */
public setUser(username: string): void {
- this.angulartics2Matomo.setUsername(
- AnalyticsService.getUserHash(username ?? "")
- );
+ const baseUrl = location.host;
+ this.angulartics2Matomo.setUsername(md5(`${baseUrl}${username ?? ""}`));
}
/**
@@ -48,7 +48,6 @@ export class AnalyticsService {
window["_paq"].push(["trackPageView"]);
window["_paq"].push(["enableLinkTracking"]);
this.setVersion();
- this.setOrganization(AppConfig.settings.site_name);
this.setUser(undefined);
this.configService.configUpdates.subscribe(() => this.setConfigValues());
}
@@ -101,6 +100,10 @@ export class AnalyticsService {
if (site_id) {
window["_paq"].push(["setSiteId", site_id]);
}
+ const { site_name } = this.configService.getConfig("appConfig");
+ if (site_name) {
+ this.setOrganization(site_name);
+ }
}
/**
diff --git a/src/app/core/app-config/app-config.model.ts b/src/app/core/app-config/app-config.model.ts
index 74a6eec9bf..24359e0063 100644
--- a/src/app/core/app-config/app-config.model.ts
+++ b/src/app/core/app-config/app-config.model.ts
@@ -25,7 +25,7 @@ import { SessionType } from "../session/session-type";
*/
export interface IAppConfig {
/** Title of the app overall */
- site_name: string;
+ site_name?: string;
/**
* which type of database session to use.
@@ -40,7 +40,7 @@ export interface IAppConfig {
demo_mode?: boolean;
/** database configuration */
- database: {
+ database?: {
/** name of the database - both remote and local */
name: string;
};
diff --git a/src/app/core/config/config-fix.ts b/src/app/core/config/config-fix.ts
index a49f6e7004..e4f7771a1c 100644
--- a/src/app/core/config/config-fix.ts
+++ b/src/app/core/config/config-fix.ts
@@ -17,7 +17,8 @@ import { ratingAnswers } from "../../features/historical-data/model/rating-answe
export const defaultJsonConfig = {
"appConfig": {
"displayLanguageSelect": true,
- "logo_path": null
+ "logo_path": null,
+ "site_name": "Aam Digital - DEMO"
},
"appConfig:usage-analytics": {
"url": "https://matomo.aam-digital.org",
diff --git a/src/app/core/session/session-service/local-session.spec.ts b/src/app/core/session/session-service/local-session.spec.ts
index 8494a86a4c..4016b99dad 100644
--- a/src/app/core/session/session-service/local-session.spec.ts
+++ b/src/app/core/session/session-service/local-session.spec.ts
@@ -33,9 +33,7 @@ describe("LocalSessionService", () => {
beforeEach(() => {
AppConfig.settings = {
- site_name: "Aam Digital - DEV",
session_type: SessionType.mock,
- database: { name: "test-db-name" },
};
userDBName = `${TEST_USER}-${AppConfig.DB_NAME}`;
deprecatedDBName = AppConfig.DB_NAME;
diff --git a/src/app/core/session/session-service/remote-session.spec.ts b/src/app/core/session/session-service/remote-session.spec.ts
index 7bb30a3134..dbc27cb6a8 100644
--- a/src/app/core/session/session-service/remote-session.spec.ts
+++ b/src/app/core/session/session-service/remote-session.spec.ts
@@ -17,9 +17,7 @@ describe("RemoteSessionService", () => {
beforeEach(() => {
AppConfig.settings = {
- site_name: "test",
session_type: SessionType.mock,
- database: { name: "database" },
};
mockHttpClient = jasmine.createSpyObj(["post", "delete"]);
mockHttpClient.delete.and.returnValue(of());
diff --git a/src/app/core/session/session-service/synced-session.service.spec.ts b/src/app/core/session/session-service/synced-session.service.spec.ts
index 063ffa6d73..8dc6cce6ec 100644
--- a/src/app/core/session/session-service/synced-session.service.spec.ts
+++ b/src/app/core/session/session-service/synced-session.service.spec.ts
@@ -63,10 +63,7 @@ describe("SyncedSessionService", () => {
],
});
AppConfig.settings = {
- site_name: "Aam Digital - DEV",
session_type: SessionType.mock,
- database: { name: "integration_tests" },
- webdav: { remote_url: "" },
};
sessionService = TestBed.inject(SyncedSessionService);
diff --git a/src/app/core/ui/ui-config.ts b/src/app/core/ui/ui-config.ts
index 4e4c7cff76..0929023e73 100644
--- a/src/app/core/ui/ui-config.ts
+++ b/src/app/core/ui/ui-config.ts
@@ -14,4 +14,9 @@ export interface UiConfig {
* This should only be used if configurations for multiple languages are available.
*/
displayLanguageSelect: boolean;
+
+ /**
+ * The title which is shown at the top of the application.
+ */
+ site_name: string;
}
diff --git a/src/app/core/ui/ui/ui.component.ts b/src/app/core/ui/ui/ui.component.ts
index c497a86892..3f0064d985 100644
--- a/src/app/core/ui/ui/ui.component.ts
+++ b/src/app/core/ui/ui/ui.component.ts
@@ -15,9 +15,8 @@
* along with ndb-core. If not, see .
*/
-import { Component, OnInit, ViewChild } from "@angular/core";
+import { Component,ViewChild } from "@angular/core";
import { SessionService } from "../../session/session-service/session.service";
-import { AppConfig } from "../../app-config/app-config";
import { Title } from "@angular/platform-browser";
import { MediaChange, MediaObserver } from "@angular/flex-layout";
import { UntilDestroy, untilDestroyed } from "@ngneat/until-destroy";
@@ -35,14 +34,14 @@ import { UiConfig } from "../ui-config";
templateUrl: "./ui.component.html",
styleUrls: ["./ui.component.scss"],
})
-export class UiComponent implements OnInit {
+export class UiComponent {
/** display mode for the menu to make it responsive and usable on smaller screens */
sideNavMode: MatDrawerMode;
/** reference to sideNav component in template, required for toggling the menu on user actions */
@ViewChild("sideNav") sideNav;
/** title displayed in the app header bar */
- title: string;
+ title = "Aam Digital";
/** path to the image of a logo */
logo_path: string;
@@ -70,16 +69,13 @@ export class UiComponent implements OnInit {
.pipe(untilDestroyed(this))
.subscribe(() => {
const uiConfig = this.configService.getConfig("appConfig");
+ this.title = uiConfig.site_name || this.title;
+ this.titleService.setTitle(this.title);
this.logo_path = uiConfig?.logo_path;
this.showLanguageSelect = uiConfig?.displayLanguageSelect === true;
});
}
- ngOnInit(): void {
- this.title = AppConfig?.settings?.site_name;
- this.titleService.setTitle(this.title);
- }
-
/**
* Check if user is logged in.
*/
diff --git a/src/app/utils/mocked-testing.module.ts b/src/app/utils/mocked-testing.module.ts
index fc9b0cf730..f9bae63299 100644
--- a/src/app/utils/mocked-testing.module.ts
+++ b/src/app/utils/mocked-testing.module.ts
@@ -88,9 +88,7 @@ export class MockedTestingModule {
data: Entity[] = []
): ModuleWithProviders {
AppConfig.settings = {
- site_name: "Aam Digital - DEV",
session_type: SessionType.mock,
- database: { name: "test-db-name" },
};
const mockedEntityMapper = mockEntityMapper([new User(TEST_USER), ...data]);
const session = createLocalSession(loginState === LoginState.LOGGED_IN);
diff --git a/src/app/utils/performance-tests.spec.ts b/src/app/utils/performance-tests.spec.ts
index 07759f7b11..ea3a8b7410 100644
--- a/src/app/utils/performance-tests.spec.ts
+++ b/src/app/utils/performance-tests.spec.ts
@@ -12,9 +12,7 @@ xdescribe("Performance Tests", () => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 150000;
AppConfig.settings = {
- site_name: "Aam Digital - DEV",
session_type: SessionType.mock, // change to SessionType.local to run performance tests with the InBrowser database
- database: { name: "test-db-name" },
};
await TestBed.configureTestingModule({
From b4f7b06742a0480a00da4050264986d26b8a7d6d Mon Sep 17 00:00:00 2001
From: Simon
Date: Wed, 6 Jul 2022 12:19:34 +0200
Subject: [PATCH 09/36] fixed tests
---
src/app/core/analytics/analytics.service.ts | 3 ++-
src/app/core/ui/ui-config.ts | 6 +++---
src/app/core/ui/ui/ui.component.ts | 5 +++--
3 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/src/app/core/analytics/analytics.service.ts b/src/app/core/analytics/analytics.service.ts
index 673a47569f..5d9f25412f 100644
--- a/src/app/core/analytics/analytics.service.ts
+++ b/src/app/core/analytics/analytics.service.ts
@@ -100,7 +100,8 @@ export class AnalyticsService {
if (site_id) {
window["_paq"].push(["setSiteId", site_id]);
}
- const { site_name } = this.configService.getConfig("appConfig");
+ const { site_name } =
+ this.configService.getConfig("appConfig") || {};
if (site_name) {
this.setOrganization(site_name);
}
diff --git a/src/app/core/ui/ui-config.ts b/src/app/core/ui/ui-config.ts
index 0929023e73..1d58bd247c 100644
--- a/src/app/core/ui/ui-config.ts
+++ b/src/app/core/ui/ui-config.ts
@@ -7,16 +7,16 @@ export interface UiConfig {
* The path to a logo icon inside the `assets` folder.
* This will be displayed on top of the navigation items.
*/
- logo_path: string;
+ logo_path?: string;
/**
* Toggle whether the language select component should be displayed.
* This should only be used if configurations for multiple languages are available.
*/
- displayLanguageSelect: boolean;
+ displayLanguageSelect?: boolean;
/**
* The title which is shown at the top of the application.
*/
- site_name: string;
+ site_name?: string;
}
diff --git a/src/app/core/ui/ui/ui.component.ts b/src/app/core/ui/ui/ui.component.ts
index 3f0064d985..81076b974c 100644
--- a/src/app/core/ui/ui/ui.component.ts
+++ b/src/app/core/ui/ui/ui.component.ts
@@ -15,7 +15,7 @@
* along with ndb-core. If not, see .
*/
-import { Component,ViewChild } from "@angular/core";
+import { Component, ViewChild } from "@angular/core";
import { SessionService } from "../../session/session-service/session.service";
import { Title } from "@angular/platform-browser";
import { MediaChange, MediaObserver } from "@angular/flex-layout";
@@ -68,7 +68,8 @@ export class UiComponent {
this.configService.configUpdates
.pipe(untilDestroyed(this))
.subscribe(() => {
- const uiConfig = this.configService.getConfig("appConfig");
+ const uiConfig =
+ this.configService.getConfig("appConfig") || {};
this.title = uiConfig.site_name || this.title;
this.titleService.setTitle(this.title);
this.logo_path = uiConfig?.logo_path;
From 6f25216125bf299f2018fc130cb330429ea89ac8 Mon Sep 17 00:00:00 2001
From: Simon
Date: Wed, 6 Jul 2022 14:18:12 +0200
Subject: [PATCH 10/36] removed session type from config.json and moved it
environment or query params
---
src/app/app.component.spec.ts | 12 +++-------
src/app/app.component.ts | 2 +-
.../core/admin/admin/admin.component.spec.ts | 4 +---
src/app/core/app-config/app-config.ts | 23 +++++++++++++++++++
.../demo-data-initializer.service.spec.ts | 6 +----
.../demo-data-initializer.service.ts | 7 +++---
.../session-service/local-session.spec.ts | 6 ++---
.../session/session-service/local-session.ts | 2 +-
.../session-service/remote-session.spec.ts | 4 +---
.../synced-session.service.spec.ts | 4 +---
src/app/core/session/session.module.ts | 2 +-
.../user-account.component.spec.ts | 5 +---
.../user-account/user-account.component.ts | 8 +++----
src/app/utils/database-testing.module.ts | 3 +++
src/app/utils/mocked-testing.module.ts | 4 +---
src/app/utils/performance-tests.spec.ts | 4 +---
src/environments/environment.ts | 4 ++++
17 files changed, 52 insertions(+), 48 deletions(-)
diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts
index ac6d198590..4936aa002c 100644
--- a/src/app/app.component.spec.ts
+++ b/src/app/app.component.spec.ts
@@ -27,7 +27,6 @@ import {
import { AppComponent } from "./app.component";
import { AppModule } from "./app.module";
import { AppConfig } from "./core/app-config/app-config";
-import { IAppConfig } from "./core/app-config/app-config.model";
import { Config } from "./core/config/config";
import { USAGE_ANALYTICS_CONFIG_ID } from "./core/analytics/usage-analytics-config";
import { environment } from "../environments/environment";
@@ -47,14 +46,9 @@ describe("AppComponent", () => {
let fixture: ComponentFixture;
let entityUpdates: Subject>;
- const mockAppSettings: IAppConfig = {
- session_type: SessionType.local,
- demo_mode: false,
- };
-
beforeEach(
waitForAsync(() => {
- AppConfig.settings = mockAppSettings;
+ AppConfig.SESSION_TYPE = SessionType.mock;
const entityMapper = mockEntityMapper();
entityUpdates = new Subject();
spyOn(entityMapper, "receiveUpdates").and.returnValue(entityUpdates);
@@ -113,13 +107,13 @@ describe("AppComponent", () => {
it("published the demo data", fakeAsync(() => {
const demoDataService = TestBed.inject(DemoDataService);
spyOn(demoDataService, "publishDemoData").and.callThrough();
- AppConfig.settings.demo_mode = true;
+ AppConfig.DEMO_MODE = true;
createComponent();
flush();
discardPeriodicTasks();
expect(demoDataService.publishDemoData).toHaveBeenCalled();
- AppConfig.settings.demo_mode = false;
+ AppConfig.DEMO_MODE = false;
}));
});
diff --git a/src/app/app.component.ts b/src/app/app.component.ts
index 6e349c3acd..0cdf00fd69 100644
--- a/src/app/app.component.ts
+++ b/src/app/app.component.ts
@@ -90,7 +90,7 @@ export class AppComponent {
this.analyticsService.init();
}
- if (AppConfig.settings.demo_mode) {
+ if (AppConfig.DEMO_MODE) {
await this.demoDataInitializer.run();
}
}
diff --git a/src/app/core/admin/admin/admin.component.spec.ts b/src/app/core/admin/admin/admin.component.spec.ts
index a5b9aecfe2..c959a34331 100644
--- a/src/app/core/admin/admin/admin.component.spec.ts
+++ b/src/app/core/admin/admin/admin.component.spec.ts
@@ -55,9 +55,7 @@ describe("AdminComponent", () => {
beforeEach(
waitForAsync(() => {
- AppConfig.settings = {
- session_type: SessionType.mock,
- };
+ AppConfig.SESSION_TYPE = SessionType.mock;
TestBed.configureTestingModule({
imports: [AdminModule, MockedTestingModule.withState()],
diff --git a/src/app/core/app-config/app-config.ts b/src/app/core/app-config/app-config.ts
index 004db4e7a6..fa284cb70c 100644
--- a/src/app/core/app-config/app-config.ts
+++ b/src/app/core/app-config/app-config.ts
@@ -16,6 +16,8 @@
*/
import { IAppConfig } from "./app-config.model";
+import { SessionType } from "../session/session-type";
+import { environment } from "../../../environments/environment";
/**
* Central app configuration.
@@ -38,6 +40,9 @@ export class AppConfig {
static readonly DB_PROXY_PREFIX = "/db";
/** Name of the database that is used */
static readonly DB_NAME = "app";
+
+ static DEMO_MODE = false;
+ static SESSION_TYPE = SessionType.synced;
/** settings for the app */
static settings: IAppConfig;
@@ -53,6 +58,24 @@ export class AppConfig {
* If the config file does not exist, uses the default config as a fallback.
*/
static load(): Promise {
+ const params = new URLSearchParams(location.search);
+ const demoMode = params.get("demo");
+ const sessionType = params.get("session");
+ if (demoMode === "true" || environment.demo_mode) {
+ AppConfig.DEMO_MODE = true;
+ }
+ if (
+ sessionType === "mock" ||
+ environment.session_type === SessionType.mock
+ ) {
+ AppConfig.SESSION_TYPE = SessionType.mock;
+ } else if (
+ sessionType === "local" ||
+ environment.session_type === SessionType.local
+ ) {
+ AppConfig.SESSION_TYPE = SessionType.local;
+ }
+ console.log("params", demoMode, sessionType);
return this.loadAppConfigJson(this.CONFIG_FILE).catch(() =>
this.loadAppConfigJson(this.DEFAULT_CONFIG_FILE)
);
diff --git a/src/app/core/demo-data/demo-data-initializer.service.spec.ts b/src/app/core/demo-data/demo-data-initializer.service.spec.ts
index 2cce870282..fd676b468c 100644
--- a/src/app/core/demo-data/demo-data-initializer.service.spec.ts
+++ b/src/app/core/demo-data/demo-data-initializer.service.spec.ts
@@ -11,7 +11,6 @@ import { AppConfig } from "../app-config/app-config";
import { PouchDatabase } from "../database/pouch-database";
import { Subject } from "rxjs";
import { LoginState } from "../session/session-states/login-state.enum";
-import { IAppConfig } from "../app-config/app-config.model";
import { Database } from "../database/database";
import { SessionType } from "../session/session-type";
@@ -25,10 +24,7 @@ describe("DemoDataInitializerService", () => {
let adminDBName: string;
beforeEach(() => {
- AppConfig.settings = {
- database: { name: "test-db" },
- session_type: SessionType.mock,
- } as IAppConfig;
+ AppConfig.SESSION_TYPE = SessionType.mock;
demoUserDBName = `${DemoUserGeneratorService.DEFAULT_USERNAME}-${AppConfig.DB_NAME}`;
adminDBName = `${DemoUserGeneratorService.ADMIN_USERNAME}-${AppConfig.DB_NAME}`;
mockDemoDataService = jasmine.createSpyObj(["publishDemoData"]);
diff --git a/src/app/core/demo-data/demo-data-initializer.service.ts b/src/app/core/demo-data/demo-data-initializer.service.ts
index 50bd44f7e6..189cb7c651 100644
--- a/src/app/core/demo-data/demo-data-initializer.service.ts
+++ b/src/app/core/demo-data/demo-data-initializer.service.ts
@@ -42,8 +42,7 @@ export class DemoDataInitializerService {
this.pouchDatabase = this.database;
} else {
this.loggingService.warn(
- "Cannot create demo data with session: " +
- AppConfig.settings.session_type
+ "Cannot create demo data with session: " + AppConfig.SESSION_TYPE
);
}
this.registerDemoUsers();
@@ -97,7 +96,7 @@ export class DemoDataInitializerService {
private async syncWithDemoUserDB() {
const dbName = `${DemoUserGeneratorService.DEFAULT_USERNAME}-${AppConfig.DB_NAME}`;
let demoUserDB: PouchDB.Database;
- if (AppConfig.settings.session_type === SessionType.mock) {
+ if (AppConfig.SESSION_TYPE === SessionType.mock) {
PouchDB.plugin(memory);
demoUserDB = new PouchDB(dbName, { adapter: "memory" });
} else {
@@ -120,7 +119,7 @@ export class DemoDataInitializerService {
private initializeDefaultDatabase() {
const dbName = `${DemoUserGeneratorService.DEFAULT_USERNAME}-${AppConfig.DB_NAME}`;
- if (AppConfig.settings.session_type === SessionType.mock) {
+ if (AppConfig.SESSION_TYPE === SessionType.mock) {
this.pouchDatabase.initInMemoryDB(dbName);
} else {
this.pouchDatabase.initIndexedDB(dbName);
diff --git a/src/app/core/session/session-service/local-session.spec.ts b/src/app/core/session/session-service/local-session.spec.ts
index 4016b99dad..85dcd7bda1 100644
--- a/src/app/core/session/session-service/local-session.spec.ts
+++ b/src/app/core/session/session-service/local-session.spec.ts
@@ -32,9 +32,7 @@ describe("LocalSessionService", () => {
let database: jasmine.SpyObj;
beforeEach(() => {
- AppConfig.settings = {
- session_type: SessionType.mock,
- };
+ AppConfig.SESSION_TYPE = SessionType.mock;
userDBName = `${TEST_USER}-${AppConfig.DB_NAME}`;
deprecatedDBName = AppConfig.DB_NAME;
database = jasmine.createSpyObj([
@@ -130,7 +128,7 @@ describe("LocalSessionService", () => {
) {
database.initInMemoryDB.calls.reset();
database.initIndexedDB.calls.reset();
- AppConfig.settings.session_type = sessionType;
+ AppConfig.SESSION_TYPE = sessionType;
await localSession.login(TEST_USER, TEST_PASSWORD);
if (expectedDB === "inMemory") {
expect(database.initInMemoryDB).toHaveBeenCalled();
diff --git a/src/app/core/session/session-service/local-session.ts b/src/app/core/session/session-service/local-session.ts
index f312f9a9a6..92a259e510 100644
--- a/src/app/core/session/session-service/local-session.ts
+++ b/src/app/core/session/session-service/local-session.ts
@@ -99,7 +99,7 @@ export class LocalSession extends SessionService {
}
private initDatabase(dbName: string, db = this.database) {
- if (AppConfig.settings.session_type === SessionType.mock) {
+ if (AppConfig.SESSION_TYPE === SessionType.mock) {
db.initInMemoryDB(dbName);
} else {
db.initIndexedDB(dbName);
diff --git a/src/app/core/session/session-service/remote-session.spec.ts b/src/app/core/session/session-service/remote-session.spec.ts
index dbc27cb6a8..8f6bec6862 100644
--- a/src/app/core/session/session-service/remote-session.spec.ts
+++ b/src/app/core/session/session-service/remote-session.spec.ts
@@ -16,9 +16,7 @@ describe("RemoteSessionService", () => {
let dbUser: DatabaseUser;
beforeEach(() => {
- AppConfig.settings = {
- session_type: SessionType.mock,
- };
+ AppConfig.SESSION_TYPE = SessionType.mock;
mockHttpClient = jasmine.createSpyObj(["post", "delete"]);
mockHttpClient.delete.and.returnValue(of());
diff --git a/src/app/core/session/session-service/synced-session.service.spec.ts b/src/app/core/session/session-service/synced-session.service.spec.ts
index 8dc6cce6ec..3087903f6e 100644
--- a/src/app/core/session/session-service/synced-session.service.spec.ts
+++ b/src/app/core/session/session-service/synced-session.service.spec.ts
@@ -62,9 +62,7 @@ describe("SyncedSessionService", () => {
{ provide: LOCATION_TOKEN, useValue: mockLocation },
],
});
- AppConfig.settings = {
- session_type: SessionType.mock,
- };
+ AppConfig.SESSION_TYPE = SessionType.mock;
sessionService = TestBed.inject(SyncedSessionService);
localSession = TestBed.inject(LocalSession);
diff --git a/src/app/core/session/session.module.ts b/src/app/core/session/session.module.ts
index 2947ee0733..67e03c4189 100644
--- a/src/app/core/session/session.module.ts
+++ b/src/app/core/session/session.module.ts
@@ -70,7 +70,7 @@ import { SessionType } from "./session-type";
{
provide: SessionService,
useFactory: (injector: Injector) => {
- if (AppConfig?.settings?.session_type === SessionType.synced) {
+ if (AppConfig.SESSION_TYPE === SessionType.synced) {
return injector.get(SyncedSessionService);
} else {
return injector.get(LocalSession);
diff --git a/src/app/core/user/user-account/user-account.component.spec.ts b/src/app/core/user/user-account/user-account.component.spec.ts
index 6fba8aef08..16e1eac4ac 100644
--- a/src/app/core/user/user-account/user-account.component.spec.ts
+++ b/src/app/core/user/user-account/user-account.component.spec.ts
@@ -30,7 +30,6 @@ import { AppConfig } from "../../app-config/app-config";
import { UserAccountService } from "./user-account.service";
import { UserModule } from "../user.module";
import { SessionType } from "../../session/session-type";
-import { IAppConfig } from "../../app-config/app-config.model";
import { LoggingService } from "../../logging/logging.service";
import { TabStateModule } from "../../../utils/tab-state/tab-state.module";
import { RouterTestingModule } from "@angular/router/testing";
@@ -45,9 +44,7 @@ describe("UserAccountComponent", () => {
beforeEach(
waitForAsync(() => {
- AppConfig.settings = {
- session_type: SessionType.synced, // password change only available in synced mode
- } as IAppConfig;
+ AppConfig.SESSION_TYPE = SessionType.synced; // password change only available in synced mode
mockSessionService = jasmine.createSpyObj("sessionService", [
"getCurrentUser",
"login",
diff --git a/src/app/core/user/user-account/user-account.component.ts b/src/app/core/user/user-account/user-account.component.ts
index 10976345f3..0891260333 100644
--- a/src/app/core/user/user-account/user-account.component.ts
+++ b/src/app/core/user/user-account/user-account.component.ts
@@ -79,7 +79,7 @@ export class UserAccountComponent implements OnInit {
this.disabledForOfflineMode = false;
this.passwordForm.enable();
- if (AppConfig.settings.session_type !== SessionType.synced) {
+ if (AppConfig.SESSION_TYPE !== SessionType.synced) {
this.disabledForDemoMode = true;
this.passwordForm.disable();
} else if (!navigator.onLine) {
@@ -117,9 +117,9 @@ export class UserAccountComponent implements OnInit {
}
private passwordMatchValidator(): ValidationErrors | null {
- const newPassword: string = this?.passwordForm?.get("newPassword")?.value;
- const confirmPassword: string =
- this?.passwordForm?.get("confirmPassword")?.value;
+ const newPassword: string = this.passwordForm.get("newPassword")?.value;
+ const confirmPassword: string = this.passwordForm.get("confirmPassword")
+ ?.value;
if (newPassword !== confirmPassword) {
this.passwordForm
.get("confirmPassword")
diff --git a/src/app/utils/database-testing.module.ts b/src/app/utils/database-testing.module.ts
index fbf0cc55c4..369ab00ffa 100644
--- a/src/app/utils/database-testing.module.ts
+++ b/src/app/utils/database-testing.module.ts
@@ -20,6 +20,8 @@ import {
ConfigService,
createTestingConfigService,
} from "../core/config/config.service";
+import { AppConfig } from "../core/app-config/app-config";
+import { SessionType } from "../core/session/session-type";
/**
* Utility module that creates a simple environment where a correctly configured database and session is set up.
@@ -48,6 +50,7 @@ import {
})
export class DatabaseTestingModule {
constructor(pouchDatabase: PouchDatabase) {
+ AppConfig.SESSION_TYPE = SessionType.mock;
pouchDatabase.initInMemoryDB();
}
}
diff --git a/src/app/utils/mocked-testing.module.ts b/src/app/utils/mocked-testing.module.ts
index f9bae63299..e523117186 100644
--- a/src/app/utils/mocked-testing.module.ts
+++ b/src/app/utils/mocked-testing.module.ts
@@ -87,9 +87,7 @@ export class MockedTestingModule {
loginState = LoginState.LOGGED_IN,
data: Entity[] = []
): ModuleWithProviders {
- AppConfig.settings = {
- session_type: SessionType.mock,
- };
+ AppConfig.SESSION_TYPE = SessionType.mock;
const mockedEntityMapper = mockEntityMapper([new User(TEST_USER), ...data]);
const session = createLocalSession(loginState === LoginState.LOGGED_IN);
return {
diff --git a/src/app/utils/performance-tests.spec.ts b/src/app/utils/performance-tests.spec.ts
index ea3a8b7410..bdfee538db 100644
--- a/src/app/utils/performance-tests.spec.ts
+++ b/src/app/utils/performance-tests.spec.ts
@@ -11,9 +11,7 @@ xdescribe("Performance Tests", () => {
beforeEach(async () => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 150000;
- AppConfig.settings = {
- session_type: SessionType.mock, // change to SessionType.local to run performance tests with the InBrowser database
- };
+ AppConfig.SESSION_TYPE = SessionType.mock; // change to SessionType.local to run performance tests with the InBrowser database
await TestBed.configureTestingModule({
imports: [AppModule, DatabaseTestingModule],
diff --git a/src/environments/environment.ts b/src/environments/environment.ts
index cd0e7a99f6..9d9a0cc0cd 100644
--- a/src/environments/environment.ts
+++ b/src/environments/environment.ts
@@ -15,6 +15,8 @@
* along with ndb-core. If not, see .
*/
+import { SessionType } from "../app/core/session/session-type";
+
/**
* Central environment that allows to configure differences between a "dev" and a "prod" build.
*
@@ -28,4 +30,6 @@ export const environment = {
appVersion: "0.0.0", // replaced automatically during docker build
repositoryId: "Aam-Digital/ndb-core",
remoteLoggingDsn: undefined, // only set for production mode in environment.prod.ts
+ demo_mode: true,
+ session_type: SessionType.mock,
};
From 70d87d446e443dfec2bd761523784dbc1c0fb9f9 Mon Sep 17 00:00:00 2001
From: Simon
Date: Thu, 7 Jul 2022 14:20:12 +0200
Subject: [PATCH 11/36] added default env options to prod settings
---
src/environments/environment.prod.ts | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/environments/environment.prod.ts b/src/environments/environment.prod.ts
index ec5209edb0..5294f80299 100644
--- a/src/environments/environment.prod.ts
+++ b/src/environments/environment.prod.ts
@@ -15,6 +15,8 @@
* along with ndb-core. If not, see .
*/
+import { SessionType } from "../app/core/session/session-type";
+
/**
* Central environment that allows to configure differences between a "dev" and a "prod" build.
*
@@ -29,4 +31,6 @@ export const environment = {
repositoryId: "Aam-Digital/ndb-core",
remoteLoggingDsn:
"https://bd6aba79ca514d35bb06a4b4e0c2a21e@sentry.io/1242399",
+ demo_mode: false,
+ session_type: SessionType.synced,
};
From edcfba0a05836e1bbccd2d0b701edc13d2b35c60 Mon Sep 17 00:00:00 2001
From: Simon
Date: Fri, 8 Jul 2022 11:06:20 +0200
Subject: [PATCH 12/36] added demo redirect to nginx conf and option to disable
it to dockerfile
---
build/Dockerfile | 9 +++++----
build/default.conf | 14 +++++++++++---
2 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/build/Dockerfile b/build/Dockerfile
index 3a062f9427..cfae6af112 100644
--- a/build/Dockerfile
+++ b/build/Dockerfile
@@ -1,9 +1,8 @@
# This docker image can be used to run the application locally.
# To use it only Docker needs to be installed locally
# Run the following commands from the root folder to build, run and kill the application
-# >> docker build -f build/Dockerfile -t aam/digital:latest .
-# >> docker run -p=80:80 aam/digital:latest
-# >> docker kill aam-digital
+# >> docker build -f build/Dockerfile -t aam-digital .
+# >> docker run -p=80:80 aam-digital
FROM node:16.14.2-alpine3.15 as builder
WORKDIR /app
@@ -73,6 +72,8 @@ ENV WEBDAV_URL="http://localhost"
ENV COUCHDB_URL="http://localhost"
# The language which should be loaded on default options are "en-US" and "de"
ENV DEFAULT_LANGUAGE="en-US"
+# Whether the app should be started in demo mode. Everything else then "true" is considered as "false".
+ENV DEMO="true"
# variables are inserted into the nginx config
-CMD envsubst '$$PORT $$WEBDAV_URL $$COUCHDB_URL $$DEFAULT_LANGUAGE' < /etc/nginx/templates/default.conf > /etc/nginx/conf.d/default.conf &&\
+CMD envsubst '$$PORT $$WEBDAV_URL $$COUCHDB_URL $$DEFAULT_LANGUAGE $$DEMO' < /etc/nginx/templates/default.conf > /etc/nginx/conf.d/default.conf &&\
nginx -g 'daemon off;'
diff --git a/build/default.conf b/build/default.conf
index 6840fcce02..842532633a 100644
--- a/build/default.conf
+++ b/build/default.conf
@@ -7,6 +7,14 @@ server {
root /usr/share/nginx/html;
+ # If ${DEMO}=true is injected then the demo url params are added if not present yet.
+ if ($arg_demo != "true") {
+ set $demo "${DEMO}true";
+ }
+ if ($demo = "truetrue") {
+ rewrite ^ $uri?demo=true&session=mock redirect;
+ }
+
# Catch requests to the (locale) assets folder and add fallback to super-folder
# E.g. if '/en-US/assets/config.json' doesn't exist, try '/assets/config.json'
location ~* ^/.+/assets/(.+)$ {
@@ -21,17 +29,17 @@ server {
location /de {
index index.html index.htm;
- try_files $uri $uri/ /de/index.html;
+ try_files $uri $uri/ /de/index.html =404;
}
location /fr {
index index.html index.htm;
- try_files $uri $uri/ /fr/index.html;
+ try_files $uri $uri/ /fr/index.html =404;
}
location /en {
index index.html index.htm;
- try_files $uri $uri/ /en-US/index.html;
+ try_files $uri $uri/ /en-US/index.html =404;
}
# Append the default language when no other path matches (e.g. requesting root index.html)
From b50268081394cdc3346ce6df22f6a84778f4c0d4 Mon Sep 17 00:00:00 2001
From: Simon
Date: Fri, 8 Jul 2022 11:25:27 +0200
Subject: [PATCH 13/36] cleaned up initialization of AppConfig settings and
removed old references
---
src/app/app.module.ts | 2 +
src/app/core/admin/admin/admin.component.html | 29 ++++-----
src/app/core/admin/admin/admin.component.ts | 4 --
src/app/core/app-config/app-config.model.ts | 64 -------------------
src/app/core/app-config/app-config.ts | 49 +++-----------
src/main.ts | 8 +--
6 files changed, 23 insertions(+), 133 deletions(-)
delete mode 100644 src/app/core/app-config/app-config.model.ts
diff --git a/src/app/app.module.ts b/src/app/app.module.ts
index 507f38ad4f..1e50f93357 100644
--- a/src/app/app.module.ts
+++ b/src/app/app.module.ts
@@ -80,6 +80,7 @@ import { SupportModule } from "./core/support/support.module";
import { DemoConfigGeneratorService } from "./core/config/demo-config-generator.service";
import { DatabaseModule } from "./core/database/database.module";
import { Angulartics2Matomo, Angulartics2Module } from "angulartics2";
+import { AppConfig } from "./core/app-config/app-config";
/**
* Main entry point of the application.
@@ -168,6 +169,7 @@ import { Angulartics2Matomo, Angulartics2Module } from "angulartics2";
})
export class AppModule {
constructor(icons: FaIconLibrary) {
+ AppConfig.initSettings();
icons.addIconPacks(fas, far);
}
}
diff --git a/src/app/core/admin/admin/admin.component.html b/src/app/core/admin/admin/admin.component.html
index 0d93f810cb..32ee5d030a 100644
--- a/src/app/core/admin/admin/admin.component.html
+++ b/src/app/core/admin/admin/admin.component.html
@@ -5,8 +5,8 @@ Administration & Configuration
you know what you are doing.
-
-
+
+
Utility Functions
-
-
+
+
Backup
-
-
+
+
Export
-
-
+
+
Application Configuration
-
-
-AppConfig
-{{ appConfig | json }}
-
-
-
+
+
Debug the PouchDB
-
-
+
+
Alert Log
diff --git a/src/app/core/admin/admin/admin.component.ts b/src/app/core/admin/admin/admin.component.ts
index ce00938358..196ea7b7be 100644
--- a/src/app/core/admin/admin/admin.component.ts
+++ b/src/app/core/admin/admin/admin.component.ts
@@ -1,5 +1,4 @@
import { Component, OnInit } from "@angular/core";
-import { AppConfig } from "../../app-config/app-config";
import { AlertService } from "../../alerts/alert.service";
import { Alert } from "../../alerts/alert";
import { BackupService } from "../services/backup.service";
@@ -23,9 +22,6 @@ import { Database } from "../../database/database";
styleUrls: ["./admin.component.scss"],
})
export class AdminComponent implements OnInit {
- /** app-wide configuration */
- appConfig = AppConfig.settings;
-
/** all alerts */
alerts: Alert[];
diff --git a/src/app/core/app-config/app-config.model.ts b/src/app/core/app-config/app-config.model.ts
deleted file mode 100644
index 24359e0063..0000000000
--- a/src/app/core/app-config/app-config.model.ts
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * This file is part of ndb-core.
- *
- * ndb-core is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * ndb-core is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with ndb-core. If not, see .
- */
-
-import { SessionType } from "../session/session-type";
-
-/**
- * Interface to facilitate use of AppConfig.settings.
- *
- * This defines the settings that should be available in the config.json and therefore in the AppConfig.settings.
- * Adapt this interface when you add more config options to the core.
- */
-export interface IAppConfig {
- /** Title of the app overall */
- site_name?: string;
-
- /**
- * which type of database session to use.
- *
- * see {@link SessionType} for details on available modes
- */
- session_type: SessionType;
-
- /**
- * whether the app should offer to generate demo data and show special demo guidance for users
- */
- demo_mode?: boolean;
-
- /** database configuration */
- database?: {
- /** name of the database - both remote and local */
- name: string;
- };
-
- /**
- * Optional configuration of a webdav (e.g. Nextcloud) integration
- */
- webdav?: {
- /**
- * URL to the webdav endpoint of the Nextcloud server
- *
- * Beware of CORS issues if this is on a different domain than the app is served from.
- */
- remote_url: string;
- };
-
- /**
- * Optional flag to activate additional debugging output to troubleshoot problems on a user's device
- */
- debug?: boolean;
-}
diff --git a/src/app/core/app-config/app-config.ts b/src/app/core/app-config/app-config.ts
index fa284cb70c..d7c4f25922 100644
--- a/src/app/core/app-config/app-config.ts
+++ b/src/app/core/app-config/app-config.ts
@@ -15,7 +15,6 @@
* along with ndb-core. If not, see .
*/
-import { IAppConfig } from "./app-config.model";
import { SessionType } from "../session/session-type";
import { environment } from "../../../environments/environment";
@@ -40,24 +39,19 @@ export class AppConfig {
static readonly DB_PROXY_PREFIX = "/db";
/** Name of the database that is used */
static readonly DB_NAME = "app";
-
+ /**
+ * Whether the app is running in demo mode.
+ */
static DEMO_MODE = false;
+ /**
+ * The session type that is used.
+ */
static SESSION_TYPE = SessionType.synced;
- /** settings for the app */
- static settings: IAppConfig;
-
- /** file location of the config file to be created by the administrator */
- private static readonly CONFIG_FILE = "assets/config.json";
-
- /** fallback file location of the config that is part of the project already if the "real" config file isn't found */
- private static readonly DEFAULT_CONFIG_FILE = "assets/config.default.json";
/**
- * Load the config file into the `AppConfig.settings` so they can be used synchronously anywhere in the code after that.
- *
- * If the config file does not exist, uses the default config as a fallback.
+ * Initializes static settings through the environment or the URL params.
*/
- static load(): Promise {
+ static initSettings() {
const params = new URLSearchParams(location.search);
const demoMode = params.get("demo");
const sessionType = params.get("session");
@@ -75,32 +69,5 @@ export class AppConfig {
) {
AppConfig.SESSION_TYPE = SessionType.local;
}
- console.log("params", demoMode, sessionType);
- return this.loadAppConfigJson(this.CONFIG_FILE).catch(() =>
- this.loadAppConfigJson(this.DEFAULT_CONFIG_FILE)
- );
- }
-
- /**
- * Load the given file and set it as AppConfig.settings.
- *
- * This requires a HTTP request because the "assets" folder including the config.json is on our server
- * while this javascript code is executed in the users browser.
- *
- * @param jsonFileLocation The file path of the json file to be loaded as config
- */
- private static loadAppConfigJson(
- jsonFileLocation: string
- ): Promise {
- return fetch(jsonFileLocation)
- .then((result) => result.json())
- .then((result: IAppConfig) => (AppConfig.settings = result))
- .catch((response: any) => {
- throw new Error(
- `Could not load file '${jsonFileLocation}': ${JSON.stringify(
- response
- )}`
- );
- });
}
}
diff --git a/src/main.ts b/src/main.ts
index 4d883308fe..b87fbe2fcb 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -20,7 +20,6 @@ import { platformBrowserDynamic } from "@angular/platform-browser-dynamic";
import { AppModule } from "./app/app.module";
import { environment } from "./environments/environment";
-import { AppConfig } from "./app/core/app-config/app-config";
// Import hammer.js to enable gestures
// on mobile devices
@@ -30,9 +29,4 @@ if (environment.production) {
enableProdMode();
}
-/**
- * Loading AppConfig before bootstrap process (see {@link https://stackoverflow.com/a/66957293/10713841})
- */
-AppConfig.load().then(() =>
- platformBrowserDynamic().bootstrapModule(AppModule)
-);
+platformBrowserDynamic().bootstrapModule(AppModule);
From e7f2ff8f8ce678067735693ec7d5915959b3f557 Mon Sep 17 00:00:00 2001
From: Simon
Date: Fri, 8 Jul 2022 11:46:03 +0200
Subject: [PATCH 14/36] fixed tests
---
src/app/app.component.spec.ts | 27 ++++----
.../user-account.component.spec.ts | 63 +++++++++----------
.../user-account/user-account.component.ts | 5 +-
3 files changed, 44 insertions(+), 51 deletions(-)
diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts
index 4936aa002c..562d1a896c 100644
--- a/src/app/app.component.spec.ts
+++ b/src/app/app.component.spec.ts
@@ -21,7 +21,6 @@ import {
fakeAsync,
flush,
TestBed,
- tick,
waitForAsync,
} from "@angular/core/testing";
import { AppComponent } from "./app.component";
@@ -46,21 +45,19 @@ describe("AppComponent", () => {
let fixture: ComponentFixture;
let entityUpdates: Subject>;
- beforeEach(
- waitForAsync(() => {
- AppConfig.SESSION_TYPE = SessionType.mock;
- const entityMapper = mockEntityMapper();
- entityUpdates = new Subject();
- spyOn(entityMapper, "receiveUpdates").and.returnValue(entityUpdates);
+ beforeEach(waitForAsync(() => {
+ AppConfig.SESSION_TYPE = SessionType.mock;
+ const entityMapper = mockEntityMapper();
+ entityUpdates = new Subject();
+ spyOn(entityMapper, "receiveUpdates").and.returnValue(entityUpdates);
- TestBed.configureTestingModule({
- imports: [AppModule, HttpClientTestingModule],
- providers: [{ provide: EntityMapperService, useValue: entityMapper }],
- }).compileComponents();
+ TestBed.configureTestingModule({
+ imports: [AppModule, HttpClientTestingModule],
+ providers: [{ provide: EntityMapperService, useValue: entityMapper }],
+ }).compileComponents();
- spyOn(TestBed.inject(EntityRegistry), "add"); // Prevent error with duplicate registration
- })
- );
+ spyOn(TestBed.inject(EntityRegistry), "add"); // Prevent error with duplicate registration
+ }));
function createComponent() {
fixture = TestBed.createComponent(AppComponent);
@@ -93,7 +90,7 @@ describe("AppComponent", () => {
window["_paq"] = [];
createComponent();
- tick();
+ flush();
expect(startTrackingSpy).toHaveBeenCalledTimes(1);
expect(window["_paq"]).toContain([
diff --git a/src/app/core/user/user-account/user-account.component.spec.ts b/src/app/core/user/user-account/user-account.component.spec.ts
index 16e1eac4ac..6b765f41d4 100644
--- a/src/app/core/user/user-account/user-account.component.spec.ts
+++ b/src/app/core/user/user-account/user-account.component.spec.ts
@@ -42,39 +42,36 @@ describe("UserAccountComponent", () => {
let mockUserAccountService: jasmine.SpyObj;
let mockLoggingService: jasmine.SpyObj;
- beforeEach(
- waitForAsync(() => {
- AppConfig.SESSION_TYPE = SessionType.synced; // password change only available in synced mode
- mockSessionService = jasmine.createSpyObj("sessionService", [
- "getCurrentUser",
- "login",
- "checkPassword",
- ]);
- mockSessionService.getCurrentUser.and.returnValue({
- name: "TestUser",
- roles: [],
- });
- mockUserAccountService = jasmine.createSpyObj("mockUserAccount", [
- "changePassword",
- ]);
- mockLoggingService = jasmine.createSpyObj(["error"]);
-
- TestBed.configureTestingModule({
- declarations: [UserAccountComponent],
- imports: [
- UserModule,
- NoopAnimationsModule,
- TabStateModule,
- RouterTestingModule,
- ],
- providers: [
- { provide: SessionService, useValue: mockSessionService },
- { provide: UserAccountService, useValue: mockUserAccountService },
- { provide: LoggingService, useValue: mockLoggingService },
- ],
- });
- })
- );
+ beforeEach(waitForAsync(() => {
+ AppConfig.SESSION_TYPE = SessionType.synced; // password change only available in synced mode
+ mockSessionService = jasmine.createSpyObj("sessionService", [
+ "getCurrentUser",
+ "login",
+ "checkPassword",
+ ]);
+ mockSessionService.getCurrentUser.and.returnValue({
+ name: "TestUser",
+ roles: [],
+ });
+ mockUserAccountService = jasmine.createSpyObj("mockUserAccount", [
+ "changePassword",
+ ]);
+ mockLoggingService = jasmine.createSpyObj(["error"]);
+
+ TestBed.configureTestingModule({
+ imports: [
+ UserModule,
+ NoopAnimationsModule,
+ TabStateModule,
+ RouterTestingModule,
+ ],
+ providers: [
+ { provide: SessionService, useValue: mockSessionService },
+ { provide: UserAccountService, useValue: mockUserAccountService },
+ { provide: LoggingService, useValue: mockLoggingService },
+ ],
+ });
+ }));
beforeEach(() => {
fixture = TestBed.createComponent(UserAccountComponent);
diff --git a/src/app/core/user/user-account/user-account.component.ts b/src/app/core/user/user-account/user-account.component.ts
index 0891260333..9bca1850fc 100644
--- a/src/app/core/user/user-account/user-account.component.ts
+++ b/src/app/core/user/user-account/user-account.component.ts
@@ -117,9 +117,8 @@ export class UserAccountComponent implements OnInit {
}
private passwordMatchValidator(): ValidationErrors | null {
- const newPassword: string = this.passwordForm.get("newPassword")?.value;
- const confirmPassword: string = this.passwordForm.get("confirmPassword")
- ?.value;
+ const newPassword = this.passwordForm?.get("newPassword").value;
+ const confirmPassword = this.passwordForm?.get("confirmPassword").value;
if (newPassword !== confirmPassword) {
this.passwordForm
.get("confirmPassword")
From aee369787801d6cb1cd0ab7c754f4af3f936c0cf Mon Sep 17 00:00:00 2001
From: Simon
Date: Fri, 8 Jul 2022 11:59:32 +0200
Subject: [PATCH 15/36] fix doc styling
---
src/app/core/app-config/app-config.ts | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/src/app/core/app-config/app-config.ts b/src/app/core/app-config/app-config.ts
index d7c4f25922..f1b6de0d7f 100644
--- a/src/app/core/app-config/app-config.ts
+++ b/src/app/core/app-config/app-config.ts
@@ -39,13 +39,9 @@ export class AppConfig {
static readonly DB_PROXY_PREFIX = "/db";
/** Name of the database that is used */
static readonly DB_NAME = "app";
- /**
- * Whether the app is running in demo mode.
- */
+ /** Whether the app is running in demo mode */
static DEMO_MODE = false;
- /**
- * The session type that is used.
- */
+ /** The session type that is used */
static SESSION_TYPE = SessionType.synced;
/**
From 39091aba75d10127ca128057432ba34506d8d7e0 Mon Sep 17 00:00:00 2001
From: Simon
Date: Fri, 8 Jul 2022 12:10:05 +0200
Subject: [PATCH 16/36] disabled port in redirect
---
build/default.conf | 1 +
1 file changed, 1 insertion(+)
diff --git a/build/default.conf b/build/default.conf
index 842532633a..3f388ddfab 100644
--- a/build/default.conf
+++ b/build/default.conf
@@ -11,6 +11,7 @@ server {
if ($arg_demo != "true") {
set $demo "${DEMO}true";
}
+ port_in_redirect false;
if ($demo = "truetrue") {
rewrite ^ $uri?demo=true&session=mock redirect;
}
From f8d81d1029ed063d93734edeb56a939c875aaddb Mon Sep 17 00:00:00 2001
From: Simon
Date: Fri, 8 Jul 2022 12:18:51 +0200
Subject: [PATCH 17/36] fixed typo
---
build/default.conf | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/build/default.conf b/build/default.conf
index 3f388ddfab..d8c8dfaca4 100644
--- a/build/default.conf
+++ b/build/default.conf
@@ -11,7 +11,7 @@ server {
if ($arg_demo != "true") {
set $demo "${DEMO}true";
}
- port_in_redirect false;
+ port_in_redirect off;
if ($demo = "truetrue") {
rewrite ^ $uri?demo=true&session=mock redirect;
}
From eb0cca53d825ee7505c4a92fb89efcd947fc23b8 Mon Sep 17 00:00:00 2001
From: Simon
Date: Fri, 8 Jul 2022 12:38:45 +0200
Subject: [PATCH 18/36] better rewriting to use correct port and schema
---
build/default.conf | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/build/default.conf b/build/default.conf
index d8c8dfaca4..2c5979bcb3 100644
--- a/build/default.conf
+++ b/build/default.conf
@@ -11,9 +11,8 @@ server {
if ($arg_demo != "true") {
set $demo "${DEMO}true";
}
- port_in_redirect off;
if ($demo = "truetrue") {
- rewrite ^ $uri?demo=true&session=mock redirect;
+ rewrite ^ $scheme://$http_host$uri?demo=true&session=mock redirect;
}
# Catch requests to the (locale) assets folder and add fallback to super-folder
From e8d9b1d27d216d70975a923da462f5e79754b19c Mon Sep 17 00:00:00 2001
From: Simon
Date: Fri, 8 Jul 2022 13:51:03 +0200
Subject: [PATCH 19/36] using https on default
---
build/default.conf | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/build/default.conf b/build/default.conf
index 2c5979bcb3..a89d217350 100644
--- a/build/default.conf
+++ b/build/default.conf
@@ -12,7 +12,7 @@ server {
set $demo "${DEMO}true";
}
if ($demo = "truetrue") {
- rewrite ^ $scheme://$http_host$uri?demo=true&session=mock redirect;
+ rewrite ^ https://$http_host$uri?demo=true&session=mock redirect;
}
# Catch requests to the (locale) assets folder and add fallback to super-folder
From 688cddb5b3a5549e6d22f2dcf218bfae5ad00d75 Mon Sep 17 00:00:00 2001
From: Simon
Date: Mon, 11 Jul 2022 16:50:08 +0200
Subject: [PATCH 20/36] changed try-files clause for language locations
---
build/default.conf | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/build/default.conf b/build/default.conf
index a89d217350..70afc4239d 100644
--- a/build/default.conf
+++ b/build/default.conf
@@ -6,6 +6,7 @@ server {
#access_log /var/log/nginx/host.access.log main;
root /usr/share/nginx/html;
+ rewrite_log on;
# If ${DEMO}=true is injected then the demo url params are added if not present yet.
if ($arg_demo != "true") {
@@ -29,22 +30,26 @@ server {
location /de {
index index.html index.htm;
- try_files $uri $uri/ /de/index.html =404;
+ try_files $uri /de/index.html =404;
}
location /fr {
index index.html index.htm;
- try_files $uri $uri/ /fr/index.html =404;
+ try_files $uri /fr/index.html =404;
}
- location /en {
+ location /en-US {
index index.html index.htm;
- try_files $uri $uri/ /en-US/index.html =404;
+ try_files $uri /en-US/index.html =404;
+ }
+
+ location /en {
+ rewrite ^/ /en-US redirect;
}
# Append the default language when no other path matches (e.g. requesting root index.html)
location / {
- rewrite ^/ /${DEFAULT_LANGUAGE}/$uri;
+ rewrite ^/ /${DEFAULT_LANGUAGE}/$uri redirect;
}
#error_page 404 /404.html;
From 862eb3c81e045507c94bfa73a3299a4102310ada Mon Sep 17 00:00:00 2001
From: Simon
Date: Mon, 11 Jul 2022 17:58:58 +0200
Subject: [PATCH 21/36] directly navigating to index.html file on language
change
---
build/default.conf | 30 +++++++------------
.../language-select.component.html | 2 +-
.../language-select.component.ts | 6 ++--
3 files changed, 13 insertions(+), 25 deletions(-)
diff --git a/build/default.conf b/build/default.conf
index 70afc4239d..7feef11b2a 100644
--- a/build/default.conf
+++ b/build/default.conf
@@ -8,14 +8,6 @@ server {
root /usr/share/nginx/html;
rewrite_log on;
- # If ${DEMO}=true is injected then the demo url params are added if not present yet.
- if ($arg_demo != "true") {
- set $demo "${DEMO}true";
- }
- if ($demo = "truetrue") {
- rewrite ^ https://$http_host$uri?demo=true&session=mock redirect;
- }
-
# Catch requests to the (locale) assets folder and add fallback to super-folder
# E.g. if '/en-US/assets/config.json' doesn't exist, try '/assets/config.json'
location ~* ^/.+/assets/(.+)$ {
@@ -28,23 +20,21 @@ server {
try_files $uri =404;
}
- location /de {
- index index.html index.htm;
- try_files $uri /de/index.html =404;
- }
-
- location /fr {
- index index.html index.htm;
- try_files $uri /fr/index.html =404;
- }
- location /en-US {
+ location ~* ^/(de|fr|en.*)/?.*$ {
+ # If ${DEMO}=true is injected then the demo url params are added if not present yet.
+ if ($arg_demo != "true") {
+ set $demo "${DEMO}true";
+ }
+ if ($demo = "truetrue") {
+ rewrite ^ https://$http_host$uri?demo=true&session=mock redirect;
+ }
index index.html index.htm;
- try_files $uri /en-US/index.html =404;
+ try_files $uri $uri/ $1/index.html /${DEFAULT_LANGUAGE}/index.html =404;
}
location /en {
- rewrite ^/ /en-US redirect;
+ rewrite ^/en /en-US redirect;
}
# Append the default language when no other path matches (e.g. requesting root index.html)
diff --git a/src/app/core/translation/language-selector/language-select.component.html b/src/app/core/translation/language-selector/language-select.component.html
index 353128658b..51d84afc00 100644
--- a/src/app/core/translation/language-selector/language-select.component.html
+++ b/src/app/core/translation/language-selector/language-select.component.html
@@ -5,7 +5,7 @@
event instanceof NavigationEnd)
)
- .subscribe(() => {
- this.currentUrl = this.router.url;
- });
+ .subscribe(() => (this.currentUrl = this.router.url.split("?")[0]));
}
/**
From 35a62c1cbb2e9c68db2ec8b81206ece2327aff99 Mon Sep 17 00:00:00 2001
From: Simon
Date: Tue, 19 Jul 2022 14:39:48 +0200
Subject: [PATCH 22/36] added automatic demo query params to new nginx config
---
build/default.conf | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/build/default.conf b/build/default.conf
index 3e3707c3d4..d4924fe7c8 100644
--- a/build/default.conf
+++ b/build/default.conf
@@ -14,6 +14,12 @@ server {
}
location / {
+ if ($arg_demo != "true") {
+ set $demo "${DEMO}true";
+ }
+ if ($demo = "truetrue") {
+ rewrite ^ $uri?demo=true&session=mock redirect;
+ }
index index.html index.htm;
try_files $uri $uri/ /index.html =404;
}
From 281f97ddde43f5ed36809257521d34e376d593af Mon Sep 17 00:00:00 2001
From: Simon
Date: Tue, 19 Jul 2022 15:38:06 +0200
Subject: [PATCH 23/36] files are captured in separate location block
---
build/default.conf | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/build/default.conf b/build/default.conf
index d4924fe7c8..5c511ffec5 100644
--- a/build/default.conf
+++ b/build/default.conf
@@ -13,6 +13,11 @@ server {
try_files $uri =404;
}
+ # Files should be directly accessed
+ location ~* \.[a-zA-Z]+$ {
+ try_files $uri =404;
+ }
+
location / {
if ($arg_demo != "true") {
set $demo "${DEMO}true";
From 62a66733e7aba69fe83457058d911d7da02eb9ea Mon Sep 17 00:00:00 2001
From: Simon
Date: Tue, 19 Jul 2022 15:57:40 +0200
Subject: [PATCH 24/36] enforcing https in rewrite
---
build/default.conf | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/build/default.conf b/build/default.conf
index 5c511ffec5..ac61f67549 100644
--- a/build/default.conf
+++ b/build/default.conf
@@ -23,7 +23,7 @@ server {
set $demo "${DEMO}true";
}
if ($demo = "truetrue") {
- rewrite ^ $uri?demo=true&session=mock redirect;
+ rewrite ^ https://$hostname$uri?demo=true&session=mock redirect;
}
index index.html index.htm;
try_files $uri $uri/ /index.html =404;
From 579dc82edb71efbad24ecf92b324c4547538a0e3 Mon Sep 17 00:00:00 2001
From: Simon
Date: Tue, 19 Jul 2022 16:05:28 +0200
Subject: [PATCH 25/36] using correct host variable
---
build/default.conf | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/build/default.conf b/build/default.conf
index ac61f67549..0609e7a92e 100644
--- a/build/default.conf
+++ b/build/default.conf
@@ -23,7 +23,7 @@ server {
set $demo "${DEMO}true";
}
if ($demo = "truetrue") {
- rewrite ^ https://$hostname$uri?demo=true&session=mock redirect;
+ rewrite ^ https://$http_host?demo=true&session=mock redirect;
}
index index.html index.htm;
try_files $uri $uri/ /index.html =404;
From da65aeeec0a6743da43be1b5ee9622784eda3040 Mon Sep 17 00:00:00 2001
From: Simon
Date: Tue, 19 Jul 2022 16:13:06 +0200
Subject: [PATCH 26/36] added local storage option to preserve query params
---
src/app/core/app-config/app-config.ts | 49 +++++++++++++++++++--------
1 file changed, 34 insertions(+), 15 deletions(-)
diff --git a/src/app/core/app-config/app-config.ts b/src/app/core/app-config/app-config.ts
index f1b6de0d7f..5aa650f213 100644
--- a/src/app/core/app-config/app-config.ts
+++ b/src/app/core/app-config/app-config.ts
@@ -39,31 +39,50 @@ export class AppConfig {
static readonly DB_PROXY_PREFIX = "/db";
/** Name of the database that is used */
static readonly DB_NAME = "app";
+
+ static readonly DEMO_LOCAL_STORAGE_KEY = "demo_mode";
+
+ static readonly SESSION_LOCAL_STORAGE_KEY = "session_type";
/** Whether the app is running in demo mode */
static DEMO_MODE = false;
/** The session type that is used */
static SESSION_TYPE = SessionType.synced;
/**
- * Initializes static settings through the environment or the URL params.
+ * Initializes static settings through the URL params, the local storage or the environment.
+ *
+ * The settings are checked and used in the following order:
+ * 1. URL params
+ * 2. Local storage
+ * 3. Environment
*/
static initSettings() {
const params = new URLSearchParams(location.search);
- const demoMode = params.get("demo");
- const sessionType = params.get("session");
- if (demoMode === "true" || environment.demo_mode) {
- AppConfig.DEMO_MODE = true;
+ this.DEMO_MODE = this.isDemoMode(params);
+ this.SESSION_TYPE = this.getSession(params);
+ }
+
+ private static isDemoMode(params: URLSearchParams): boolean {
+ const demoParam = params.get("demo");
+ const demoStorage = localStorage.getItem(this.DEMO_LOCAL_STORAGE_KEY);
+ if (demoParam) {
+ localStorage.setItem(this.DEMO_LOCAL_STORAGE_KEY, demoParam);
+ return demoParam === "true";
+ } else if (demoStorage) {
+ return demoStorage === "true";
}
- if (
- sessionType === "mock" ||
- environment.session_type === SessionType.mock
- ) {
- AppConfig.SESSION_TYPE = SessionType.mock;
- } else if (
- sessionType === "local" ||
- environment.session_type === SessionType.local
- ) {
- AppConfig.SESSION_TYPE = SessionType.local;
+ return environment.demo_mode;
+ }
+
+ private static getSession(params: URLSearchParams): SessionType {
+ const sessionParam = params.get("session");
+ const sessionStorage = localStorage.getItem(this.SESSION_LOCAL_STORAGE_KEY);
+ if (sessionParam) {
+ localStorage.setItem(this.SESSION_LOCAL_STORAGE_KEY, sessionParam);
+ return sessionParam as SessionType;
+ } else if (sessionStorage) {
+ return sessionStorage as SessionType;
}
+ return environment.session_type;
}
}
From 90a027350982d6582994b64a9759c5ff79cc3336 Mon Sep 17 00:00:00 2001
From: Simon
Date: Tue, 19 Jul 2022 19:03:38 +0200
Subject: [PATCH 27/36] using permanent rewrite for demo mode
---
build/default.conf | 2 +-
.../confirmation-dialog.service.ts | 26 ++++++++++---------
2 files changed, 15 insertions(+), 13 deletions(-)
diff --git a/build/default.conf b/build/default.conf
index 0609e7a92e..cdf7a544a7 100644
--- a/build/default.conf
+++ b/build/default.conf
@@ -23,7 +23,7 @@ server {
set $demo "${DEMO}true";
}
if ($demo = "truetrue") {
- rewrite ^ https://$http_host?demo=true&session=mock redirect;
+ rewrite ^ https://$http_host$uri?demo=true&session=mock permanent;
}
index index.html index.htm;
try_files $uri $uri/ /index.html =404;
diff --git a/src/app/core/confirmation-dialog/confirmation-dialog.service.ts b/src/app/core/confirmation-dialog/confirmation-dialog.service.ts
index 804f31788a..157a39559e 100644
--- a/src/app/core/confirmation-dialog/confirmation-dialog.service.ts
+++ b/src/app/core/confirmation-dialog/confirmation-dialog.service.ts
@@ -6,6 +6,7 @@ import {
YesNoButtons,
} from "./confirmation-dialog/confirmation-dialog.component";
import { map } from "rxjs/operators";
+import { firstValueFrom } from "rxjs";
/**
* Inject this service instead of MatDialog if you need a simple, configurable confirmation dialog box
@@ -41,17 +42,18 @@ export class ConfirmationDialogService {
buttons: ConfirmationDialogButton[] = YesNoButtons,
closeButton = true
): Promise {
- return this.dialog
- .open(ConfirmationDialogComponent, {
- data: {
- title: title,
- text: text,
- buttons: buttons,
- closeButton: closeButton,
- },
- })
- .afterClosed()
- .pipe(map((choice) => !!choice))
- .toPromise();
+ return firstValueFrom(
+ this.dialog
+ .open(ConfirmationDialogComponent, {
+ data: {
+ title: title,
+ text: text,
+ buttons: buttons,
+ closeButton: closeButton,
+ },
+ })
+ .afterClosed()
+ .pipe(map((choice) => !!choice))
+ );
}
}
From 9b407e16677b52ab6eaed197df0fa6c6208406f8 Mon Sep 17 00:00:00 2001
From: Simon
Date: Tue, 19 Jul 2022 19:18:26 +0200
Subject: [PATCH 28/36] improved documentation
---
build/default.conf | 2 ++
src/app/core/app-config/app-config.ts | 5 +++--
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/build/default.conf b/build/default.conf
index cdf7a544a7..d39891ae53 100644
--- a/build/default.conf
+++ b/build/default.conf
@@ -19,12 +19,14 @@ server {
}
location / {
+ # Demo mode params are added to URL when not yet present and DEMO is set to true
if ($arg_demo != "true") {
set $demo "${DEMO}true";
}
if ($demo = "truetrue") {
rewrite ^ https://$http_host$uri?demo=true&session=mock permanent;
}
+
index index.html index.htm;
try_files $uri $uri/ /index.html =404;
}
diff --git a/src/app/core/app-config/app-config.ts b/src/app/core/app-config/app-config.ts
index 5aa650f213..c0df31fe9d 100644
--- a/src/app/core/app-config/app-config.ts
+++ b/src/app/core/app-config/app-config.ts
@@ -39,9 +39,8 @@ export class AppConfig {
static readonly DB_PROXY_PREFIX = "/db";
/** Name of the database that is used */
static readonly DB_NAME = "app";
-
+ /** Demo and session can be persisted in local storage */
static readonly DEMO_LOCAL_STORAGE_KEY = "demo_mode";
-
static readonly SESSION_LOCAL_STORAGE_KEY = "session_type";
/** Whether the app is running in demo mode */
static DEMO_MODE = false;
@@ -55,6 +54,8 @@ export class AppConfig {
* 1. URL params
* 2. Local storage
* 3. Environment
+ *
+ * If params are found in the URL query params, then they are persisted in the local storage.
*/
static initSettings() {
const params = new URLSearchParams(location.search);
From db882684b43446428f4eb9de85a844bdf5b13e8e Mon Sep 17 00:00:00 2001
From: Simon
Date: Tue, 19 Jul 2022 19:27:57 +0200
Subject: [PATCH 29/36] added comment about heroku workaround
---
build/default.conf | 2 ++
1 file changed, 2 insertions(+)
diff --git a/build/default.conf b/build/default.conf
index d39891ae53..67a3a78262 100644
--- a/build/default.conf
+++ b/build/default.conf
@@ -24,6 +24,8 @@ server {
set $demo "${DEMO}true";
}
if ($demo = "truetrue") {
+ # This first part is required because Heroku does some internal redirects which break the rewrite otherwise
+ # This does not work in localhost as it enforces HTTPS
rewrite ^ https://$http_host$uri?demo=true&session=mock permanent;
}
From 1ff29ab999116319beb7310dd99bd98349f84bb0 Mon Sep 17 00:00:00 2001
From: Simon
Date: Wed, 27 Jul 2022 09:58:44 +0200
Subject: [PATCH 30/36] removed webdav references
---
README.md | 36 -------------------
build/Dockerfile | 4 +--
proxy.conf.json | 9 -----
.../child-photo.service.spec.ts | 2 +-
4 files changed, 2 insertions(+), 49 deletions(-)
diff --git a/README.md b/README.md
index f62cb7481c..97e272f112 100644
--- a/README.md
+++ b/README.md
@@ -21,42 +21,6 @@ You can directly run the system using Docker.
More information in our [Aam-Digital/ndb-setup repository](https://github.com/Aam-Digital/ndb-setup/).
In that case you do not have to clone this repository and install all the dependencies as everything is packaged into the docker image already.
-## Configuration
-The custom configuration for your service instance is set in the `assets/config.json` file.
-You can copy the `assets/config.default.json` as a starting point.
-
-### Nextcloud (webdav) Integration
-You can integrate Aam Digital with an existing Nextcloud server to allow users to update photos on their own.
-To avoid CORS issues the webdav URL in your _config.json_ should be a relative URL
-in combination with a reverse-proxy that is forwarding to the actual Nextcloud server address:
-
-_assets/config.json:_
-```
- "webdav": {
- "remote_url": "nextcloud/"
- }
-```
-
-_proxy.conf.json_ (for local development):
-```
- "/nextcloud": {
- "target": "https:///remote.php/webdav",
- "secure": true,
- "changeOrigin": true,
- "pathRewrite": {
- "^/nextcloud": ""
- }
- }
-```
-
-_docker-compose.yml_ (for production server):
-```
- environment:
- WEBDAV_URL: https:///remote.php/webdav
-```
-
------
-
# Development
## Setup
diff --git a/build/Dockerfile b/build/Dockerfile
index f3a319ad75..b29a45c84b 100644
--- a/build/Dockerfile
+++ b/build/Dockerfile
@@ -66,12 +66,10 @@ COPY ./build/default.conf /etc/nginx/templates/default.conf
COPY --from=builder /app/dist/ /usr/share/nginx/html
# The port on which the app will run in the Docker container
ENV PORT=80
-# The url to the webdav server
-ENV WEBDAV_URL="http://localhost"
# The url to the CouchDB database
ENV COUCHDB_URL="http://localhost"
# Whether the app should be started in demo mode. Everything else then "true" is considered as "false".
ENV DEMO="true"
# variables are inserted into the nginx config
-CMD envsubst '$$PORT $$WEBDAV_URL $$COUCHDB_URL $$DEMO' < /etc/nginx/templates/default.conf > /etc/nginx/conf.d/default.conf &&\
+CMD envsubst '$$PORT $$COUCHDB_URL $$DEMO' < /etc/nginx/templates/default.conf > /etc/nginx/conf.d/default.conf &&\
nginx -g 'daemon off;'
diff --git a/proxy.conf.json b/proxy.conf.json
index ed34a75bf5..3db0054f1c 100644
--- a/proxy.conf.json
+++ b/proxy.conf.json
@@ -7,14 +7,5 @@
"pathRewrite": {
"/db": ""
}
- },
- "/nextcloud": {
- "target": "https://nextcloud.aam-digital.com/remote.php/webdav",
- "secure": true,
- "logLevel": "debug",
- "changeOrigin": true,
- "pathRewrite": {
- "^/nextcloud": ""
- }
}
}
diff --git a/src/app/child-dev-project/children/child-photo-service/child-photo.service.spec.ts b/src/app/child-dev-project/children/child-photo-service/child-photo.service.spec.ts
index 481c6fb432..c4774e4487 100644
--- a/src/app/child-dev-project/children/child-photo-service/child-photo.service.spec.ts
+++ b/src/app/child-dev-project/children/child-photo-service/child-photo.service.spec.ts
@@ -19,7 +19,7 @@ describe("ChildPhotoService", () => {
expect(service).toBeTruthy();
});
- it("should getFile default if no webdav connection", async () => {
+ it("should getFile default", async () => {
const testChild = new Child("1");
const actualImage = await service.getImage(testChild);
expect(actualImage).toBe(DEFAULT_IMG);
From 2ef6fd8303d175af5e544fbe5ce783e83b3a0606 Mon Sep 17 00:00:00 2001
From: Simon
Date: Wed, 27 Jul 2022 10:00:16 +0200
Subject: [PATCH 31/36] cleaned up demo check in nginx config
---
build/default.conf | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/build/default.conf b/build/default.conf
index 67a3a78262..8724367e14 100644
--- a/build/default.conf
+++ b/build/default.conf
@@ -21,9 +21,9 @@ server {
location / {
# Demo mode params are added to URL when not yet present and DEMO is set to true
if ($arg_demo != "true") {
- set $demo "${DEMO}true";
+ set $demo "${DEMO}";
}
- if ($demo = "truetrue") {
+ if ($demo = "true") {
# This first part is required because Heroku does some internal redirects which break the rewrite otherwise
# This does not work in localhost as it enforces HTTPS
rewrite ^ https://$http_host$uri?demo=true&session=mock permanent;
From 13985d33c3f5d2f68e1b4718c4acf1e26ce688a3 Mon Sep 17 00:00:00 2001
From: Simon
Date: Wed, 27 Jul 2022 10:36:34 +0200
Subject: [PATCH 32/36] cleaned up fetching of runtime settings
---
build/default.conf | 4 +-
src/app/core/app-config/app-config.ts | 74 +++++++++++----------------
2 files changed, 32 insertions(+), 46 deletions(-)
diff --git a/build/default.conf b/build/default.conf
index 8724367e14..e2c19ffb4c 100644
--- a/build/default.conf
+++ b/build/default.conf
@@ -20,13 +20,13 @@ server {
location / {
# Demo mode params are added to URL when not yet present and DEMO is set to true
- if ($arg_demo != "true") {
+ if ($arg_demo_mode != "true") {
set $demo "${DEMO}";
}
if ($demo = "true") {
# This first part is required because Heroku does some internal redirects which break the rewrite otherwise
# This does not work in localhost as it enforces HTTPS
- rewrite ^ https://$http_host$uri?demo=true&session=mock permanent;
+ rewrite ^ https://$http_host$uri?demo_mode=true&session_type=mock permanent;
}
index index.html index.htm;
diff --git a/src/app/core/app-config/app-config.ts b/src/app/core/app-config/app-config.ts
index c0df31fe9d..15a6d09f64 100644
--- a/src/app/core/app-config/app-config.ts
+++ b/src/app/core/app-config/app-config.ts
@@ -21,69 +21,55 @@ import { environment } from "../../../environments/environment";
/**
* Central app configuration.
*
- * The settings are defined in a json file and can therefore be changed for different deployments
- * without code changes.
- *
- * Simply use the static `AppConfig.settings` for easy access to the app's configuration.
- * You do _not_ have to inject the AppConfig service into your code in order to access the app settings.
- * AppConfig is an Angular service only because this is required for initially loading the remote settings into
- * the static AppConfig.settings object.
- *
- * @example
- * this.title = AppConfig.settings.site_name;
- * // just directly use AppConfig and let your IDE add an "import" statement to the file
- * // no need for dependency injection here
+ * Some settings are fixed, others can be changed at runtime.
*/
export class AppConfig {
/** Path for the reverse proxy that forwards to the database - configured in `proxy.conf.json` and `default.conf` */
static readonly DB_PROXY_PREFIX = "/db";
/** Name of the database that is used */
static readonly DB_NAME = "app";
- /** Demo and session can be persisted in local storage */
- static readonly DEMO_LOCAL_STORAGE_KEY = "demo_mode";
- static readonly SESSION_LOCAL_STORAGE_KEY = "session_type";
/** Whether the app is running in demo mode */
static DEMO_MODE = false;
/** The session type that is used */
static SESSION_TYPE = SessionType.synced;
+ /** Demo mode and session type can be persisted in local storage */
+ private static readonly DEMO_MODE_KEY = "demo_mode";
+ private static readonly SESSION_TYPE_KEY = "session_type";
+
+ /**
+ * Initializes settings that can be changed at runtime.
+ */
+ static initSettings() {
+ const demoMode = this.getSetting(this.DEMO_MODE_KEY);
+ this.DEMO_MODE = demoMode === "true";
+ const sessionType = this.getSetting(this.SESSION_TYPE_KEY);
+ this.SESSION_TYPE = sessionType as SessionType;
+ }
+
/**
- * Initializes static settings through the URL params, the local storage or the environment.
+ * A setting can be applied through the url params, the local storage and the environment.
+ * If params are found in the URL query params, then they are persisted in the local storage.
*
* The settings are checked and used in the following order:
* 1. URL params
* 2. Local storage
* 3. Environment
*
- * If params are found in the URL query params, then they are persisted in the local storage.
+ * @param key The key of the setting
+ * @returns first value of the setting
+ * @private
*/
- static initSettings() {
- const params = new URLSearchParams(location.search);
- this.DEMO_MODE = this.isDemoMode(params);
- this.SESSION_TYPE = this.getSession(params);
- }
-
- private static isDemoMode(params: URLSearchParams): boolean {
- const demoParam = params.get("demo");
- const demoStorage = localStorage.getItem(this.DEMO_LOCAL_STORAGE_KEY);
- if (demoParam) {
- localStorage.setItem(this.DEMO_LOCAL_STORAGE_KEY, demoParam);
- return demoParam === "true";
- } else if (demoStorage) {
- return demoStorage === "true";
- }
- return environment.demo_mode;
- }
-
- private static getSession(params: URLSearchParams): SessionType {
- const sessionParam = params.get("session");
- const sessionStorage = localStorage.getItem(this.SESSION_LOCAL_STORAGE_KEY);
- if (sessionParam) {
- localStorage.setItem(this.SESSION_LOCAL_STORAGE_KEY, sessionParam);
- return sessionParam as SessionType;
- } else if (sessionStorage) {
- return sessionStorage as SessionType;
+ private static getSetting(key: string): string {
+ const paramValue = new URLSearchParams(location.search).get(key);
+ const localStorageValue = localStorage.getItem(this.SESSION_TYPE_KEY);
+ if (paramValue) {
+ localStorage.setItem(key, paramValue);
+ return paramValue;
+ } else if (localStorageValue) {
+ return localStorageValue;
+ } else {
+ return environment[key];
}
- return environment.session_type;
}
}
From 1532db3f2b2728c43eb2e1ef08d3c9a1c795909b Mon Sep 17 00:00:00 2001
From: Simon
Date: Wed, 27 Jul 2022 10:48:22 +0200
Subject: [PATCH 33/36] renamed AppConfig to AppSettings
---
build/default.conf | 2 +-
src/app/app.component.spec.ts | 8 +--
src/app/app.component.ts | 4 +-
src/app/app.module.ts | 4 +-
.../core/admin/admin/admin.component.spec.ts | 4 +-
src/app/core/analytics/analytics.service.ts | 13 ++---
.../{app-config.ts => app-settings.ts} | 4 +-
.../demo-data-initializer.service.spec.ts | 8 +--
.../demo-data-initializer.service.ts | 12 ++--
.../session-service/local-session.spec.ts | 14 ++---
.../session/session-service/local-session.ts | 10 ++--
.../session-service/remote-session.spec.ts | 4 +-
.../session/session-service/remote-session.ts | 12 ++--
.../synced-session.service.spec.ts | 4 +-
.../session-service/synced-session.service.ts | 4 +-
src/app/core/session/session.module.ts | 4 +-
src/app/core/ui/ui/ui.component.spec.ts | 58 +++++++++----------
.../user-account.component.spec.ts | 4 +-
.../user-account/user-account.component.ts | 4 +-
src/app/utils/database-testing.module.ts | 4 +-
src/app/utils/mocked-testing.module.ts | 4 +-
src/app/utils/performance-tests.spec.ts | 4 +-
22 files changed, 91 insertions(+), 98 deletions(-)
rename src/app/core/app-config/{app-config.ts => app-settings.ts} (97%)
diff --git a/build/default.conf b/build/default.conf
index e2c19ffb4c..78234f002d 100644
--- a/build/default.conf
+++ b/build/default.conf
@@ -42,7 +42,7 @@ server {
root /usr/share/nginx/html;
}
- # The proxy path should be the same as in AppConfig.DB_PROXY_PREFIX
+ # The proxy path should be the same as in AppSettings.DB_PROXY_PREFIX
location ^~ /db {
rewrite /db/(.*) /$1 break;
proxy_pass ${COUCHDB_URL};
diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts
index 562d1a896c..0979270a0c 100644
--- a/src/app/app.component.spec.ts
+++ b/src/app/app.component.spec.ts
@@ -25,7 +25,7 @@ import {
} from "@angular/core/testing";
import { AppComponent } from "./app.component";
import { AppModule } from "./app.module";
-import { AppConfig } from "./core/app-config/app-config";
+import { AppSettings } from "./core/app-config/app-settings";
import { Config } from "./core/config/config";
import { USAGE_ANALYTICS_CONFIG_ID } from "./core/analytics/usage-analytics-config";
import { environment } from "../environments/environment";
@@ -46,7 +46,7 @@ describe("AppComponent", () => {
let entityUpdates: Subject>;
beforeEach(waitForAsync(() => {
- AppConfig.SESSION_TYPE = SessionType.mock;
+ AppSettings.SESSION_TYPE = SessionType.mock;
const entityMapper = mockEntityMapper();
entityUpdates = new Subject();
spyOn(entityMapper, "receiveUpdates").and.returnValue(entityUpdates);
@@ -104,13 +104,13 @@ describe("AppComponent", () => {
it("published the demo data", fakeAsync(() => {
const demoDataService = TestBed.inject(DemoDataService);
spyOn(demoDataService, "publishDemoData").and.callThrough();
- AppConfig.DEMO_MODE = true;
+ AppSettings.DEMO_MODE = true;
createComponent();
flush();
discardPeriodicTasks();
expect(demoDataService.publishDemoData).toHaveBeenCalled();
- AppConfig.DEMO_MODE = false;
+ AppSettings.DEMO_MODE = false;
}));
});
diff --git a/src/app/app.component.ts b/src/app/app.component.ts
index 0cdf00fd69..93d60ca78f 100644
--- a/src/app/app.component.ts
+++ b/src/app/app.component.ts
@@ -26,7 +26,7 @@ import { environment } from "../environments/environment";
import { Child } from "./child-dev-project/children/model/child";
import { School } from "./child-dev-project/schools/model/school";
import { DemoDataInitializerService } from "./core/demo-data/demo-data-initializer.service";
-import { AppConfig } from "./core/app-config/app-config";
+import { AppSettings } from "./core/app-config/app-settings";
import { LoginState } from "./core/session/session-states/login-state.enum";
import { LoggingService } from "./core/logging/logging.service";
import { EntityRegistry } from "./core/entity/database-entity.decorator";
@@ -90,7 +90,7 @@ export class AppComponent {
this.analyticsService.init();
}
- if (AppConfig.DEMO_MODE) {
+ if (AppSettings.DEMO_MODE) {
await this.demoDataInitializer.run();
}
}
diff --git a/src/app/app.module.ts b/src/app/app.module.ts
index c766a01732..92771140b1 100644
--- a/src/app/app.module.ts
+++ b/src/app/app.module.ts
@@ -84,7 +84,7 @@ import {
DEFAULT_LANGUAGE,
LANGUAGE_LOCAL_STORAGE_KEY,
} from "./core/language/language-statics";
-import { AppConfig } from "./core/app-config/app-config";
+import { AppSettings } from "./core/app-config/app-settings";
/**
* Main entry point of the application.
@@ -178,7 +178,7 @@ import { AppConfig } from "./core/app-config/app-config";
})
export class AppModule {
constructor(icons: FaIconLibrary) {
- AppConfig.initSettings();
+ AppSettings.initSettings();
icons.addIconPacks(fas, far);
}
}
diff --git a/src/app/core/admin/admin/admin.component.spec.ts b/src/app/core/admin/admin/admin.component.spec.ts
index c959a34331..45a761b98f 100644
--- a/src/app/core/admin/admin/admin.component.spec.ts
+++ b/src/app/core/admin/admin/admin.component.spec.ts
@@ -8,7 +8,7 @@ import {
} from "@angular/core/testing";
import { AdminComponent } from "./admin.component";
import { BackupService } from "../services/backup.service";
-import { AppConfig } from "../../app-config/app-config";
+import { AppSettings } from "../../app-config/app-settings";
import { ConfigService } from "../../config/config.service";
import { ConfirmationDialogService } from "../../confirmation-dialog/confirmation-dialog.service";
import { SessionType } from "../../session/session-type";
@@ -55,7 +55,7 @@ describe("AdminComponent", () => {
beforeEach(
waitForAsync(() => {
- AppConfig.SESSION_TYPE = SessionType.mock;
+ AppSettings.SESSION_TYPE = SessionType.mock;
TestBed.configureTestingModule({
imports: [AdminModule, MockedTestingModule.withState()],
diff --git a/src/app/core/analytics/analytics.service.ts b/src/app/core/analytics/analytics.service.ts
index 5d9f25412f..fe45b05b39 100644
--- a/src/app/core/analytics/analytics.service.ts
+++ b/src/app/core/analytics/analytics.service.ts
@@ -37,7 +37,7 @@ export class AnalyticsService {
}
/**
- * Set up usage analytics tracking - if the AppConfig specifies the required settings.
+ * Set up usage analytics tracking.
*/
init(): void {
window["_paq"] = window["_paq"] || [];
@@ -72,13 +72,10 @@ export class AnalyticsService {
* @private
*/
private setConfigValues() {
- const {
- url,
- site_id,
- no_cookies,
- } = this.configService.getConfig(
- USAGE_ANALYTICS_CONFIG_ID
- ) || { url: "https://matomo.aam-digital.org" };
+ const { url, site_id, no_cookies } =
+ this.configService.getConfig(
+ USAGE_ANALYTICS_CONFIG_ID
+ ) || { url: "https://matomo.aam-digital.org" };
const u = url.endsWith("/") ? url : url + "/";
if (!this.isInitialized) {
diff --git a/src/app/core/app-config/app-config.ts b/src/app/core/app-config/app-settings.ts
similarity index 97%
rename from src/app/core/app-config/app-config.ts
rename to src/app/core/app-config/app-settings.ts
index 15a6d09f64..b727a85dfc 100644
--- a/src/app/core/app-config/app-config.ts
+++ b/src/app/core/app-config/app-settings.ts
@@ -19,11 +19,11 @@ import { SessionType } from "../session/session-type";
import { environment } from "../../../environments/environment";
/**
- * Central app configuration.
+ * Central app settings.
*
* Some settings are fixed, others can be changed at runtime.
*/
-export class AppConfig {
+export class AppSettings {
/** Path for the reverse proxy that forwards to the database - configured in `proxy.conf.json` and `default.conf` */
static readonly DB_PROXY_PREFIX = "/db";
/** Name of the database that is used */
diff --git a/src/app/core/demo-data/demo-data-initializer.service.spec.ts b/src/app/core/demo-data/demo-data-initializer.service.spec.ts
index fd676b468c..2084a3fb7b 100644
--- a/src/app/core/demo-data/demo-data-initializer.service.spec.ts
+++ b/src/app/core/demo-data/demo-data-initializer.service.spec.ts
@@ -7,7 +7,7 @@ import { LocalSession } from "../session/session-service/local-session";
import { DatabaseUser } from "../session/session-service/local-user";
import { MatDialog } from "@angular/material/dialog";
import { DemoDataGeneratingProgressDialogComponent } from "./demo-data-generating-progress-dialog.component";
-import { AppConfig } from "../app-config/app-config";
+import { AppSettings } from "../app-config/app-settings";
import { PouchDatabase } from "../database/pouch-database";
import { Subject } from "rxjs";
import { LoginState } from "../session/session-states/login-state.enum";
@@ -24,9 +24,9 @@ describe("DemoDataInitializerService", () => {
let adminDBName: string;
beforeEach(() => {
- AppConfig.SESSION_TYPE = SessionType.mock;
- demoUserDBName = `${DemoUserGeneratorService.DEFAULT_USERNAME}-${AppConfig.DB_NAME}`;
- adminDBName = `${DemoUserGeneratorService.ADMIN_USERNAME}-${AppConfig.DB_NAME}`;
+ AppSettings.SESSION_TYPE = SessionType.mock;
+ demoUserDBName = `${DemoUserGeneratorService.DEFAULT_USERNAME}-${AppSettings.DB_NAME}`;
+ adminDBName = `${DemoUserGeneratorService.ADMIN_USERNAME}-${AppSettings.DB_NAME}`;
mockDemoDataService = jasmine.createSpyObj(["publishDemoData"]);
mockDemoDataService.publishDemoData.and.resolveTo();
mockDialog = jasmine.createSpyObj(["open"]);
diff --git a/src/app/core/demo-data/demo-data-initializer.service.ts b/src/app/core/demo-data/demo-data-initializer.service.ts
index 189cb7c651..1f612253b1 100644
--- a/src/app/core/demo-data/demo-data-initializer.service.ts
+++ b/src/app/core/demo-data/demo-data-initializer.service.ts
@@ -5,7 +5,7 @@ import { LocalSession } from "../session/session-service/local-session";
import { MatDialog } from "@angular/material/dialog";
import { DemoDataGeneratingProgressDialogComponent } from "./demo-data-generating-progress-dialog.component";
import { LoggingService } from "../logging/logging.service";
-import { AppConfig } from "../app-config/app-config";
+import { AppSettings } from "../app-config/app-settings";
import { LoginState } from "../session/session-states/login-state.enum";
import PouchDB from "pouchdb-browser";
import { SessionType } from "../session/session-type";
@@ -42,7 +42,7 @@ export class DemoDataInitializerService {
this.pouchDatabase = this.database;
} else {
this.loggingService.warn(
- "Cannot create demo data with session: " + AppConfig.SESSION_TYPE
+ "Cannot create demo data with session: " + AppSettings.SESSION_TYPE
);
}
this.registerDemoUsers();
@@ -94,9 +94,9 @@ export class DemoDataInitializerService {
}
private async syncWithDemoUserDB() {
- const dbName = `${DemoUserGeneratorService.DEFAULT_USERNAME}-${AppConfig.DB_NAME}`;
+ const dbName = `${DemoUserGeneratorService.DEFAULT_USERNAME}-${AppSettings.DB_NAME}`;
let demoUserDB: PouchDB.Database;
- if (AppConfig.SESSION_TYPE === SessionType.mock) {
+ if (AppSettings.SESSION_TYPE === SessionType.mock) {
PouchDB.plugin(memory);
demoUserDB = new PouchDB(dbName, { adapter: "memory" });
} else {
@@ -118,8 +118,8 @@ export class DemoDataInitializerService {
}
private initializeDefaultDatabase() {
- const dbName = `${DemoUserGeneratorService.DEFAULT_USERNAME}-${AppConfig.DB_NAME}`;
- if (AppConfig.SESSION_TYPE === SessionType.mock) {
+ const dbName = `${DemoUserGeneratorService.DEFAULT_USERNAME}-${AppSettings.DB_NAME}`;
+ if (AppSettings.SESSION_TYPE === SessionType.mock) {
this.pouchDatabase.initInMemoryDB(dbName);
} else {
this.pouchDatabase.initIndexedDB(dbName);
diff --git a/src/app/core/session/session-service/local-session.spec.ts b/src/app/core/session/session-service/local-session.spec.ts
index 85dcd7bda1..5121b835c4 100644
--- a/src/app/core/session/session-service/local-session.spec.ts
+++ b/src/app/core/session/session-service/local-session.spec.ts
@@ -15,7 +15,7 @@
* along with ndb-core. If not, see .
*/
-import { AppConfig } from "../../app-config/app-config";
+import { AppSettings } from "../../app-config/app-settings";
import { LocalSession } from "./local-session";
import { SessionType } from "../session-type";
import { DatabaseUser, LocalUser, passwordEqualsEncrypted } from "./local-user";
@@ -32,9 +32,9 @@ describe("LocalSessionService", () => {
let database: jasmine.SpyObj;
beforeEach(() => {
- AppConfig.SESSION_TYPE = SessionType.mock;
- userDBName = `${TEST_USER}-${AppConfig.DB_NAME}`;
- deprecatedDBName = AppConfig.DB_NAME;
+ AppSettings.SESSION_TYPE = SessionType.mock;
+ userDBName = `${TEST_USER}-${AppSettings.DB_NAME}`;
+ deprecatedDBName = AppSettings.DB_NAME;
database = jasmine.createSpyObj([
"initInMemoryDB",
"initIndexedDB",
@@ -116,19 +116,19 @@ describe("LocalSessionService", () => {
await localSession.login(TEST_USER, TEST_PASSWORD);
expect(database.initInMemoryDB).toHaveBeenCalledWith(
- TEST_USER + "-" + AppConfig.DB_NAME
+ TEST_USER + "-" + AppSettings.DB_NAME
);
expect(localSession.getDatabase()).toBe(database);
});
- it("should create the database according to the session type in the AppConfig", async () => {
+ it("should create the database according to the session type in the AppSettings", async () => {
async function testDatabaseCreation(
sessionType: SessionType,
expectedDB: "inMemory" | "indexed"
) {
database.initInMemoryDB.calls.reset();
database.initIndexedDB.calls.reset();
- AppConfig.SESSION_TYPE = sessionType;
+ AppSettings.SESSION_TYPE = sessionType;
await localSession.login(TEST_USER, TEST_PASSWORD);
if (expectedDB === "inMemory") {
expect(database.initInMemoryDB).toHaveBeenCalled();
diff --git a/src/app/core/session/session-service/local-session.ts b/src/app/core/session/session-service/local-session.ts
index 92a259e510..df2931cc62 100644
--- a/src/app/core/session/session-service/local-session.ts
+++ b/src/app/core/session/session-service/local-session.ts
@@ -24,7 +24,7 @@ import {
} from "./local-user";
import { SessionService } from "./session.service";
import { PouchDatabase } from "../../database/pouch-database";
-import { AppConfig } from "../../app-config/app-config";
+import { AppSettings } from "../../app-config/app-settings";
import { SessionType } from "../session-type";
/**
@@ -69,7 +69,7 @@ export class LocalSession extends SessionService {
}
private async initializeDatabaseForCurrentUser() {
- const userDBName = `${this.currentDBUser.name}-${AppConfig.DB_NAME}`;
+ const userDBName = `${this.currentDBUser.name}-${AppSettings.DB_NAME}`;
// Work on a temporary database before initializing the real one
const tmpDB = new PouchDatabase(undefined);
this.initDatabase(userDBName, tmpDB);
@@ -79,7 +79,7 @@ export class LocalSession extends SessionService {
return;
}
- this.initDatabase(AppConfig.DB_NAME, tmpDB);
+ this.initDatabase(AppSettings.DB_NAME, tmpDB);
const dbFallback = window.localStorage.getItem(
LocalSession.DEPRECATED_DB_KEY
);
@@ -90,7 +90,7 @@ export class LocalSession extends SessionService {
LocalSession.DEPRECATED_DB_KEY,
this.currentDBUser.name
);
- this.initDatabase(AppConfig.DB_NAME);
+ this.initDatabase(AppSettings.DB_NAME);
return;
}
@@ -99,7 +99,7 @@ export class LocalSession extends SessionService {
}
private initDatabase(dbName: string, db = this.database) {
- if (AppConfig.SESSION_TYPE === SessionType.mock) {
+ if (AppSettings.SESSION_TYPE === SessionType.mock) {
db.initInMemoryDB(dbName);
} else {
db.initIndexedDB(dbName);
diff --git a/src/app/core/session/session-service/remote-session.spec.ts b/src/app/core/session/session-service/remote-session.spec.ts
index 8f6bec6862..a066d420ad 100644
--- a/src/app/core/session/session-service/remote-session.spec.ts
+++ b/src/app/core/session/session-service/remote-session.spec.ts
@@ -2,7 +2,7 @@ import { TestBed } from "@angular/core/testing";
import { RemoteSession } from "./remote-session";
import { HttpClient, HttpErrorResponse } from "@angular/common/http";
import { of, throwError } from "rxjs";
-import { AppConfig } from "../../app-config/app-config";
+import { AppSettings } from "../../app-config/app-settings";
import { SessionType } from "../session-type";
import { LoggingService } from "../../logging/logging.service";
import { testSessionServiceImplementation } from "./session.service.spec";
@@ -16,7 +16,7 @@ describe("RemoteSessionService", () => {
let dbUser: DatabaseUser;
beforeEach(() => {
- AppConfig.SESSION_TYPE = SessionType.mock;
+ AppSettings.SESSION_TYPE = SessionType.mock;
mockHttpClient = jasmine.createSpyObj(["post", "delete"]);
mockHttpClient.delete.and.returnValue(of());
diff --git a/src/app/core/session/session-service/remote-session.ts b/src/app/core/session/session-service/remote-session.ts
index d173d44fc9..bcc199077e 100644
--- a/src/app/core/session/session-service/remote-session.ts
+++ b/src/app/core/session/session-service/remote-session.ts
@@ -14,7 +14,6 @@
* You should have received a copy of the GNU General Public License
* along with ndb-core. If not, see .
*/
-import { AppConfig } from "../../app-config/app-config";
import { Injectable } from "@angular/core";
import { HttpClient, HttpErrorResponse } from "@angular/common/http";
import { DatabaseUser } from "./local-user";
@@ -23,6 +22,7 @@ import { LoginState } from "../session-states/login-state.enum";
import { PouchDatabase } from "../../database/pouch-database";
import { LoggingService } from "../../logging/logging.service";
import PouchDB from "pouchdb-browser";
+import { AppSettings } from "app/core/app-config/app-settings";
/**
* Responsibilities:
@@ -48,15 +48,15 @@ export class RemoteSession extends SessionService {
) {
super();
this.database = new PouchDatabase(this.loggingService).initIndexedDB(
- `${AppConfig.DB_PROXY_PREFIX}/${AppConfig.DB_NAME}`,
+ `${AppSettings.DB_PROXY_PREFIX}/${AppSettings.DB_NAME}`,
{
adapter: "http",
skip_setup: true,
fetch: (url, opts) => {
if (typeof url === "string") {
return PouchDB.fetch(
- AppConfig.DB_PROXY_PREFIX +
- url.split(AppConfig.DB_PROXY_PREFIX)[1],
+ AppSettings.DB_PROXY_PREFIX +
+ url.split(AppSettings.DB_PROXY_PREFIX)[1],
opts
);
}
@@ -74,7 +74,7 @@ export class RemoteSession extends SessionService {
try {
const response = await this.httpClient
.post(
- `${AppConfig.DB_PROXY_PREFIX}/_session`,
+ `${AppSettings.DB_PROXY_PREFIX}/_session`,
{ name: username, password: password },
{ withCredentials: true }
)
@@ -114,7 +114,7 @@ export class RemoteSession extends SessionService {
*/
public async logout(): Promise {
await this.httpClient
- .delete(`${AppConfig.DB_PROXY_PREFIX}/_session`, {
+ .delete(`${AppSettings.DB_PROXY_PREFIX}/_session`, {
withCredentials: true,
})
.toPromise()
diff --git a/src/app/core/session/session-service/synced-session.service.spec.ts b/src/app/core/session/session-service/synced-session.service.spec.ts
index 3087903f6e..d4469f7e32 100644
--- a/src/app/core/session/session-service/synced-session.service.spec.ts
+++ b/src/app/core/session/session-service/synced-session.service.spec.ts
@@ -17,7 +17,7 @@
import { SyncedSessionService } from "./synced-session.service";
import { LoginState } from "../session-states/login-state.enum";
-import { AppConfig } from "../../app-config/app-config";
+import { AppSettings } from "../../app-config/app-settings";
import { LocalSession } from "./local-session";
import { RemoteSession } from "./remote-session";
import { SessionType } from "../session-type";
@@ -62,7 +62,7 @@ describe("SyncedSessionService", () => {
{ provide: LOCATION_TOKEN, useValue: mockLocation },
],
});
- AppConfig.SESSION_TYPE = SessionType.mock;
+ AppSettings.SESSION_TYPE = SessionType.mock;
sessionService = TestBed.inject(SyncedSessionService);
localSession = TestBed.inject(LocalSession);
diff --git a/src/app/core/session/session-service/synced-session.service.ts b/src/app/core/session/session-service/synced-session.service.ts
index 8848339c43..68f6de62bf 100644
--- a/src/app/core/session/session-service/synced-session.service.ts
+++ b/src/app/core/session/session-service/synced-session.service.ts
@@ -29,7 +29,7 @@ import { HttpClient } from "@angular/common/http";
import { DatabaseUser } from "./local-user";
import { waitForChangeTo } from "../session-states/session-utils";
import { zip } from "rxjs";
-import { AppConfig } from "app/core/app-config/app-config";
+import { AppSettings } from "app/core/app-config/app-settings";
import { filter } from "rxjs/operators";
import { LOCATION_TOKEN } from "../../../utils/di-tokens";
@@ -75,7 +75,7 @@ export class SyncedSessionService extends SessionService {
*/
checkForValidSession() {
this.httpClient
- .get(`${AppConfig.DB_PROXY_PREFIX}/_session`, {
+ .get(`${AppSettings.DB_PROXY_PREFIX}/_session`, {
withCredentials: true,
})
.subscribe((res: any) => {
diff --git a/src/app/core/session/session.module.ts b/src/app/core/session/session.module.ts
index 67e03c4189..2c2b75c3ee 100644
--- a/src/app/core/session/session.module.ts
+++ b/src/app/core/session/session.module.ts
@@ -34,7 +34,7 @@ import { SyncedSessionService } from "./session-service/synced-session.service";
import { LocalSession } from "./session-service/local-session";
import { RemoteSession } from "./session-service/remote-session";
import { SessionService } from "./session-service/session.service";
-import { AppConfig } from "../app-config/app-config";
+import { AppSettings } from "../app-config/app-settings";
import { SessionType } from "./session-type";
/**
@@ -70,7 +70,7 @@ import { SessionType } from "./session-type";
{
provide: SessionService,
useFactory: (injector: Injector) => {
- if (AppConfig.SESSION_TYPE === SessionType.synced) {
+ if (AppSettings.SESSION_TYPE === SessionType.synced) {
return injector.get(SyncedSessionService);
} else {
return injector.get(LocalSession);
diff --git a/src/app/core/ui/ui/ui.component.spec.ts b/src/app/core/ui/ui/ui.component.spec.ts
index b50dde6410..9237dd167c 100644
--- a/src/app/core/ui/ui/ui.component.spec.ts
+++ b/src/app/core/ui/ui/ui.component.spec.ts
@@ -20,7 +20,6 @@ import { ComponentFixture, TestBed, waitForAsync } from "@angular/core/testing";
import { UiComponent } from "./ui.component";
import { SwUpdate } from "@angular/service-worker";
import { of, Subject } from "rxjs";
-import { ApplicationInitStatus } from "@angular/core";
import { UiModule } from "../ui.module";
import { ConfigService } from "../../config/config.service";
import { MockedTestingModule } from "../../../utils/mocked-testing.module";
@@ -32,38 +31,35 @@ describe("UiComponent", () => {
let component: UiComponent;
let fixture: ComponentFixture;
- beforeEach(
- waitForAsync(() => {
- const mockSwUpdate = { available: of(), checkForUpdate: () => {} };
- const mockIndexingService = jasmine.createSpyObj(
- ["createIndex"],
- {
- indicesRegistered: new Subject(),
- }
- );
- mockIndexingService.createIndex.and.resolveTo();
+ beforeEach(waitForAsync(() => {
+ const mockSwUpdate = { available: of(), checkForUpdate: () => {} };
+ const mockIndexingService = jasmine.createSpyObj(
+ ["createIndex"],
+ {
+ indicesRegistered: new Subject(),
+ }
+ );
+ mockIndexingService.createIndex.and.resolveTo();
- TestBed.configureTestingModule({
- imports: [
- UiModule,
- MockedTestingModule.withState(),
- FontAwesomeTestingModule,
- TabStateModule,
- ],
- providers: [
- { provide: SwUpdate, useValue: mockSwUpdate },
- {
- provide: DatabaseIndexingService,
- useValue: mockIndexingService,
- },
- ],
- }).compileComponents();
- TestBed.inject(ApplicationInitStatus); // This ensures that the AppConfig is loaded before test execution
+ TestBed.configureTestingModule({
+ imports: [
+ UiModule,
+ MockedTestingModule.withState(),
+ FontAwesomeTestingModule,
+ TabStateModule,
+ ],
+ providers: [
+ { provide: SwUpdate, useValue: mockSwUpdate },
+ {
+ provide: DatabaseIndexingService,
+ useValue: mockIndexingService,
+ },
+ ],
+ }).compileComponents();
- const configService = TestBed.inject(ConfigService);
- configService.saveConfig({ navigationMenu: { items: [] } });
- })
- );
+ const configService = TestBed.inject(ConfigService);
+ configService.saveConfig({ navigationMenu: { items: [] } });
+ }));
beforeEach(() => {
fixture = TestBed.createComponent(UiComponent);
diff --git a/src/app/core/user/user-account/user-account.component.spec.ts b/src/app/core/user/user-account/user-account.component.spec.ts
index 6b765f41d4..a476385419 100644
--- a/src/app/core/user/user-account/user-account.component.spec.ts
+++ b/src/app/core/user/user-account/user-account.component.spec.ts
@@ -26,7 +26,7 @@ import {
import { UserAccountComponent } from "./user-account.component";
import { SessionService } from "../../session/session-service/session.service";
import { NoopAnimationsModule } from "@angular/platform-browser/animations";
-import { AppConfig } from "../../app-config/app-config";
+import { AppSettings } from "../../app-config/app-settings";
import { UserAccountService } from "./user-account.service";
import { UserModule } from "../user.module";
import { SessionType } from "../../session/session-type";
@@ -43,7 +43,7 @@ describe("UserAccountComponent", () => {
let mockLoggingService: jasmine.SpyObj;
beforeEach(waitForAsync(() => {
- AppConfig.SESSION_TYPE = SessionType.synced; // password change only available in synced mode
+ AppSettings.SESSION_TYPE = SessionType.synced; // password change only available in synced mode
mockSessionService = jasmine.createSpyObj("sessionService", [
"getCurrentUser",
"login",
diff --git a/src/app/core/user/user-account/user-account.component.ts b/src/app/core/user/user-account/user-account.component.ts
index ada2a0e9c4..13c41009ff 100644
--- a/src/app/core/user/user-account/user-account.component.ts
+++ b/src/app/core/user/user-account/user-account.component.ts
@@ -19,7 +19,7 @@ import { Component, OnInit } from "@angular/core";
import { SessionService } from "../../session/session-service/session.service";
import { UserAccountService } from "./user-account.service";
import { FormBuilder, ValidationErrors, Validators } from "@angular/forms";
-import { AppConfig } from "../../app-config/app-config";
+import { AppSettings } from "../../app-config/app-settings";
import { LoggingService } from "../../logging/logging.service";
import { SessionType } from "../../session/session-type";
@@ -77,7 +77,7 @@ export class UserAccountComponent implements OnInit {
this.disabledForOfflineMode = false;
this.passwordForm.enable();
- if (AppConfig.SESSION_TYPE !== SessionType.synced) {
+ if (AppSettings.SESSION_TYPE !== SessionType.synced) {
this.disabledForDemoMode = true;
this.passwordForm.disable();
} else if (!navigator.onLine) {
diff --git a/src/app/utils/database-testing.module.ts b/src/app/utils/database-testing.module.ts
index 369ab00ffa..461f4653c1 100644
--- a/src/app/utils/database-testing.module.ts
+++ b/src/app/utils/database-testing.module.ts
@@ -20,7 +20,7 @@ import {
ConfigService,
createTestingConfigService,
} from "../core/config/config.service";
-import { AppConfig } from "../core/app-config/app-config";
+import { AppSettings } from "../core/app-config/app-settings";
import { SessionType } from "../core/session/session-type";
/**
@@ -50,7 +50,7 @@ import { SessionType } from "../core/session/session-type";
})
export class DatabaseTestingModule {
constructor(pouchDatabase: PouchDatabase) {
- AppConfig.SESSION_TYPE = SessionType.mock;
+ AppSettings.SESSION_TYPE = SessionType.mock;
pouchDatabase.initInMemoryDB();
}
}
diff --git a/src/app/utils/mocked-testing.module.ts b/src/app/utils/mocked-testing.module.ts
index e523117186..ea929788f5 100644
--- a/src/app/utils/mocked-testing.module.ts
+++ b/src/app/utils/mocked-testing.module.ts
@@ -10,7 +10,7 @@ import { NoopAnimationsModule } from "@angular/platform-browser/animations";
import { Angulartics2Module } from "angulartics2";
import { RouterTestingModule } from "@angular/router/testing";
import { Database } from "../core/database/database";
-import { AppConfig } from "../core/app-config/app-config";
+import { AppSettings } from "../core/app-config/app-settings";
import { SessionType } from "../core/session/session-type";
import { PouchDatabase } from "../core/database/pouch-database";
import { LOCATION_TOKEN } from "./di-tokens";
@@ -87,7 +87,7 @@ export class MockedTestingModule {
loginState = LoginState.LOGGED_IN,
data: Entity[] = []
): ModuleWithProviders {
- AppConfig.SESSION_TYPE = SessionType.mock;
+ AppSettings.SESSION_TYPE = SessionType.mock;
const mockedEntityMapper = mockEntityMapper([new User(TEST_USER), ...data]);
const session = createLocalSession(loginState === LoginState.LOGGED_IN);
return {
diff --git a/src/app/utils/performance-tests.spec.ts b/src/app/utils/performance-tests.spec.ts
index bdfee538db..048f15651f 100644
--- a/src/app/utils/performance-tests.spec.ts
+++ b/src/app/utils/performance-tests.spec.ts
@@ -3,7 +3,7 @@ import { AppModule } from "../app.module";
import moment from "moment";
import { Database } from "../core/database/database";
import { DemoDataService } from "../core/demo-data/demo-data.service";
-import { AppConfig } from "../core/app-config/app-config";
+import { AppSettings } from "../core/app-config/app-settings";
import { SessionType } from "../core/session/session-type";
import { DatabaseTestingModule } from "./database-testing.module";
@@ -11,7 +11,7 @@ xdescribe("Performance Tests", () => {
beforeEach(async () => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 150000;
- AppConfig.SESSION_TYPE = SessionType.mock; // change to SessionType.local to run performance tests with the InBrowser database
+ AppSettings.SESSION_TYPE = SessionType.mock; // change to SessionType.local to run performance tests with the InBrowser database
await TestBed.configureTestingModule({
imports: [AppModule, DatabaseTestingModule],
From 18de4862d21e994f0da213767daf828af051909b Mon Sep 17 00:00:00 2001
From: Simon
Date: Wed, 27 Jul 2022 10:51:23 +0200
Subject: [PATCH 34/36] changed order of config attributes
---
src/app/core/config/config-fix.ts | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/app/core/config/config-fix.ts b/src/app/core/config/config-fix.ts
index 44a03dcaab..ca0194d87b 100644
--- a/src/app/core/config/config-fix.ts
+++ b/src/app/core/config/config-fix.ts
@@ -16,10 +16,10 @@ import { ratingAnswers } from "../../features/historical-data/model/rating-answe
// prettier-ignore
export const defaultJsonConfig = {
"appConfig": {
+ "default_language": "en-US",
"displayLanguageSelect": true,
"logo_path": null,
- "site_name": "Aam Digital - DEMO",
- "default_language": "en-US"
+ "site_name": "Aam Digital - DEMO (automatically generated data)",
},
"appConfig:usage-analytics": {
"url": "https://matomo.aam-digital.org",
From fb3df4b533f6c5cae54669496eade82e6a3b1652 Mon Sep 17 00:00:00 2001
From: Simon
Date: Wed, 27 Jul 2022 10:52:08 +0200
Subject: [PATCH 35/36] removed config.default.json
---
src/assets/config.default.json | 8 --------
1 file changed, 8 deletions(-)
delete mode 100644 src/assets/config.default.json
diff --git a/src/assets/config.default.json b/src/assets/config.default.json
deleted file mode 100644
index 223ed4fe6b..0000000000
--- a/src/assets/config.default.json
+++ /dev/null
@@ -1,8 +0,0 @@
-{
- "site_name": "Aam Digital - DEV",
-
- "session_type": "mock",
- "demo_mode": true,
-
- "debug": false
-}
From 474572e766d5c511fcad57c6b3fbc51edc861215 Mon Sep 17 00:00:00 2001
From: Simon
Date: Wed, 27 Jul 2022 11:53:16 +0200
Subject: [PATCH 36/36] moved demo_mode and session_type to environment.ts
---
src/app/app.component.spec.ts | 7 ++--
src/app/app.component.ts | 3 +-
src/app/app.module.ts | 2 +-
.../core/admin/admin/admin.component.spec.ts | 39 +++++++++----------
src/app/core/app-config/app-settings.ts | 21 +++++-----
.../demo-data-initializer.service.spec.ts | 3 +-
.../demo-data-initializer.service.ts | 7 ++--
.../session-service/local-session.spec.ts | 5 ++-
.../session/session-service/local-session.ts | 3 +-
.../session-service/remote-session.spec.ts | 4 +-
.../synced-session.service.spec.ts | 4 +-
src/app/core/session/session.module.ts | 4 +-
.../user-account.component.spec.ts | 4 +-
.../user-account/user-account.component.ts | 4 +-
src/app/utils/database-testing.module.ts | 4 +-
src/app/utils/mocked-testing.module.ts | 4 +-
src/app/utils/performance-tests.spec.ts | 12 +++---
17 files changed, 62 insertions(+), 68 deletions(-)
diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts
index 0979270a0c..29832e4b2f 100644
--- a/src/app/app.component.spec.ts
+++ b/src/app/app.component.spec.ts
@@ -25,7 +25,6 @@ import {
} from "@angular/core/testing";
import { AppComponent } from "./app.component";
import { AppModule } from "./app.module";
-import { AppSettings } from "./core/app-config/app-settings";
import { Config } from "./core/config/config";
import { USAGE_ANALYTICS_CONFIG_ID } from "./core/analytics/usage-analytics-config";
import { environment } from "../environments/environment";
@@ -46,7 +45,7 @@ describe("AppComponent", () => {
let entityUpdates: Subject>;
beforeEach(waitForAsync(() => {
- AppSettings.SESSION_TYPE = SessionType.mock;
+ environment.session_type = SessionType.mock;
const entityMapper = mockEntityMapper();
entityUpdates = new Subject();
spyOn(entityMapper, "receiveUpdates").and.returnValue(entityUpdates);
@@ -104,13 +103,13 @@ describe("AppComponent", () => {
it("published the demo data", fakeAsync(() => {
const demoDataService = TestBed.inject(DemoDataService);
spyOn(demoDataService, "publishDemoData").and.callThrough();
- AppSettings.DEMO_MODE = true;
+ environment.demo_mode = true;
createComponent();
flush();
discardPeriodicTasks();
expect(demoDataService.publishDemoData).toHaveBeenCalled();
- AppSettings.DEMO_MODE = false;
+ environment.demo_mode = false;
}));
});
diff --git a/src/app/app.component.ts b/src/app/app.component.ts
index 93d60ca78f..cbe8ec62e8 100644
--- a/src/app/app.component.ts
+++ b/src/app/app.component.ts
@@ -26,7 +26,6 @@ import { environment } from "../environments/environment";
import { Child } from "./child-dev-project/children/model/child";
import { School } from "./child-dev-project/schools/model/school";
import { DemoDataInitializerService } from "./core/demo-data/demo-data-initializer.service";
-import { AppSettings } from "./core/app-config/app-settings";
import { LoginState } from "./core/session/session-states/login-state.enum";
import { LoggingService } from "./core/logging/logging.service";
import { EntityRegistry } from "./core/entity/database-entity.decorator";
@@ -90,7 +89,7 @@ export class AppComponent {
this.analyticsService.init();
}
- if (AppSettings.DEMO_MODE) {
+ if (environment.demo_mode) {
await this.demoDataInitializer.run();
}
}
diff --git a/src/app/app.module.ts b/src/app/app.module.ts
index 92771140b1..336fa398ff 100644
--- a/src/app/app.module.ts
+++ b/src/app/app.module.ts
@@ -178,7 +178,7 @@ import { AppSettings } from "./core/app-config/app-settings";
})
export class AppModule {
constructor(icons: FaIconLibrary) {
- AppSettings.initSettings();
+ AppSettings.initRuntimeSettings();
icons.addIconPacks(fas, far);
}
}
diff --git a/src/app/core/admin/admin/admin.component.spec.ts b/src/app/core/admin/admin/admin.component.spec.ts
index 45a761b98f..3a1c43ac8b 100644
--- a/src/app/core/admin/admin/admin.component.spec.ts
+++ b/src/app/core/admin/admin/admin.component.spec.ts
@@ -8,12 +8,12 @@ import {
} from "@angular/core/testing";
import { AdminComponent } from "./admin.component";
import { BackupService } from "../services/backup.service";
-import { AppSettings } from "../../app-config/app-settings";
import { ConfigService } from "../../config/config.service";
import { ConfirmationDialogService } from "../../confirmation-dialog/confirmation-dialog.service";
import { SessionType } from "../../session/session-type";
import { AdminModule } from "../admin.module";
import { MockedTestingModule } from "../../../utils/mocked-testing.module";
+import { environment } from "../../../../environments/environment";
describe("AdminComponent", () => {
let component: AdminComponent;
@@ -31,9 +31,8 @@ describe("AdminComponent", () => {
"importJson",
]);
- const confirmationDialogMock = jasmine.createSpyObj(
- ["getConfirmation"]
- );
+ const confirmationDialogMock =
+ jasmine.createSpyObj(["getConfirmation"]);
const tmplink: jasmine.SpyObj = jasmine.createSpyObj(
"mockLink",
@@ -53,23 +52,21 @@ describe("AdminComponent", () => {
return mockFileReader;
}
- beforeEach(
- waitForAsync(() => {
- AppSettings.SESSION_TYPE = SessionType.mock;
-
- TestBed.configureTestingModule({
- imports: [AdminModule, MockedTestingModule.withState()],
- providers: [
- { provide: BackupService, useValue: mockBackupService },
- { provide: ConfigService, useValue: mockConfigService },
- {
- provide: ConfirmationDialogService,
- useValue: confirmationDialogMock,
- },
- ],
- }).compileComponents();
- })
- );
+ beforeEach(waitForAsync(() => {
+ environment.session_type = SessionType.mock;
+
+ TestBed.configureTestingModule({
+ imports: [AdminModule, MockedTestingModule.withState()],
+ providers: [
+ { provide: BackupService, useValue: mockBackupService },
+ { provide: ConfigService, useValue: mockConfigService },
+ {
+ provide: ConfirmationDialogService,
+ useValue: confirmationDialogMock,
+ },
+ ],
+ }).compileComponents();
+ }));
beforeEach(() => {
fixture = TestBed.createComponent(AdminComponent);
diff --git a/src/app/core/app-config/app-settings.ts b/src/app/core/app-config/app-settings.ts
index b727a85dfc..0f077f0757 100644
--- a/src/app/core/app-config/app-settings.ts
+++ b/src/app/core/app-config/app-settings.ts
@@ -19,19 +19,14 @@ import { SessionType } from "../session/session-type";
import { environment } from "../../../environments/environment";
/**
- * Central app settings.
- *
- * Some settings are fixed, others can be changed at runtime.
+ * Central static app settings.
+ * More dynamic settings can be found in the environment.ts file.
*/
export class AppSettings {
/** Path for the reverse proxy that forwards to the database - configured in `proxy.conf.json` and `default.conf` */
static readonly DB_PROXY_PREFIX = "/db";
/** Name of the database that is used */
static readonly DB_NAME = "app";
- /** Whether the app is running in demo mode */
- static DEMO_MODE = false;
- /** The session type that is used */
- static SESSION_TYPE = SessionType.synced;
/** Demo mode and session type can be persisted in local storage */
private static readonly DEMO_MODE_KEY = "demo_mode";
@@ -40,11 +35,15 @@ export class AppSettings {
/**
* Initializes settings that can be changed at runtime.
*/
- static initSettings() {
+ static initRuntimeSettings() {
const demoMode = this.getSetting(this.DEMO_MODE_KEY);
- this.DEMO_MODE = demoMode === "true";
+ if (demoMode) {
+ environment.demo_mode = demoMode === "true";
+ }
const sessionType = this.getSetting(this.SESSION_TYPE_KEY);
- this.SESSION_TYPE = sessionType as SessionType;
+ if (sessionType) {
+ environment.session_type = sessionType as SessionType;
+ }
}
/**
@@ -68,8 +67,6 @@ export class AppSettings {
return paramValue;
} else if (localStorageValue) {
return localStorageValue;
- } else {
- return environment[key];
}
}
}
diff --git a/src/app/core/demo-data/demo-data-initializer.service.spec.ts b/src/app/core/demo-data/demo-data-initializer.service.spec.ts
index 2084a3fb7b..9c8ba052d7 100644
--- a/src/app/core/demo-data/demo-data-initializer.service.spec.ts
+++ b/src/app/core/demo-data/demo-data-initializer.service.spec.ts
@@ -13,6 +13,7 @@ import { Subject } from "rxjs";
import { LoginState } from "../session/session-states/login-state.enum";
import { Database } from "../database/database";
import { SessionType } from "../session/session-type";
+import { environment } from "../../../environments/environment";
describe("DemoDataInitializerService", () => {
let service: DemoDataInitializerService;
@@ -24,7 +25,7 @@ describe("DemoDataInitializerService", () => {
let adminDBName: string;
beforeEach(() => {
- AppSettings.SESSION_TYPE = SessionType.mock;
+ environment.session_type = SessionType.mock;
demoUserDBName = `${DemoUserGeneratorService.DEFAULT_USERNAME}-${AppSettings.DB_NAME}`;
adminDBName = `${DemoUserGeneratorService.ADMIN_USERNAME}-${AppSettings.DB_NAME}`;
mockDemoDataService = jasmine.createSpyObj(["publishDemoData"]);
diff --git a/src/app/core/demo-data/demo-data-initializer.service.ts b/src/app/core/demo-data/demo-data-initializer.service.ts
index 1f612253b1..16dcd42879 100644
--- a/src/app/core/demo-data/demo-data-initializer.service.ts
+++ b/src/app/core/demo-data/demo-data-initializer.service.ts
@@ -12,6 +12,7 @@ import { SessionType } from "../session/session-type";
import memory from "pouchdb-adapter-memory";
import { Database } from "../database/database";
import { PouchDatabase } from "../database/pouch-database";
+import { environment } from "../../../environments/environment";
/**
* This service handles everything related to the demo-mode
@@ -42,7 +43,7 @@ export class DemoDataInitializerService {
this.pouchDatabase = this.database;
} else {
this.loggingService.warn(
- "Cannot create demo data with session: " + AppSettings.SESSION_TYPE
+ "Cannot create demo data with session: " + environment.session_type
);
}
this.registerDemoUsers();
@@ -96,7 +97,7 @@ export class DemoDataInitializerService {
private async syncWithDemoUserDB() {
const dbName = `${DemoUserGeneratorService.DEFAULT_USERNAME}-${AppSettings.DB_NAME}`;
let demoUserDB: PouchDB.Database;
- if (AppSettings.SESSION_TYPE === SessionType.mock) {
+ if (environment.session_type === SessionType.mock) {
PouchDB.plugin(memory);
demoUserDB = new PouchDB(dbName, { adapter: "memory" });
} else {
@@ -119,7 +120,7 @@ export class DemoDataInitializerService {
private initializeDefaultDatabase() {
const dbName = `${DemoUserGeneratorService.DEFAULT_USERNAME}-${AppSettings.DB_NAME}`;
- if (AppSettings.SESSION_TYPE === SessionType.mock) {
+ if (environment.session_type === SessionType.mock) {
this.pouchDatabase.initInMemoryDB(dbName);
} else {
this.pouchDatabase.initIndexedDB(dbName);
diff --git a/src/app/core/session/session-service/local-session.spec.ts b/src/app/core/session/session-service/local-session.spec.ts
index 5121b835c4..dd3d60bed4 100644
--- a/src/app/core/session/session-service/local-session.spec.ts
+++ b/src/app/core/session/session-service/local-session.spec.ts
@@ -23,6 +23,7 @@ import { LoginState } from "../session-states/login-state.enum";
import { testSessionServiceImplementation } from "./session.service.spec";
import { TEST_PASSWORD, TEST_USER } from "../../../utils/mocked-testing.module";
import { PouchDatabase } from "../../database/pouch-database";
+import { environment } from "../../../../environments/environment";
describe("LocalSessionService", () => {
let userDBName;
@@ -32,7 +33,7 @@ describe("LocalSessionService", () => {
let database: jasmine.SpyObj;
beforeEach(() => {
- AppSettings.SESSION_TYPE = SessionType.mock;
+ environment.session_type = SessionType.mock;
userDBName = `${TEST_USER}-${AppSettings.DB_NAME}`;
deprecatedDBName = AppSettings.DB_NAME;
database = jasmine.createSpyObj([
@@ -128,7 +129,7 @@ describe("LocalSessionService", () => {
) {
database.initInMemoryDB.calls.reset();
database.initIndexedDB.calls.reset();
- AppSettings.SESSION_TYPE = sessionType;
+ environment.session_type = sessionType;
await localSession.login(TEST_USER, TEST_PASSWORD);
if (expectedDB === "inMemory") {
expect(database.initInMemoryDB).toHaveBeenCalled();
diff --git a/src/app/core/session/session-service/local-session.ts b/src/app/core/session/session-service/local-session.ts
index df2931cc62..cbfb0145cc 100644
--- a/src/app/core/session/session-service/local-session.ts
+++ b/src/app/core/session/session-service/local-session.ts
@@ -26,6 +26,7 @@ import { SessionService } from "./session.service";
import { PouchDatabase } from "../../database/pouch-database";
import { AppSettings } from "../../app-config/app-settings";
import { SessionType } from "../session-type";
+import { environment } from "../../../../environments/environment";
/**
* Responsibilities:
@@ -99,7 +100,7 @@ export class LocalSession extends SessionService {
}
private initDatabase(dbName: string, db = this.database) {
- if (AppSettings.SESSION_TYPE === SessionType.mock) {
+ if (environment.session_type === SessionType.mock) {
db.initInMemoryDB(dbName);
} else {
db.initIndexedDB(dbName);
diff --git a/src/app/core/session/session-service/remote-session.spec.ts b/src/app/core/session/session-service/remote-session.spec.ts
index a066d420ad..18c34721d3 100644
--- a/src/app/core/session/session-service/remote-session.spec.ts
+++ b/src/app/core/session/session-service/remote-session.spec.ts
@@ -2,13 +2,13 @@ import { TestBed } from "@angular/core/testing";
import { RemoteSession } from "./remote-session";
import { HttpClient, HttpErrorResponse } from "@angular/common/http";
import { of, throwError } from "rxjs";
-import { AppSettings } from "../../app-config/app-settings";
import { SessionType } from "../session-type";
import { LoggingService } from "../../logging/logging.service";
import { testSessionServiceImplementation } from "./session.service.spec";
import { DatabaseUser } from "./local-user";
import { LoginState } from "../session-states/login-state.enum";
import { TEST_PASSWORD, TEST_USER } from "../../../utils/mocked-testing.module";
+import { environment } from "../../../../environments/environment";
describe("RemoteSessionService", () => {
let service: RemoteSession;
@@ -16,7 +16,7 @@ describe("RemoteSessionService", () => {
let dbUser: DatabaseUser;
beforeEach(() => {
- AppSettings.SESSION_TYPE = SessionType.mock;
+ environment.session_type = SessionType.mock;
mockHttpClient = jasmine.createSpyObj(["post", "delete"]);
mockHttpClient.delete.and.returnValue(of());
diff --git a/src/app/core/session/session-service/synced-session.service.spec.ts b/src/app/core/session/session-service/synced-session.service.spec.ts
index d4469f7e32..c91611f488 100644
--- a/src/app/core/session/session-service/synced-session.service.spec.ts
+++ b/src/app/core/session/session-service/synced-session.service.spec.ts
@@ -17,7 +17,6 @@
import { SyncedSessionService } from "./synced-session.service";
import { LoginState } from "../session-states/login-state.enum";
-import { AppSettings } from "../../app-config/app-settings";
import { LocalSession } from "./local-session";
import { RemoteSession } from "./remote-session";
import { SessionType } from "../session-type";
@@ -32,6 +31,7 @@ import { FontAwesomeTestingModule } from "@fortawesome/angular-fontawesome/testi
import { PouchDatabase } from "../../database/pouch-database";
import { SessionModule } from "../session.module";
import { LOCATION_TOKEN } from "../../../utils/di-tokens";
+import { environment } from "../../../../environments/environment";
describe("SyncedSessionService", () => {
let sessionService: SyncedSessionService;
@@ -62,7 +62,7 @@ describe("SyncedSessionService", () => {
{ provide: LOCATION_TOKEN, useValue: mockLocation },
],
});
- AppSettings.SESSION_TYPE = SessionType.mock;
+ environment.session_type = SessionType.mock;
sessionService = TestBed.inject(SyncedSessionService);
localSession = TestBed.inject(LocalSession);
diff --git a/src/app/core/session/session.module.ts b/src/app/core/session/session.module.ts
index 2c2b75c3ee..e6197070a7 100644
--- a/src/app/core/session/session.module.ts
+++ b/src/app/core/session/session.module.ts
@@ -34,8 +34,8 @@ import { SyncedSessionService } from "./session-service/synced-session.service";
import { LocalSession } from "./session-service/local-session";
import { RemoteSession } from "./session-service/remote-session";
import { SessionService } from "./session-service/session.service";
-import { AppSettings } from "../app-config/app-settings";
import { SessionType } from "./session-type";
+import { environment } from "../../../environments/environment";
/**
* The core session logic handling user login as well as connection and synchronization with the remote database.
@@ -70,7 +70,7 @@ import { SessionType } from "./session-type";
{
provide: SessionService,
useFactory: (injector: Injector) => {
- if (AppSettings.SESSION_TYPE === SessionType.synced) {
+ if (environment.session_type === SessionType.synced) {
return injector.get(SyncedSessionService);
} else {
return injector.get(LocalSession);
diff --git a/src/app/core/user/user-account/user-account.component.spec.ts b/src/app/core/user/user-account/user-account.component.spec.ts
index a476385419..767a5192e1 100644
--- a/src/app/core/user/user-account/user-account.component.spec.ts
+++ b/src/app/core/user/user-account/user-account.component.spec.ts
@@ -26,13 +26,13 @@ import {
import { UserAccountComponent } from "./user-account.component";
import { SessionService } from "../../session/session-service/session.service";
import { NoopAnimationsModule } from "@angular/platform-browser/animations";
-import { AppSettings } from "../../app-config/app-settings";
import { UserAccountService } from "./user-account.service";
import { UserModule } from "../user.module";
import { SessionType } from "../../session/session-type";
import { LoggingService } from "../../logging/logging.service";
import { TabStateModule } from "../../../utils/tab-state/tab-state.module";
import { RouterTestingModule } from "@angular/router/testing";
+import { environment } from "../../../../environments/environment";
describe("UserAccountComponent", () => {
let component: UserAccountComponent;
@@ -43,7 +43,7 @@ describe("UserAccountComponent", () => {
let mockLoggingService: jasmine.SpyObj;
beforeEach(waitForAsync(() => {
- AppSettings.SESSION_TYPE = SessionType.synced; // password change only available in synced mode
+ environment.session_type = SessionType.synced; // password change only available in synced mode
mockSessionService = jasmine.createSpyObj("sessionService", [
"getCurrentUser",
"login",
diff --git a/src/app/core/user/user-account/user-account.component.ts b/src/app/core/user/user-account/user-account.component.ts
index 13c41009ff..a088adea07 100644
--- a/src/app/core/user/user-account/user-account.component.ts
+++ b/src/app/core/user/user-account/user-account.component.ts
@@ -19,9 +19,9 @@ import { Component, OnInit } from "@angular/core";
import { SessionService } from "../../session/session-service/session.service";
import { UserAccountService } from "./user-account.service";
import { FormBuilder, ValidationErrors, Validators } from "@angular/forms";
-import { AppSettings } from "../../app-config/app-settings";
import { LoggingService } from "../../logging/logging.service";
import { SessionType } from "../../session/session-type";
+import { environment } from "../../../../environments/environment";
/**
* User account form to allow the user to view and edit information.
@@ -77,7 +77,7 @@ export class UserAccountComponent implements OnInit {
this.disabledForOfflineMode = false;
this.passwordForm.enable();
- if (AppSettings.SESSION_TYPE !== SessionType.synced) {
+ if (environment.session_type !== SessionType.synced) {
this.disabledForDemoMode = true;
this.passwordForm.disable();
} else if (!navigator.onLine) {
diff --git a/src/app/utils/database-testing.module.ts b/src/app/utils/database-testing.module.ts
index 461f4653c1..6be78298b1 100644
--- a/src/app/utils/database-testing.module.ts
+++ b/src/app/utils/database-testing.module.ts
@@ -20,8 +20,8 @@ import {
ConfigService,
createTestingConfigService,
} from "../core/config/config.service";
-import { AppSettings } from "../core/app-config/app-settings";
import { SessionType } from "../core/session/session-type";
+import { environment } from "../../environments/environment";
/**
* Utility module that creates a simple environment where a correctly configured database and session is set up.
@@ -50,7 +50,7 @@ import { SessionType } from "../core/session/session-type";
})
export class DatabaseTestingModule {
constructor(pouchDatabase: PouchDatabase) {
- AppSettings.SESSION_TYPE = SessionType.mock;
+ environment.session_type = SessionType.mock;
pouchDatabase.initInMemoryDB();
}
}
diff --git a/src/app/utils/mocked-testing.module.ts b/src/app/utils/mocked-testing.module.ts
index ea929788f5..e97ef58728 100644
--- a/src/app/utils/mocked-testing.module.ts
+++ b/src/app/utils/mocked-testing.module.ts
@@ -10,7 +10,6 @@ import { NoopAnimationsModule } from "@angular/platform-browser/animations";
import { Angulartics2Module } from "angulartics2";
import { RouterTestingModule } from "@angular/router/testing";
import { Database } from "../core/database/database";
-import { AppSettings } from "../core/app-config/app-settings";
import { SessionType } from "../core/session/session-type";
import { PouchDatabase } from "../core/database/pouch-database";
import { LOCATION_TOKEN } from "./di-tokens";
@@ -33,6 +32,7 @@ import {
ConfigService,
createTestingConfigService,
} from "../core/config/config.service";
+import { environment } from "../../environments/environment";
export const TEST_USER = "test";
export const TEST_PASSWORD = "pass";
@@ -87,7 +87,7 @@ export class MockedTestingModule {
loginState = LoginState.LOGGED_IN,
data: Entity[] = []
): ModuleWithProviders {
- AppSettings.SESSION_TYPE = SessionType.mock;
+ environment.session_type = SessionType.mock;
const mockedEntityMapper = mockEntityMapper([new User(TEST_USER), ...data]);
const session = createLocalSession(loginState === LoginState.LOGGED_IN);
return {
diff --git a/src/app/utils/performance-tests.spec.ts b/src/app/utils/performance-tests.spec.ts
index 048f15651f..23ec5aee5a 100644
--- a/src/app/utils/performance-tests.spec.ts
+++ b/src/app/utils/performance-tests.spec.ts
@@ -3,15 +3,15 @@ import { AppModule } from "../app.module";
import moment from "moment";
import { Database } from "../core/database/database";
import { DemoDataService } from "../core/demo-data/demo-data.service";
-import { AppSettings } from "../core/app-config/app-settings";
import { SessionType } from "../core/session/session-type";
import { DatabaseTestingModule } from "./database-testing.module";
+import { environment } from "../../environments/environment";
xdescribe("Performance Tests", () => {
beforeEach(async () => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 150000;
- AppSettings.SESSION_TYPE = SessionType.mock; // change to SessionType.local to run performance tests with the InBrowser database
+ environment.session_type = SessionType.mock; // change to SessionType.local to run performance tests with the InBrowser database
await TestBed.configureTestingModule({
imports: [AppModule, DatabaseTestingModule],
@@ -22,11 +22,9 @@ xdescribe("Performance Tests", () => {
console.log("finished publishing demo data", setup.getDuration());
});
- afterEach(
- waitForAsync(() => {
- return TestBed.inject(Database).destroy();
- })
- );
+ afterEach(waitForAsync(() => {
+ return TestBed.inject(Database).destroy();
+ }));
it("basic test example", async () => {
await comparePerformance(