Merge branch 'SI-2786-BUG-delete-Kontakte-fehlerhaftes-PLZ-handling' of ssh://git.eclipse.org:29418/openk-usermodules/org.eclipse.openk-usermodules.gridFailureInformation.frontend into DEVELOP
diff --git a/projects/grid-failure-information-app/src/app/shared/models/settings.model.ts b/projects/grid-failure-information-app/src/app/shared/models/settings.model.ts index 282dc18..27abdc0 100644 --- a/projects/grid-failure-information-app/src/app/shared/models/settings.model.ts +++ b/projects/grid-failure-information-app/src/app/shared/models/settings.model.ts
@@ -19,6 +19,7 @@ public overviewMapInitialLatitude: string = null; public overviewMapInitialLongitude: string = null; public visibilityConfiguration: VisibilityConfigurationInterface = null; + public dataExternInitialVisibility: string = null; public constructor(data: any = null) { Object.keys(data || {})
diff --git a/projects/grid-failure-information-app/src/app/shared/utility/utilityHelpers.spec.ts b/projects/grid-failure-information-app/src/app/shared/utility/utilityHelpers.spec.ts index ef6b322..ef7905d 100644 --- a/projects/grid-failure-information-app/src/app/shared/utility/utilityHelpers.spec.ts +++ b/projects/grid-failure-information-app/src/app/shared/utility/utilityHelpers.spec.ts
@@ -12,6 +12,7 @@ ********************************************************************************/ import * as utilityHelpers from '@grid-failure-information-app/shared/utility/utilityHelpers'; import { FailureHousenumber } from '@grid-failure-information-app/shared/models'; +import { VisibilityConfigurationInterface } from '@grid-failure-information-app/shared/interfaces/visibility-configuration.interface'; describe('utilityHelpers', () => { it('should navigate to overview after call navigateHome', () => { @@ -112,4 +113,15 @@ testValue = utilityHelpers.sortAlphaNum(inputFailureHousenumber, inputFailureHousenumber2); expect(testValue).toBe(0); }); + + it('should return true for detailFieldVisibility in case no config is provided', () => { + let config: VisibilityConfigurationInterface = null; + let testValue = utilityHelpers.determineDetailFieldVisibility(config, 'fieldVisibility', 'description'); + expect(testValue).toBeTruthy(); + }); + + it('should determine addressRelevan Branch', () => { + let testValue = utilityHelpers.getAddressRelevantBranch('S'); + expect(testValue).toBe('S'); + }); });
diff --git a/projects/grid-failure-information-map-app/src/app/app-config.service.ts b/projects/grid-failure-information-map-app/src/app/app-config.service.ts index 96aea46..4810aee 100644 --- a/projects/grid-failure-information-map-app/src/app/app-config.service.ts +++ b/projects/grid-failure-information-map-app/src/app/app-config.service.ts
@@ -12,6 +12,7 @@ ********************************************************************************/ import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; +import { MapOptions } from '@openk-libs/grid-failure-information-map/shared/models/map-options.model'; @Injectable({ providedIn: 'root', @@ -20,6 +21,6 @@ constructor(private http: HttpClient) {} getConfig() { - return this.http.get('public-settings'); + return this.http.get<MapOptions>('public-settings'); } }
diff --git a/projects/grid-failure-information-map-app/src/app/grid-failure/grid-failure.sandbox.spec.ts b/projects/grid-failure-information-map-app/src/app/grid-failure/grid-failure.sandbox.spec.ts index 679f27e..2a39df8 100644 --- a/projects/grid-failure-information-map-app/src/app/grid-failure/grid-failure.sandbox.spec.ts +++ b/projects/grid-failure-information-map-app/src/app/grid-failure/grid-failure.sandbox.spec.ts
@@ -14,9 +14,10 @@ import { GridFailureService } from '@grid-failure-information-map-app/app/grid-failure/grid-failure.service'; import { AppConfigService } from '@grid-failure-information-map-app/app/app-config.service'; import { of } from 'rxjs'; -import { GridFailure } from '@grid-failure-information-app/shared/models'; +import { GridFailure, Settings } from '@grid-failure-information-app/shared/models'; +import { VisibilityEnum } from '@grid-failure-information-app/shared/constants/enums'; -describe('GridFailureSandbox', () => { +describe('GridFailureSandbox ', () => { let sandbox: GridFailureSandbox; let gridFailureService: GridFailureService; let configService: AppConfigService; @@ -24,17 +25,15 @@ let gridFailureMapList: GridFailure[] = []; beforeEach(() => { + let config = new Settings(); + config.dataExternInitialVisibility = VisibilityEnum.SHOW; configService = { - getConfig: () => of(new Object()), + getConfig: () => of(config), } as any; gridFailureService = { - getGridFailureData: () => of(new Object()), + getGridFailureData: () => of([new GridFailure()]), } as any; - gridFailureMapListAll = [ - new GridFailure({postcode: '007'}), - new GridFailure({postcode: '4711'}), - new GridFailure({postcode: '0815'}), - ]; + gridFailureMapListAll = [new GridFailure({ postcode: '007' }), new GridFailure({ postcode: '4711' }), new GridFailure({ postcode: '0815' })]; gridFailureMapList = gridFailureMapListAll.map(i => Object.assign(i)); sandbox = new GridFailureSandbox(gridFailureService, configService); (sandbox as any)._gridFailureMapListAll = gridFailureMapListAll; @@ -45,12 +44,6 @@ expect(sandbox).toBeTruthy(); }); - it('should add two subscriptions', () => { - const spy: any = spyOn(sandbox['_subscription'], 'add'); - sandbox.initSandbox(); - expect(spy).toHaveBeenCalledTimes(2); - }); - it('should unsubscribe subscriptions', () => { const spy: any = spyOn(sandbox['_subscription'], 'unsubscribe'); sandbox.unsubscribe(); @@ -58,13 +51,15 @@ }); it('filterGridFailureMapList() should assign all gridfailure to map property ', () => { + sandbox.initSandbox(); sandbox.filterGridFailureMapList(); - expect(sandbox.gridFailureMapList.length).toEqual(gridFailureMapListAll.length); + expect(sandbox.gridFailureMapList.length).toEqual(1); }); it('filterGridFailureMapList("") should assign all gridfailure to map property ', () => { + sandbox.initSandbox(); sandbox.filterGridFailureMapList(''); - expect(sandbox.gridFailureMapList.length).toEqual(gridFailureMapListAll.length); + expect(sandbox.gridFailureMapList.length).toEqual(1); }); it('filterGridFailureMapList("007") should assign only one gridfailure to map property ', () => {
diff --git a/projects/grid-failure-information-map-app/src/app/grid-failure/grid-failure.sandbox.ts b/projects/grid-failure-information-map-app/src/app/grid-failure/grid-failure.sandbox.ts index cb114d8..0dfac51 100644 --- a/projects/grid-failure-information-map-app/src/app/grid-failure/grid-failure.sandbox.ts +++ b/projects/grid-failure-information-map-app/src/app/grid-failure/grid-failure.sandbox.ts
@@ -12,48 +12,39 @@ ********************************************************************************/ import { Injectable } from '@angular/core'; import { GridFailureService } from '@grid-failure-information-map-app/app/grid-failure/grid-failure.service'; -import { Subscription } from 'rxjs'; +import { Subscription, combineLatest } from 'rxjs'; import { MapOptions } from '@openk-libs/grid-failure-information-map/shared/models/map-options.model'; import { AppConfigService } from '@grid-failure-information-map-app/app/app-config.service'; import { take } from 'rxjs/operators'; import { GridFailure } from '@grid-failure-information-app/shared/models'; +import { VisibilityEnum } from '@grid-failure-information-app/shared/constants/enums'; @Injectable() export class GridFailureSandbox { public gridFailureMapList: GridFailure[] = []; public mapOptions: MapOptions = new MapOptions(); - public postcode: string = ''; private _gridFailureMapListAll: GridFailure[] = []; + private _gridFailureMapListAllConfigured: GridFailure[] = []; private _subscription: Subscription = new Subscription(); constructor(private _gridFailureService: GridFailureService, private _configService: AppConfigService) {} public initSandbox() { - this._subscription.add( - this._configService - .getConfig() - .pipe(take(1)) - .subscribe((data: MapOptions) => { - this.mapOptions = new MapOptions(data); - this.mapOptions.extendMarkerInformation = true; - }) - ); - - this._subscription.add( - this._gridFailureService - .getGridFailureData() - .pipe(take(1)) - .subscribe((data: GridFailure[]) => { - this.gridFailureMapList = data; - this._gridFailureMapListAll = data; - }) - ); + this._subscription = combineLatest([this._configService.getConfig(), this._gridFailureService.getGridFailureData()]) + .pipe(take(1)) + .subscribe(([config, data]) => { + this.mapOptions = new MapOptions(config); + this.mapOptions.extendMarkerInformation = true; + this.gridFailureMapList = config && config.dataExternInitialVisibility === VisibilityEnum.HIDE ? [] : data; + this._gridFailureMapListAll = data; + this._gridFailureMapListAllConfigured = config && config.dataExternInitialVisibility === VisibilityEnum.HIDE ? [] : data; + }); } public filterGridFailureMapList(postcode: string = '') { postcode = postcode.trim(); - this.gridFailureMapList = postcode.length > 0 ? this._gridFailureMapListAll.filter(y => y.postcode === postcode) : this._gridFailureMapListAll; + this.gridFailureMapList = postcode.length > 0 ? this._gridFailureMapListAll.filter(y => y.postcode === postcode) : this._gridFailureMapListAllConfigured; } public unsubscribe() {
diff --git a/projects/grid-failure-information-map-app/src/app/grid-failure/grid-failure.service.ts b/projects/grid-failure-information-map-app/src/app/grid-failure/grid-failure.service.ts index ddefa01..ed4fba6 100644 --- a/projects/grid-failure-information-map-app/src/app/grid-failure/grid-failure.service.ts +++ b/projects/grid-failure-information-map-app/src/app/grid-failure/grid-failure.service.ts
@@ -1,26 +1,26 @@ /******************************************************************************** -* Copyright (c) 2020 Contributors to the Eclipse Foundation -* -* See the NOTICE file(s) distributed with this work for additional -* information regarding copyright ownership. -* -* This program and the accompanying materials are made available under the -* terms of the Eclipse Public License v. 2.0 which is available at -* http://www.eclipse.org/legal/epl-2.0. -* -* SPDX-License-Identifier: EPL-2.0 -********************************************************************************/ + * Copyright (c) 2020 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + ********************************************************************************/ import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; +import { GridFailure } from '@grid-failure-information-app/shared/models'; @Injectable({ - providedIn: 'root' + providedIn: 'root', }) export class GridFailureService { + constructor(private _http: HttpClient) {} - constructor(private _http: HttpClient) { } - - getGridFailureData(){ - return this._http.get('public-sit'); + getGridFailureData() { + return this._http.get<GridFailure[]>('public-sit'); } }
diff --git a/projects/grid-failure-information-table-app/src/app/app-config.service.ts b/projects/grid-failure-information-table-app/src/app/app-config.service.ts index 96aea46..cef247c 100644 --- a/projects/grid-failure-information-table-app/src/app/app-config.service.ts +++ b/projects/grid-failure-information-table-app/src/app/app-config.service.ts
@@ -12,6 +12,7 @@ ********************************************************************************/ import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; +import { Settings } from '@grid-failure-information-app/shared/models'; @Injectable({ providedIn: 'root', @@ -20,6 +21,6 @@ constructor(private http: HttpClient) {} getConfig() { - return this.http.get('public-settings'); + return this.http.get<Settings>('public-settings'); } }
diff --git a/projects/grid-failure-information-table-app/src/app/app.component.spec.ts b/projects/grid-failure-information-table-app/src/app/app.component.spec.ts index 79a3fb9..3821ac2 100644 --- a/projects/grid-failure-information-table-app/src/app/app.component.spec.ts +++ b/projects/grid-failure-information-table-app/src/app/app.component.spec.ts
@@ -16,8 +16,9 @@ import { GridFailure, Settings } from '@grid-failure-information-app/shared/models'; import { of } from 'rxjs'; import { DatePipe } from '@angular/common'; +import { VisibilityEnum } from '@grid-failure-information-app/shared/constants/enums'; -describe('AppComponent', () => { +describe('AppComponent ', () => { let component: TableComponent; let service: AppTableService; let configService: AppConfigService; @@ -26,7 +27,7 @@ beforeEach(() => { service = { - loadGridFailureData: () => of(true), + loadGridFailureData: () => of([new GridFailure()]), } as any; configService = { getConfig: () => of(true), @@ -63,9 +64,16 @@ }); it('should assign all gridfailures to table', () => { + let config = new Settings(); + config.dataExternInitialVisibility = VisibilityEnum.SHOW; + configService = { + getConfig: () => of(config), + } as any; + component = new TableComponent(service, configService, null); component.postcode = ''; component['_datePipe'] = { transform: () => '18.09.2020 / 10:17' } as any; - expect(component.gridFailures.length).toEqual(gridFailureMapListAll.length); + component.ngOnInit(); + expect(component.gridFailures.length).toEqual(1); }); it('should assign only gridfailures with postcode 007 to table', () => {
diff --git a/projects/grid-failure-information-table-app/src/app/app.component.ts b/projects/grid-failure-information-table-app/src/app/app.component.ts index a83235a..bccf565 100644 --- a/projects/grid-failure-information-table-app/src/app/app.component.ts +++ b/projects/grid-failure-information-table-app/src/app/app.component.ts
@@ -16,7 +16,7 @@ import { APP_TABLE_COLDEF } from '@grid-failure-information-table-app/app/app-table-column-definition'; import { GridOptions } from 'ag-grid-community'; import { Globals } from '@grid-failure-information-app/shared/constants/globals'; -import { Subscription } from 'rxjs'; +import { Subscription, combineLatest } from 'rxjs'; import { DatePipe } from '@angular/common'; import { AppConfigService } from '@grid-failure-information-table-app/app/app-config.service'; import { take } from 'rxjs/operators'; @@ -39,6 +39,7 @@ private _gridApi; private _gridFailuresAll: GridFailure[] = []; + private _gridFailuresAllConfigured: GridFailure[]; private _subscription: Subscription = new Subscription(); constructor(private _appTableService: AppTableService, private _configService: AppConfigService, private _datePipe: DatePipe) { @@ -52,36 +53,28 @@ value = value.trim(); let filterFunc = (x: GridFailure) => x.postcode === value || x.freetextPostcode === value; if (!!this._gridFailuresAll && this._gridFailuresAll.length > 0) { - this.gridFailures = value.length > 0 ? this._gridFailuresAll.filter(filterFunc) : this._gridFailuresAll; + this.gridFailures = value.length > 0 ? this._gridFailuresAll.filter(filterFunc) : this._gridFailuresAllConfigured; } } ngOnInit() { - this._subscription.add( - this._configService - .getConfig() - .pipe(take(1)) - .subscribe((config: Settings) => { - if (config && config.visibilityConfiguration) { - APP_TABLE_COLDEF.forEach((column: any) => { - column['hide'] = config.visibilityConfiguration.tableExternColumnVisibility[column['field']] === VisibilityEnum.HIDE; - }); - this.columnDefs = APP_TABLE_COLDEF; - } - }) - ); - this._subscription.add( - this._appTableService - .loadGridFailureData() - .pipe(take(1)) - .subscribe((data: GridFailure[]) => { - this.gridFailures = data; - this._gridFailuresAll = data; - if (this._datePipe) { - this.lastModDate = this._datePipe.transform(this._getLastModeDate(), Globals.DATE_TIME_FORMAT); - } - }) - ); + this._subscription = combineLatest([this._configService.getConfig(), this._appTableService.loadGridFailureData()]) + .pipe(take(1)) + .subscribe(([config, data]) => { + if (config && config.visibilityConfiguration) { + APP_TABLE_COLDEF.forEach((column: any) => { + column['hide'] = config.visibilityConfiguration.tableExternColumnVisibility[column['field']] === VisibilityEnum.HIDE; + }); + this.columnDefs = APP_TABLE_COLDEF; + } + this.gridFailures = config && config.dataExternInitialVisibility === VisibilityEnum.HIDE ? [] : data; + this._gridFailuresAll = data; + this._gridFailuresAllConfigured = config && config.dataExternInitialVisibility === VisibilityEnum.HIDE ? [] : data; + if (this._datePipe) { + this.lastModDate = this._datePipe.transform(this._getLastModeDate(), Globals.DATE_TIME_FORMAT); + } + }); + this.gridOptions = { localeText: Globals.LOCALE_TEXT, };
diff --git a/projects/openk/grid-failure-information-map/src/shared/models/map-options.model.ts b/projects/openk/grid-failure-information-map/src/shared/models/map-options.model.ts index 031f129..ae5e3dd 100644 --- a/projects/openk/grid-failure-information-map/src/shared/models/map-options.model.ts +++ b/projects/openk/grid-failure-information-map/src/shared/models/map-options.model.ts
@@ -21,6 +21,7 @@ public overviewMapInitialLatitude: string = null; public overviewMapInitialLongitude: string = null; public visibilityConfiguration: VisibilityConfigurationInterface = null; + public dataExternInitialVisibility: string = null; public constructor(data: any = null) { Object.keys(data || {})
diff --git a/projects/openk/grid-failure-information-map/src/shared/utility/utilityHelpers.spec.ts b/projects/openk/grid-failure-information-map/src/shared/utility/utilityHelpers.spec.ts index c1d8917..df78e04 100644 --- a/projects/openk/grid-failure-information-map/src/shared/utility/utilityHelpers.spec.ts +++ b/projects/openk/grid-failure-information-map/src/shared/utility/utilityHelpers.spec.ts
@@ -11,6 +11,7 @@ * SPDX-License-Identifier: EPL-2.0 ********************************************************************************/ import * as utilityHelpers from '@openk-libs/grid-failure-information-map/shared/utility/utilityHelpers'; +import { VisibilityConfigurationInterface } from '@openk-libs/grid-failure-information-map/shared/models/visibility-configuration.interface'; describe('utilityHelpers', () => { it('should parse string to Integer via toInteger()', () => { @@ -43,4 +44,10 @@ let testValue = utilityHelpers.convertISOToLocalDateTime(dateString); expect(testValue).toBe('19.11.2020 / 14:13'); }); + + it('should return true for detailFieldVisibility in case no config is provided', () => { + let config: VisibilityConfigurationInterface = null; + let testValue = utilityHelpers.determineDetailFieldVisibility(config, 'fieldVisibility', 'description'); + expect(testValue).toBeTruthy(); + }); });