diff --git a/kdb-web/package.json b/kdb-web/package.json index 70c9306f..d6381d85 100644 --- a/kdb-web/package.json +++ b/kdb-web/package.json @@ -1,6 +1,6 @@ { "name": "kdb-web", - "version": "1.0.dev268_achievements", + "version": "1.0.dev294_frontend_version", "scripts": { "ng": "ng", "update-version": "ts-node-esm update-version.ts", diff --git a/kdb-web/src/app/models/config/app-settings.ts b/kdb-web/src/app/models/config/app-settings.ts new file mode 100644 index 00000000..7f45d9a1 --- /dev/null +++ b/kdb-web/src/app/models/config/app-settings.ts @@ -0,0 +1,21 @@ +import { SoftwareVersion } from "./software-version"; +import { Theme } from '../view/theme'; + +export interface AppAndVersionSettings { + ApiURL: string; + PrivacyURL: string; + ImprintURL: string; + Themes: Theme[]; + WebVersion: SoftwareVersion; +} + +export interface AppSettings { + ApiURL: string; + PrivacyURL: string; + ImprintURL: string; + Themes: Theme[]; +} + +export interface VersionSettings { + WebVersion: SoftwareVersion; +} diff --git a/kdb-web/src/app/models/config/appsettings.ts b/kdb-web/src/app/models/config/appsettings.ts deleted file mode 100644 index f3f5796b..00000000 --- a/kdb-web/src/app/models/config/appsettings.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { SoftwareVersion } from "./software-version"; -import { Theme } from '../view/theme'; - -export interface Appsettings { - ApiURL: string; - PrivacyURL: string; - ImprintURL: string; - WebVersion: SoftwareVersion; - Themes: Theme[]; -} diff --git a/kdb-web/src/app/services/settings/settings.service.ts b/kdb-web/src/app/services/settings/settings.service.ts index 81afc135..d1c3809f 100644 --- a/kdb-web/src/app/services/settings/settings.service.ts +++ b/kdb-web/src/app/services/settings/settings.service.ts @@ -1,76 +1,86 @@ import { HttpClient } from "@angular/common/http"; import { Injectable } from "@angular/core"; -import { throwError } from "rxjs"; +import { forkJoin, throwError } from "rxjs"; import { catchError } from "rxjs/operators"; -import { Appsettings } from "src/app/models/config/appsettings"; +import { AppAndVersionSettings, AppSettings, VersionSettings } from "src/app/models/config/app-settings"; import { SoftwareVersion } from "src/app/models/config/software-version"; import { Theme } from "src/app/models/view/theme"; @Injectable({ - providedIn: 'root' + providedIn: "root" }) export class SettingsService { - appsettings!: Appsettings; + appSettings!: AppSettings; + versionSettings!: VersionSettings; constructor( private http: HttpClient - ) { } + ) { + } - loadSettings(): Promise { + loadSettings(version: boolean = false): Promise { return new Promise((resolve, reject) => { - this.http.get('../../assets/config.json') - .pipe(catchError(error => { - reject(error); - return throwError(() => error); - })).subscribe(settings => { - this.appsettings = settings; - resolve(settings); - }); + forkJoin([ + this.http.get("../../assets/config.json") + .pipe(catchError(error => { + reject(error); + return throwError(() => error); + })), + this.http.get("../../assets/version.json") + .pipe(catchError(error => { + reject(error); + return throwError(() => error); + })) + ]).subscribe(settings => { + this.appSettings = settings[0]; + this.versionSettings = settings[1]; + resolve({...settings[0], ...settings[1]}); + }); }); } public getApiURL(): string { - if (!this.appsettings || !this.appsettings.ApiURL) { - console.error('ApiUrl is not set!'); + if (!this.appSettings || !this.appSettings.ApiURL) { + console.error("ApiUrl is not set!"); return ""; } - return this.appsettings.ApiURL; + return this.appSettings.ApiURL; } public getPrivacyURL(): string { - if (!this.appsettings || !this.appsettings.PrivacyURL) { - console.error('PrivacyURL is not set!'); + if (!this.appSettings || !this.appSettings.PrivacyURL) { + console.error("PrivacyURL is not set!"); return ""; } - return this.appsettings.PrivacyURL; + return this.appSettings.PrivacyURL; } public getImprintURL(): string { - if (!this.appsettings || !this.appsettings.ImprintURL) { - console.error('ImprintURL is not set!'); + if (!this.appSettings || !this.appSettings.ImprintURL) { + console.error("ImprintURL is not set!"); return ""; } - return this.appsettings.ImprintURL; + return this.appSettings.ImprintURL; } public getWebVersion(): SoftwareVersion | null { - if (!this.appsettings || !this.appsettings.WebVersion) { - console.error('WebVersion is not set!'); + if (!this.versionSettings || !this.versionSettings.WebVersion) { + console.error("WebVersion is not set!"); return null; } return new SoftwareVersion( - this.appsettings.WebVersion.Major, - this.appsettings.WebVersion.Minor, - this.appsettings.WebVersion.Micro + this.versionSettings.WebVersion.Major, + this.versionSettings.WebVersion.Minor, + this.versionSettings.WebVersion.Micro ); } public getThemes(): Theme[] | null { - if (!this.appsettings || !this.appsettings.Themes) { - console.error('Themes is not set!'); + if (!this.appSettings || !this.appSettings.Themes) { + console.error("Themes is not set!"); return null; } - return this.appsettings.Themes; + return this.appSettings.Themes; } } diff --git a/kdb-web/src/assets/version.json b/kdb-web/src/assets/version.json new file mode 100644 index 00000000..8d4c9ae3 --- /dev/null +++ b/kdb-web/src/assets/version.json @@ -0,0 +1,7 @@ +{ + "WebVersion": { + "Major": "1", + "Minor": "0", + "Micro": "dev294_frontend_version" + } +} \ No newline at end of file diff --git a/kdb-web/update-version.ts b/kdb-web/update-version.ts index 7e3c56c8..57c90424 100644 --- a/kdb-web/update-version.ts +++ b/kdb-web/update-version.ts @@ -1,8 +1,8 @@ -import { Appsettings } from "./src/app/models/config/appsettings"; +import { VersionSettings } from "./src/app/models/config/app-settings"; import { SoftwareVersion } from "./src/app/models/config/software-version"; import fs from "fs"; -const jsonFilePath = "./src/assets/config.json"; +const jsonFilePath = "./src/assets/version.json"; function Main(): void { getVersion() @@ -38,13 +38,13 @@ async function getVersion(): Promise { } } else if (branch.startsWith("#")) { const fs = require("fs"); - const config: Appsettings = JSON.parse(fs.readFileSync(jsonFilePath, "utf-8")); + const config: VersionSettings = JSON.parse(fs.readFileSync(jsonFilePath, "utf-8")); major = config.WebVersion.Major; minor = config.WebVersion.Minor; micro = `dev${branch.split("#")[1]}`; } else { const fs = require("fs"); - const config: Appsettings = JSON.parse(fs.readFileSync(jsonFilePath, "utf-8")); + const config: VersionSettings = JSON.parse(fs.readFileSync(jsonFilePath, "utf-8")); major = config.WebVersion.Major; minor = config.WebVersion.Minor; micro = config.WebVersion.Micro; @@ -59,7 +59,7 @@ async function setVersion(version: SoftwareVersion) { if (err) { throw err; } - const settings: Appsettings = JSON.parse(data); + const settings: VersionSettings = JSON.parse(data); settings.WebVersion = version; fs.writeFile(jsonFilePath, JSON.stringify(settings, null, 4), "utf8", () => { });