Merge branch 'DEVELOP' of ssh://git.eclipse.org:29418/openk-usermodules/org.eclipse.openk-usermodules.gridFailureInformation.frontend into SI-1633-Zeige-aktuelle-Adresse
diff --git a/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-details/grid-failure-details.component.ts b/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-details/grid-failure-details.component.ts
index 71c94b4..cb67509 100644
--- a/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-details/grid-failure-details.component.ts
+++ b/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-details/grid-failure-details.component.ts
@@ -157,7 +157,8 @@
};
this.gridOptions = { ...this.gridOptions };
}
- public changeMode(currentV?: string) {
+
+ public changeMode() {
this.gridFailureDetailsSandbox.gridFailureStations$.pipe(take(1), takeUntil(this._endSubscriptions$)).subscribe(() => {
this.gridFailureDetailsSandbox.oldVersion
? this.events$.next({ eventType: this._modeEnum.oldVersionMode })
diff --git a/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-list/grid-failure-list.component.html b/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-list/grid-failure-list.component.html
index 3dd27c1..c3964c6 100644
--- a/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-list/grid-failure-list.component.html
+++ b/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-list/grid-failure-list.component.html
@@ -82,7 +82,7 @@
id="filterSwitch"
[checked]="sandbox.publisherFilterIsActive"
[disabled]="sandbox.qualifierFilterIsActive"
- (change)="changeFilter($event.target.checked, RolesEnum.PUBLISHER)"
+ (change)="changeFilter($event.target.checked, Globals.STATUS_PUBLICATION_FIELD)"
/>
<label class="custom-control-label" for="filterSwitch">{{ 'GridFailures.PublisherFilterLabel' | translate }}</label>
</div>
@@ -93,7 +93,7 @@
id="qualifierFilterSwitch"
[checked]="sandbox.qualifierFilterIsActive"
[disabled]="sandbox.publisherFilterIsActive"
- (change)="changeFilter($event.target.checked, RolesEnum.QUALIFIER)"
+ (change)="changeFilter($event.target.checked, Globals.STATUS_INTERN_FIELD)"
/>
<label class="custom-control-label" for="qualifierFilterSwitch">{{ 'GridFailures.QualifierFilterLabel' | translate }}</label>
</div>
@@ -113,7 +113,6 @@
[frameworkComponents]="frameworkComponents"
[rowData]="sandbox.overviewGridFailureList"
[overlayNoRowsTemplate]="noRowsTemplate"
- (gridReady)="initGridFilter($event)"
>
</ag-grid-angular>
</div>
diff --git a/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-list/grid-failure-list.component.spec.ts b/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-list/grid-failure-list.component.spec.ts
index 778d7bf..2584a18 100644
--- a/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-list/grid-failure-list.component.spec.ts
+++ b/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-list/grid-failure-list.component.spec.ts
@@ -14,7 +14,7 @@
import { Router } from '@angular/router';
import { GridFailure } from '@grid-failure-information-app/shared/models';
import { GridFailureSandbox } from '@grid-failure-information-app/pages/grid-failure/grid-failure-list/grid-failure.sandbox';
-import { Subscription, of } from 'rxjs';
+import { Subscription, of, Subject } from 'rxjs';
import { UtilService } from '@grid-failure-information-app/shared/utility';
import { RolesEnum } from '@grid-failure-information-app/shared/constants/enums';
@@ -22,6 +22,7 @@
let component: GridFailureListComponent;
let router: Router;
let sandbox: GridFailureSandbox;
+
let subscription: Subscription;
let utilService: UtilService;
let appState$: any;
@@ -31,6 +32,7 @@
beforeEach(() => {
router = { navigate() {} } as any;
sandbox = {
+ filterOptions: { filterModel: {} },
condensationList: [{ branch: 'F' }],
endSubscriptions() {},
clearGridFailureCondensation() {},
@@ -40,14 +42,17 @@
loadCondensedGridFailures() {},
permissions: { reader: true },
setFilteredGridFailureMapList() {},
+ gridFailureListSuccess$: of({}),
} as any;
utilService = {
displayNotification() {},
} as any;
appState$ = { dispatch: () => {}, pipe: () => of(true), select: () => of(true) } as any;
subscription = { unsubscribe() {} } as any;
- _gridApi = { getFilterInstance(key: any): any {}, onFilterChanged() {}, setFilterModel(model: any) {} } as any;
+ _gridApi = { onFilterChanged() {}, setFilterModel(model: any) {} } as any;
component = new GridFailureListComponent(sandbox, appState$, router, utilService);
+
+ component['_gridApi'] = { setFilterModel: () => {} } as any;
filterInstance = {
getModel() {
return { value: 'test' };
@@ -132,17 +137,10 @@
const mockGridApi = {
setFilterModel() {},
} as any;
- const spy2: any = spyOn(component, 'changeFilter');
- component.sandbox.publisherFilterIsActive = true;
- component.initGridFilter({ api: mockGridApi });
-
- setTimeout(() => {
- expect(spy2).toHaveBeenCalled();
- }, 2000);
- component.sandbox.publisherFilterIsActive = false;
- component.sandbox.qualifierFilterIsActive = true;
- component.initGridFilter({ api: mockGridApi });
- expect(spy2).toHaveBeenCalledTimes(2);
+ const spy2: any = spyOn(component, 'initGridFilter');
+ component['_setInitialGridOptions']();
+ component.gridOptions.onGridReady({ api: mockGridApi } as any);
+ expect(spy2).toHaveBeenCalled();
});
it('should call and check if changeToSelectionMode() works fine', () => {
@@ -183,37 +181,6 @@
expect(spy).toHaveBeenCalled();
});
- it('should call getFilterInstance(...) when changeFilter(true, RolesEnum.PUBLISHER) is called', () => {
- component['_gridApi'] = _gridApi;
- const spy: any = spyOn(_gridApi, 'getFilterInstance').and.returnValue(filterInstance as any);
- component.changeFilter(true, RolesEnum.PUBLISHER);
- expect(spy).toHaveBeenCalled();
- });
-
- it('should _resetFilterModelForQuickFilter(..) when changeFilter(false, RolesEnum.PUBLISHER) is called', () => {
- spyOn(_gridApi, 'getFilterInstance').and.returnValue(filterInstance as any);
- component['_gridApi'] = _gridApi;
- const spy: any = spyOn<any>(component, '_resetFilterModelForQuickFilter').and.callThrough();
- component.changeFilter(false, RolesEnum.PUBLISHER);
- expect(spy).toHaveBeenCalled();
- });
-
- it('should call _setFilterModelForQuickFilter(...) when changeFilter(true, RolesEnum.QUALIFIER) is called', () => {
- spyOn(_gridApi, 'getFilterInstance').and.returnValue(filterInstance as any);
- component['_gridApi'] = _gridApi;
- const spy: any = spyOn<any>(component, '_setFilterModelForQuickFilter').and.callThrough();
- component.changeFilter(true, RolesEnum.QUALIFIER);
- expect(spy).toHaveBeenCalled();
- });
-
- it('should _setFilterModelForQuickFilter(...) when changeFilter(false, RolesEnum.QUALIFIER) is called', () => {
- spyOn(_gridApi, 'getFilterInstance').and.returnValue(filterInstance as any);
- component['_gridApi'] = _gridApi;
- const spy: any = spyOn<any>(component, '_setFilterModelForQuickFilter').and.callThrough();
- component.changeFilter(false, RolesEnum.QUALIFIER);
- expect(spy).toHaveBeenCalled();
- });
-
it('should navigate to detail when navigateToDetail-function was called', () => {
const spy: any = spyOn(router, 'navigate');
component.navigateToDetails('test');
@@ -230,6 +197,6 @@
const spy2: any = spyOn(mockGridApi, 'getFilterModel').and.returnValue('test');
component.initGridFilter({ api: mockGridApi });
component.setMapFilter();
- expect(component.sandbox.filterOptions).toBe('test');
+ expect(component.sandbox.filterOptions).toEqual({ filterModel: 'test' });
});
});
diff --git a/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-list/grid-failure-list.component.ts b/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-list/grid-failure-list.component.ts
index 9565aeb..6b9c3f0 100644
--- a/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-list/grid-failure-list.component.ts
+++ b/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-list/grid-failure-list.component.ts
@@ -20,15 +20,15 @@
import { ModeEnum, EventTypeEnum, StateEnum } from '@grid-failure-information-app/shared/constants/enums';
import { SetFilterComponent } from '@grid-failure-information-app/shared/filters/ag-grid/set-filter/set-filter.component';
import { UtilService } from '@grid-failure-information-app/shared/utility';
-import { GridApi, GridOptions, IFilterComp, IFilterParams } from 'ag-grid-community';
+import { GridApi, GridOptions } from 'ag-grid-community';
import { Subject } from 'rxjs';
-import { takeUntil, take } from 'rxjs/operators';
+import { takeUntil, take, delay } from 'rxjs/operators';
import { Globals } from '@grid-failure-information-app/shared/constants/globals';
import { RolesEnum } from '@grid-failure-information-app/shared/constants/enums';
-import { GridFailure } from '@grid-failure-information-app/shared/models';
import { MapOptions } from '@openk-libs/grid-failure-information-map/shared/models/map-options.model';
import * as store from '@grid-failure-information-app/shared/store';
import { Store } from '@ngrx/store';
+import { GridFailure } from '@grid-failure-information-app/shared/models';
@Component({
selector: 'app-grid-failure-list',
@@ -78,81 +78,39 @@
public initGridFilter(params): void {
this._gridApi = params.api;
- if (this.sandbox.publisherFilterIsActive) {
- this.changeFilter(true, RolesEnum.PUBLISHER);
- } else if (this.sandbox.qualifierFilterIsActive) {
- this.changeFilter(true, RolesEnum.QUALIFIER);
- } else {
- this.sandbox.gridFailureListSuccess$ &&
- this.sandbox.gridFailureListSuccess$.pipe(take(1), takeUntil(this._endSubscriptions$)).subscribe(() => {
- setTimeout(() => {
- this._gridApi.setFilterModel(this.sandbox.filterOptions);
- }, 100);
- });
- }
- }
-
- public changeFilter(checked: boolean, userRole: string): any {
- this.overviewColumnDefinition = this.overviewColumnDefinition.map(column => {
- const fieldValueOfColDef: string = column['field'];
- if (!!fieldValueOfColDef) {
- if (
- userRole === RolesEnum.PUBLISHER &&
- (fieldValueOfColDef === Globals.STATUS_INTERN_FIELD || fieldValueOfColDef === Globals.STATUS_PUBLICATION_FIELD)
- ) {
- this.sandbox.publisherFilterIsActive = checked;
- return this.processFiltering(fieldValueOfColDef, checked, userRole, column);
- } else if (userRole === RolesEnum.QUALIFIER && fieldValueOfColDef === Globals.STATUS_INTERN_FIELD) {
- this.sandbox.qualifierFilterIsActive = checked;
- return this.processFiltering(fieldValueOfColDef, checked, userRole, column);
- }
- }
- return column;
+ this.sandbox.gridFailureListSuccess$.pipe(delay(500), takeUntil(this._endSubscriptions$)).subscribe(() => {
+ this._gridApi.setFilterModel(this.sandbox.filterOptions.filterModel);
});
}
- private processFiltering(fieldValueOfColDef: string, checked: boolean, userRole: string, column: any) {
- const filterInstance = this._gridApi.getFilterInstance(fieldValueOfColDef);
- const filterModel = filterInstance.getModel();
- const filterModelAll = this.sandbox.filterOptions ? this.sandbox.filterOptions : {};
- if (checked) {
- this._getFilterModelForQuickFilter(filterModel, userRole);
- this._setFilterModelForQuickFilter(filterModelAll, fieldValueOfColDef, filterModel, 1500);
- } else {
- this._resetFilterModelForQuickFilter(filterModel);
- this._setFilterModelForQuickFilter(filterModelAll, fieldValueOfColDef, filterModel);
- }
- return { ...column, suppressMenu: checked };
- }
-
- private _setFilterModelForQuickFilter(filterModelAll: any, filterName: string, filterModel: any, msDelayToSetFilterModel: number = 0) {
- filterModelAll[filterName] = filterModel;
- this.sandbox.filterOptions = filterModelAll;
- setTimeout(() => {
- this._gridApi.setFilterModel(filterModelAll);
- }, msDelayToSetFilterModel);
- this._gridApi.onFilterChanged();
- }
-
- private _resetFilterModelForQuickFilter(filterModel: any) {
- const filterValues = filterModel['values'];
- for (const valueKey in filterValues) {
- filterValues[valueKey]['checked'] = true;
+ public doesExternalFilterPass(node): boolean {
+ if (this.sandbox.publisherFilterIsActive) {
+ return node.data[Globals.STATUS_PUBLICATION_FIELD] === StateEnum.PUBLISHED || node.data[Globals.STATUS_INTERN_FIELD] === StateEnum.QUALIFIED;
+ } else if (this.sandbox.qualifierFilterIsActive) {
+ return (
+ node.data[Globals.STATUS_INTERN_FIELD] === StateEnum.CREATED ||
+ node.data[Globals.STATUS_INTERN_FIELD] === StateEnum.PLANNED ||
+ node.data[Globals.STATUS_INTERN_FIELD] === StateEnum.UPDATED
+ );
}
}
- private _getFilterModelForQuickFilter(filterModel: any, userRole: string) {
- const filterValues = filterModel['values'];
- for (const valueKey in filterValues) {
- switch (userRole) {
- case RolesEnum.QUALIFIER:
- filterValues[valueKey]['checked'] = valueKey === StateEnum.CREATED || valueKey === StateEnum.PLANNED || valueKey === StateEnum.UPDATED;
- break;
- case RolesEnum.PUBLISHER:
- filterValues[valueKey]['checked'] = valueKey === StateEnum.QUALIFIED || valueKey === StateEnum.PUBLISHED;
- break;
+ public changeFilter(checked: boolean = true, columnId: string): any {
+ this.sandbox.publisherFilterIsActive = checked && columnId === Globals.STATUS_PUBLICATION_FIELD;
+ this.sandbox.qualifierFilterIsActive = checked && columnId === Globals.STATUS_INTERN_FIELD;
+
+ this.overviewColumnDefinition = this.overviewColumnDefinition.map(column => {
+ const columnId: string = column['field'];
+ if (columnId === Globals.STATUS_INTERN_FIELD || columnId === Globals.STATUS_PUBLICATION_FIELD) {
+ return { ...column, suppressMenu: checked };
+ } else if (columnId === Globals.STATUS_INTERN_FIELD) {
+ return { ...column, suppressMenu: checked };
}
- }
+
+ return column;
+ });
+
+ this._gridApi.onFilterChanged();
}
public clearGridFailureCondensation(): void {
@@ -174,17 +132,10 @@
public addCompleteTable(): void {
let isNotificationAlreadyShown: boolean = false;
this._gridApi.forEachNodeAfterFilter(node => {
- if (
- (this.sandbox.condensationList.length == 0 || node.data.branch === this.sandbox.condensationList[0].branch) &&
- !node.data.condensed &&
- node.data.publicationStatus !== StateEnum.PUBLISHED &&
- node.data.publicationStatus !== StateEnum.WITHDRAWN
- ) {
+ if ((!this.sandbox.condensationList.length || node.data.branch === this.sandbox.condensationList[0].branch) && !node.data.condensed) {
this.sandbox.addItemToCondensationList(node.data);
- } else if (node.data.condensed || node.data.publicationStatus === StateEnum.PUBLISHED || node.data.publicationStatus === StateEnum.WITHDRAWN) {
- return;
- } else {
- if (!isNotificationAlreadyShown) this._utilService.displayNotification('DifferentBranchesWarning', 'alert');
+ } else if (!isNotificationAlreadyShown) {
+ this._utilService.displayNotification('DifferentBranchesWarning', 'alert');
isNotificationAlreadyShown = true;
}
});
@@ -202,25 +153,33 @@
this.enableSelectionMode = false;
this._changeMode();
}
+
public navigateToDetails(id: string) {
this._router.navigate(['/grid-failures', id]);
}
public setMapFilter() {
- // set filtered list
+ const filterModel = this._gridApi.getFilterModel();
+ const isColumnFilterActive = !!Object.keys(filterModel).length;
const filteredGridFailureMapList: GridFailure[] = [];
this._gridApi.forEachNodeAfterFilter(node => {
filteredGridFailureMapList.push(new GridFailure(node.data));
});
this.sandbox.setFilteredGridFailureMapList(filteredGridFailureMapList);
- this.sandbox.filterOptions = this._gridApi.getFilterModel();
+ this.sandbox.filterOptions = isColumnFilterActive ? { ...this.sandbox.filterOptions, filterModel } : {};
}
private _setInitialGridOptions(): void {
- this.gridOptions.context = { ...this.gridOptions.context, icons: { readonly: this.sandbox.permissions.reader } };
+ this.gridOptions.context = {
+ ...this.gridOptions.context,
+ icons: { readonly: this.sandbox.permissions.reader },
+ };
this.gridOptions = {
...this.gridOptions,
onFilterChanged: this.setMapFilter.bind(this),
+ onGridReady: this.initGridFilter.bind(this),
+ doesExternalFilterPass: this.doesExternalFilterPass.bind(this),
+ isExternalFilterPresent: () => this.sandbox.publisherFilterIsActive || this.sandbox.qualifierFilterIsActive,
};
this.gridOptions.context.eventSubject.pipe(takeUntil(this._endSubscriptions$)).subscribe(event => {
switch (event.type) {
@@ -250,6 +209,9 @@
break;
case this._eventTypeEnum.AddAllItems:
this.addCompleteTable();
+ setTimeout(() => {
+ this._gridApi.setFilterModel(this.sandbox.filterOptions.filterModel);
+ }, 100);
break;
case this._eventTypeEnum.InitialLoad:
this._changeMode();
@@ -268,6 +230,9 @@
switch (event.type) {
case this._eventTypeEnum.Remove:
this.sandbox.removeItemFromCondensationList(event.data);
+ setTimeout(() => {
+ this._gridApi.setFilterModel(this.sandbox.filterOptions.filterModel);
+ }, 100);
break;
case this._eventTypeEnum.Edit:
case this._eventTypeEnum.Readonly:
diff --git a/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-list/grid-failure.sandbox.ts b/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-list/grid-failure.sandbox.ts
index 3173860..0db9128 100644
--- a/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-list/grid-failure.sandbox.ts
+++ b/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-list/grid-failure.sandbox.ts
@@ -22,7 +22,7 @@
import { BaseSandbox } from '@grid-failure-information-app/shared/sandbox/base.sandbox';
import * as fromGridFailuresDetailFormReducer from '@grid-failure-information-app/shared/store/reducers/grid-failures/grid-failure-details-form.reducer';
import { ofType } from '@ngrx/effects';
-import { map, take, filter } from 'rxjs/operators';
+import { map, skipWhile, take } from 'rxjs/operators';
import { StateEnum, RolesEnum } from '@grid-failure-information-app/shared/constants/enums';
import { Subscription } from 'rxjs/Subscription';
import { TimerObservable } from 'rxjs/observable/TimerObservable';
@@ -40,7 +40,7 @@
public overviewGridFailureList: GridFailure[] = new Array();
public filteredGridFailureMapList: GridFailure[];
- public filterOptions: any;
+ public filterOptions: any = {};
public publisherFilterIsActive: boolean = false;
public qualifierFilterIsActive: boolean = false;
public condensationList: GridFailure[] = new Array();
@@ -51,9 +51,8 @@
public isReminderActive$: Observable<boolean> = this.appState$.select(store.getGridFailureReminderData);
private _timer;
- private _subscription: Subscription;
- constructor(protected appState$: Store<store.State>, private _router: Router, private actionsSubject: ActionsSubject) {
+ constructor(protected appState$: Store<store.State>, private _router: Router, public actionsSubject: ActionsSubject) {
super(appState$);
this._registerEvents();
this._startPolling();
@@ -74,7 +73,6 @@
this.condenseId = null;
this.condenseBranch = null;
this.condensationList = [];
- this.loadGridFailures();
}
public addItemToCondensationList(data: GridFailure): void {
@@ -108,11 +106,12 @@
this.appState$.dispatch(gridFailureActions.loadCondensedGridFailures({ payload: id }));
}
- public setFilteredGridFailureMapList(gridFailures: GridFailure[]) {
- this.filteredGridFailureMapList = gridFailures;
+ private _registerEvents(): void {
+ this._initCondesationList();
+ this._initOverviewList();
}
- private _registerEvents(): void {
+ private _initCondesationList() {
const allStations$ = this._loadAllStations();
combineLatest(
allStations$,
@@ -126,14 +125,11 @@
this.condenseBranch = condensedGridFailures[0].branch;
}
});
+ }
- combineLatest(
- allStations$,
- this.actionsSubject.pipe(
- ofType(gridFailureActions.loadGridFailuresSuccess),
- map((action: { payload: GridFailure[] }) => action.payload)
- )
- ).subscribe(([stations, gridFailures]) => {
+ private _initOverviewList() {
+ const allStations$ = this._loadAllStations();
+ combineLatest(allStations$, this.gridFailureList$).subscribe(([stations, gridFailures]) => {
if (gridFailures && gridFailures.length) {
this.overviewGridFailureList = this._getGridFailureWithReadableStationInformation(gridFailures, stations);
}
@@ -146,11 +142,14 @@
return cgf;
}) as any;
}
-
+ public setFilteredGridFailureMapList(gridFailures: GridFailure[]) {
+ this.filteredGridFailureMapList = gridFailures;
+ }
private _loadAllStations(): Observable<FailureStation[]> {
return this.actionsSubject.pipe(
ofType(gridFailureActions.loadStationsSuccess.type),
- map(action => action['payload'])
+ map(action => action['payload']),
+ take(1)
);
}
@@ -170,6 +169,6 @@
private _startPolling() {
this._timer = TimerObservable.create(Globals.REMINDER_JOB_POLLING_START_DELAY, Globals.REMINDER_JOB_POLLING_INTERVALL);
- this._subscription = this._timer.subscribe(() => this.appState$.dispatch(gridFailureActions.loadFailureReminder()));
+ this._timer.subscribe(() => this.appState$.dispatch(gridFailureActions.loadFailureReminder()));
}
}
diff --git a/projects/grid-failure-information-app/src/app/shared/filters/ag-grid/set-filter/set-filter.component.spec.ts b/projects/grid-failure-information-app/src/app/shared/filters/ag-grid/set-filter/set-filter.component.spec.ts
index 8940b08..ca3b547 100644
--- a/projects/grid-failure-information-app/src/app/shared/filters/ag-grid/set-filter/set-filter.component.spec.ts
+++ b/projects/grid-failure-information-app/src/app/shared/filters/ag-grid/set-filter/set-filter.component.spec.ts
@@ -13,6 +13,7 @@
import { SetFilterComponent } from '@grid-failure-information-app/shared/filters/ag-grid/set-filter/set-filter.component';
import { IFilterParams, RowNode } from 'ag-grid-community';
import { ALL_NGRX_FORMS_ACTION_TYPES } from 'ngrx-forms';
+import { of } from 'rxjs';
describe('SetFilterComponent', () => {
let component: SetFilterComponent;
@@ -49,14 +50,12 @@
component = new SetFilterComponent();
component['_params'] = params;
component.setItems = {
- FilterText1: {checked: true},
- FilterText2: {checkde: false},
- }
+ FilterText1: { checked: true },
+ FilterText2: { checkde: false },
+ };
component['_valueGetter'] = () => {
return { id: '0' };
};
-
-
});
it('should create', () => {
@@ -96,8 +95,7 @@
});
it('should add a checked filtered filterItem to the filterModel in _addItemToFilterModel()', () => {
- const oldFilterItems = {
- };
+ const oldFilterItems = {};
const compAnonym = component as any;
compAnonym.filterText = 'Filter';
compAnonym._addItemToFilterModel(oldFilterItems, 'FilterText');
@@ -109,8 +107,8 @@
it('should add a checked filterItem to the filterModel in _addItemToFilterModel()', () => {
const oldFilterItems = {
FilterText: {
- checked: true
- }
+ checked: true,
+ },
};
const compAnonym = component as any;
compAnonym.filterText = '';
@@ -238,7 +236,7 @@
component['_valueGetter'] = () => 'oncle tom';
component.setItems = { oncle: { checked: true } };
const returnValue = component.doesFilterPass({} as any);
- expect(returnValue).toBeTruthy();
+ expect(returnValue).toBeFalsy();
});
it('should set params via agInit()', () => {
@@ -267,7 +265,12 @@
},
};
},
- gridOptionsWrapper: { gridOptions: { onGridSizeChanged: () => {}, onRowDataChanged: () => {} } },
+ gridOptionsWrapper: {
+ gridOptions: {
+ onGridSizeChanged: () => {},
+ onRowDataChanged: () => {},
+ },
+ },
},
} as any;
component['_valueGetter'] = () => {
@@ -284,9 +287,8 @@
});
it('should return false in _areAllFilterItemsSelected() when filter textbox is not empty', () => {
- component.filterText = "0815";
+ component.filterText = '0815';
const allFilterItemsSelected: boolean = (component as any)._areAllFilterItemsSelected();
expect(allFilterItemsSelected).toBe(false);
});
-
});
diff --git a/projects/grid-failure-information-app/src/app/shared/filters/ag-grid/set-filter/set-filter.component.ts b/projects/grid-failure-information-app/src/app/shared/filters/ag-grid/set-filter/set-filter.component.ts
index 943db4d..43e9643 100644
--- a/projects/grid-failure-information-app/src/app/shared/filters/ag-grid/set-filter/set-filter.component.ts
+++ b/projects/grid-failure-information-app/src/app/shared/filters/ag-grid/set-filter/set-filter.component.ts
@@ -10,26 +10,33 @@
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
-import { Component } from '@angular/core';
+import { Component, OnDestroy } from '@angular/core';
import { AgFilterComponent } from 'ag-grid-angular';
import { IDoesFilterPassParams, IFilterParams, RowDataChangedEvent, RowNode } from 'ag-grid-community';
import { convertEmptyValueToNull } from '@grid-failure-information-app/shared/utility/utilityHelpers';
+import { Subject } from 'rxjs';
+import { takeUntil } from 'rxjs/operators';
@Component({
selector: 'filter-cell',
templateUrl: './set-filter.component.html',
styleUrls: ['./set-filter.component.css'],
})
-export class SetFilterComponent implements AgFilterComponent {
+export class SetFilterComponent implements AgFilterComponent, OnDestroy {
public setItems: any = {};
public gridHeight: number;
public filterText: string = '';
public selectAllChecked: boolean = true;
+ public isQuickfilterPublishChecked: boolean = false;
+ public publisherFilterIsActive: boolean = false;
+
private _filteredItems: any = {};
private _params: IFilterParams;
private _valueGetter: (rowNode: RowNode) => any;
private _filterId: string = '';
+ protected _endSubscriptions$: Subject<boolean> = new Subject();
+
filterCheckboxList(text: string) {
text
.toLowerCase()
@@ -74,24 +81,8 @@
}
doesFilterPass(params: IDoesFilterPassParams): boolean {
- let nodeValue = this._valueGetter(params.node);
- nodeValue = !!nodeValue ? nodeValue : null; //Set to null if undefined, null or ''
- let passed: boolean = false;
- for (let itemKey in this.setItems) {
- if (isNaN(nodeValue)) {
- passed = itemKey === 'null' ? !nodeValue || nodeValue === '' : !!nodeValue && nodeValue.includes(itemKey);
- } else {
- // is numeric or null
- if (!nodeValue) {
- passed = nodeValue === null && itemKey === 'null';
- } else {
- passed = nodeValue.toString() === itemKey;
- }
- }
- passed = passed && this.setItems[itemKey].checked;
- if (passed) return passed;
- }
- return passed;
+ const itemKey = this._valueGetter(params.node);
+ return this.setItems[itemKey] !== undefined && this.setItems[itemKey].checked;
}
getModel(): any {
@@ -104,7 +95,7 @@
}
afterGuiAttached(params?: any) {
- if (this.filterText && this.filterText.trim().length > 0) {
+ if (!!this.filterText && this.filterText.trim().length > 0) {
this.filterCheckboxList(this.filterText.trim());
}
this._setFilterItems(params);
@@ -128,13 +119,17 @@
};
}
+ ngOnDestroy(): void {
+ this._endSubscriptions$.next(true);
+ }
+
private _setFilterItems(params: IFilterParams) {
const allGridRowNodes = (this._params.rowModel as any).nodeManager.allNodesMap || {};
const oldFilterItems = {};
Object.assign(oldFilterItems, this.setItems);
this.setItems = {};
- for (const allRowsKey in Object.keys(allGridRowNodes)) {
- const rowNode = allGridRowNodes[allRowsKey];
+ for (const nodeKey in Object.keys(allGridRowNodes)) {
+ const rowNode = allGridRowNodes[nodeKey];
if (this._params.doesRowPassOtherFilter(rowNode)) {
let filterItem = convertEmptyValueToNull(this._valueGetter(rowNode));
const valueSeparator: string = this._params.colDef['valueSeparator'];
@@ -156,7 +151,7 @@
const isFilterItemInOldFilter = oldFilterItems.hasOwnProperty(item);
let checked: boolean = (!isFilterItemInOldFilter && this.selectAllChecked) || (isFilterItemInOldFilter && oldFilterItems[item]['checked'] === true);
const itemValueObject = { visible: true, checked: checked };
- if (this.filterText && this.filterText.trim().length > 0) {
+ if (!!this.filterText && this.filterText.trim().length > 0) {
if (!!item && this._contains(item, this.filterText.trim())) {
this.setItems[item] = itemValueObject;
}