Fixed Rule Chains page: openRuleChain(). Refactored getRuleNodeComponents()

This commit is contained in:
Artem Babak 2020-10-19 12:37:47 +03:00
parent 84a0604c08
commit e393f3b51d
4 changed files with 9 additions and 11 deletions

View File

@ -53,8 +53,7 @@ export class ComponentDescriptorService {
} }
} }
public getComponentDescriptorsByTypes(componentTypes: Array<ComponentType>, type: string, public getComponentDescriptorsByTypes(componentTypes: Array<ComponentType>, config?: RequestConfig): Observable<Array<ComponentDescriptor>> {
config?: RequestConfig): Observable<Array<ComponentDescriptor>> {
let result: ComponentDescriptor[] = []; let result: ComponentDescriptor[] = [];
for (let i = componentTypes.length - 1; i >= 0; i--) { for (let i = componentTypes.length - 1; i >= 0; i--) {
const componentType = componentTypes[i]; const componentType = componentTypes[i];
@ -67,7 +66,7 @@ export class ComponentDescriptorService {
if (!componentTypes.length) { if (!componentTypes.length) {
return of(result); return of(result);
} else { } else {
return this.http.get<Array<ComponentDescriptor>>(`/api/components/${type}?componentTypes=${componentTypes.join(',')}`, return this.http.get<Array<ComponentDescriptor>>(`/api/components/?componentTypes=${componentTypes.join(',')}`,
defaultHttpOptionsFromConfig(config)).pipe( defaultHttpOptionsFromConfig(config)).pipe(
map((componentDescriptors) => { map((componentDescriptors) => {
componentDescriptors.forEach((componentDescriptor) => { componentDescriptors.forEach((componentDescriptor) => {

View File

@ -117,12 +117,12 @@ export class RuleChainService {
); );
} }
public getRuleNodeComponents(ruleNodeConfigResourcesModulesMap: {[key: string]: any}, type: string, config?: RequestConfig): public getRuleNodeComponents(ruleNodeConfigResourcesModulesMap: {[key: string]: any}, config?: RequestConfig):
Observable<Array<RuleNodeComponentDescriptor>> { Observable<Array<RuleNodeComponentDescriptor>> {
if (this.ruleNodeComponents) { if (this.ruleNodeComponents) {
return of(this.ruleNodeComponents); return of(this.ruleNodeComponents);
} else { } else {
return this.loadRuleNodeComponents(type, config).pipe( return this.loadRuleNodeComponents(config).pipe(
mergeMap((components) => { mergeMap((components) => {
return this.resolveRuleNodeComponentsUiResources(components, ruleNodeConfigResourcesModulesMap).pipe( return this.resolveRuleNodeComponentsUiResources(components, ruleNodeConfigResourcesModulesMap).pipe(
map((ruleNodeComponents) => { map((ruleNodeComponents) => {
@ -205,8 +205,8 @@ export class RuleChainService {
} }
} }
private loadRuleNodeComponents(type: string, config?: RequestConfig): Observable<Array<RuleNodeComponentDescriptor>> { private loadRuleNodeComponents(config?: RequestConfig): Observable<Array<RuleNodeComponentDescriptor>> {
return this.componentDescriptorService.getComponentDescriptorsByTypes(ruleNodeTypeComponentTypes, type, config).pipe( return this.componentDescriptorService.getComponentDescriptorsByTypes(ruleNodeTypeComponentTypes, config).pipe(
map((components) => { map((components) => {
const ruleNodeComponents: RuleNodeComponentDescriptor[] = []; const ruleNodeComponents: RuleNodeComponentDescriptor[] = [];
components.forEach((component) => { components.forEach((component) => {

View File

@ -71,8 +71,7 @@ export class RuleNodeComponentsResolver implements Resolve<Array<RuleNodeCompone
} }
resolve(route: ActivatedRouteSnapshot): Observable<Array<RuleNodeComponentDescriptor>> { resolve(route: ActivatedRouteSnapshot): Observable<Array<RuleNodeComponentDescriptor>> {
const type = route.data.type; return this.ruleChainService.getRuleNodeComponents(this.modulesMap);
return this.ruleChainService.getRuleNodeComponents(this.modulesMap, type);
} }
} }

View File

@ -269,7 +269,7 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
this.importExport.importRuleChain().subscribe((ruleChainImport) => { this.importExport.importRuleChain().subscribe((ruleChainImport) => {
if (ruleChainImport) { if (ruleChainImport) {
this.itembuffer.storeRuleChainImport(ruleChainImport); this.itembuffer.storeRuleChainImport(ruleChainImport);
this.router.navigateByUrl(`ruleChains/ruleChain/import`); this.router.navigateByUrl(`${this.router.routerState.snapshot.url}/ruleChain/import`);
} }
}); });
} }
@ -278,7 +278,7 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
if ($event) { if ($event) {
$event.stopPropagation(); $event.stopPropagation();
} }
this.router.navigateByUrl(`ruleChains/${ruleChain.id.id}`); this.router.navigateByUrl(`${this.router.routerState.snapshot.url}/${ruleChain.id.id}`);
} }
saveRuleChain(ruleChain: RuleChain) { saveRuleChain(ruleChain: RuleChain) {