Add Entity Type alias. Fix Key filter value conditional processing.
This commit is contained in:
parent
2b7111516c
commit
99c9c099ba
@ -155,7 +155,7 @@ export class EntityDataSubscription {
|
||||
clearTimeout(this.timer);
|
||||
this.timer = null;
|
||||
}
|
||||
if (this.datasourceType === DatasourceType.entity) {
|
||||
if (this.datasourceType === DatasourceType.entity || this.datasourceType === DatasourceType.entityCount) {
|
||||
if (this.subscriber) {
|
||||
this.subscriber.unsubscribe();
|
||||
this.subscriber = null;
|
||||
@ -318,24 +318,30 @@ export class EntityDataSubscription {
|
||||
entityType: null
|
||||
};
|
||||
|
||||
const entityData: EntityData = {
|
||||
entityId,
|
||||
timeseries: {},
|
||||
latest: {}
|
||||
};
|
||||
entityData.latest[EntityKeyType.ENTITY_FIELD] = {
|
||||
name: {ts: Date.now(), value: DatasourceType.entityCount},
|
||||
};
|
||||
|
||||
const countKey = this.entityDataSubscriptionOptions.dataKeys[0];
|
||||
|
||||
let dataReceived = false;
|
||||
|
||||
this.subscriber.entityCount$.subscribe(
|
||||
(entityCountUpdate) => {
|
||||
if (!entityData.latest[EntityKeyType.COUNT]) {
|
||||
entityData.latest[EntityKeyType.COUNT] = {};
|
||||
entityData.latest[EntityKeyType.COUNT][countKey.name] = {
|
||||
if (!dataReceived) {
|
||||
const entityData: EntityData = {
|
||||
entityId,
|
||||
latest: {
|
||||
[EntityKeyType.ENTITY_FIELD]: {
|
||||
name: {
|
||||
ts: Date.now(),
|
||||
value: DatasourceType.entityCount
|
||||
}
|
||||
},
|
||||
[EntityKeyType.COUNT]: {
|
||||
[countKey.name]: {
|
||||
ts: Date.now(),
|
||||
value: entityCountUpdate.count + ''
|
||||
}
|
||||
}
|
||||
},
|
||||
timeseries: {}
|
||||
};
|
||||
const pageData: PageData<EntityData> = {
|
||||
data: [entityData],
|
||||
@ -344,12 +350,20 @@ export class EntityDataSubscription {
|
||||
totalPages: 1
|
||||
};
|
||||
this.onPageData(pageData);
|
||||
dataReceived = true;
|
||||
} else {
|
||||
const update = [deepClone(entityData)];
|
||||
update[0].latest[EntityKeyType.COUNT][countKey.name] = {
|
||||
const update: EntityData[] = [{
|
||||
entityId,
|
||||
latest: {
|
||||
[EntityKeyType.COUNT]: {
|
||||
[countKey.name]: {
|
||||
ts: Date.now(),
|
||||
value: entityCountUpdate.count + ''
|
||||
};
|
||||
}
|
||||
}
|
||||
},
|
||||
timeseries: {}
|
||||
}];
|
||||
this.onDataUpdate(update);
|
||||
}
|
||||
}
|
||||
|
||||
@ -481,6 +481,8 @@ export class EntityService {
|
||||
return entityTypes.indexOf(filter.entityType) > -1 ? true : false;
|
||||
case AliasFilterType.entityName:
|
||||
return entityTypes.indexOf(filter.entityType) > -1 ? true : false;
|
||||
case AliasFilterType.entityType:
|
||||
return entityTypes.indexOf(filter.entityType) > -1 ? true : false;
|
||||
case AliasFilterType.stateEntity:
|
||||
return true;
|
||||
case AliasFilterType.assetType:
|
||||
@ -540,6 +542,8 @@ export class EntityService {
|
||||
return true;
|
||||
case AliasFilterType.entityName:
|
||||
return true;
|
||||
case AliasFilterType.entityType:
|
||||
return true;
|
||||
case AliasFilterType.stateEntity:
|
||||
return true;
|
||||
case AliasFilterType.assetType:
|
||||
@ -805,6 +809,9 @@ export class EntityService {
|
||||
case AliasFilterType.entityName:
|
||||
result.entityFilter = deepClone(filter);
|
||||
return of(result);
|
||||
case AliasFilterType.entityType:
|
||||
result.entityFilter = deepClone(filter);
|
||||
return of(result);
|
||||
case AliasFilterType.stateEntity:
|
||||
result.stateEntity = true;
|
||||
if (stateEntityId) {
|
||||
|
||||
@ -76,6 +76,10 @@ export class EntityFilterViewComponent implements ControlValueAccessor {
|
||||
this.filterDisplayValue = this.translate.instant(entityTypeTranslations.get(entityType).nameStartsWith,
|
||||
{prefix});
|
||||
break;
|
||||
case AliasFilterType.entityType:
|
||||
entityType = this.filter.entityType;
|
||||
this.filterDisplayValue = this.translate.instant(entityTypeTranslations.get(entityType).typePlural);
|
||||
break;
|
||||
case AliasFilterType.stateEntity:
|
||||
this.filterDisplayValue = this.translate.instant('alias.filter-type-state-entity-description');
|
||||
break;
|
||||
|
||||
@ -59,6 +59,13 @@
|
||||
</mat-error>
|
||||
</mat-form-field>
|
||||
</ng-template>
|
||||
<ng-template [ngSwitchCase]="aliasFilterType.entityType">
|
||||
<tb-entity-type-select required
|
||||
showLabel
|
||||
[allowedEntityTypes]="allowedEntityTypes"
|
||||
formControlName="entityType">
|
||||
</tb-entity-type-select>
|
||||
</ng-template>
|
||||
<ng-template [ngSwitchCase]="aliasFilterType.stateEntity">
|
||||
<mat-form-field floatLabel="always" class="mat-block">
|
||||
<mat-label translate>alias.state-entity-parameter-name</mat-label>
|
||||
|
||||
@ -123,6 +123,11 @@ export class EntityFilterComponent implements ControlValueAccessor, OnInit {
|
||||
entityNameFilter: [filter ? filter.entityNameFilter : '', [Validators.required]],
|
||||
});
|
||||
break;
|
||||
case AliasFilterType.entityType:
|
||||
this.filterFormGroup = this.fb.group({
|
||||
entityType: [filter ? filter.entityType : null, [Validators.required]]
|
||||
});
|
||||
break;
|
||||
case AliasFilterType.stateEntity:
|
||||
this.filterFormGroup = this.fb.group({
|
||||
stateEntityParamName: [filter ? filter.stateEntityParamName : null, []],
|
||||
|
||||
@ -107,12 +107,15 @@ export class KeyFilterDialogComponent extends
|
||||
key: [this.data.keyFilter.key.key, [Validators.required]]
|
||||
}
|
||||
),
|
||||
value: [this.data.keyFilter.value],
|
||||
valueType: [this.data.keyFilter.valueType, [Validators.required]],
|
||||
predicates: [this.data.keyFilter.predicates, [Validators.required]]
|
||||
}
|
||||
);
|
||||
|
||||
if (this.data.telemetryKeysOnly) {
|
||||
this.keyFilterFormGroup.addControl(
|
||||
'value', this.fb.control(this.data.keyFilter.value)
|
||||
);
|
||||
}
|
||||
if (!this.data.readonly) {
|
||||
this.keyFilterFormGroup.get('valueType').valueChanges.pipe(
|
||||
takeUntil(this.destroy$)
|
||||
@ -144,6 +147,7 @@ export class KeyFilterDialogComponent extends
|
||||
} else {
|
||||
this.showAutocomplete = false;
|
||||
}
|
||||
if (this.data.telemetryKeysOnly) {
|
||||
if (type === EntityKeyType.CONSTANT) {
|
||||
this.keyFilterFormGroup.get('value').setValidators(Validators.required);
|
||||
this.keyFilterFormGroup.get('value').updateValueAndValidity();
|
||||
@ -151,6 +155,7 @@ export class KeyFilterDialogComponent extends
|
||||
this.keyFilterFormGroup.get('value').clearValidators();
|
||||
this.keyFilterFormGroup.get('value').updateValueAndValidity();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
this.keyFilterFormGroup.get('key.key').valueChanges.pipe(
|
||||
|
||||
@ -24,7 +24,7 @@ import {
|
||||
NG_VALUE_ACCESSOR
|
||||
} from '@angular/forms';
|
||||
import { AliasEntityType, EntityType } from '@shared/models/entity-type.models';
|
||||
import { EntityTypeFilter } from '@shared/models/relation.models';
|
||||
import { RelationEntityTypeFilter } from '@shared/models/relation.models';
|
||||
import { PageComponent } from '@shared/components/page.component';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { AppState } from '@core/core.state';
|
||||
@ -80,7 +80,7 @@ export class RelationFiltersComponent extends PageComponent implements ControlVa
|
||||
this.disabled = isDisabled;
|
||||
}
|
||||
|
||||
writeValue(filters: Array<EntityTypeFilter>): void {
|
||||
writeValue(filters: Array<RelationEntityTypeFilter>): void {
|
||||
if (this.valueChangeSubscription) {
|
||||
this.valueChangeSubscription.unsubscribe();
|
||||
}
|
||||
@ -102,14 +102,14 @@ export class RelationFiltersComponent extends PageComponent implements ControlVa
|
||||
|
||||
public addFilter() {
|
||||
const relationFiltersFormArray = this.relationFiltersFormGroup.get('relationFilters') as FormArray;
|
||||
const filter: EntityTypeFilter = {
|
||||
const filter: RelationEntityTypeFilter = {
|
||||
relationType: null,
|
||||
entityTypes: []
|
||||
};
|
||||
relationFiltersFormArray.push(this.createRelationFilterFormGroup(filter));
|
||||
}
|
||||
|
||||
private createRelationFilterFormGroup(filter: EntityTypeFilter): AbstractControl {
|
||||
private createRelationFilterFormGroup(filter: RelationEntityTypeFilter): AbstractControl {
|
||||
return this.fb.group({
|
||||
relationType: [filter ? filter.relationType : null],
|
||||
entityTypes: [filter ? filter.entityTypes : []]
|
||||
@ -117,7 +117,7 @@ export class RelationFiltersComponent extends PageComponent implements ControlVa
|
||||
}
|
||||
|
||||
private updateModel() {
|
||||
const filters: Array<EntityTypeFilter> = this.relationFiltersFormGroup.get('relationFilters').value;
|
||||
const filters: Array<RelationEntityTypeFilter> = this.relationFiltersFormGroup.get('relationFilters').value;
|
||||
this.propagateChange(filters);
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,14 +16,14 @@
|
||||
|
||||
import { EntityType } from '@shared/models/entity-type.models';
|
||||
import { EntityId } from '@shared/models/id/entity-id';
|
||||
import { EntitySearchDirection, EntityTypeFilter } from '@shared/models/relation.models';
|
||||
import { EntityInfo } from './entity.models';
|
||||
import { EntitySearchDirection, RelationEntityTypeFilter } from '@shared/models/relation.models';
|
||||
import { EntityFilter } from '@shared/models/query/query.models';
|
||||
|
||||
export enum AliasFilterType {
|
||||
singleEntity = 'singleEntity',
|
||||
entityList = 'entityList',
|
||||
entityName = 'entityName',
|
||||
entityType = 'entityType',
|
||||
stateEntity = 'stateEntity',
|
||||
assetType = 'assetType',
|
||||
deviceType = 'deviceType',
|
||||
@ -40,6 +40,7 @@ export const aliasFilterTypeTranslationMap = new Map<AliasFilterType, string>(
|
||||
[ AliasFilterType.singleEntity, 'alias.filter-type-single-entity' ],
|
||||
[ AliasFilterType.entityList, 'alias.filter-type-entity-list' ],
|
||||
[ AliasFilterType.entityName, 'alias.filter-type-entity-name' ],
|
||||
[ AliasFilterType.entityType, 'alias.filter-type-entity-type' ],
|
||||
[ AliasFilterType.stateEntity, 'alias.filter-type-state-entity' ],
|
||||
[ AliasFilterType.assetType, 'alias.filter-type-asset-type' ],
|
||||
[ AliasFilterType.deviceType, 'alias.filter-type-device-type' ],
|
||||
@ -66,6 +67,10 @@ export interface EntityNameFilter {
|
||||
entityNameFilter?: string;
|
||||
}
|
||||
|
||||
export interface EntityTypeFilter {
|
||||
entityType?: EntityType;
|
||||
}
|
||||
|
||||
export interface StateEntityFilter {
|
||||
stateEntityParamName?: string;
|
||||
defaultStateEntity?: EntityId;
|
||||
@ -92,7 +97,7 @@ export interface RelationsQueryFilter {
|
||||
defaultStateEntity?: EntityId;
|
||||
rootEntity?: EntityId;
|
||||
direction?: EntitySearchDirection;
|
||||
filters?: Array<EntityTypeFilter>;
|
||||
filters?: Array<RelationEntityTypeFilter>;
|
||||
maxLevel?: number;
|
||||
fetchLastLevelOnly?: boolean;
|
||||
}
|
||||
@ -129,6 +134,7 @@ export type EntityFilters =
|
||||
SingleEntityFilter &
|
||||
EntityListFilter &
|
||||
EntityNameFilter &
|
||||
EntityTypeFilter &
|
||||
StateEntityFilter &
|
||||
AssetTypeFilter &
|
||||
DeviceTypeFilter &
|
||||
|
||||
@ -351,14 +351,14 @@ export interface KeyFilterPredicateInfo {
|
||||
export interface KeyFilter {
|
||||
key: EntityKey;
|
||||
valueType: EntityKeyValueType;
|
||||
value: string | number | boolean;
|
||||
value?: string | number | boolean;
|
||||
predicate: KeyFilterPredicate;
|
||||
}
|
||||
|
||||
export interface KeyFilterInfo {
|
||||
key: EntityKey;
|
||||
valueType: EntityKeyValueType;
|
||||
value: string | number | boolean;
|
||||
value?: string | number | boolean;
|
||||
predicates: Array<KeyFilterPredicateInfo>;
|
||||
}
|
||||
|
||||
|
||||
@ -52,7 +52,7 @@ export const directionTypeTranslations = new Map<EntitySearchDirection, string>(
|
||||
]
|
||||
);
|
||||
|
||||
export interface EntityTypeFilter {
|
||||
export interface RelationEntityTypeFilter {
|
||||
relationType: string;
|
||||
entityTypes: Array<EntityType>;
|
||||
}
|
||||
@ -68,7 +68,7 @@ export interface RelationsSearchParameters {
|
||||
|
||||
export interface EntityRelationsQuery {
|
||||
parameters: RelationsSearchParameters;
|
||||
filters: Array<EntityTypeFilter>;
|
||||
filters: Array<RelationEntityTypeFilter>;
|
||||
}
|
||||
|
||||
export interface EntitySearchQuery {
|
||||
|
||||
@ -299,6 +299,7 @@
|
||||
"filter-type-single-entity": "Single entity",
|
||||
"filter-type-entity-list": "Entity list",
|
||||
"filter-type-entity-name": "Entity name",
|
||||
"filter-type-entity-type": "Entity type",
|
||||
"filter-type-state-entity": "Entity from dashboard state",
|
||||
"filter-type-state-entity-description": "Entity taken from dashboard state parameters",
|
||||
"filter-type-asset-type": "Asset type",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user