From a75fc2ea0df54b2c6f89ee499dc12d4a621d2850 Mon Sep 17 00:00:00 2001 From: deaflynx Date: Thu, 29 Oct 2020 11:28:59 +0200 Subject: [PATCH] Fixed edge rule chains --- ui-ngx/src/app/core/http/edge.service.ts | 6 +-- .../rulechains-table-config.resolver.ts | 37 ++++++++++++++----- ui-ngx/src/app/shared/models/edge.models.ts | 2 + .../assets/locale/locale.constant-de_DE.json | 6 +-- .../assets/locale/locale.constant-en_US.json | 6 +-- .../assets/locale/locale.constant-es_ES.json | 6 +-- .../assets/locale/locale.constant-fr_FR.json | 6 +-- ui/src/app/edge/edge.controller.js | 6 +-- .../set-root-rule-chain-to-edges.tpl.html | 6 +-- 9 files changed, 50 insertions(+), 31 deletions(-) diff --git a/ui-ngx/src/app/core/http/edge.service.ts b/ui-ngx/src/app/core/http/edge.service.ts index fe54696615..b8bf6c7282 100644 --- a/ui-ngx/src/app/core/http/edge.service.ts +++ b/ui-ngx/src/app/core/http/edge.service.ts @@ -73,7 +73,7 @@ export class EdgeService { } public assignEdgeToCustomer(customerId: string, edgeId: string, config?: RequestConfig): Observable { - return this.http.post(`/api/customer/${customerId}/edge/${edgeId}`, null, defaultHttpOptionsFromConfig(config)); + return this.http.post(`/api/customer/${customerId}/edge/${edgeId}`, defaultHttpOptionsFromConfig(config)); } public unassignEdgeFromCustomer(edgeId: string, config?: RequestConfig) { @@ -81,11 +81,11 @@ export class EdgeService { } public makeEdgePublic(edgeId: string, config?: RequestConfig): Observable { - return this.http.post(`/api/customer/public/edge/${edgeId}`, null, defaultHttpOptionsFromConfig(config)); + return this.http.post(`/api/customer/public/edge/${edgeId}`, defaultHttpOptionsFromConfig(config)); } public setRootRuleChain(edgeId: string, ruleChainId: string, config?: RequestConfig): Observable { - return this.http.post(`/api/edge/${edgeId}/${ruleChainId}/root`, null, defaultHttpOptionsFromConfig(config)); + return this.http.post(`/api/edge/${edgeId}/${ruleChainId}/root`, defaultHttpOptionsFromConfig(config)); } public getTenantEdgeInfos(pageLink: PageLink, type: string = '', diff --git a/ui-ngx/src/app/modules/home/pages/rulechain/rulechains-table-config.resolver.ts b/ui-ngx/src/app/modules/home/pages/rulechain/rulechains-table-config.resolver.ts index d832704476..89082a1d19 100644 --- a/ui-ngx/src/app/modules/home/pages/rulechain/rulechains-table-config.resolver.ts +++ b/ui-ngx/src/app/modules/home/pages/rulechain/rulechains-table-config.resolver.ts @@ -46,12 +46,14 @@ import { import { MatDialog } from "@angular/material/dialog"; import { isDefined, isUndefined } from "@core/utils"; import { PageLink } from "@shared/models/page/page-link"; +import { Edge } from "@shared/models/edge.models"; @Injectable() export class RuleChainsTableConfigResolver implements Resolve> { private readonly config: EntityTableConfig = new EntityTableConfig(); private edgeId: string; + private edge: Edge; constructor(private ruleChainService: RuleChainService, private dialogService: DialogService, @@ -62,7 +64,6 @@ export class RuleChainsTableConfigResolver implements Resolve('name', 'rulechain.name', '100%'), new EntityTableColumn('root', 'rulechain.root', '60px', entity => { + if (isDefined(this.edgeId) && this.edgeId != null) { + return checkBoxCell((this.edge.rootRuleChainId.id == entity.id.id)); + } else { return checkBoxCell(entity.root); + } }) ); this.config.deleteEntityTitle = ruleChain => this.translate.instant('rulechain.delete-rulechain-title', @@ -87,7 +92,13 @@ export class RuleChainsTableConfigResolver implements Resolve this.ruleChainService.deleteRuleChain(id.id); this.config.onEntityAction = action => this.onRuleChainAction(action); this.config.deleteEnabled = (ruleChain) => ruleChain && !ruleChain.root; - this.config.entitySelectionEnabled = (ruleChain) => ruleChain && !ruleChain.root; + this.config.entitySelectionEnabled = (ruleChain) => { + if (isDefined(this.edgeId) && this.edgeId != null) { + return this.edge.rootRuleChainId.id != ruleChain.id.id; + } else { + return ruleChain && !ruleChain.root; + } + } } resolve(route: ActivatedRouteSnapshot): EntityTableConfig { @@ -143,13 +154,15 @@ export class RuleChainsTableConfigResolver implements Resolve this.fetchEdgeRuleChains(pageLink); } else if (ruleChainScope === 'edge') { - if (this.edgeId) { + if (isDefined(this.edgeId) && this.edgeId != null) { this.edgeService.getEdge(this.edgeId) - .pipe(map(edge => this.config.tableTitle = edge.name + ': ' + this.translate.instant('rulechain.edge-rulechains'))) - .subscribe(); + .pipe(map(edge => { + this.edge = edge; + this.config.tableTitle = edge.name + ': ' + this.translate.instant('rulechain.edge-rulechains') + })).subscribe(); } this.config.entitiesFetchFunction = pageLink => this.ruleChainService.getEdgeRuleChains(this.edgeId, pageLink); - this.config.deleteEnabled = () => false; + this.config.entitiesDeleteEnabled = false; } } @@ -221,7 +234,7 @@ export class RuleChainsTableConfigResolver implements Resolve this.isNonRootRuleChain(entity), onAction: ($event, entity) => this.setRootRuleChain($event, entity) @@ -229,7 +242,7 @@ export class RuleChainsTableConfigResolver implements Resolve true, + isEnabled: (entity) => entity.id.id != this.edge.rootRuleChainId.id, onAction: ($event, entity) => this.unassignFromEdge($event, entity) } ) @@ -286,9 +299,10 @@ export class RuleChainsTableConfigResolver implements Resolve { if (res) { - if (this.edgeId) { + if (isDefined(this.edgeId) && this.edgeId != null) { this.edgeService.setRootRuleChain(this.edgeId, ruleChain.id.id).subscribe( - () => { + (edge) => { + this.edge = edge; this.config.table.updateData(); } ) @@ -457,6 +471,9 @@ export class RuleChainsTableConfigResolver implements Resolve { tenantId?: TenantId; @@ -31,6 +32,7 @@ export interface Edge extends BaseData { edgeLicenseKey: string; label?: string; additionalInfo?: any; + rootRuleChainId?: RuleChainId; } export interface EdgeInfo extends Edge { diff --git a/ui-ngx/src/assets/locale/locale.constant-de_DE.json b/ui-ngx/src/assets/locale/locale.constant-de_DE.json index 5bce3e1d2e..8705e9ab98 100644 --- a/ui-ngx/src/assets/locale/locale.constant-de_DE.json +++ b/ui-ngx/src/assets/locale/locale.constant-de_DE.json @@ -802,9 +802,9 @@ "assets": "Rand Objekte", "devices": "Objekte Geräte", "entity-views": "Objekte Entitätsansichten", - "set-root-rule-chain-text": "Bitte wählen Sie die Regelkette zur Wurzel rule chain für die Rand", - "set-root-rule-chain-to-edges": "Regelkette zur Wurzel machen für die Rand", - "set-root-rule-chain-to-edges-text": "Die Regelkette zur Wurzel für { count, plural, 1 {1 Rand} other {# Rand} } machen", + "set-root-rulechain-text": "Bitte wählen Sie die Regelkette zur Wurzel rule chain für die Rand", + "set-root-rulechain-to-edges": "Regelkette zur Wurzel machen für die Rand", + "set-root-rulechain-to-edges-text": "Die Regelkette zur Wurzel für { count, plural, 1 {1 Rand} other {# Rand} } machen", "status": "Von Rand empfangen", "success": "Bereitgestellt", "failed": "Steht aus", diff --git a/ui-ngx/src/assets/locale/locale.constant-en_US.json b/ui-ngx/src/assets/locale/locale.constant-en_US.json index 9ec51539df..a419648612 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -994,9 +994,9 @@ "assets": "Edge assets", "devices": "Edge devices", "entity-views": "Edge entity views", - "set-root-rule-chain-text": "Please select root rule chain for edge(s)", - "set-root-rule-chain-to-edges": "Set root rule chain for Edge(s)", - "set-root-rule-chain-to-edges-text": "Set root rule chain for { count, plural, 1 {1 edge} other {# edges} }", + "set-root-rulechain-text": "Please select root rule chain for edge(s)", + "set-root-rulechain-to-edges": "Set root rule chain for Edge(s)", + "set-root-rulechain-to-edges-text": "Set root rule chain for { count, plural, 1 {1 edge} other {# edges} }", "status": "Received by edge", "success": "Deployed", "failed": "Pending", diff --git a/ui-ngx/src/assets/locale/locale.constant-es_ES.json b/ui-ngx/src/assets/locale/locale.constant-es_ES.json index ffdb8d46e0..107765501c 100644 --- a/ui-ngx/src/assets/locale/locale.constant-es_ES.json +++ b/ui-ngx/src/assets/locale/locale.constant-es_ES.json @@ -824,9 +824,9 @@ "assets": "Activos de borde", "devices": "Dispositivos de borde", "entity-views": "Vistas de entidad de borde", - "set-root-rule-chain-text": "Seleccione la cadena de reglas raíz para los bordes", - "set-root-rule-chain-to-edges": "Establecer la cadena de reglas raíz para Edge (s)", - "set-root-rule-chain-to-edges-text": "Establecer la cadena de la regla raíz para {count, plural, 1 {1 borde} other {# bordes}}", + "set-root-rulechain-text": "Seleccione la cadena de reglas raíz para los bordes", + "set-root-rulechain-to-edges": "Establecer la cadena de reglas raíz para Edge (s)", + "set-root-rulechain-to-edges-text": "Establecer la cadena de la regla raíz para {count, plural, 1 {1 borde} other {# bordes}}", "status": "Recibido por borde", "success": "Desplegada", "failed": "Pendiente", diff --git a/ui-ngx/src/assets/locale/locale.constant-fr_FR.json b/ui-ngx/src/assets/locale/locale.constant-fr_FR.json index 85565723ac..d984e9e9e7 100644 --- a/ui-ngx/src/assets/locale/locale.constant-fr_FR.json +++ b/ui-ngx/src/assets/locale/locale.constant-fr_FR.json @@ -820,9 +820,9 @@ "assets": "Actifs de la bordure", "devices": "Dispositifs de la bordure", "entity-views": "Vues de l'entité bordure", - "set-root-rule-chain-text": "Veuillez sélectionner la chaîne de règles racine pour les bordure(s)", - "set-root-rule-chain-to-edges": "Définir la chaîne de règles racine pour bordure(s)", - "set-root-rule-chain-to-edges-text": "Définir la chaîne de règles racine pour {count, plural, 1 {1 bordure} other {# bordures} }", + "set-root-rulechain-text": "Veuillez sélectionner la chaîne de règles racine pour les bordure(s)", + "set-rootrule-chain-to-edges": "Définir la chaîne de règles racine pour bordure(s)", + "set-root-rulechain-to-edges-text": "Définir la chaîne de règles racine pour {count, plural, 1 {1 bordure} other {# bordures} }", "status": "Reçu par bord", "success": "Déployée", "failed": "En attente", diff --git a/ui/src/app/edge/edge.controller.js b/ui/src/app/edge/edge.controller.js index 94f076c1af..036c72f2b1 100644 --- a/ui/src/app/edge/edge.controller.js +++ b/ui/src/app/edge/edge.controller.js @@ -19,7 +19,7 @@ import addEdgeTemplate from './add-edge.tpl.html'; import edgeCard from './edge-card.tpl.html'; import assignToCustomerTemplate from './assign-to-customer.tpl.html'; import addEdgesToCustomerTemplate from './add-edges-to-customer.tpl.html'; -import setRootRuleChainToEdgesTemplate from './set-root-rule-chain-to-edges.tpl.html'; +import setRootRuleChainToEdgesTemplate from './set-root-rulechain-to-edges.tpl.html'; /* eslint-enable import/no-unresolved, import/default */ @@ -303,9 +303,9 @@ export function EdgeController($rootScope, userService, edgeService, customerSer onAction: function ($event, items) { setRootRuleChainToEdges($event, items); }, - name: function() { return $translate.instant('edge.set-root-rule-chain-to-edges') }, + name: function() { return $translate.instant('edge.set-rootrule-chain-to-edges') }, details: function(selectedCount) { - return $translate.instant('edge.set-root-rule-chain-to-edges-text', {count: selectedCount}, "messageformat"); + return $translate.instant('edge.set-root-rulechain-to-edges-text', {count: selectedCount}, "messageformat"); }, icon: "flag" } diff --git a/ui/src/app/edge/set-root-rule-chain-to-edges.tpl.html b/ui/src/app/edge/set-root-rule-chain-to-edges.tpl.html index 8034899157..369a2d3cc6 100644 --- a/ui/src/app/edge/set-root-rule-chain-to-edges.tpl.html +++ b/ui/src/app/edge/set-root-rule-chain-to-edges.tpl.html @@ -15,11 +15,11 @@ limitations under the License. --> - +
-

edge.set-root-rule-chain-to-edges

+

edge.set-root-rulechain-to-edges

@@ -31,7 +31,7 @@
- edge.set-root-rule-chain-text + edge.set-root-rulechain-text