Refactoring

This commit is contained in:
Chantsova Ekaterina 2023-04-27 13:27:33 +03:00
parent 4058b9e468
commit bc93e16ced
2 changed files with 22 additions and 25 deletions

View File

@ -49,7 +49,7 @@ export class CustomDialogService {
config?: MatDialogConfig): Observable<any> {
const modules = [this.sharedModule, CommonModule, this.sharedHomeComponentsModule, this.homeComponentsModule];
if (isObject(data) && data.hasOwnProperty('customModules')) {
modules.push(data.customModules);
modules.push(...data.customModules);
}
return this.dynamicComponentFactoryService.createDynamicComponentFactory(
class CustomDialogComponentInstance extends CustomDialogComponent {}, template, modules).pipe(

View File

@ -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> {
const resourceTasks: Observable<string>[] = [];
const modulesTasks: Observable<ModulesWithFactories | string>[] = [];
if (isDefined(customCss) && customCss.length > 0) {
this.cssParser.cssPreviewNamespace = actionNamespace;
this.cssParser.createStyleElement(actionNamespace, customCss, 'nonamespace');
}
const resourceTasks: Observable<string>[] = [];
const modulesTasks: Observable<ModulesWithFactories | string>[] = [];
if (isDefined(customResources) && customResources.length > 0) {
customResources.filter(r => r.isModule).forEach(
(resource) => {
customResources.forEach(resource => {
if (resource.isModule) {
modulesTasks.push(
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}'`))
)
);
} 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) {
@ -1521,28 +1522,24 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI
);
resourceTasks.push(modulesObservable.pipe(
mergeMap((resolvedModules) => {
map((resolvedModules) => {
if (typeof resolvedModules === 'string') {
return of(resolvedModules);
return resolvedModules;
} else {
actionDescriptor.customModules = resolvedModules;
return of(null);
return null;
}
})));
}
return forkJoin(resourceTasks).pipe(
switchMap(msgs => {
let errors: string[];
if (msgs && msgs.length) {
errors = msgs.filter(msg => msg && msg.length > 0);
}
if (errors && errors.length) {
return throwError(errors);
} else {
return of(null);
}
}
const errors = msgs.filter(msg => msg && msg.length > 0);
if (errors.length > 0) {
return throwError(() => errors);
} else {
return of(null);
}}
));
} else {
return of(null);