components/control-panel/control-panel.component.ts
Control panel with form fields to call disagg service.
Handles disagg service with return period and imt.
OnInit
OnDestroy
selector | app-control-panel |
imports |
NshmpLibNgHazardModelFormComponent
NshmpLibNgHazardLocationFormComponent
NshmpLibNgMapSelectSiteComponent
NshmpLibNgHazardSiteClassFormComponent
NshmpLibNgControlPanelButtonsComponent
NshmpLibNgHazardReturnPeriodFormComponent
NshmpLibNgControlPanelButtonsComponent
MatFormField
MatLabel
MatSelect
MatOption
MatRadioGroup
MatRadioButton
MatInput
MatError
MatCheckbox
ReactiveFormsModule
|
templateUrl | ./control-panel.component.html |
styleUrl | ./control-panel.component.scss |
Properties |
|
Methods |
|
constructor(service: AppService, nshmpService: NshmpService)
|
|||||||||
Parameters :
|
ngOnDestroy |
ngOnDestroy()
|
Returns :
void
|
ngOnInit |
ngOnInit()
|
Returns :
void
|
Private onModelChange |
onModelChange()
|
Returns :
void
|
onSubmit |
onSubmit()
|
On form submit.
Returns :
void
|
DisaggTarget |
Default value : DisaggTarget
|
Disaggregation target enum |
form |
Default value : this.service.formGroup
|
Form fields state |
imlRange |
Default value : computed(() => {
const usage = this.service.usage();
if (usage) {
return usage.response.iml.range[this.form.getRawValue().imt];
}
})
|
IML range from usage, based on IMT value |
Public service |
Type : AppService
|
serviceCallInfo |
Default value : this.service.serviceCallInfo
|
Service call info state |
siteClasses |
Default value : computed(
() => this.service.usage()?.response.model.siteClasses,
)
|
The site classes |
sourceModel |
Default value : computed(() => this.service.usage()?.response?.model)
|
Source model info from usage |
Private subs |
Type : Subscription[]
|
Default value : []
|
import {Component, computed, OnDestroy, OnInit, Signal} from '@angular/core';
import {ReactiveFormsModule} from '@angular/forms';
import {MatCheckbox} from '@angular/material/checkbox';
import {MatOption} from '@angular/material/core';
import {MatError, MatFormField, MatLabel} from '@angular/material/form-field';
import {MatInput} from '@angular/material/input';
import {MatRadioButton, MatRadioGroup} from '@angular/material/radio';
import {MatSelect} from '@angular/material/select';
import {
DisaggTarget,
NshmpLibNgHazardLocationFormComponent,
NshmpLibNgHazardModelFormComponent,
NshmpLibNgHazardReturnPeriodFormComponent,
NshmpLibNgHazardSiteClassFormComponent,
} from '@ghsc/nshmp-lib-ng/hazard';
import {
NshmpLibNgMapSelectSiteComponent,
SelectSiteDialogData,
} from '@ghsc/nshmp-lib-ng/map';
import {
NshmpLibNgControlPanelButtonsComponent,
NshmpService,
} from '@ghsc/nshmp-lib-ng/nshmp';
import {environment} from 'projects/nshmp-apps/src/environments/environment';
import {combineLatest, Subscription} from 'rxjs';
import {AppService} from '../../services/app.service';
/**
* Control panel with form fields to call disagg service.
*
* Handles disagg service with return period and imt.
*/
@Component({
imports: [
NshmpLibNgHazardModelFormComponent,
NshmpLibNgHazardLocationFormComponent,
NshmpLibNgMapSelectSiteComponent,
NshmpLibNgHazardSiteClassFormComponent,
NshmpLibNgControlPanelButtonsComponent,
NshmpLibNgHazardReturnPeriodFormComponent,
NshmpLibNgControlPanelButtonsComponent,
MatFormField,
MatLabel,
MatSelect,
MatOption,
MatRadioGroup,
MatRadioButton,
MatInput,
MatError,
MatCheckbox,
ReactiveFormsModule,
],
selector: 'app-control-panel',
styleUrl: './control-panel.component.scss',
templateUrl: './control-panel.component.html',
})
export class ControlPanelComponent implements OnInit, OnDestroy {
/** Disaggregation target enum */
DisaggTarget = DisaggTarget;
/** Form fields state */
form = this.service.formGroup;
/** IML range from usage, based on IMT value */
imlRange = computed(() => {
const usage = this.service.usage();
if (usage) {
return usage.response.iml.range[this.form.getRawValue().imt];
}
});
/** Data for select site component */
selectSiteData: Signal<SelectSiteDialogData> = computed(() => {
const usage = this.service.usage();
const nshmService = this.service.nshmService();
if (usage === null) {
return;
}
const services = environment.webServices.nshmpHazWs.services.curveServices;
return {
mapUrl: `${nshmService.url}${services.map}?raw=true`,
sitesUrl: `${nshmService.url}${services.sites}?raw=true`,
};
});
/** Service call info state */
serviceCallInfo = this.service.serviceCallInfo;
/** The site classes */
siteClasses = computed(
() => this.service.usage()?.response.model.siteClasses,
);
/** Source model info from usage */
sourceModel = computed(() => this.service.usage()?.response?.model);
private subs: Subscription[] = [];
constructor(
public service: AppService,
private nshmpService: NshmpService,
) {}
ngOnInit(): void {
const controls = this.form.controls;
this.subs.push(
controls.disaggTarget.valueChanges.subscribe(() => {
this.service.onDisaggTarget();
this.service.resetState();
}),
);
this.subs.push(
controls.model.valueChanges.subscribe(() => this.onModelChange()),
);
this.subs.push(
combineLatest([
controls.iml.valueChanges,
controls.imt.valueChanges,
controls.latitude.valueChanges,
controls.longitude.valueChanges,
controls.returnPeriod.valueChanges,
controls.vs30.valueChanges,
]).subscribe(() => {
this.service.resetState();
}),
);
}
ngOnDestroy(): void {
this.subs.forEach(sub => sub?.unsubscribe());
}
private onModelChange(): void {
const {latitude, longitude} = this.form.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.form.patchValue({
latitude: NaN,
longitude: NaN,
});
}
this.form.controls.latitude.markAsPristine();
this.form.controls.longitude.markAsPristine();
this.service.resetState();
}
/**
* On form submit.
*/
onSubmit(): void {
this.service.callService();
this.nshmpService.selectPlotControl();
}
}
<!-- Control Panel -->
<form
class="height-full overflow-auto"
[formGroup]="form"
(submit)="onSubmit()"
>
<!-- Model -->
<nshmp-lib-ng-hazard-model-form
[modelControl]="form.controls.model"
[models]="service.availableModels()"
/>
@if (service.usage()) {
<!-- Latitude -->
<nshmp-lib-ng-hazard-location-form
class="latitude-input"
[locationControl]="form.controls.latitude"
label="Latitude"
[bounds]="service.usage()?.response?.latitude"
/>
<!-- Longitude -->
<nshmp-lib-ng-hazard-location-form
class="longitude-input"
[locationControl]="form.controls.longitude"
label="Longitude"
[bounds]="service.usage()?.response?.longitude"
/>
}
<!-- Select site -->
<nshmp-lib-ng-map-select-site
[data]="selectSiteData()"
(siteSelect)="service.setLocation($event)"
/>
<!-- Site Class -->
<div class="grid-row grid-gap-sm">
<!-- Site classes -->
@if (siteClasses()) {
<nshmp-lib-ng-hazard-site-class-form
[siteClassControl]="form.controls.siteClass"
[siteClasses]="siteClasses()"
[vs30Control]="form.controls.vs30"
[vs30Bounds]="service.usage()?.response?.vs30"
/>
}
</div>
<!-- Imt -->
<mat-form-field class="grid-col-12 imt-select">
<mat-label> Intensity Measure Type </mat-label>
<mat-select [formControl]="form.controls.imt">
@for (imt of sourceModel()?.imts; track imt) {
<mat-option [value]="imt?.value">
{{ imt?.display }}
</mat-option>
}
</mat-select>
</mat-form-field>
<!-- Disagg target -->
<div class="display-flex">
<!-- Target selector -->
<div class="disagg-target-selector">
<mat-radio-group [formControl]="form.controls.disaggTarget">
<mat-radio-button
[value]="DisaggTarget.RETURN_PERIOD"
aria-label="Select return period"
/>
<mat-radio-button [value]="DisaggTarget.IML" aria-label="Select IML" />
</mat-radio-group>
</div>
<div class="grid-col-12">
<!-- Return Period Controls -->
<div class="disagg-target-return-period">
<nshmp-lib-ng-hazard-return-period-form
[returnPeriodControl]="form.controls.returnPeriod"
[commonReturnPeriodControl]="form.controls.commonReturnPeriods"
/>
</div>
<!-- IML controls -->
<div class="disagg-target-iml">
<div class="grid-row grid-gap-sm">
<mat-form-field class="grid-col-6">
<mat-label>
Intensity Measure Level ({{ imlRange()?.units }})
</mat-label>
<input
type="number"
matInput
[formControl]="form.controls.iml"
[min]="imlRange()?.min"
[max]="imlRange()?.max"
step="any"
/>
<mat-error>
[{{ imlRange()?.min }}, {{ imlRange()?.max }}]
</mat-error>
</mat-form-field>
<div class="grid-col-6 center-y">
<mat-checkbox
class="padding-left-1"
[formControl]="form.controls.maxDirection"
>
Max Direction
</mat-checkbox>
</div>
</div>
</div>
</div>
</div>
<nshmp-lib-ng-control-panel-buttons
[plotDisabled]="form.invalid"
[serviceCallInfo]="serviceCallInfo()"
[resetDisabled]="form.pristine"
(resetClick)="service.resetControlPanel()"
/>
</form>