Refactoring
This commit is contained in:
parent
4058b9e468
commit
bc93e16ced
@ -49,7 +49,7 @@ export class CustomDialogService {
|
|||||||
config?: MatDialogConfig): Observable<any> {
|
config?: MatDialogConfig): Observable<any> {
|
||||||
const modules = [this.sharedModule, CommonModule, this.sharedHomeComponentsModule, this.homeComponentsModule];
|
const modules = [this.sharedModule, CommonModule, this.sharedHomeComponentsModule, this.homeComponentsModule];
|
||||||
if (isObject(data) && data.hasOwnProperty('customModules')) {
|
if (isObject(data) && data.hasOwnProperty('customModules')) {
|
||||||
modules.push(data.customModules);
|
modules.push(...data.customModules);
|
||||||
}
|
}
|
||||||
return this.dynamicComponentFactoryService.createDynamicComponentFactory(
|
return this.dynamicComponentFactoryService.createDynamicComponentFactory(
|
||||||
class CustomDialogComponentInstance extends CustomDialogComponent {}, template, modules).pipe(
|
class CustomDialogComponentInstance extends CustomDialogComponent {}, template, modules).pipe(
|
||||||
|
|||||||
@ -1479,28 +1479,29 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI
|
|||||||
}
|
}
|
||||||
|
|
||||||
private loadCustomActionResources(actionNamespace: string, customCss: string, customResources: Array<WidgetResource>, actionDescriptor: WidgetActionDescriptor): Observable<any> {
|
private loadCustomActionResources(actionNamespace: string, customCss: string, customResources: Array<WidgetResource>, actionDescriptor: WidgetActionDescriptor): Observable<any> {
|
||||||
|
const resourceTasks: Observable<string>[] = [];
|
||||||
|
const modulesTasks: Observable<ModulesWithFactories | string>[] = [];
|
||||||
|
|
||||||
if (isDefined(customCss) && customCss.length > 0) {
|
if (isDefined(customCss) && customCss.length > 0) {
|
||||||
this.cssParser.cssPreviewNamespace = actionNamespace;
|
this.cssParser.cssPreviewNamespace = actionNamespace;
|
||||||
this.cssParser.createStyleElement(actionNamespace, customCss, 'nonamespace');
|
this.cssParser.createStyleElement(actionNamespace, customCss, 'nonamespace');
|
||||||
}
|
}
|
||||||
const resourceTasks: Observable<string>[] = [];
|
|
||||||
const modulesTasks: Observable<ModulesWithFactories | string>[] = [];
|
|
||||||
if (isDefined(customResources) && customResources.length > 0) {
|
if (isDefined(customResources) && customResources.length > 0) {
|
||||||
customResources.filter(r => r.isModule).forEach(
|
customResources.forEach(resource => {
|
||||||
(resource) => {
|
if (resource.isModule) {
|
||||||
modulesTasks.push(
|
modulesTasks.push(
|
||||||
this.resources.loadFactories(resource.url, this.modulesMap).pipe(
|
this.resources.loadFactories(resource.url, this.modulesMap).pipe(
|
||||||
catchError((e: Error) => of(e?.message ? e.message : `Failed to load custom action resource module: '${resource.url}'`))
|
catchError((e: Error) => of(e?.message ? e.message : `Failed to load custom action resource module: '${resource.url}'`))
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
resourceTasks.push(
|
||||||
|
this.resources.loadResource(resource.url).pipe(
|
||||||
|
catchError(() => of(`Failed to load custom action resource: '${resource.url}'`))
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
);
|
|
||||||
customResources.filter(r => !r.isModule).forEach((resource) => {
|
|
||||||
resourceTasks.push(
|
|
||||||
this.resources.loadResource(resource.url).pipe(
|
|
||||||
catchError(e => of(`Failed to load custom action resource: '${resource.url}'`))
|
|
||||||
)
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (modulesTasks.length) {
|
if (modulesTasks.length) {
|
||||||
@ -1521,28 +1522,24 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI
|
|||||||
);
|
);
|
||||||
|
|
||||||
resourceTasks.push(modulesObservable.pipe(
|
resourceTasks.push(modulesObservable.pipe(
|
||||||
mergeMap((resolvedModules) => {
|
map((resolvedModules) => {
|
||||||
if (typeof resolvedModules === 'string') {
|
if (typeof resolvedModules === 'string') {
|
||||||
return of(resolvedModules);
|
return resolvedModules;
|
||||||
} else {
|
} else {
|
||||||
actionDescriptor.customModules = resolvedModules;
|
actionDescriptor.customModules = resolvedModules;
|
||||||
return of(null);
|
return null;
|
||||||
}
|
}
|
||||||
})));
|
})));
|
||||||
}
|
}
|
||||||
|
|
||||||
return forkJoin(resourceTasks).pipe(
|
return forkJoin(resourceTasks).pipe(
|
||||||
switchMap(msgs => {
|
switchMap(msgs => {
|
||||||
let errors: string[];
|
const errors = msgs.filter(msg => msg && msg.length > 0);
|
||||||
if (msgs && msgs.length) {
|
if (errors.length > 0) {
|
||||||
errors = msgs.filter(msg => msg && msg.length > 0);
|
return throwError(() => errors);
|
||||||
}
|
} else {
|
||||||
if (errors && errors.length) {
|
return of(null);
|
||||||
return throwError(errors);
|
}}
|
||||||
} else {
|
|
||||||
return of(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
return of(null);
|
return of(null);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user