Merge pull request #7926 from engix-ltd/exclude_subtype
Exclude specified subtypes from autocomplete widget.
This commit is contained in:
commit
e7169d8419
@ -342,12 +342,9 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit
|
|||||||
map((data) => {
|
map((data) => {
|
||||||
if (data) {
|
if (data) {
|
||||||
if (this.excludeEntityIds && this.excludeEntityIds.length) {
|
if (this.excludeEntityIds && this.excludeEntityIds.length) {
|
||||||
|
const excludeEntityIdsSet = new Set(this.excludeEntityIds);
|
||||||
const entities: Array<BaseData<EntityId>> = [];
|
const entities: Array<BaseData<EntityId>> = [];
|
||||||
data.forEach((entity) => {
|
data.forEach(entity => !excludeEntityIdsSet.has(entity.id.id) && entities.push(entity));
|
||||||
if (this.excludeEntityIds.indexOf(entity.id.id) === -1) {
|
|
||||||
entities.push(entity);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return entities;
|
return entities;
|
||||||
} else {
|
} else {
|
||||||
return data;
|
return data;
|
||||||
|
|||||||
@ -15,7 +15,7 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
|
|
||||||
-->
|
-->
|
||||||
<mat-form-field [formGroup]="subTypeFormGroup" class="mat-block">
|
<mat-form-field [formGroup]="subTypeFormGroup" class="mat-block" [appearance]="appearance">
|
||||||
<mat-label>{{ entitySubtypeText | translate }}</mat-label>
|
<mat-label>{{ entitySubtypeText | translate }}</mat-label>
|
||||||
<input matInput type="text" placeholder="{{ selectEntitySubtypeText | translate }}"
|
<input matInput type="text" placeholder="{{ selectEntitySubtypeText | translate }}"
|
||||||
#subTypeInput
|
#subTypeInput
|
||||||
|
|||||||
@ -37,6 +37,7 @@ import { coerceBooleanProperty } from '@angular/cdk/coercion';
|
|||||||
import { AssetService } from '@core/http/asset.service';
|
import { AssetService } from '@core/http/asset.service';
|
||||||
import { EntityViewService } from '@core/http/entity-view.service';
|
import { EntityViewService } from '@core/http/entity-view.service';
|
||||||
import { EdgeService } from '@core/http/edge.service';
|
import { EdgeService } from '@core/http/edge.service';
|
||||||
|
import { MatFormFieldAppearance } from '@angular/material/form-field/form-field';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'tb-entity-subtype-autocomplete',
|
selector: 'tb-entity-subtype-autocomplete',
|
||||||
@ -71,6 +72,12 @@ export class EntitySubTypeAutocompleteComponent implements ControlValueAccessor,
|
|||||||
@Input()
|
@Input()
|
||||||
disabled: boolean;
|
disabled: boolean;
|
||||||
|
|
||||||
|
@Input()
|
||||||
|
excludeSubTypes: Array<string>;
|
||||||
|
|
||||||
|
@Input()
|
||||||
|
appearance: MatFormFieldAppearance = 'legacy';
|
||||||
|
|
||||||
@ViewChild('subTypeInput', {static: true}) subTypeInput: ElementRef;
|
@ViewChild('subTypeInput', {static: true}) subTypeInput: ElementRef;
|
||||||
|
|
||||||
selectEntitySubtypeText: string;
|
selectEntitySubtypeText: string;
|
||||||
@ -238,9 +245,14 @@ export class EntitySubTypeAutocompleteComponent implements ControlValueAccessor,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (subTypesObservable) {
|
if (subTypesObservable) {
|
||||||
|
const excludeSubTypesSet = new Set(this.excludeSubTypes);
|
||||||
this.subTypes = subTypesObservable.pipe(
|
this.subTypes = subTypesObservable.pipe(
|
||||||
catchError(() => of([] as Array<EntitySubtype>)),
|
catchError(() => of([] as Array<EntitySubtype>)),
|
||||||
map(subTypes => subTypes.map(subType => subType.type)),
|
map(subTypes => {
|
||||||
|
const filteredSubTypes: Array<string> = [];
|
||||||
|
subTypes.forEach(subType => !excludeSubTypesSet.has(subType.type) && filteredSubTypes.push(subType.type));
|
||||||
|
return filteredSubTypes;
|
||||||
|
}),
|
||||||
publishReplay(1),
|
publishReplay(1),
|
||||||
refCount()
|
refCount()
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user