diff --git a/ui-ngx/src/app/core/http/alarm.service.ts b/ui-ngx/src/app/core/http/alarm.service.ts index 54e21d9af9..dc68a092b3 100644 --- a/ui-ngx/src/app/core/http/alarm.service.ts +++ b/ui-ngx/src/app/core/http/alarm.service.ts @@ -28,8 +28,8 @@ import { AlarmSeverity, AlarmStatus } from '@shared/models/alarm.models'; -import { UtilsService } from '@core/services/utils.service'; import { EntitySubtype } from '@shared/models/entity-type.models'; +import { PageLink } from '@shared/models/page/page-link'; @Injectable({ providedIn: 'root' @@ -37,8 +37,7 @@ import { EntitySubtype } from '@shared/models/entity-type.models'; export class AlarmService { constructor( - private http: HttpClient, - private utils: UtilsService + private http: HttpClient ) { } public getAlarm(alarmId: string, config?: RequestConfig): Observable { @@ -109,8 +108,8 @@ export class AlarmService { defaultHttpOptionsFromConfig(config)); } - public getAlarmTypes(config?: RequestConfig): Observable> { - return this.http.get>('/api/alarm/types', defaultHttpOptionsFromConfig(config)); + public getAlarmTypes(pageLink: PageLink, config?: RequestConfig): Observable> { + return this.http.get>(`/api/alarm/types${pageLink.toQuery()}`, defaultHttpOptionsFromConfig(config)); } } diff --git a/ui-ngx/src/app/modules/home/components/alarm/alarm-filter-config.component.html b/ui-ngx/src/app/modules/home/components/alarm/alarm-filter-config.component.html index dd97db6b87..3a1be706ed 100644 --- a/ui-ngx/src/app/modules/home/components/alarm/alarm-filter-config.component.html +++ b/ui-ngx/src/app/modules/home/components/alarm/alarm-filter-config.component.html @@ -72,10 +72,13 @@ -
+
alarm.alarm-type-list
- +
diff --git a/ui-ngx/src/app/modules/home/components/alarm/alarm-filter-config.component.scss b/ui-ngx/src/app/modules/home/components/alarm/alarm-filter-config.component.scss index edac6ddef1..9b0c323a40 100644 --- a/ui-ngx/src/app/modules/home/components/alarm/alarm-filter-config.component.scss +++ b/ui-ngx/src/app/modules/home/components/alarm/alarm-filter-config.component.scss @@ -37,6 +37,11 @@ .tb-alarm-filter-config-component { flex: 1; + tb-entity-subtype-list { + flex: 1; + width: 180px; + } + .mat-mdc-chip { .mdc-evolution-chip__cell, .mat-mdc-chip-action, .mat-mdc-chip-action-label { overflow: hidden; diff --git a/ui-ngx/src/app/shared/components/entity/entity-subtype-list.component.ts b/ui-ngx/src/app/shared/components/entity/entity-subtype-list.component.ts index 563b7857eb..cb7cc7b63d 100644 --- a/ui-ngx/src/app/shared/components/entity/entity-subtype-list.component.ts +++ b/ui-ngx/src/app/shared/components/entity/entity-subtype-list.component.ts @@ -16,14 +16,12 @@ import { AfterViewInit, Component, ElementRef, forwardRef, Input, OnDestroy, OnInit, ViewChild } from '@angular/core'; import { ControlValueAccessor, FormBuilder, FormGroup, NG_VALUE_ACCESSOR, Validators } from '@angular/forms'; -import { Observable, Subscription, throwError } from 'rxjs'; -import { map, mergeMap, publishReplay, refCount, share } from 'rxjs/operators'; -import { Store } from '@ngrx/store'; -import { AppState } from '@app/core/core.state'; +import { Observable, ReplaySubject, Subscription, throwError } from 'rxjs'; +import { debounceTime, map, mergeMap, share } from 'rxjs/operators'; import { TranslateService } from '@ngx-translate/core'; import { EntitySubtype, EntityType } from '@shared/models/entity-type.models'; import { MatAutocomplete, MatAutocompleteSelectedEvent } from '@angular/material/autocomplete'; -import { MatChipInputEvent, MatChipGrid } from '@angular/material/chips'; +import { MatChipGrid, MatChipInputEvent } from '@angular/material/chips'; import { AssetService } from '@core/http/asset.service'; import { DeviceService } from '@core/http/device.service'; import { EdgeService } from '@core/http/edge.service'; @@ -31,9 +29,10 @@ import { EntityViewService } from '@core/http/entity-view.service'; import { BroadcastService } from '@core/services/broadcast.service'; import { COMMA, ENTER, SEMICOLON } from '@angular/cdk/keycodes'; import { AlarmService } from '@core/http/alarm.service'; -import { MatFormFieldAppearance, SubscriptSizing } from '@angular/material/form-field'; +import { FloatLabelType, MatFormFieldAppearance, SubscriptSizing } from '@angular/material/form-field'; import { coerceArray, coerceBoolean } from '@shared/decorators/coercion'; -import { FloatLabelType } from '@angular/material/form-field'; +import { PageLink } from '@shared/models/page/page-link'; +import { PageData } from '@shared/models/page/page-data'; @Component({ selector: 'tb-entity-subtype-list', @@ -102,7 +101,7 @@ export class EntitySubTypeListComponent implements ControlValueAccessor, OnInit, entitySubtypeList: Array = []; filteredEntitySubtypeList: Observable>; - entitySubtypes: Observable>; + private entitySubtypes: Observable>; private broadcastSubscription: Subscription; @@ -119,8 +118,11 @@ export class EntitySubTypeListComponent implements ControlValueAccessor, OnInit, private propagateChange = (v: any) => { }; - constructor(private store: Store, - private broadcast: BroadcastService, + private hasPageDataEntitySubTypes = new Set([ + EntityType.ALARM + ]); + + constructor(private broadcast: BroadcastService, public translate: TranslateService, private assetService: AssetService, private deviceService: DeviceService, @@ -195,9 +197,6 @@ export class EntitySubTypeListComponent implements ControlValueAccessor, OnInit, this.secondaryPlaceholder = '+' + this.translate.instant('alarm.alarm-type'); this.noSubtypesMathingText = 'alarm.no-alarm-types-matching'; this.subtypeListEmptyText = 'alarm.alarm-type-list-empty'; - this.broadcastSubscription = this.broadcast.on('alarmSaved', () => { - this.entitySubtypes = null; - }); break; } @@ -208,12 +207,12 @@ export class EntitySubTypeListComponent implements ControlValueAccessor, OnInit, this.secondaryPlaceholder = this.filledInputPlaceholder; } - this.filteredEntitySubtypeList = this.entitySubtypeListFormGroup.get('entitySubtype').valueChanges - .pipe( - map(value => value ? value : ''), - mergeMap(name => this.fetchEntitySubtypes(name) ), - share() - ); + this.filteredEntitySubtypeList = this.entitySubtypeListFormGroup.get('entitySubtype').valueChanges.pipe( + debounceTime(150), + map(value => value ? value : ''), + mergeMap(name => this.fetchEntitySubtypes(name)), + share() + ); } ngAfterViewInit(): void { @@ -289,11 +288,16 @@ export class EntitySubTypeListComponent implements ControlValueAccessor, OnInit, return entitySubtype ? entitySubtype : undefined; } - fetchEntitySubtypes(searchText?: string): Observable> { + private fetchEntitySubtypes(searchText?: string): Observable> { this.searchText = searchText; - return this.getEntitySubtypes().pipe( + return this.getEntitySubtypes(searchText).pipe( map(subTypes => { - let result = subTypes.filter( subType => searchText ? subType.toUpperCase().startsWith(searchText.toUpperCase()) : true); + let result; + if (this.hasPageDataEntitySubTypes.has(this.entityType)) { + result = subTypes; + } else { + result = subTypes.filter(subType => searchText ? subType.toUpperCase().startsWith(searchText.toUpperCase()) : true); + } if (!result.length) { result = [searchText]; } @@ -302,7 +306,23 @@ export class EntitySubTypeListComponent implements ControlValueAccessor, OnInit, ); } - getEntitySubtypes(): Observable> { + private getEntitySubtypes(searchText?: string): Observable> { + if (this.hasPageDataEntitySubTypes.has(this.entityType)) { + const pageLink = new PageLink(25, 0, searchText); + let subTypesPagesObservable: Observable>; + switch (this.entityType) { + case EntityType.ALARM: + subTypesPagesObservable = this.alarmService.getAlarmTypes(pageLink, {ignoreLoading: true}); + break; + } + if (subTypesPagesObservable) { + this.entitySubtypes = subTypesPagesObservable.pipe( + map(subTypesPage => subTypesPage.data.map(subType => subType.type)), + ); + } else { + return throwError(null); + } + } if (!this.entitySubtypes) { let subTypesObservable: Observable>; switch (this.entityType) { @@ -318,15 +338,16 @@ export class EntitySubTypeListComponent implements ControlValueAccessor, OnInit, case EntityType.ENTITY_VIEW: subTypesObservable = this.entityViewService.getEntityViewTypes({ignoreLoading: true}); break; - case EntityType.ALARM: - subTypesObservable = this.alarmService.getAlarmTypes({ignoreLoading: true}); - break; } if (subTypesObservable) { this.entitySubtypes = subTypesObservable.pipe( map(subTypes => subTypes.map(subType => subType.type)), - publishReplay(1), - refCount() + share({ + connector: () => new ReplaySubject(1), + resetOnError: false, + resetOnComplete: false, + resetOnRefCountZero: true, + }), ); } else { return throwError(null);