Compare commits

...

1 Commits

3 changed files with 23 additions and 31 deletions

View File

@ -3,7 +3,7 @@ import { Title } from '@angular/platform-browser';
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 { MANUAL_BASE_URL, THEME_DIRECTORIES } from '../utils/constants';
import { IStoredTenantId, TenantsService } from '../tenants';
@Injectable()
@ -14,7 +14,6 @@ export class IqserConfigService<T extends IqserAppConfig = IqserAppConfig> {
constructor(@Inject('Doesnt matter') protected _values: T) {
this._checkFrontendVersion();
this.#updateAppType();
this._titleService.setTitle(this._values.APP_NAME);
}
@ -48,28 +47,6 @@ 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>() {

View File

@ -119,6 +119,11 @@ export class TenantsService extends GenericService<Tenant> {
this.#logger.info('[TENANTS] Stored tenants at logout: ', storedTenants);
}
clearStoredTenants() {
this.#logger.warn('[TENANTS] Delete all stored tenants');
localStorage.removeItem(STORED_TENANTS_KEY);
}
getActiveTenant<TD extends TenantDetails>(): Observable<Tenant<TD>> {
return this._getOne([this.activeTenantId]);
}

View File

@ -1,4 +1,4 @@
import { ChangeDetectionStrategy, Component, inject, Input } from '@angular/core';
import { AfterViewInit, ChangeDetectionStrategy, Component, inject, Input, OnInit } from '@angular/core';
import { FormBuilder, Validators } from '@angular/forms';
import { Title } from '@angular/platform-browser';
import { KeycloakService } from 'keycloak-angular';
@ -10,6 +10,7 @@ import { UI_ROOT } from '../../utils';
import { getKeycloakOptions } from '../keycloak-options';
import { IStoredTenantId, TenantsService } from '../services';
import { KeycloakStatusService } from '../services/keycloak-status.service';
import { CacheApiService } from '../../caching';
@Component({
templateUrl: './tenant-select.component.html',
@ -17,8 +18,9 @@ import { KeycloakStatusService } from '../services/keycloak-status.service';
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: false,
})
export class TenantSelectComponent {
export class TenantSelectComponent implements OnInit {
readonly #uiRoot = inject(UI_ROOT);
readonly #cacheApiService = inject(CacheApiService);
protected readonly logger = inject(NGXLogger);
protected readonly tenantsService = inject(TenantsService);
protected storedTenants: IStoredTenantId[] = [];
@ -35,8 +37,8 @@ export class TenantSelectComponent {
@Input() isLoggedOut = false;
@Input() noRoleLogOut = false;
constructor() {
this.#loadStoredTenants();
async ngOnInit() {
await this.#loadStoredTenants();
}
updateTenantSelection() {
@ -66,16 +68,24 @@ export class TenantSelectComponent {
return this.keycloakService.logout(url);
}
removeStored(tenantId: string) {
async removeStored(tenantId: string) {
this.tenantsService.removeStored(tenantId);
this.#loadStoredTenants();
await this.#loadStoredTenants();
}
protected tenantIcon(tenant: IStoredTenantId) {
return `red:${tenant.documine ? 'documine' : 'redaction'}-logo`;
}
#loadStoredTenants() {
async #loadStoredTenants() {
const lastVersionAppVersion = await this.#cacheApiService.getCachedValue('FRONTEND_APP_VERSION');
const currentAppVersion = this.config.FRONTEND_APP_VERSION;
console.log(lastVersionAppVersion);
console.log(currentAppVersion);
if (lastVersionAppVersion !== currentAppVersion) {
this.tenantsService.clearStoredTenants();
}
this.storedTenants = this.tenantsService.getStoredTenants().sort((a, b) => a.tenantId.localeCompare(b.tenantId));
}
}