Skip to content
Snippets Groups Projects
Commit aa0ddab1 authored by Clayton, Brandon Scott's avatar Clayton, Brandon Scott
Browse files

Merge branch 'rates--service-calls' into 'main'

Rates  app:  service calls

See merge request !519
parents 61073240 b2bd9061
No related branches found
No related tags found
1 merge request!519Rates app: service calls
Pipeline #511921 passed with warnings
import {Component, computed, Signal} from '@angular/core'; import {Component, computed, OnDestroy, OnInit, Signal} from '@angular/core';
import {ReactiveFormsModule} from '@angular/forms'; import {ReactiveFormsModule} from '@angular/forms';
import {MatFormFieldModule} from '@angular/material/form-field'; import {MatFormFieldModule} from '@angular/material/form-field';
import {MatInputModule} from '@angular/material/input'; import {MatInputModule} from '@angular/material/input';
...@@ -13,6 +13,7 @@ import { ...@@ -13,6 +13,7 @@ import {
import {NshmpLibNgControlPanelButtonsComponent} from '@ghsc/nshmp-lib-ng/nshmp'; import {NshmpLibNgControlPanelButtonsComponent} from '@ghsc/nshmp-lib-ng/nshmp';
import {Location} from '@ghsc/nshmp-utils-ts/libs/nshmp-lib/geo'; import {Location} from '@ghsc/nshmp-utils-ts/libs/nshmp-lib/geo';
import {environment} from 'projects/nshmp-apps/src/environments/environment'; import {environment} from 'projects/nshmp-apps/src/environments/environment';
import {Subscription} from 'rxjs';
import {AppService} from '../../services/app.service'; import {AppService} from '../../services/app.service';
...@@ -31,7 +32,7 @@ import {AppService} from '../../services/app.service'; ...@@ -31,7 +32,7 @@ import {AppService} from '../../services/app.service';
styleUrl: './control-panel.component.scss', styleUrl: './control-panel.component.scss',
templateUrl: './control-panel.component.html', templateUrl: './control-panel.component.html',
}) })
export class ControlPanelComponent { export class ControlPanelComponent implements OnInit, OnDestroy {
formGroup = this.service.formGroup; formGroup = this.service.formGroup;
/** Data for select site component */ /** Data for select site component */
...@@ -54,8 +55,58 @@ export class ControlPanelComponent { ...@@ -54,8 +55,58 @@ export class ControlPanelComponent {
parameters = computed(() => this.service.usage()?.response); parameters = computed(() => this.service.usage()?.response);
private subs: Subscription[] = [];
constructor(public service: AppService) {} constructor(public service: AppService) {}
ngOnInit(): void {
const controls = this.formGroup.controls;
this.subs.push(
controls.model.valueChanges.subscribe(() => this.onModelChange())
);
this.subs.push(
controls.latitude.valueChanges.subscribe(() => this.service.resetState())
);
this.subs.push(
controls.longitude.valueChanges.subscribe(() => this.service.resetState())
);
this.subs.push(
controls.distance.valueChanges.subscribe(() => this.service.resetState())
);
this.subs.push(
controls.timespan.valueChanges.subscribe(() => this.service.resetState())
);
}
ngOnDestroy(): void {
this.subs.forEach(sub => sub.unsubscribe());
}
private onModelChange(): void {
const {latitude, longitude} = this.formGroup.getRawValue();
const latitudeBounds = this.service.usage().response.latitude;
const longitudeBounds = this.service.usage().response.longitude;
if (
!(
latitude >= latitudeBounds.min &&
latitude <= latitudeBounds.max &&
longitude >= longitudeBounds.min &&
longitude <= longitudeBounds.max
)
) {
this.formGroup.patchValue({
latitude: null,
longitude: null,
});
}
this.formGroup.controls.latitude.markAsPristine();
this.formGroup.controls.longitude.markAsPristine();
this.service.resetState();
}
onSubmit(): void { onSubmit(): void {
this.service.callService(); this.service.callService();
} }
......
...@@ -160,6 +160,12 @@ export class AppService ...@@ -160,6 +160,12 @@ export class AppService
) )
.subscribe(([rateResponse, probabilityResponse]) => { .subscribe(([rateResponse, probabilityResponse]) => {
this.handleServiceResponse(rateResponse, probabilityResponse); this.handleServiceResponse(rateResponse, probabilityResponse);
this.updateState({
serviceCallInfo: {
...this.state().serviceCallInfo,
serviceCalls: [rateUrl, probUrl],
},
});
spinnerRef.close(); spinnerRef.close();
}); });
} }
...@@ -266,6 +272,7 @@ export class AppService ...@@ -266,6 +272,7 @@ export class AppService
usageResponses, usageResponses,
}); });
this.updateUsageUrl();
this.initialFormSet(); this.initialFormSet();
}); });
} }
...@@ -310,6 +317,7 @@ export class AppService ...@@ -310,6 +317,7 @@ export class AppService
serviceCalls: [], serviceCalls: [],
}, },
}); });
this.updateUsageUrl();
} }
/** /**
...@@ -459,6 +467,15 @@ export class AppService ...@@ -459,6 +467,15 @@ export class AppService
.catch((error: Error) => this.nshmpService.throwError$(error)); .catch((error: Error) => this.nshmpService.throwError$(error));
} }
private updateUsageUrl(): void {
this.updateState({
serviceCallInfo: {
...this.state().serviceCallInfo,
usage: [`${this.nshmService().url}${this.probabilityEndpoint}`],
},
});
}
/** /**
* Determine the X axis range from rate and probability magnitudes. * Determine the X axis range from rate and probability magnitudes.
* *
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment