Browse Source

UI: entity data fixes

pull/3053/head
Igor Kulikov 6 years ago
parent
commit
ab93e5455c
  1. 8
      ui-ngx/src/app/core/api/entity-data-subscription.ts
  2. 34
      ui-ngx/src/app/core/api/widget-subscription.ts
  3. 21
      ui-ngx/src/app/core/http/entity.service.ts
  4. 15
      ui-ngx/src/app/modules/home/components/widget/widget.component.ts
  5. 39
      ui-ngx/src/app/shared/models/query/query.models.ts

8
ui-ngx/src/app/core/api/entity-data-subscription.ts

@ -23,6 +23,7 @@ import {
EntityFilter, EntityFilter,
EntityKey, EntityKey,
EntityKeyType, EntityKeyType,
entityKeyTypeToDataKeyType,
KeyFilter, KeyFilter,
TsValue TsValue
} from '@shared/models/query/query.models'; } from '@shared/models/query/query.models';
@ -41,8 +42,8 @@ import { PageData } from '@shared/models/page/page-data';
import { DataAggregator } from '@core/api/data-aggregator'; import { DataAggregator } from '@core/api/data-aggregator';
import { NULL_UUID } from '@shared/models/id/has-uuid'; import { NULL_UUID } from '@shared/models/id/has-uuid';
import { EntityType } from '@shared/models/entity-type.models'; import { EntityType } from '@shared/models/entity-type.models';
import Timeout = NodeJS.Timeout;
import { Observable, of, ReplaySubject, Subject } from 'rxjs'; import { Observable, of, ReplaySubject, Subject } from 'rxjs';
import Timeout = NodeJS.Timeout;
export interface EntityDataSubscriptionOptions { export interface EntityDataSubscriptionOptions {
datasourceType: DatasourceType; datasourceType: DatasourceType;
@ -473,7 +474,8 @@ export class EntityDataSubscription {
if (this.entityDataSubscriptionOptions.type === widgetType.latest && entityData.latest) { if (this.entityDataSubscriptionOptions.type === widgetType.latest && entityData.latest) {
for (const type of Object.keys(entityData.latest)) { for (const type of Object.keys(entityData.latest)) {
const subscriptionData = this.toSubscriptionData(entityData.latest[type], false); const subscriptionData = this.toSubscriptionData(entityData.latest[type], false);
this.onData(subscriptionData, type, dataIndex, true, dataUpdatedCb); const dataKeyType = entityKeyTypeToDataKeyType(EntityKeyType[type]);
this.onData(subscriptionData, dataKeyType, dataIndex, true, dataUpdatedCb);
} }
} }
if (this.entityDataSubscriptionOptions.type === widgetType.timeseries && entityData.timeseries) { if (this.entityDataSubscriptionOptions.type === widgetType.timeseries && entityData.timeseries) {
@ -486,7 +488,7 @@ export class EntityDataSubscription {
} }
} }
private onData(sourceData: SubscriptionData, type: string, dataIndex: number, detectChanges: boolean, private onData(sourceData: SubscriptionData, type: DataKeyType, dataIndex: number, detectChanges: boolean,
dataUpdatedCb: DataUpdatedCb) { dataUpdatedCb: DataUpdatedCb) {
for (const keyName of Object.keys(sourceData)) { for (const keyName of Object.keys(sourceData)) {
const keyData = sourceData[keyName]; const keyData = sourceData[keyName];

34
ui-ngx/src/app/core/api/widget-subscription.ts

@ -52,7 +52,13 @@ import { EntityId } from '@app/shared/models/id/entity-id';
import * as moment_ from 'moment'; import * as moment_ from 'moment';
import { PageData } from '@shared/models/page/page-data'; import { PageData } from '@shared/models/page/page-data';
import { EntityDataListener } from '@core/api/entity-data.service'; import { EntityDataListener } from '@core/api/entity-data.service';
import { EntityData, EntityDataPageLink, EntityKeyType, KeyFilter } from '@shared/models/query/query.models'; import {
EntityData,
EntityDataPageLink,
entityDataToEntityInfo,
EntityKeyType,
KeyFilter
} from '@shared/models/query/query.models';
import { map } from 'rxjs/operators'; import { map } from 'rxjs/operators';
const moment = moment_; const moment = moment_;
@ -414,6 +420,7 @@ export class WidgetSubscription implements IWidgetSubscription {
this.configureLoadedData(); this.configureLoadedData();
this.hasResolvedData = true; this.hasResolvedData = true;
this.notifyDataLoaded(); this.notifyDataLoaded();
this.onDataUpdated(true);
}) })
); );
} }
@ -881,7 +888,6 @@ export class WidgetSubscription implements IWidgetSubscription {
private dataSubscribe() { private dataSubscribe() {
if (!this.hasDataPageLink) { if (!this.hasDataPageLink) {
this.notifyDataLoading();
if (this.type === widgetType.timeseries && this.timeWindowConfig) { if (this.type === widgetType.timeseries && this.timeWindowConfig) {
this.updateRealtimeSubscription(); this.updateRealtimeSubscription();
if (this.comparisonEnabled) { if (this.comparisonEnabled) {
@ -897,7 +903,6 @@ export class WidgetSubscription implements IWidgetSubscription {
this.ctx.entityDataService.startSubscription(listener); this.ctx.entityDataService.startSubscription(listener);
}); });
if (forceUpdate) { if (forceUpdate) {
this.notifyDataLoaded();
this.onDataUpdated(); this.onDataUpdated();
} }
} }
@ -1269,23 +1274,11 @@ export class WidgetSubscription implements IWidgetSubscription {
newDatasource.entityId = entityData.entityId.id; newDatasource.entityId = entityData.entityId.id;
newDatasource.entityType = entityData.entityId.entityType as EntityType; newDatasource.entityType = entityData.entityId.entityType as EntityType;
if (configDatasource.type === DatasourceType.entity) { if (configDatasource.type === DatasourceType.entity) {
let name; const entityInfo = entityDataToEntityInfo(entityData);
let label; newDatasource.name = entityInfo.name;
if (entityData.latest && entityData.latest[EntityKeyType.ENTITY_FIELD]) { newDatasource.entityName = entityInfo.name;
const fields = entityData.latest[EntityKeyType.ENTITY_FIELD]; newDatasource.entityLabel = entityInfo.label;
if (fields.name) { newDatasource.entityDescription = entityInfo.entityDescription;
name = fields.name.value;
}
if (fields.label) {
label = fields.label.value;
}
}
name = name || 'TODO';
label = label || 'TODO';
newDatasource.name = name;
newDatasource.entityName = name;
newDatasource.entityLabel = label;
newDatasource.entityDescription = 'TODO';
} }
newDatasource.generated = index > 0 ? true : false; newDatasource.generated = index > 0 ? true : false;
return newDatasource; return newDatasource;
@ -1296,7 +1289,6 @@ export class WidgetSubscription implements IWidgetSubscription {
const startIndex = configuredDatasource.dataKeyStartIndex; const startIndex = configuredDatasource.dataKeyStartIndex;
const dataKeysCount = configuredDatasource.dataKeys.length; const dataKeysCount = configuredDatasource.dataKeys.length;
const index = startIndex + dataIndex*dataKeysCount + dataKeyIndex; const index = startIndex + dataIndex*dataKeysCount + dataKeyIndex;
this.notifyDataLoaded();
let update = true; let update = true;
let currentData: DataSetHolder; let currentData: DataSetHolder;
if (this.displayLegend && this.legendData.keys[index].dataKey.hidden) { if (this.displayLegend && this.legendData.keys[index].dataKey.hidden) {

21
ui-ngx/src/app/core/http/entity.service.ts

@ -54,7 +54,7 @@ import { AttributeService } from '@core/http/attribute.service';
import { import {
createDefaultEntityDataPageLink, createDefaultEntityDataPageLink,
EntityData, EntityData,
EntityDataQuery, EntityDataQuery, entityDataToEntityInfo,
EntityFilter, EntityFilter,
EntityKeyType EntityKeyType
} from '@shared/models/query/query.models'; } from '@shared/models/query/query.models';
@ -365,23 +365,6 @@ export class EntityService {
return this.http.post<PageData<EntityData>>('/api/entitiesQuery/find', query, defaultHttpOptionsFromConfig(config)); return this.http.post<PageData<EntityData>>('/api/entitiesQuery/find', query, defaultHttpOptionsFromConfig(config));
} }
private entityDataToEntityInfo(entityData: EntityData): EntityInfo {
const entityInfo: EntityInfo = {
id: entityData.entityId.id,
entityType: entityData.entityId.entityType as EntityType
};
if (entityData.latest && entityData.latest[EntityKeyType.ENTITY_FIELD]) {
const fields = entityData.latest[EntityKeyType.ENTITY_FIELD];
if (fields.name) {
entityInfo.name = fields.name.value;
}
if (fields.label) {
entityInfo.label = fields.label.value;
}
}
return entityInfo;
}
public findSingleEntityInfoByEntityFilter(filter: EntityFilter, config?: RequestConfig): Observable<EntityInfo> { public findSingleEntityInfoByEntityFilter(filter: EntityFilter, config?: RequestConfig): Observable<EntityInfo> {
const query: EntityDataQuery = { const query: EntityDataQuery = {
entityFilter: filter, entityFilter: filter,
@ -401,7 +384,7 @@ export class EntityService {
map((data) => { map((data) => {
if (data.data.length) { if (data.data.length) {
const entityData = data.data[0]; const entityData = data.data[0];
return this.entityDataToEntityInfo(entityData); return entityDataToEntityInfo(entityData);
} else { } else {
return null; return null;
} }

15
ui-ngx/src/app/modules/home/components/widget/widget.component.ts

@ -138,6 +138,8 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI
subscriptionInited = false; subscriptionInited = false;
destroyed = false; destroyed = false;
widgetSizeDetected = false; widgetSizeDetected = false;
widgetInstanceInited = false;
dataUpdatePending = false;
cafs: {[cafId: string]: CancelAnimationFrame} = {}; cafs: {[cafId: string]: CancelAnimationFrame} = {};
@ -363,6 +365,7 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI
subscription.destroy(); subscription.destroy();
} }
this.subscriptionInited = false; this.subscriptionInited = false;
this.dataUpdatePending = false;
this.widgetContext.subscriptions = {}; this.widgetContext.subscriptions = {};
if (this.widgetContext.inited) { if (this.widgetContext.inited) {
this.widgetContext.inited = false; this.widgetContext.inited = false;
@ -375,6 +378,7 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI
try { try {
if (shouldDestroyWidgetInstance) { if (shouldDestroyWidgetInstance) {
this.widgetTypeInstance.onDestroy(); this.widgetTypeInstance.onDestroy();
this.widgetInstanceInited = false;
} }
} catch (e) { } catch (e) {
this.handleWidgetException(e); this.handleWidgetException(e);
@ -479,6 +483,11 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI
try { try {
if (this.displayWidgetInstance()) { if (this.displayWidgetInstance()) {
this.widgetTypeInstance.onInit(); this.widgetTypeInstance.onInit();
this.widgetInstanceInited = true;
if (this.dataUpdatePending) {
this.widgetTypeInstance.onDataUpdated();
this.dataUpdatePending = false;
}
} else { } else {
this.loadingData = false; this.loadingData = false;
} }
@ -798,7 +807,11 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI
onDataUpdated: () => { onDataUpdated: () => {
try { try {
if (this.displayWidgetInstance()) { if (this.displayWidgetInstance()) {
this.widgetTypeInstance.onDataUpdated(); if (this.widgetInstanceInited) {
this.widgetTypeInstance.onDataUpdated();
} else {
this.dataUpdatePending = true;
}
} }
} catch (e){} } catch (e){}
}, },

39
ui-ngx/src/app/shared/models/query/query.models.ts

@ -17,6 +17,9 @@
import { AliasFilterType, EntityFilters } from '@shared/models/alias.models'; import { AliasFilterType, EntityFilters } from '@shared/models/alias.models';
import { EntityId } from '@shared/models/id/entity-id'; import { EntityId } from '@shared/models/id/entity-id';
import { SortDirection } from '@angular/material/sort'; import { SortDirection } from '@angular/material/sort';
import { DataKeyType } from '@shared/models/telemetry/telemetry.models';
import { EntityInfo } from '@shared/models/entity.models';
import { EntityType } from '@shared/models/entity-type.models';
export enum EntityKeyType { export enum EntityKeyType {
ATTRIBUTE = 'ATTRIBUTE', ATTRIBUTE = 'ATTRIBUTE',
@ -27,6 +30,20 @@ export enum EntityKeyType {
ENTITY_FIELD = 'ENTITY_FIELD' ENTITY_FIELD = 'ENTITY_FIELD'
} }
export function entityKeyTypeToDataKeyType(entityKeyType: EntityKeyType): DataKeyType {
switch (entityKeyType) {
case EntityKeyType.ATTRIBUTE:
case EntityKeyType.CLIENT_ATTRIBUTE:
case EntityKeyType.SHARED_ATTRIBUTE:
case EntityKeyType.SERVER_ATTRIBUTE:
return DataKeyType.attribute
case EntityKeyType.TIME_SERIES:
return DataKeyType.timeseries;
case EntityKeyType.ENTITY_FIELD:
return DataKeyType.entityField;
}
}
export interface EntityKey { export interface EntityKey {
type: EntityKeyType; type: EntityKeyType;
key: string; key: string;
@ -168,3 +185,25 @@ export interface EntityData {
latest: {[entityKeyType: string]: {[key: string]: TsValue}}; latest: {[entityKeyType: string]: {[key: string]: TsValue}};
timeseries: {[key: string]: Array<TsValue>}; timeseries: {[key: string]: Array<TsValue>};
} }
export function entityDataToEntityInfo(entityData: EntityData): EntityInfo {
const entityInfo: EntityInfo = {
id: entityData.entityId.id,
entityType: entityData.entityId.entityType as EntityType
};
if (entityData.latest && entityData.latest[EntityKeyType.ENTITY_FIELD]) {
const fields = entityData.latest[EntityKeyType.ENTITY_FIELD];
if (fields.name) {
entityInfo.name = fields.name.value;
} else {
entityInfo.name = '';
}
if (fields.label) {
entityInfo.label = fields.label.value;
} else {
entityInfo.label = '';
}
entityInfo.entityDescription = 'TODO: Not implemented';
}
return entityInfo;
}

Loading…
Cancel
Save