Commit cf2da5c9b1302cd98f9a60949228381f0c166a89

Authored by Artem Babak
1 parent 91c4affb

Fixed filter edge by type. Added edge to entity-filer/subtype

... ... @@ -14,11 +14,11 @@
14 14 /// limitations under the License.
15 15 ///
16 16
17   -import { Component, forwardRef } from '@angular/core';
18   -import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
19   -import { AliasFilterType, EntityAliasFilter } from '@shared/models/alias.models';
20   -import { AliasEntityType, EntityType, entityTypeTranslations } from '@shared/models/entity-type.models';
21   -import { TranslateService } from '@ngx-translate/core';
  17 +import {Component, forwardRef} from '@angular/core';
  18 +import {ControlValueAccessor, NG_VALUE_ACCESSOR} from '@angular/forms';
  19 +import {AliasFilterType, EntityAliasFilter} from '@shared/models/alias.models';
  20 +import {AliasEntityType, EntityType, entityTypeTranslations} from '@shared/models/entity-type.models';
  21 +import {TranslateService} from '@ngx-translate/core';
22 22
23 23 @Component({
24 24 selector: 'tb-entity-filter-view',
... ... @@ -101,6 +101,17 @@ export class EntityFilterViewComponent implements ControlValueAccessor {
101 101 {deviceType});
102 102 }
103 103 break;
  104 + case AliasFilterType.edgeType:
  105 + const edgeType = this.filter.edgeType;
  106 + prefix = this.filter.edgeNameFilter;
  107 + if (prefix && prefix.length) {
  108 + this.filterDisplayValue = this.translate.instant('alias.filter-type-edge-type-and-name-description',
  109 + {edgeType, prefix});
  110 + } else {
  111 + this.filterDisplayValue = this.translate.instant('alias.filter-type-edge-type-description',
  112 + {edgeType});
  113 + }
  114 + break;
104 115 case AliasFilterType.entityViewType:
105 116 const entityView = this.filter.entityViewType;
106 117 prefix = this.filter.entityViewNameFilter;
... ... @@ -166,6 +177,7 @@ export class EntityFilterViewComponent implements ControlValueAccessor {
166 177 break;
167 178 case AliasFilterType.assetSearchQuery:
168 179 case AliasFilterType.deviceSearchQuery:
  180 + case AliasFilterType.edgeSearchQuery:
169 181 case AliasFilterType.entityViewSearchQuery:
170 182 allEntitiesText = this.translate.instant('alias.all-entities');
171 183 anyRelationText = this.translate.instant('alias.any-relation');
... ... @@ -207,6 +219,16 @@ export class EntityFilterViewComponent implements ControlValueAccessor {
207 219 this.filterDisplayValue = this.translate.instant('alias.filter-type-device-search-query-description',
208 220 translationValues
209 221 );
  222 + } else if (this.filter.type === AliasFilterType.edgeSearchQuery) {
  223 + const edgeTypesQuoted = [];
  224 + this.filter.edgeTypes.forEach((filterEdgeType) => {
  225 + edgeTypesQuoted.push(`'${filterEdgeType}'`);
  226 + });
  227 + const edgeTypesText = edgeTypesQuoted.join(', ');
  228 + translationValues.edgeTypes = edgeTypesText;
  229 + this.filterDisplayValue = this.translate.instant('alias.filter-type-edge-search-query-description',
  230 + translationValues
  231 + );
210 232 } else if (this.filter.type === AliasFilterType.entityViewSearchQuery) {
211 233 const entityViewTypesQuoted = [];
212 234 this.filter.entityViewTypes.forEach((filterEntityViewType) => {
... ...
... ... @@ -103,6 +103,16 @@
103 103 <input matInput formControlName="entityViewNameFilter">
104 104 </mat-form-field>
105 105 </ng-template>
  106 + <ng-template [ngSwitchCase]="aliasFilterType.edgeType">
  107 + <tb-entity-subtype-autocomplete required
  108 + formControlName="edgeType"
  109 + [entityType]="entityType.EDGE">
  110 + </tb-entity-subtype-autocomplete>
  111 + <mat-form-field class="mat-block">
  112 + <mat-label translate>edge.name-starts-with</mat-label>
  113 + <input matInput formControlName="edgeNameFilter">
  114 + </mat-form-field>
  115 + </ng-template>
106 116 <ng-template [ngSwitchCase]="aliasFilterType.relationsQuery">
107 117 <section fxLayout="column" id="relationsQueryFilter">
108 118 <label class="tb-small">{{ 'alias.root-entity' | translate }}</label>
... ... @@ -169,6 +179,7 @@
169 179 </ng-template>
170 180 <ng-template [ngSwitchCase]="entityFilterFormGroup.get('type').value === aliasFilterType.assetSearchQuery ||
171 181 entityFilterFormGroup.get('type').value === aliasFilterType.deviceSearchQuery ||
  182 + entityFilterFormGroup.get('type').value === aliasFilterType.edgeSearchQuery ||
172 183 entityFilterFormGroup.get('type').value === aliasFilterType.entityViewSearchQuery ?
173 184 entityFilterFormGroup.get('type').value : ''">
174 185 <label class="tb-small">{{ 'alias.root-entity' | translate }}</label>
... ... @@ -248,6 +259,14 @@
248 259 formControlName="deviceTypes">
249 260 </tb-entity-subtype-list>
250 261 </ng-template>
  262 + <ng-template [ngSwitchCase]="aliasFilterType.edgeSearchQuery">
  263 + <div class="mat-caption tb-required" style="color: rgba(0,0,0,0.57);" translate>edge.edge-types</div>
  264 + <tb-entity-subtype-list
  265 + required
  266 + [entityType]="entityType.EDGE"
  267 + formControlName="edgeTypes">
  268 + </tb-entity-subtype-list>
  269 + </ng-template>
251 270 <ng-template [ngSwitchCase]="aliasFilterType.entityViewSearchQuery">
252 271 <div class="mat-caption tb-required" style="color: rgba(0,0,0,0.57);" translate>entity-view.entity-view-types</div>
253 272 <tb-entity-subtype-list
... ...
... ... @@ -141,6 +141,12 @@ export class EntityFilterComponent implements ControlValueAccessor, OnInit {
141 141 deviceNameFilter: [filter ? filter.deviceNameFilter : '', []],
142 142 });
143 143 break;
  144 + case AliasFilterType.edgeType:
  145 + this.filterFormGroup = this.fb.group({
  146 + edgeType: [filter ? filter.edgeType : null, [Validators.required]],
  147 + edgeNameFilter: [filter ? filter.edgeNameFilter : '', []],
  148 + });
  149 + break;
144 150 case AliasFilterType.entityViewType:
145 151 this.filterFormGroup = this.fb.group({
146 152 entityViewType: [filter ? filter.entityViewType : null, [Validators.required]],
... ... @@ -150,6 +156,7 @@ export class EntityFilterComponent implements ControlValueAccessor, OnInit {
150 156 case AliasFilterType.relationsQuery:
151 157 case AliasFilterType.assetSearchQuery:
152 158 case AliasFilterType.deviceSearchQuery:
  159 + case AliasFilterType.edgeSearchQuery:
153 160 case AliasFilterType.entityViewSearchQuery:
154 161 this.filterFormGroup = this.fb.group({
155 162 rootStateEntity: [filter ? filter.rootStateEntity : false, []],
... ... @@ -176,6 +183,9 @@ export class EntityFilterComponent implements ControlValueAccessor, OnInit {
176 183 } else if (type === AliasFilterType.deviceSearchQuery) {
177 184 this.filterFormGroup.addControl('deviceTypes',
178 185 this.fb.control(filter ? filter.deviceTypes : [], [Validators.required]));
  186 + } else if (type === AliasFilterType.edgeSearchQuery) {
  187 + this.filterFormGroup.addControl('edgeTypes',
  188 + this.fb.control(filter ? filter.edgeTypes : [], [Validators.required]));
179 189 } else if (type === AliasFilterType.entityViewSearchQuery) {
180 190 this.filterFormGroup.addControl('entityViewTypes',
181 191 this.fb.control(filter ? filter.entityViewTypes : [], [Validators.required]));
... ...
... ... @@ -103,7 +103,8 @@ export class EdgesTableConfigResolver implements Resolve<EntityTableConfig<EdgeI
103 103 resolve(route: ActivatedRouteSnapshot): Observable<EntityTableConfig<EdgeInfo>> {
104 104 const routeParams = route.params;
105 105 this.config.componentsData = {
106   - edgeScope: route.data.edgesType
  106 + edgeScope: route.data.edgesType,
  107 + edgeType: ''
107 108 };
108 109 this.customerId = routeParams.customerId;
109 110 return this.store.pipe(select(selectAuthUser), take(1)).pipe(
... ... @@ -161,7 +162,7 @@ export class EdgesTableConfigResolver implements Resolve<EntityTableConfig<EdgeI
161 162 configureEntityFunctions(edgeScope: string): void {
162 163 if (edgeScope === 'tenant') {
163 164 this.config.entitiesFetchFunction = pageLink =>
164   - this.edgeService.getTenantEdgeInfos(pageLink);
  165 + this.edgeService.getTenantEdgeInfos(pageLink, this.config.componentsData.edgeType);
165 166 this.config.deleteEntity = id => this.edgeService.deleteEdge(id.id);
166 167 }
167 168 if (edgeScope === 'customer') {
... ...
... ... @@ -143,9 +143,10 @@ export class EntitySubTypeListComponent implements ControlValueAccessor, OnInit,
143 143 break;
144 144 case EntityType.EDGE:
145 145 this.placeholder = this.required ? this.translate.instant('edge.enter-edge-type')
146   - : this.translate.instant('edge.edge-any-edge');
  146 + : this.translate.instant('edge.any-edge');
147 147 this.secondaryPlaceholder = '+' + this.translate.instant('edge.edge-type');
148 148 this.noSubtypesMathingText = 'edge.no-edge-types-matching';
  149 + this.subtypeListEmptyText = 'edge.edge-type-list-empty';
149 150 this.broadcastSubscription = this.broadcast.on('edgeSaved', () => {
150 151 this.entitySubtypes = null;
151 152 });
... ...
... ... @@ -33,3 +33,4 @@ export * from './tenant-profile-id';
33 33 export * from './user-id';
34 34 export * from './widget-type-id';
35 35 export * from './widgets-bundle-id';
  36 +export * from './edge-id';
... ...
... ... @@ -213,6 +213,7 @@
213 213 "filter-type-entity-view-type-and-name-description": "Entity Views of type '{{entityView}}' and with name starting with '{{prefix}}'",
214 214 "filter-type-edge-type": "Edge type",
215 215 "filter-type-edge-type-description": "Edges of type '{{edgeType}}'",
  216 + "filter-type-edge-type-and-name-description": "Edges of type '{{edgeType}}' and with name starting with '{{prefix}}'",
216 217 "filter-type-relations-query": "Relations query",
217 218 "filter-type-relations-query-description": "{{entities}} that have {{relationType}} relation {{direction}} {{rootEntity}}",
218 219 "filter-type-asset-search-query": "Asset search query",
... ... @@ -1002,7 +1003,9 @@
1002 1003 "selected-edges": "{ count, plural, 1 {1 edge} other {# edges} } selected",
1003 1004 "enter-edge-type": "Enter entity view type",
1004 1005 "any-edge": "Any edge",
1005   - "no-edge-types-matching": "No edge types matching '{{entitySubtype}}' were found."
  1006 + "no-edge-types-matching": "No edge types matching '{{entitySubtype}}' were found.",
  1007 + "edge-type-list-empty": "No device types selected.",
  1008 + "edge-types": "Edge types"
1006 1009 },
1007 1010 "error": {
1008 1011 "unable-to-connect": "Unable to connect to the server! Please check your internet connection.",
... ...