Commit b285b2b00c5b42c779d5111860435aba7f37e55f

Authored by Artem Babak
1 parent c19cf237

Fix for edge rulechains

... ... @@ -20,7 +20,7 @@ import {ActivatedRouteSnapshot, Resolve, Route, Router} from '@angular/router';
20 20 import {
21 21 CellActionDescriptor,
22 22 checkBoxCell,
23   - DateEntityTableColumn,
  23 + DateEntityTableColumn, EntityColumn,
24 24 EntityTableColumn,
25 25 EntityTableConfig,
26 26 GroupActionDescriptor, HeaderActionDescriptor
... ... @@ -86,54 +86,55 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
86 86 ruleChainScope: route.data.ruleChainsType,
87 87 edgeId: routeParams.edgeId
88 88 };
89   -
90   - if (this.config.componentsData.ruleChainScope === 'edges') {
91   - this.config.columns = [];
92   - this.config.columns.push(
93   - new DateEntityTableColumn<RuleChain>('createdTime', 'common.created-time', this.datePipe, '150px'),
94   - new EntityTableColumn<RuleChain>('name', 'rulechain.name', '100%'),
95   - new EntityTableColumn<RuleChain>('root', 'rulechain.default-root', '60px',
96   - entity => {
97   - return checkBoxCell(entity.root);
98   - })
99   - );
100   - } else {
101   - this.config.columns = [];
102   - this.config.columns.push(
103   - new DateEntityTableColumn<RuleChain>('createdTime', 'common.created-time', this.datePipe, '150px'),
104   - new EntityTableColumn<RuleChain>('name', 'rulechain.name', '100%'),
105   - new EntityTableColumn<RuleChain>('root', 'rulechain.root', '60px',
106   - entity => {
107   - if (this.config.componentsData.edgeId) {
108   - return checkBoxCell((this.config.componentsData.edge.rootRuleChainId.id == entity.id.id));
109   - } else {
110   - return checkBoxCell(entity.root);
111   - }
112   -
113   - })
114   - );
115   - }
116   -
  89 + this.config.columns = this.configuteEntityTableColumns(this.config.componentsData.ruleChainScope);
  90 + this.configureEntityFunctions(this.config.componentsData.ruleChainScope);
  91 + this.config.groupActionDescriptors = this.configureGroupActions(this.config.componentsData.ruleChainScope);
  92 + this.config.addActionDescriptors = this.configureAddActions(this.config.componentsData.ruleChainScope);
  93 + this.config.cellActionDescriptors = this.configureCellActions(this.config.componentsData.ruleChainScope);
117 94 if (this.config.componentsData.edgeId) {
118   - this.config.entitySelectionEnabled = ruleChain => this.config.componentsData.edge.rootRuleChainId.id != ruleChain.id.id;
  95 + this.config.entitySelectionEnabled = ruleChain => this.config.componentsData.rootRuleChainId !== ruleChain.id.id;
119 96 this.edgeService.getEdge(this.config.componentsData.edgeId).subscribe(edge => {
120   - this.config.componentsData.edge = edge;
121 97 this.config.componentsData.rootRuleChainId = edge.rootRuleChainId.id;
122 98 this.config.tableTitle = edge.name + ': ' + this.translate.instant('rulechain.edge-rulechains');
123 99 });
124 100 this.config.entitiesDeleteEnabled = false;
125   - }
126   - else {
  101 + } else {
127 102 this.config.entitySelectionEnabled = ruleChain => ruleChain && !ruleChain.root;
128 103 this.config.deleteEnabled = (ruleChain) => ruleChain && !ruleChain.root;
  104 + this.config.entitiesDeleteEnabled = true;
129 105 }
130   - this.configureEntityFunctions(this.config.componentsData.ruleChainScope);
131   - this.config.groupActionDescriptors = this.configureGroupActions(this.config.componentsData.ruleChainScope);
132   - this.config.addActionDescriptors = this.configureAddActions(this.config.componentsData.ruleChainScope);
133   - this.config.cellActionDescriptors = this.configureCellActions(this.config.componentsData.ruleChainScope);
134 106 return this.config;
135 107 }
136 108
  109 + configuteEntityTableColumns(ruleChainScope: string): Array<EntityColumn<RuleChain>> {
  110 + const columns: Array<EntityColumn<RuleChain>> = [];
  111 + if (ruleChainScope === 'tenant' || ruleChainScope === 'edge') {
  112 + columns.push(
  113 + new DateEntityTableColumn<RuleChain>('createdTime', 'common.created-time', this.datePipe, '150px'),
  114 + new EntityTableColumn<RuleChain>('name', 'rulechain.name', '100%'),
  115 + new EntityTableColumn<RuleChain>('root', 'rulechain.root', '60px',
  116 + entity => {
  117 + if (ruleChainScope === 'edge') {
  118 + return checkBoxCell((this.config.componentsData.rootRuleChainId == entity.id.id));
  119 + } else {
  120 + return checkBoxCell(entity.root);
  121 + }
  122 + })
  123 + );
  124 + }
  125 + if (ruleChainScope === 'edges') {
  126 + columns.push(
  127 + new DateEntityTableColumn<RuleChain>('createdTime', 'common.created-time', this.datePipe, '150px'),
  128 + new EntityTableColumn<RuleChain>('name', 'rulechain.name', '100%'),
  129 + new EntityTableColumn<RuleChain>('root', 'rulechain.default-root', '60px',
  130 + entity => {
  131 + return checkBoxCell(entity.root);
  132 + })
  133 + );
  134 + }
  135 + return columns;
  136 + }
  137 +
137 138 configureAddActions(ruleChainScope: string): Array<HeaderActionDescriptor> {
138 139 const actions: Array<HeaderActionDescriptor> = [];
139 140 if (ruleChainScope === 'tenant' || ruleChainScope === 'edges') {
... ... @@ -253,7 +254,7 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
253 254 {
254 255 name: this.translate.instant('edge.unassign-from-edge'),
255 256 icon: 'portable_wifi_off',
256   - isEnabled: (entity) => entity.id.id != this.config.componentsData.edge.rootRuleChainId.id,
  257 + isEnabled: (entity) => entity.id.id != this.config.componentsData.rootRuleChainId,
257 258 onAction: ($event, entity) => this.unassignFromEdge($event, entity)
258 259 }
259 260 )
... ... @@ -486,7 +487,7 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
486 487
487 488 isNonRootRuleChain(ruleChain: RuleChain) {
488 489 if (this.config.componentsData.edgeId) {
489   - return (isDefined(this.config.componentsData.edge.rootRuleChainId) && this.config.componentsData.edge.rootRuleChainId != null && this.config.componentsData.edge.rootRuleChainId.id != ruleChain.id.id);
  490 + return (this.config.componentsData.rootRuleChainId && this.config.componentsData.rootRuleChainId != null && this.config.componentsData.rootRuleChainId != ruleChain.id.id);
490 491 }
491 492 return (isDefined(ruleChain)) && !ruleChain.root;
492 493 }
... ...