[SI-1054] set active location button in create mode correctly
[SI-1053] show correct visualization of required field validation in create mode
diff --git a/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-details/grid-failure-details.component.html b/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-details/grid-failure-details.component.html
index 0ce179d..d6f7576 100644
--- a/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-details/grid-failure-details.component.html
+++ b/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-details/grid-failure-details.component.html
@@ -320,36 +320,33 @@
<button
class="btn btn-primary non-outline"
(click)="
- mapInteractionMode = false;
- failureLocationView = 'NS';
+ failureLocationView = Globals.FAILURE_LOCATION_NS;
disableUnnecessaryRequiredProperties();
gridFailureDetailsSandbox.resetFailureLocationValues()
"
- [class.active]="failureLocationView === 'NS'"
+ [class.active]="failureLocationView === Globals.FAILURE_LOCATION_NS"
>
{{ 'GridFailure.SubTitle3' | translate }}
</button>
<button
class="btn btn-primary non-outline"
(click)="
- mapInteractionMode = false;
- failureLocationView = 'MS';
+ failureLocationView = Globals.FAILURE_LOCATION_MS;
disableUnnecessaryRequiredProperties();
gridFailureDetailsSandbox.resetFailureLocationValues()
"
- [class.active]="failureLocationView === 'MS'"
+ [class.active]="failureLocationView === Globals.FAILURE_LOCATION_MS"
>
{{ 'GridFailure.SubTitle4' | translate }}
</button>
<button
class="btn btn-primary non-outline"
(click)="
- mapInteractionMode = true;
- failureLocationView = 'map';
+ failureLocationView = Globals.FAILURE_LOCATION_MAP;
disableUnnecessaryRequiredProperties();
gridFailureDetailsSandbox.resetFailureLocationValues()
"
- [class.active]="failureLocationView === 'map'"
+ [class.active]="failureLocationView === Globals.FAILURE_LOCATION_MAP"
>
{{ 'GridFailure.Map' | translate }}
</button>
@@ -357,7 +354,7 @@
</div>
<div class="fault-location-container">
- <div class="NS-fields" *ngIf="failureLocationView === 'NS'">
+ <div class="NS-fields" *ngIf="failureLocationView === Globals.FAILURE_LOCATION_NS">
<!-- postcode -->
<div class="form-group row">
<label for="postcode" class="col-sm-5 col-form-label">{{ 'GridFailure.Postcode' | translate }}</label>
@@ -446,7 +443,7 @@
</div>
</div>
- <div class="MS-fields" *ngIf="failureLocationView === 'MS'">
+ <div class="MS-fields" *ngIf="failureLocationView === Globals.FAILURE_LOCATION_MS">
<!-- stationDescription -->
<div class="form-group row">
<label for="stationDescription" class="col-sm-5 col-form-label">{{ 'GridFailure.StationDescription' | translate }}</label>
diff --git a/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-details/grid-failure-details.component.spec.ts b/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-details/grid-failure-details.component.spec.ts
index eaf647e..440082b 100644
--- a/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-details/grid-failure-details.component.spec.ts
+++ b/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-details/grid-failure-details.component.spec.ts
@@ -1,3 +1,4 @@
+import { logging } from 'protractor';
/********************************************************************************
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
@@ -15,7 +16,7 @@
import { Store } from '@ngrx/store';
import { State } from '@grid-failure-information-app/shared/store';
import { async } from '@angular/core/testing';
-import { GridFailure } from '@grid-failure-information-app/shared/models';
+import { Globals } from '@grid-failure-information-app/shared/constants/globals';
describe('GridFailureDetailsComponent', () => {
let component: GridFailureDetailsComponent;
@@ -45,7 +46,7 @@
resetPostCode() {},
disableUnnecessaryRequiredProperties() {},
gridFailureDetailsFormState$: of(gridFailureDetailsFormResponse as any),
- isAdressLoaded() {
+ isAddressLoaded() {
return of(true);
},
} as any;
@@ -84,54 +85,49 @@
}));
it('checks if disableUnnecessaryRequiredProperties works fine', async(() => {
- component.failureLocationView = 'MS';
+ component.failureLocationView = Globals.FAILURE_LOCATION_NS;
const spy = spyOn(gridFailureSandbox, 'disableUnnecessaryRequiredProperties');
component.disableUnnecessaryRequiredProperties();
expect(spy).toHaveBeenCalled();
}));
it('checks if _initialFailureLocationState works fine', async(() => {
- component.mapInteractionMode = true;
+ component.failureLocationView === Globals.FAILURE_LOCATION_MAP;
+ //MAP
component.gridFailureDetailsSandbox.currentFormState = {
...component.gridFailureDetailsSandbox.currentFormState,
controls: {
- postcode: { value: null } as any,
- stationDescription: { value: null } as any,
+ housenumber: { value: null } as any,
+ radius: { value: null } as any,
latitude: { value: null } as any,
- } as any,
- };
- (component as any)._initialFailureLocationState();
- expect(component.mapInteractionMode).toBeFalsy();
-
- component.gridFailureDetailsSandbox.currentFormState = {
- ...component.gridFailureDetailsSandbox.currentFormState,
- controls: {
- postcode: { value: null } as any,
- stationDescription: { value: null } as any,
- latitude: { value: 1.24 } as any,
+ longitude: { value: null } as any,
} as any,
};
(component as any)._initialFailureLocationState();
expect(component.mapInteractionMode).toBeTruthy();
+ //NS
component.gridFailureDetailsSandbox.currentFormState = {
...component.gridFailureDetailsSandbox.currentFormState,
controls: {
- postcode: { value: null } as any,
- stationDescription: { value: 'test' } as any,
- latitude: { value: 1.24 } as any,
+ housenumber: { value: null } as any,
+ radius: { value: 100 } as any,
+ latitude: { value: 11 } as any,
+ longitude: { value: 22 } as any,
} as any,
};
(component as any)._initialFailureLocationState();
expect(component.mapInteractionMode).toBeFalsy();
+ //MS
component.gridFailureDetailsSandbox.currentFormState = {
...component.gridFailureDetailsSandbox.currentFormState,
controls: {
- postcode: { value: '00000' } as any,
- stationDescription: { value: 'test' } as any,
- latitude: { value: 1.24 } as any,
+ housenumber: { value: 44 } as any,
+ radius: { value: null } as any,
+ latitude: { value: 11 } as any,
+ longitude: { value: 12 } as any,
} as any,
};
(component as any)._initialFailureLocationState();
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 1e308e9..7515a2c 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
@@ -18,7 +18,6 @@
import * as store from '@grid-failure-information-app/shared/store';
import { Store } from '@ngrx/store';
import { Observable } from 'rxjs';
-import { take, takeUntil } from 'rxjs/operators';
@Component({
selector: 'app-grid-failure-details',
@@ -30,8 +29,11 @@
public RolesEnum = RolesEnum;
public StateEnum = StateEnum;
public gridFailureVersions$: Observable<GridFailure[]> = this.appState$.select(store.getGridFailureVersionsData);
- public failureLocationView: string;
- public mapInteractionMode: boolean;
+ public failureLocationView: string = Globals.FAILURE_LOCATION_MAP;
+
+ public get mapInteractionMode(): boolean {
+ return this.failureLocationView === Globals.FAILURE_LOCATION_MAP;
+ }
constructor(public gridFailureDetailsSandbox: GridFailureDetailsSandbox, protected appState$: Store<store.State>) {}
@@ -51,30 +53,24 @@
this.gridFailureDetailsSandbox.disableUnnecessaryRequiredProperties(this.failureLocationView);
}
private _initialFailureLocationState() {
- this.gridFailureDetailsSandbox.isAdressLoaded().subscribe(() => {
+ this.gridFailureDetailsSandbox.isAddressLoaded().subscribe(() => {
const currentFormState = this.gridFailureDetailsSandbox.currentFormState;
if (!!currentFormState && !!currentFormState.controls) {
- if (!!currentFormState.controls.postcode.value) {
+ const coordinatesExsist = !!currentFormState.controls.latitude.value && !!currentFormState.controls.longitude.value;
+ //The user is forced to set other address data before he can edity the hosuenumber
+ //and housenumber is the last to edit value, we can assume that coordinates have been set correctly
+ const nsDataExist = !!currentFormState.controls.housenumber.value && coordinatesExsist;
+ //Radius is the only required field, we can assume that coordinates have been set correctly
+ const msDataExist = !!currentFormState.controls.radius.value && coordinatesExsist;
+ if (nsDataExist) {
this.failureLocationView = Globals.FAILURE_LOCATION_NS;
- this.gridFailureDetailsSandbox.disableUnnecessaryRequiredProperties(this.failureLocationView);
- this.mapInteractionMode = false;
- } else if (!!currentFormState.controls.stationDescription.value) {
+ } else if (msDataExist) {
this.failureLocationView = Globals.FAILURE_LOCATION_MS;
- this.gridFailureDetailsSandbox.disableUnnecessaryRequiredProperties(this.failureLocationView);
- this.mapInteractionMode = false;
- } else if (
- !currentFormState.controls.postcode.value &&
- !currentFormState.controls.stationDescription.value &&
- currentFormState.controls.latitude.value
- ) {
- this.failureLocationView = Globals.FAILURE_LOCATION_MAP;
- this.gridFailureDetailsSandbox.disableUnnecessaryRequiredProperties(this.failureLocationView);
- this.mapInteractionMode = true;
} else {
- this.failureLocationView = Globals.FAILURE_LOCATION_NS;
- this.gridFailureDetailsSandbox.disableUnnecessaryRequiredProperties(this.failureLocationView);
- this.mapInteractionMode = false;
+ this.failureLocationView = Globals.FAILURE_LOCATION_MAP;
}
+
+ this.gridFailureDetailsSandbox.disableUnnecessaryRequiredProperties(this.failureLocationView);
}
});
}
diff --git a/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-details/grid-failure-details.sandbox.spec.ts b/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-details/grid-failure-details.sandbox.spec.ts
index f496ed3..281d911 100644
--- a/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-details/grid-failure-details.sandbox.spec.ts
+++ b/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-details/grid-failure-details.sandbox.spec.ts
@@ -601,7 +601,7 @@
});
it('should call saveFailureLocationSpecificParts', () => {
- const subject = service.isAdressLoaded();
+ const subject = service.isAddressLoaded();
subject.subscribe(item => {
expect(item).toBeTruthy();
});
diff --git a/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-details/grid-failure-details.sandbox.ts b/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-details/grid-failure-details.sandbox.ts
index 631846d..4c1fee7 100644
--- a/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-details/grid-failure-details.sandbox.ts
+++ b/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure-details/grid-failure-details.sandbox.ts
@@ -458,7 +458,7 @@
this.appState$.dispatch(new DisableAction(fromGridFailuresDetailFormReducer.INITIAL_STATE.controls.housenumber.id));
}
- public isAdressLoaded(): Observable<boolean> {
+ public isAddressLoaded(): Observable<boolean> {
return this.actionsSubject.pipe(
ofType(loadAddressCommunities.type),
map(item => true),
diff --git a/projects/grid-failure-information-app/src/app/shared/directives/form-validator.directive.ts b/projects/grid-failure-information-app/src/app/shared/directives/form-validator.directive.ts
index 1c96a27..c472937 100644
--- a/projects/grid-failure-information-app/src/app/shared/directives/form-validator.directive.ts
+++ b/projects/grid-failure-information-app/src/app/shared/directives/form-validator.directive.ts
@@ -27,7 +27,7 @@
export class FormValidatorDirective {
@Input() public ngrxFormControlState: FormControlState<any>;
- @HostBinding('class.ngrx-forms-invalid')
+ @HostBinding('class.ngrx-forms-invalid-directive')
get invalid(): boolean {
return this.ngrxFormControlState.isDisabled && !this.ngrxFormControlState.value;
}