Edge widget refactored
This commit is contained in:
parent
6d83477fe6
commit
c519936ae9
@ -1159,10 +1159,9 @@ export class EntityService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public getAssignedToEdgeEntitiesByType(node: NavTreeNode, pageLink: PageLink): Observable<PageData<any>> {
|
public getAssignedToEdgeEntitiesByType(edgeId: string, entityType: EntityType, pageLink: PageLink): Observable<PageData<any>> {
|
||||||
let edgeId = node.data.entity.id.id;
|
|
||||||
let entitiesObservable: Observable<PageData<any>>;
|
let entitiesObservable: Observable<PageData<any>>;
|
||||||
switch (node.data.entityType) {
|
switch (entityType) {
|
||||||
case (EntityType.ASSET):
|
case (EntityType.ASSET):
|
||||||
entitiesObservable = this.assetService.getEdgeAssets(edgeId, pageLink);
|
entitiesObservable = this.assetService.getEdgeAssets(edgeId, pageLink);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -19,7 +19,7 @@ import { PageComponent } from '@shared/components/page.component';
|
|||||||
import { Store } from '@ngrx/store';
|
import { Store } from '@ngrx/store';
|
||||||
import { AppState } from '@core/core.state';
|
import { AppState } from '@core/core.state';
|
||||||
import { WidgetContext } from '@home/models/widget-component.models';
|
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 { IWidgetSubscription } from '@core/api/widget-api.models';
|
||||||
import { UtilsService } from '@core/services/utils.service';
|
import { UtilsService } from '@core/services/utils.service';
|
||||||
import { LoadNodesCallback } from '@shared/components/nav-tree.component';
|
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 { EntityId } from "@shared/models/id/entity-id";
|
||||||
import { getCurrentAuthUser } from "@core/auth/auth.selectors";
|
import { getCurrentAuthUser } from "@core/auth/auth.selectors";
|
||||||
import { Authority } from "@shared/models/authority.enum";
|
import { Authority } from "@shared/models/authority.enum";
|
||||||
import { Direction } from "@shared/models/page/sort-order";
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'tb-edges-overview-widget',
|
selector: 'tb-edges-overview-widget',
|
||||||
@ -78,29 +77,29 @@ export class EdgesOverviewWidgetComponent extends PageComponent implements OnIni
|
|||||||
this.widgetConfig = this.ctx.widgetConfig;
|
this.widgetConfig = this.ctx.widgetConfig;
|
||||||
this.subscription = this.ctx.defaultSubscription;
|
this.subscription = this.ctx.defaultSubscription;
|
||||||
this.datasources = this.subscription.datasources as Array<EntityNodeDatasource>;
|
this.datasources = this.subscription.datasources as Array<EntityNodeDatasource>;
|
||||||
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();
|
this.ctx.updateWidgetParams();
|
||||||
}
|
}
|
||||||
|
|
||||||
public loadNodes: LoadNodesCallback = (node, cb) => {
|
public loadNodes: LoadNodesCallback = (node, cb) => {
|
||||||
if (node.id === '#' && this.datasources.length > 0) {
|
const datasource: Datasource = this.datasources[0];
|
||||||
var selectedEdge: BaseData<EntityId> = null;
|
if (node.id === '#' && datasource) {
|
||||||
if (this.datasources[0].entity.id.entityType === EntityType.EDGE) {
|
if (datasource.type === DatasourceType.entity && datasource.entity.id.entityType === EntityType.EDGE) {
|
||||||
selectedEdge = this.datasources[0].entity;
|
var selectedEdge: BaseData<EntityId> = datasource.entity;
|
||||||
}
|
this.getCustomerTitle(selectedEdge.id.id);
|
||||||
if (selectedEdge) {
|
this.ctx.widgetTitle = selectedEdge.name;
|
||||||
cb(this.loadNodesForEdge(selectedEdge.id.id, selectedEdge));
|
cb(this.loadNodesForEdge(selectedEdge.id.id, selectedEdge));
|
||||||
|
} else if (datasource.type === DatasourceType.function) {
|
||||||
|
cb(this.loadNodesForEdge(datasource.entityId, datasource.entity));
|
||||||
} else {
|
} 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 };
|
else if (node.data && node.data.entity.id.entityType === EntityType.EDGE) {
|
||||||
const pageLink = new PageLink(10, 0, null, sortOrder);
|
const edgeId = node.data.entity.id.id;
|
||||||
this.entityService.getAssignedToEdgeEntitiesByType(node, pageLink).subscribe(
|
const entityType = node.data.entityType;
|
||||||
|
const pageLink = new PageLink(datasource.pageLink.pageSize);
|
||||||
|
this.entityService.getAssignedToEdgeEntitiesByType(edgeId, entityType, pageLink).subscribe(
|
||||||
(entities) => {
|
(entities) => {
|
||||||
if (entities.data.length > 0) {
|
if (entities.data.length > 0) {
|
||||||
cb(this.entitiesToNodes(node.id, entities.data));
|
cb(this.entitiesToNodes(node.id, entities.data));
|
||||||
|
|||||||
@ -1287,7 +1287,8 @@
|
|||||||
"no-downlinks-prompt": "No downlinks found",
|
"no-downlinks-prompt": "No downlinks found",
|
||||||
"sync-process-started-successfully": "Sync process started successfully!",
|
"sync-process-started-successfully": "Sync process started successfully!",
|
||||||
"missing-related-rule-chains-title": "Edge has missing related rule chain(s)",
|
"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. <br><br> List of missing rule chain(s): <br> {{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. <br><br> List of missing rule chain(s): <br> {{missingRuleChains}}",
|
||||||
|
"widget-datasource-error": "This widget supports only EDGE entity"
|
||||||
},
|
},
|
||||||
"edge-event": {
|
"edge-event": {
|
||||||
"type-dashboard": "Dashboard",
|
"type-dashboard": "Dashboard",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user