Commit a75fc2ea0df54b2c6f89ee499dc12d4a621d2850

Authored by deaflynx
1 parent e764042f

Fixed edge rule chains

... ... @@ -73,7 +73,7 @@ export class EdgeService {
73 73 }
74 74
75 75 public assignEdgeToCustomer(customerId: string, edgeId: string, config?: RequestConfig): Observable<Edge> {
76   - return this.http.post<Edge>(`/api/customer/${customerId}/edge/${edgeId}`, null, defaultHttpOptionsFromConfig(config));
  76 + return this.http.post<Edge>(`/api/customer/${customerId}/edge/${edgeId}`, defaultHttpOptionsFromConfig(config));
77 77 }
78 78
79 79 public unassignEdgeFromCustomer(edgeId: string, config?: RequestConfig) {
... ... @@ -81,11 +81,11 @@ export class EdgeService {
81 81 }
82 82
83 83 public makeEdgePublic(edgeId: string, config?: RequestConfig): Observable<Edge> {
84   - return this.http.post<Edge>(`/api/customer/public/edge/${edgeId}`, null, defaultHttpOptionsFromConfig(config));
  84 + return this.http.post<Edge>(`/api/customer/public/edge/${edgeId}`, defaultHttpOptionsFromConfig(config));
85 85 }
86 86
87 87 public setRootRuleChain(edgeId: string, ruleChainId: string, config?: RequestConfig): Observable<Edge> {
88   - return this.http.post<Edge>(`/api/edge/${edgeId}/${ruleChainId}/root`, null, defaultHttpOptionsFromConfig(config));
  88 + return this.http.post<Edge>(`/api/edge/${edgeId}/${ruleChainId}/root`, defaultHttpOptionsFromConfig(config));
89 89 }
90 90
91 91 public getTenantEdgeInfos(pageLink: PageLink, type: string = '',
... ...
... ... @@ -46,12 +46,14 @@ import {
46 46 import { MatDialog } from "@angular/material/dialog";
47 47 import { isDefined, isUndefined } from "@core/utils";
48 48 import { PageLink } from "@shared/models/page/page-link";
  49 +import { Edge } from "@shared/models/edge.models";
49 50
50 51 @Injectable()
51 52 export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<RuleChain>> {
52 53
53 54 private readonly config: EntityTableConfig<RuleChain> = new EntityTableConfig<RuleChain>();
54 55 private edgeId: string;
  56 + private edge: Edge;
55 57
56 58 constructor(private ruleChainService: RuleChainService,
57 59 private dialogService: DialogService,
... ... @@ -62,7 +64,6 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
62 64 private translate: TranslateService,
63 65 private datePipe: DatePipe,
64 66 private router: Router) {
65   -
66 67 this.config.entityType = EntityType.RULE_CHAIN;
67 68 this.config.entityComponent = RuleChainComponent;
68 69 this.config.entityTabsComponent = RuleChainTabsComponent;
... ... @@ -74,7 +75,11 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
74 75 new EntityTableColumn<RuleChain>('name', 'rulechain.name', '100%'),
75 76 new EntityTableColumn<RuleChain>('root', 'rulechain.root', '60px',
76 77 entity => {
  78 + if (isDefined(this.edgeId) && this.edgeId != null) {
  79 + return checkBoxCell((this.edge.rootRuleChainId.id == entity.id.id));
  80 + } else {
77 81 return checkBoxCell(entity.root);
  82 + }
78 83 })
79 84 );
80 85 this.config.deleteEntityTitle = ruleChain => this.translate.instant('rulechain.delete-rulechain-title',
... ... @@ -87,7 +92,13 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
87 92 this.config.deleteEntity = id => this.ruleChainService.deleteRuleChain(id.id);
88 93 this.config.onEntityAction = action => this.onRuleChainAction(action);
89 94 this.config.deleteEnabled = (ruleChain) => ruleChain && !ruleChain.root;
90   - this.config.entitySelectionEnabled = (ruleChain) => ruleChain && !ruleChain.root;
  95 + this.config.entitySelectionEnabled = (ruleChain) => {
  96 + if (isDefined(this.edgeId) && this.edgeId != null) {
  97 + return this.edge.rootRuleChainId.id != ruleChain.id.id;
  98 + } else {
  99 + return ruleChain && !ruleChain.root;
  100 + }
  101 + }
91 102 }
92 103
93 104 resolve(route: ActivatedRouteSnapshot): EntityTableConfig<RuleChain> {
... ... @@ -143,13 +154,15 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
143 154 this.config.tableTitle = this.translate.instant('rulechain.edge-rulechains');
144 155 this.config.entitiesFetchFunction = pageLink => this.fetchEdgeRuleChains(pageLink);
145 156 } else if (ruleChainScope === 'edge') {
146   - if (this.edgeId) {
  157 + if (isDefined(this.edgeId) && this.edgeId != null) {
147 158 this.edgeService.getEdge(this.edgeId)
148   - .pipe(map(edge => this.config.tableTitle = edge.name + ': ' + this.translate.instant('rulechain.edge-rulechains')))
149   - .subscribe();
  159 + .pipe(map(edge => {
  160 + this.edge = edge;
  161 + this.config.tableTitle = edge.name + ': ' + this.translate.instant('rulechain.edge-rulechains')
  162 + })).subscribe();
150 163 }
151 164 this.config.entitiesFetchFunction = pageLink => this.ruleChainService.getEdgeRuleChains(this.edgeId, pageLink);
152   - this.config.deleteEnabled = () => false;
  165 + this.config.entitiesDeleteEnabled = false;
153 166 }
154 167 }
155 168
... ... @@ -221,7 +234,7 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
221 234 if (ruleChainScope === 'edge') {
222 235 actions.push(
223 236 {
224   - name: this.translate.instant('edge.set-root'),
  237 + name: this.translate.instant('rulechain.set-root'),
225 238 icon: 'flag',
226 239 isEnabled: (entity) => this.isNonRootRuleChain(entity),
227 240 onAction: ($event, entity) => this.setRootRuleChain($event, entity)
... ... @@ -229,7 +242,7 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
229 242 {
230 243 name: this.translate.instant('edge.unassign-from-edge'),
231 244 icon: 'portable_wifi_off',
232   - isEnabled: () => true,
  245 + isEnabled: (entity) => entity.id.id != this.edge.rootRuleChainId.id,
233 246 onAction: ($event, entity) => this.unassignFromEdge($event, entity)
234 247 }
235 248 )
... ... @@ -286,9 +299,10 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
286 299 true
287 300 ).subscribe((res) => {
288 301 if (res) {
289   - if (this.edgeId) {
  302 + if (isDefined(this.edgeId) && this.edgeId != null) {
290 303 this.edgeService.setRootRuleChain(this.edgeId, ruleChain.id.id).subscribe(
291   - () => {
  304 + (edge) => {
  305 + this.edge = edge;
292 306 this.config.table.updateData();
293 307 }
294 308 )
... ... @@ -457,6 +471,9 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
457 471 }
458 472
459 473 isNonRootRuleChain(ruleChain: RuleChain) {
  474 + if (isDefined(this.edgeId) && this.edgeId != null) {
  475 + return (isDefined(this.edge.rootRuleChainId) && this.edge.rootRuleChainId != null && this.edge.rootRuleChainId.id != ruleChain.id.id);
  476 + }
460 477 return (isDefined(ruleChain)) && !ruleChain.root;
461 478 }
462 479
... ...
... ... @@ -19,6 +19,7 @@ import { TenantId } from '@shared/models/id/tenant-id';
19 19 import { CustomerId } from '@shared/models/id/customer-id';
20 20 import { EdgeId } from '@shared/models/id/edge-id';
21 21 import { EntitySearchQuery } from '@shared/models/relation.models';
  22 +import { RuleChainId } from "@shared/models/id/rule-chain-id";
22 23
23 24 export interface Edge extends BaseData<EdgeId> {
24 25 tenantId?: TenantId;
... ... @@ -31,6 +32,7 @@ export interface Edge extends BaseData<EdgeId> {
31 32 edgeLicenseKey: string;
32 33 label?: string;
33 34 additionalInfo?: any;
  35 + rootRuleChainId?: RuleChainId;
34 36 }
35 37
36 38 export interface EdgeInfo extends Edge {
... ...
... ... @@ -802,9 +802,9 @@
802 802 "assets": "Rand Objekte",
803 803 "devices": "Objekte Geräte",
804 804 "entity-views": "Objekte Entitätsansichten",
805   - "set-root-rule-chain-text": "Bitte wählen Sie die Regelkette zur Wurzel rule chain für die Rand",
806   - "set-root-rule-chain-to-edges": "Regelkette zur Wurzel machen für die Rand",
807   - "set-root-rule-chain-to-edges-text": "Die Regelkette zur Wurzel für { count, plural, 1 {1 Rand} other {# Rand} } machen",
  805 + "set-root-rulechain-text": "Bitte wählen Sie die Regelkette zur Wurzel rule chain für die Rand",
  806 + "set-root-rulechain-to-edges": "Regelkette zur Wurzel machen für die Rand",
  807 + "set-root-rulechain-to-edges-text": "Die Regelkette zur Wurzel für { count, plural, 1 {1 Rand} other {# Rand} } machen",
808 808 "status": "Von Rand empfangen",
809 809 "success": "Bereitgestellt",
810 810 "failed": "Steht aus",
... ...
... ... @@ -994,9 +994,9 @@
994 994 "assets": "Edge assets",
995 995 "devices": "Edge devices",
996 996 "entity-views": "Edge entity views",
997   - "set-root-rule-chain-text": "Please select root rule chain for edge(s)",
998   - "set-root-rule-chain-to-edges": "Set root rule chain for Edge(s)",
999   - "set-root-rule-chain-to-edges-text": "Set root rule chain for { count, plural, 1 {1 edge} other {# edges} }",
  997 + "set-root-rulechain-text": "Please select root rule chain for edge(s)",
  998 + "set-root-rulechain-to-edges": "Set root rule chain for Edge(s)",
  999 + "set-root-rulechain-to-edges-text": "Set root rule chain for { count, plural, 1 {1 edge} other {# edges} }",
1000 1000 "status": "Received by edge",
1001 1001 "success": "Deployed",
1002 1002 "failed": "Pending",
... ...
... ... @@ -824,9 +824,9 @@
824 824 "assets": "Activos de borde",
825 825 "devices": "Dispositivos de borde",
826 826 "entity-views": "Vistas de entidad de borde",
827   - "set-root-rule-chain-text": "Seleccione la cadena de reglas raíz para los bordes",
828   - "set-root-rule-chain-to-edges": "Establecer la cadena de reglas raíz para Edge (s)",
829   - "set-root-rule-chain-to-edges-text": "Establecer la cadena de la regla raíz para {count, plural, 1 {1 borde} other {# bordes}}",
  827 + "set-root-rulechain-text": "Seleccione la cadena de reglas raíz para los bordes",
  828 + "set-root-rulechain-to-edges": "Establecer la cadena de reglas raíz para Edge (s)",
  829 + "set-root-rulechain-to-edges-text": "Establecer la cadena de la regla raíz para {count, plural, 1 {1 borde} other {# bordes}}",
830 830 "status": "Recibido por borde",
831 831 "success": "Desplegada",
832 832 "failed": "Pendiente",
... ...
... ... @@ -820,9 +820,9 @@
820 820 "assets": "Actifs de la bordure",
821 821 "devices": "Dispositifs de la bordure",
822 822 "entity-views": "Vues de l'entité bordure",
823   - "set-root-rule-chain-text": "Veuillez sélectionner la chaîne de règles racine pour les bordure(s)",
824   - "set-root-rule-chain-to-edges": "Définir la chaîne de règles racine pour bordure(s)",
825   - "set-root-rule-chain-to-edges-text": "Définir la chaîne de règles racine pour {count, plural, 1 {1 bordure} other {# bordures} }",
  823 + "set-root-rulechain-text": "Veuillez sélectionner la chaîne de règles racine pour les bordure(s)",
  824 + "set-rootrule-chain-to-edges": "Définir la chaîne de règles racine pour bordure(s)",
  825 + "set-root-rulechain-to-edges-text": "Définir la chaîne de règles racine pour {count, plural, 1 {1 bordure} other {# bordures} }",
826 826 "status": "Reçu par bord",
827 827 "success": "Déployée",
828 828 "failed": "En attente",
... ...
... ... @@ -19,7 +19,7 @@ import addEdgeTemplate from './add-edge.tpl.html';
19 19 import edgeCard from './edge-card.tpl.html';
20 20 import assignToCustomerTemplate from './assign-to-customer.tpl.html';
21 21 import addEdgesToCustomerTemplate from './add-edges-to-customer.tpl.html';
22   -import setRootRuleChainToEdgesTemplate from './set-root-rule-chain-to-edges.tpl.html';
  22 +import setRootRuleChainToEdgesTemplate from './set-root-rulechain-to-edges.tpl.html';
23 23
24 24 /* eslint-enable import/no-unresolved, import/default */
25 25
... ... @@ -303,9 +303,9 @@ export function EdgeController($rootScope, userService, edgeService, customerSer
303 303 onAction: function ($event, items) {
304 304 setRootRuleChainToEdges($event, items);
305 305 },
306   - name: function() { return $translate.instant('edge.set-root-rule-chain-to-edges') },
  306 + name: function() { return $translate.instant('edge.set-rootrule-chain-to-edges') },
307 307 details: function(selectedCount) {
308   - return $translate.instant('edge.set-root-rule-chain-to-edges-text', {count: selectedCount}, "messageformat");
  308 + return $translate.instant('edge.set-root-rulechain-to-edges-text', {count: selectedCount}, "messageformat");
309 309 },
310 310 icon: "flag"
311 311 }
... ...
... ... @@ -15,11 +15,11 @@
15 15 limitations under the License.
16 16
17 17 -->
18   -<md-dialog aria-label="{{ 'edge.set-root-rule-chain-to-edges' | translate }}">
  18 +<md-dialog aria-label="{{ 'edge.set-root-rulechain-to-edges' | translate }}">
19 19 <form name="theForm" ng-submit="vm.assign()">
20 20 <md-toolbar>
21 21 <div class="md-toolbar-tools">
22   - <h2 translate>edge.set-root-rule-chain-to-edges</h2>
  22 + <h2 translate>edge.set-root-rulechain-to-edges</h2>
23 23 <span flex></span>
24 24 <md-button class="md-icon-button" ng-click="vm.cancel()">
25 25 <ng-md-icon icon="close" aria-label="{{ 'dialog.close' | translate }}"></ng-md-icon>
... ... @@ -31,7 +31,7 @@
31 31 <md-dialog-content>
32 32 <div class="md-dialog-content">
33 33 <fieldset>
34   - <span translate>edge.set-root-rule-chain-text</span>
  34 + <span translate>edge.set-root-rulechain-text</span>
35 35 <md-input-container class="md-block" style='margin-bottom: 0px;'>
36 36 <label>&nbsp;</label>
37 37 <md-icon aria-label="{{ 'action.search' | translate }}" class="material-icons">
... ...