feature service rework to import json at compiletime, its not necesasry to overwrite at runtime

This commit is contained in:
Timo Bejan 2022-03-16 14:44:07 +02:00
parent 6901b075f7
commit c2fa1959ed
3 changed files with 10 additions and 21 deletions

View File

@ -1,13 +1,6 @@
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { tap } from 'rxjs/operators';
import { HttpClient } from '@angular/common/http';
import { ConfigService } from './config.service';
interface Feature {
name: string;
minVersion: string;
}
import featuresJson from '../../assets/features/features.json';
function transform(version: string): number {
const [major, minor, patch, release] = version.split(/[.-]/).map(x => parseInt(x, 10));
@ -20,21 +13,17 @@ function transform(version: string): number {
export class FeaturesService {
private _features = new Map<string, boolean>();
constructor(private readonly _httpClient: HttpClient, private readonly _configService: ConfigService) {}
constructor(private readonly _configService: ConfigService) {}
isEnabled(feature: string): boolean {
// If feature is not defined in config object return true
return this._features.get(feature) !== false;
}
loadConfig(): Observable<any> {
return this._httpClient.get('/assets/config/features.json').pipe(
tap((config: { features: Feature[] }) => {
const BACKEND_APP_VERSION = transform(this._configService.values.BACKEND_APP_VERSION as string);
config.features.forEach(feature => {
this._features.set(feature.name, transform(feature.minVersion) <= BACKEND_APP_VERSION);
});
}),
);
loadConfig() {
const BACKEND_APP_VERSION = transform(this._configService.values.BACKEND_APP_VERSION as string);
featuresJson.features.forEach(feature => {
this._features.set(feature.name, transform(feature.minVersion) <= BACKEND_APP_VERSION);
});
}
}

View File

@ -1,7 +1,7 @@
import { catchError, filter, mergeMap, switchMap, take, tap } from 'rxjs/operators';
import { ConfigService } from '@services/config.service';
import { Title } from '@angular/platform-browser';
import { firstValueFrom, from, of, throwError } from 'rxjs';
import { firstValueFrom, from, map, of, throwError } from 'rxjs';
import { KeycloakEventType, KeycloakService } from 'keycloak-angular';
import { GeneralSettingsService } from '@services/general-settings.service';
import { LanguageService } from '@i18n/language.service';
@ -23,7 +23,7 @@ export function configurationInitializer(
firstValueFrom(
keycloakService.keycloakEvents$.pipe(
filter(event => event.type === KeycloakEventType.OnReady),
switchMap(() => from(featuresService.loadConfig())),
map(() => featuresService.loadConfig()),
switchMap(() => from(keycloakService.isLoggedIn())),
switchMap(loggedIn => (!loggedIn ? throwError('Not Logged In') : of({}))),
switchMap(() => from(userService.loadCurrentUser())),
@ -32,7 +32,7 @@ export function configurationInitializer(
tap(configuration => configService.updateDisplayName(configuration.displayName)),
switchMap(() => userPreferenceService.reload()),
catchError(e => {
console.log('catch', e);
console.log('[Redaction] Initialization error:', e);
title.setTitle('RedactManager');
return of({});
}),