diff --git a/ui-ngx/src/app/core/http/entity.service.ts b/ui-ngx/src/app/core/http/entity.service.ts index 1e2e398991..ab1fd943c9 100644 --- a/ui-ngx/src/app/core/http/entity.service.ts +++ b/ui-ngx/src/app/core/http/entity.service.ts @@ -1159,10 +1159,9 @@ export class EntityService { }); } - public getAssignedToEdgeEntitiesByType(node: NavTreeNode, pageLink: PageLink): Observable> { - let edgeId = node.data.entity.id.id; + public getAssignedToEdgeEntitiesByType(edgeId: string, entityType: EntityType, pageLink: PageLink): Observable> { let entitiesObservable: Observable>; - switch (node.data.entityType) { + switch (entityType) { case (EntityType.ASSET): entitiesObservable = this.assetService.getEdgeAssets(edgeId, pageLink); break; diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/edges-overview-widget.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/edges-overview-widget.component.ts index 60da62bab1..28457bab8a 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/edges-overview-widget.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/edges-overview-widget.component.ts @@ -19,7 +19,7 @@ import { PageComponent } from '@shared/components/page.component'; import { Store } from '@ngrx/store'; import { AppState } from '@core/core.state'; import { WidgetContext } from '@home/models/widget-component.models'; -import { WidgetConfig } from '@shared/models/widget.models'; +import { Datasource, DatasourceType, WidgetConfig } from '@shared/models/widget.models'; import { IWidgetSubscription } from '@core/api/widget-api.models'; import { UtilsService } from '@core/services/utils.service'; import { LoadNodesCallback } from '@shared/components/nav-tree.component'; @@ -41,7 +41,6 @@ import { BaseData, HasId } from "@shared/models/base-data"; import { EntityId } from "@shared/models/id/entity-id"; import { getCurrentAuthUser } from "@core/auth/auth.selectors"; import { Authority } from "@shared/models/authority.enum"; -import { Direction } from "@shared/models/page/sort-order"; @Component({ selector: 'tb-edges-overview-widget', @@ -78,29 +77,29 @@ export class EdgesOverviewWidgetComponent extends PageComponent implements OnIni this.widgetConfig = this.ctx.widgetConfig; this.subscription = this.ctx.defaultSubscription; this.datasources = this.subscription.datasources as Array; - if (this.datasources.length > 0 && this.datasources[0].entity.id.entityType === EntityType.EDGE) { - let selectedEdge = this.datasources[0].entity; - this.getCustomerTitle(selectedEdge.id.id); - this.ctx.widgetTitle = selectedEdge.name; - } this.ctx.updateWidgetParams(); } public loadNodes: LoadNodesCallback = (node, cb) => { - if (node.id === '#' && this.datasources.length > 0) { - var selectedEdge: BaseData = null; - if (this.datasources[0].entity.id.entityType === EntityType.EDGE) { - selectedEdge = this.datasources[0].entity; - } - if (selectedEdge) { + const datasource: Datasource = this.datasources[0]; + if (node.id === '#' && datasource) { + if (datasource.type === DatasourceType.entity && datasource.entity.id.entityType === EntityType.EDGE) { + var selectedEdge: BaseData = datasource.entity; + this.getCustomerTitle(selectedEdge.id.id); + this.ctx.widgetTitle = selectedEdge.name; cb(this.loadNodesForEdge(selectedEdge.id.id, selectedEdge)); + } else if (datasource.type === DatasourceType.function) { + cb(this.loadNodesForEdge(datasource.entityId, datasource.entity)); } else { - cb(this.loadNodesForEdge(this.datasources[0].entityId, this.datasources[0].entity)); + this.ctx.showErrorToast(this.translateService.instant('edge.widget-datasource-error')); + cb([]); } - } else if (node.data && node.data.entity.id.entityType === EntityType.EDGE) { - const sortOrder = { property: 'createdTime', direction: Direction.DESC }; - const pageLink = new PageLink(10, 0, null, sortOrder); - this.entityService.getAssignedToEdgeEntitiesByType(node, pageLink).subscribe( + } + else if (node.data && node.data.entity.id.entityType === EntityType.EDGE) { + const edgeId = node.data.entity.id.id; + const entityType = node.data.entityType; + const pageLink = new PageLink(datasource.pageLink.pageSize); + this.entityService.getAssignedToEdgeEntitiesByType(edgeId, entityType, pageLink).subscribe( (entities) => { if (entities.data.length > 0) { cb(this.entitiesToNodes(node.id, entities.data)); 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 26cdbe43bd..1465c9e880 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -1287,7 +1287,8 @@ "no-downlinks-prompt": "No downlinks found", "sync-process-started-successfully": "Sync process started successfully!", "missing-related-rule-chains-title": "Edge has missing related rule chain(s)", - "missing-related-rule-chains-text": "Assigned to edge rule chain(s) use rule nodes that forward message(s) to rule chain(s) that are not assigned to this edge.

List of missing rule chain(s):
{{missingRuleChains}}" + "missing-related-rule-chains-text": "Assigned to edge rule chain(s) use rule nodes that forward message(s) to rule chain(s) that are not assigned to this edge.

List of missing rule chain(s):
{{missingRuleChains}}", + "widget-datasource-error": "This widget supports only EDGE entity" }, "edge-event": { "type-dashboard": "Dashboard",