RED-10301 - set app type config vars based existing tenants from local storage or used default config if no tenant was set before

This commit is contained in:
Valentin Mihai 2024-12-11 18:22:28 +02:00
parent 0d20afcf27
commit 58382ddfee

View File

@ -1,18 +1,20 @@
import { Inject, inject, Injectable } from '@angular/core';
import { Title } from '@angular/platform-browser';
import { CacheApiService } from '../caching';
import { wipeAllCaches } from '../caching';
import { IqserAppConfig } from '../utils';
import { MANUAL_BASE_URL, THEME_DIRECTORIES } from '../utils/constants';
import { IStoredTenantId } from '../tenants';
import { CacheApiService } from '../caching/cache-api.service';
import { wipeAllCaches } from '../caching/cache-utils';
import { IqserAppConfig } from '../utils/iqser-app-config';
import { LANDING_PAGE_THEMES, MANUAL_BASE_URL, THEME_DIRECTORIES } from '../utils/constants';
import { IStoredTenantId, TenantsService } from '../tenants';
@Injectable()
export class IqserConfigService<T extends IqserAppConfig = IqserAppConfig> {
protected readonly _cacheApiService = inject(CacheApiService);
protected readonly _titleService = inject(Title);
protected readonly _tenantsService = inject(TenantsService);
constructor(@Inject('Doesnt matter') protected _values: T) {
this._checkFrontendVersion();
this.#updateAppType();
this._titleService.setTitle(this._values.APP_NAME);
}
@ -46,6 +48,28 @@ export class IqserConfigService<T extends IqserAppConfig = IqserAppConfig> {
await this._cacheApiService.cacheValue('FRONTEND_APP_VERSION', version);
});
}
#updateAppType() {
const storedTenants = this._tenantsService.getStoredTenants();
if (storedTenants.length) {
const isRedaction = !!storedTenants.find(t => !t.documine);
const isDocumine = !!storedTenants.find(t => t.documine);
const landingPageTheme =
isRedaction && isDocumine
? LANDING_PAGE_THEMES.MIXED
: isDocumine
? LANDING_PAGE_THEMES.DOCUMINE
: LANDING_PAGE_THEMES.REDACT_MANAGER;
this._values = {
...this._values,
LANDING_PAGE_THEME: landingPageTheme,
APP_NAME: landingPageTheme === LANDING_PAGE_THEMES.MIXED ? 'Knecon Cloud' : isDocumine ? 'DocuMine' : 'RedactManager',
IS_DOCUMINE: isDocumine,
THEME: !isDocumine ? THEME_DIRECTORIES.REDACT : THEME_DIRECTORIES.SCM,
};
}
}
}
export function getConfig<T extends IqserAppConfig = IqserAppConfig>() {