[AAE-4966] Extensible app config (#6914)

* merge app config from the extensions

* improved service injection in unit tests

* extra unit test

* fix content tests

* update code as per review

* fix lint

* fix lint

* update code and tests

* update schema
This commit is contained in:
Denys Vuika
2021-04-13 14:16:29 +01:00
committed by GitHub
parent bd8242922b
commit 84ce202ad2
54 changed files with 383 additions and 204 deletions

View File

@@ -19,7 +19,8 @@ import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { ObjectUtils } from '../utils/object-utils';
import { Observable, Subject } from 'rxjs';
import { map, distinctUntilChanged } from 'rxjs/operators';
import { map, distinctUntilChanged, take } from 'rxjs/operators';
import { ExtensionConfig, ExtensionService, mergeObjects } from '@alfresco/adf-extensions';
/* spellchecker: disable */
export enum AppConfigValues {
@@ -69,9 +70,13 @@ export class AppConfigService {
protected onLoadSubject: Subject<any>;
onLoad: Observable<any>;
constructor(private http: HttpClient) {
constructor(protected http: HttpClient, protected extensionService: ExtensionService) {
this.onLoadSubject = new Subject();
this.onLoad = this.onLoadSubject.asObservable();
extensionService.setup$.subscribe((config) => {
this.onExtensionsLoaded(config);
});
}
/**
@@ -142,6 +147,29 @@ export class AppConfigService {
return location.port ? prefix + location.port : '';
}
protected onLoaded() {
this.onLoadSubject.next(this.config);
}
protected onDataLoaded(data: any) {
this.config = Object.assign({}, this.config, data || {});
this.onLoadSubject.next(this.config);
this.extensionService.setup$
.pipe(take(1))
.subscribe((config) => this.onExtensionsLoaded(config));
}
protected onExtensionsLoaded(config: ExtensionConfig) {
if (config) {
const customConfig = config.appConfig;
if (customConfig) {
this.config = mergeObjects(this.config, customConfig);
}
}
}
/**
* Loads the config file.
* @returns Notification when loading is complete
@@ -152,11 +180,10 @@ export class AppConfigService {
if (this.status === Status.INIT) {
this.status = Status.LOADING;
await this.http.get(configUrl).subscribe(
this.http.get(configUrl).subscribe(
(data: any) => {
this.status = Status.LOADED;
this.config = Object.assign({}, this.config, data || {});
this.onLoadSubject.next(this.config);
this.onDataLoaded(data);
resolve(this.config);
},
() => {