diff --git a/projects/nshmp-apps/src/app/hazard/disagg/components/control-panel/control-panel.component.ts b/projects/nshmp-apps/src/app/hazard/disagg/components/control-panel/control-panel.component.ts index c0cbf2c383aab9cf9e5de22718d252148dfd690c..a90f7241df0dd1f7e9912b4bf019cb5689c0a826 100644 --- a/projects/nshmp-apps/src/app/hazard/disagg/components/control-panel/control-panel.component.ts +++ b/projects/nshmp-apps/src/app/hazard/disagg/components/control-panel/control-panel.component.ts @@ -159,10 +159,10 @@ export class ControlPanelComponent implements OnInit, OnDestroy { latitude: NaN, longitude: NaN, }); - this.form.controls.latitude.markAsPristine(); - this.form.controls.longitude.markAsPristine(); } + this.form.controls.latitude.markAsPristine(); + this.form.controls.longitude.markAsPristine(); this.service.resetState(); } diff --git a/projects/nshmp-apps/src/app/hazard/disagg/services/app.service.ts b/projects/nshmp-apps/src/app/hazard/disagg/services/app.service.ts index 3b407aaa20e6718291f267bf4d911e9dc55ab15a..5dc76643a087680dd652170e051b0439c8136f8d 100644 --- a/projects/nshmp-apps/src/app/hazard/disagg/services/app.service.ts +++ b/projects/nshmp-apps/src/app/hazard/disagg/services/app.service.ts @@ -8,7 +8,6 @@ import { hazardUtils, } from '@ghsc/nshmp-lib-ng/hazard'; import { - FormGroupControls, NshmpService, RETURN_PERIOD_BOUNDS, ReturnPeriod, @@ -58,7 +57,6 @@ export class AppService readonly formGroup = this.formBuilder.group<DisaggControlForm>( this.defaultFormValues() ); - readonly state = signal<AppState>(this.initialState()); constructor( @@ -223,10 +221,10 @@ export class AppService spinnerRef.close(); this.updateState({ - serviceCallInfo: this.serviceCallInfoFromResponse( - this.state(), - this.formGroup - ), + serviceCallInfo: { + ...this.state().serviceCallInfo, + serviceCalls: [url], + }, serviceResponse, }); @@ -280,13 +278,7 @@ export class AppService usageResponses, }); - this.updateState({ - serviceCallInfo: this.serviceCallInfoFromResponse( - this.state(), - this.formGroup - ), - }); - + this.updateUsageUrl(); this.initialFormSet(); }); } @@ -345,6 +337,7 @@ export class AppService serviceResponse: null, }); this.formGroup.controls.disaggComponent.disable(); + this.updateUsageUrl(); } /** @@ -554,38 +547,6 @@ export class AppService ); } - /** - * Returns the service call info. - * - * @param state The app state - */ - private serviceCallInfoFromResponse( - state: AppState, - form: FormGroupControls<DisaggControlForm> - ): ServiceCallInfo { - const model = form.getRawValue().model; - const service = state.nshmServices.find( - nshmService => nshmService.model === model - ); - - const serviceCalls: string[] = []; - const serviceUrl = `${service.url}${this.endpoint}`; - - if (state.serviceResponse !== null) { - const url = this.serviceEndpoint( - serviceUrl, - this.formGroup.getRawValue() - ); - serviceCalls.push(url); - } - - return { - ...state.serviceCallInfo, - serviceCalls, - usage: [serviceUrl], - }; - } - /** * Build the URL to call the appropriate backend service with the given values. * @@ -651,4 +612,17 @@ export class AppService }) .catch((error: Error) => this.nshmpService.throwError$(error)); } + + private updateUsageUrl() { + const nshmService = this.state().nshmServices.find( + nshm => nshm.model === this.formGroup.getRawValue().model + ); + + this.updateState({ + serviceCallInfo: { + ...this.state().serviceCallInfo, + usage: [nshmService.url], + }, + }); + } } diff --git a/projects/nshmp-apps/src/app/hazard/dynamic/components/control-panel/control-panel.component.ts b/projects/nshmp-apps/src/app/hazard/dynamic/components/control-panel/control-panel.component.ts index 32ffba8a78b8b4cd478f612ce0e942ba7ea40da3..134a9319b220adb80d3e938e96069b1bd5572d93 100644 --- a/projects/nshmp-apps/src/app/hazard/dynamic/components/control-panel/control-panel.component.ts +++ b/projects/nshmp-apps/src/app/hazard/dynamic/components/control-panel/control-panel.component.ts @@ -163,10 +163,10 @@ export class ControlPanelComponent implements OnInit, OnDestroy { latitude: NaN, longitude: NaN, }); - this.formGroup.controls.latitude.markAsPristine(); - this.formGroup.controls.longitude.markAsPristine(); } + this.formGroup.controls.latitude.markAsPristine(); + this.formGroup.controls.longitude.markAsPristine(); this.service.resetState(); } } diff --git a/projects/nshmp-apps/src/app/hazard/dynamic/services/app.service.ts b/projects/nshmp-apps/src/app/hazard/dynamic/services/app.service.ts index c591f841cefccea23565601c6c6deeb43b05f8a8..07a2865292a2e917caed9ce48fb673a4e7345b67 100644 --- a/projects/nshmp-apps/src/app/hazard/dynamic/services/app.service.ts +++ b/projects/nshmp-apps/src/app/hazard/dynamic/services/app.service.ts @@ -225,10 +225,10 @@ export class AppService this.updateState({ responseSpectra, - serviceCallInfo: this.serviceCallInfoFromResponse( - this.state(), - this.formGroup - ), + serviceCallInfo: { + ...this.state().serviceCallInfo, + serviceCalls: [url], + }, serviceResponse, }); @@ -280,13 +280,7 @@ export class AppService usageResponses, }); - this.updateState({ - serviceCallInfo: this.serviceCallInfoFromResponse( - this.state(), - this.formGroup - ), - }); - + this.updateUsageUrl(); this.initialFormSet(); }); } @@ -340,6 +334,7 @@ export class AppService }, serviceResponse: null, }); + this.updateUsageUrl(); } /** @@ -691,36 +686,6 @@ export class AppService }; } - /** - * Returns the service call info. - * - * @param state The app state - */ - private serviceCallInfoFromResponse( - state: AppState, - form: FormGroupControls<DynamicHazardControlForm> - ): ServiceCallInfo { - const values = form.getRawValue(); - const model = values.model; - const service = state.nshmServices.find( - nshmService => nshmService.model === model - ); - - const serviceCalls: string[] = []; - const serviceUrl = `${service.url}${this.serviceEndpoint}`; - - if (state.serviceResponse !== null) { - const url = this.createServiceEndpoint(serviceUrl, values); - serviceCalls.push(url); - } - - return { - ...state.serviceCallInfo, - serviceCalls, - usage: [serviceUrl], - }; - } - private updateUrl(): void { const values = this.formGroup.getRawValue(); @@ -732,4 +697,17 @@ export class AppService }) .catch((error: Error) => this.nshmpService.throwError$(error)); } + + private updateUsageUrl() { + const nshmService = this.state().nshmServices.find( + nshm => nshm.model === this.formGroup.getRawValue().model + ); + + this.updateState({ + serviceCallInfo: { + ...this.state().serviceCallInfo, + usage: [nshmService.url], + }, + }); + } } diff --git a/projects/nshmp-apps/src/app/hazard/static/components/control-panel/control-panel.component.ts b/projects/nshmp-apps/src/app/hazard/static/components/control-panel/control-panel.component.ts index 2ff87ead780ae523faf76c7acaa83f46d253ccbb..fef8496678eb31ce71d2fd1e81459fe5c907bb02 100644 --- a/projects/nshmp-apps/src/app/hazard/static/components/control-panel/control-panel.component.ts +++ b/projects/nshmp-apps/src/app/hazard/static/components/control-panel/control-panel.component.ts @@ -140,10 +140,10 @@ export class ControlPanelComponent implements OnInit, OnDestroy { latitude: NaN, longitude: NaN, }); - this.formGroup.controls.latitude.markAsPristine(); - this.formGroup.controls.longitude.markAsPristine(); } + this.formGroup.controls.latitude.markAsPristine(); + this.formGroup.controls.longitude.markAsPristine(); this.service.resetState(); } } diff --git a/projects/nshmp-apps/src/app/hazard/static/services/app.service.ts b/projects/nshmp-apps/src/app/hazard/static/services/app.service.ts index 35e6403c0c23eb164c25a965cd4af14dc3fa55f1..4b74f773e5aa28c11358c9736a33f730694607e6 100644 --- a/projects/nshmp-apps/src/app/hazard/static/services/app.service.ts +++ b/projects/nshmp-apps/src/app/hazard/static/services/app.service.ts @@ -226,10 +226,10 @@ export class AppService serviceResponse, this.formGroup ), - serviceCallInfo: this.serviceCallInfoFromResponse( - this.state(), - this.formGroup - ), + serviceCallInfo: { + ...this.state().serviceCallInfo, + serviceCalls: [url], + }, serviceResponse, }); @@ -296,13 +296,7 @@ export class AppService usageResponses, }); - this.updateState({ - serviceCallInfo: this.serviceCallInfoFromResponse( - this.state(), - this.formGroup - ), - }); - + this.updateUsageUrl(); this.initialFormSet(); }); } @@ -356,6 +350,8 @@ export class AppService }, serviceResponse: null, }); + + this.updateUsageUrl(); } /** @@ -794,36 +790,6 @@ export class AppService }; } - /** - * Returns the service call info. - * - * @param state The app state - */ - private serviceCallInfoFromResponse( - state: AppState, - formGroup: FormGroupControls<HazardControlForm> - ): ServiceCallInfo { - const values = formGroup.getRawValue(); - const model = values.model; - const service = state.nshmServices.find( - nshmService => nshmService.model === model - ); - - const serviceCalls: string[] = []; - const serviceUrl = `${service.url}${this.serviceEndpoint}`; - - if (state.serviceResponse !== null) { - const url = this.createServiceEndpoint(serviceUrl, values); - serviceCalls.push(url); - } - - return { - ...state.serviceCallInfo, - serviceCalls, - usage: [serviceUrl], - }; - } - /** * Returns the static service associated with a model * @@ -848,4 +814,17 @@ export class AppService }) .catch((error: Error) => this.nshmpService.throwError$(error)); } + + private updateUsageUrl() { + const nshmService = this.state().nshmServices.find( + nshm => nshm.model === this.formGroup.getRawValue().model + ); + + this.updateState({ + serviceCallInfo: { + ...this.state().serviceCallInfo, + usage: [nshmService.url], + }, + }); + } } diff --git a/projects/nshmp-apps/src/app/source/mfd/services/app.service.ts b/projects/nshmp-apps/src/app/source/mfd/services/app.service.ts index fcab215b7292b1a3868f572fe7a855160e14da11..a7dc09077edf806a202b4fa1f87775f83a23a861 100644 --- a/projects/nshmp-apps/src/app/source/mfd/services/app.service.ts +++ b/projects/nshmp-apps/src/app/source/mfd/services/app.service.ts @@ -212,10 +212,10 @@ export class AppService spinnerRef.close(); this.updateState({ - serviceCallInfo: this.serviceCallInfoFromResponse( - this.state(), - this.formGroup - ), + serviceCallInfo: { + ...this.state().serviceCallInfo, + serviceCalls: [url], + }, serviceResponse, }); @@ -353,13 +353,7 @@ export class AppService usageResponses, }); - this.updateState({ - serviceCallInfo: this.serviceCallInfoFromResponse( - this.state(), - this.formGroup - ), - }); - + this.updateUsageUrl(); this.initialFormSet(); }); } @@ -420,6 +414,8 @@ export class AppService if (this.formGroup.getRawValue().mfdType !== null) { this.formGroup.controls.mfdType.setValue(null); } + + this.updateUsageUrl(); } updateState(state: Partial<AppState>): void { @@ -755,37 +751,6 @@ export class AppService return plots; } - /** - * Returns the service call info. - * - * @param state The app state - */ - private serviceCallInfoFromResponse( - state: AppState, - formGroup: FormGroupControls<ControlForm> - ): ServiceCallInfo { - const values = formGroup.getRawValue(); - - const service = state.nshmServices.find( - nshmService => nshmService.model === values.model - ); - - const serviceCalls: string[] = []; - const usageUrl = `${service.url}${this.usageEndpoint}`; - - if (state.serviceResponse !== null) { - const serviceUrl = `${service.url}${this.serviceEndpoint}`; - const url = this.createServiceEndpoint(serviceUrl, values); - serviceCalls.push(url); - } - - return { - ...state.serviceCallInfo, - serviceCalls, - usage: [usageUrl], - }; - } - /** * Returns the logic tree plot data. * @@ -939,4 +904,17 @@ export class AppService }) .catch((error: Error) => this.nshmpService.throwError$(error)); } + + private updateUsageUrl() { + const nshmService = this.state().nshmServices.find( + nshm => nshm.model === this.formGroup.getRawValue().model + ); + + this.updateState({ + serviceCallInfo: { + ...this.state().serviceCallInfo, + usage: [nshmService.url], + }, + }); + } }