File

components/control-panel/control-panel.component.ts

Description

Control panel form fields and buttons to call GMM vs magnitude service.

Implements

OnInit OnDestroy

Metadata

Index

Properties
Methods

Constructor

constructor(service: AppService, nshmpService: NshmpService)
Parameters :
Name Type Optional
service AppService No
nshmpService NshmpService No

Methods

ngOnDestroy
ngOnDestroy()
Returns : void
ngOnInit
ngOnInit()
Returns : void
Private onGmmSource
onGmmSource()
Returns : void
Private onMultiSelectableParam
onMultiSelectableParam()
Returns : void
Private onShowEpistemicUncertainty
onShowEpistemicUncertainty()
Returns : void
onSubmit
onSubmit()

On form submit.

Returns : void

Properties

controls
Default value : this.service.formGroup.controls

Form controls state

form
Default value : this.service.formGroup

Control panel form field state

gmmSelected
Default value : this.controls.gmmSource.getRawValue()?.length > 0

Whether a GMM has been selected

parameters
Default value : computed(() => this.service.usage()?.response.parameters)

Usage parameters

Public service
Type : AppService
serviceCallInfo
Default value : this.service.serviceCallInfo

Service call info state

Private subs
Type : Subscription[]
Default value : []
supportedImts
Default value : this.service.supportedImts

Supported IMTs based on GMMs selected

import {Component, computed, OnDestroy, OnInit} from '@angular/core';
import {ReactiveFormsModule} from '@angular/forms';
import {MatOption} from '@angular/material/core';
import {MatFormField, MatLabel} from '@angular/material/form-field';
import {MatSelect} from '@angular/material/select';
import {
  gmmUtils,
  MultiSelectableParam,
  NshmpLibNgGmmMenuComponent,
  NshmpLibNgGmmMultiParamMenuComponent,
  NshmpLibNgGmmPlotOptionsControlPanelComponent,
} from '@ghsc/nshmp-lib-ng/gmm';
import {
  NshmpLibNgControlPanelButtonsComponent,
  NshmpService,
} from '@ghsc/nshmp-lib-ng/nshmp';
import {Subscription} from 'rxjs';

import {AppService} from '../../services/app.service';
import {EventParametersComponent} from '../event-parameters/event-parameters.component';
import {PathParametersComponent} from '../path-parameters/path-parameters.component';
import {SiteParametersComponent} from '../site-parameters/site-parameters.component';
import {SourceParametersComponent} from '../source-parameters/source-parameters.component';

/**
 * Control panel form fields and buttons to call GMM vs magnitude service.
 */
@Component({
  imports: [
    NshmpLibNgGmmMenuComponent,
    NshmpLibNgGmmPlotOptionsControlPanelComponent,
    NshmpLibNgControlPanelButtonsComponent,
    NshmpLibNgGmmMultiParamMenuComponent,
    MatFormField,
    MatLabel,
    MatSelect,
    MatOption,
    EventParametersComponent,
    SourceParametersComponent,
    PathParametersComponent,
    SiteParametersComponent,
    ReactiveFormsModule,
  ],
  selector: 'app-control-panel',
  styleUrl: './control-panel.component.scss',
  templateUrl: './control-panel.component.html',
})
export class ControlPanelComponent implements OnInit, OnDestroy {
  /** Form controls state */
  controls = this.service.formGroup.controls;

  /** Control panel form field state */
  form = this.service.formGroup;

  /** Whether a GMM has been selected */
  gmmSelected = this.controls.gmmSource.getRawValue()?.length > 0;

  /** Usage parameters */
  parameters = computed(() => this.service.usage()?.response.parameters);

  /** Service call info state */
  serviceCallInfo = this.service.serviceCallInfo;

  /** Supported IMTs based on GMMs selected */
  supportedImts = this.service.supportedImts;

  private subs: Subscription[] = [];

  constructor(
    public service: AppService,
    private nshmpService: NshmpService,
  ) {}

  ngOnInit(): void {
    this.subs.push(
      this.controls.gmmSource.valueChanges.subscribe(() => {
        this.onGmmSource();
      }),
    );

    this.subs.push(
      this.controls.multiSelectableParam.valueChanges.subscribe(() =>
        this.onMultiSelectableParam(),
      ),
    );

    this.subs.push(
      this.controls.showEpistemicUncertainty.valueChanges.subscribe(() =>
        this.onShowEpistemicUncertainty(),
      ),
    );

    this.subs.push(
      this.controls.imt.valueChanges.subscribe(() => this.service.resetState()),
    );
  }

  ngOnDestroy(): void {
    this.subs.forEach(sub => sub?.unsubscribe());
  }

  /**
   * On form submit.
   */
  onSubmit(): void {
    this.service.callService();
    this.nshmpService.selectPlotControl();
  }

  private onGmmSource() {
    const formValues = this.form.getRawValue();

    if (
      !this.service.state().usageResponse ||
      formValues.gmmSource.length === 0
    ) {
      this.controls.imt.patchValue(gmmUtils.imtPlaceHolder().value);
      this.service.updateState({
        supportedImts: [],
      });
      return;
    }

    const supportedImts = gmmUtils.getSupportedImts(
      formValues.gmmSource,
      this.service.state().usageResponse,
    );

    this.service.updateState({
      supportedImts,
    });

    const imt = [...supportedImts].shift();

    this.controls.imt.patchValue(imt?.value);
    this.service.resetState();
  }

  private onMultiSelectableParam(): void {
    if (!this.service.state().usageResponse) {
      return;
    }

    const {multiSelectableParam} = this.form.getRawValue();
    const parameters = this.service.state().usageResponse.response.parameters;

    if (multiSelectableParam === MultiSelectableParam.VS30) {
      this.controls.vs30.setValue(parameters.vs30.value as number);
      this.controls.gmmSource.setValue([]);
      this.controls.gmmSource.markAsPristine();
    }

    this.controls.vs30Multi.setValue([]);
    this.controls.imt.setValue(this.service.defaultFormValues().imt);
    this.service.resetState();
  }

  private onShowEpistemicUncertainty(): void {
    this.service.createPlots();
  }
}
<!-- Ground Motion vs. Magnitude Conrol Panel -->
<form
  class="settings-section control-panel height-full overflow-auto"
  [formGroup]="form"
  (submit)="onSubmit()"
  novalidate
>
  <nshmp-lib-ng-gmm-multi-param-menu
    [multiParamControl]="controls.multiSelectableParam"
    [showMw]="false"
  />

  <!-- GMM menu -->
  @if (parameters()) {
    <nshmp-lib-ng-gmm-menu
      [gmmControl]="controls.gmmSource"
      [gmmGroupTypeControl]="controls.gmmGroupType"
      [multiple]="controls.multiSelectableParam.value === 'gmm'"
      [parameters]="parameters()"
      [imtControl]="controls.imt"
      [supportedImts]="supportedImts()"
    />
  }

  <!-- IMT select menu -->
  <mat-form-field class="grid-col-12 imt-select">
    <mat-label>Intensity Measure Type</mat-label>
    <mat-select #imtSelectEl [formControl]="controls.imt">
      @if (gmmSelected === false) {
        <mat-option selected="true" value="default">
          --- Choose a GMM ---
        </mat-option>
      }
      @for (imt of supportedImts(); track imt) {
        <mat-option [value]="imt.value">
          {{ imt.display }}
        </mat-option>
      }
    </mat-select>
  </mat-form-field>

  <app-event-parameters />

  <app-source-parameters />

  <app-path-parameters />

  <app-site-parameters />

  <nshmp-lib-ng-gmm-plot-options-control-panel
    [showEpistemicFormControl]="controls?.showEpistemicUncertainty"
  />

  <div class="padding-y-3"></div>

  <nshmp-lib-ng-control-panel-buttons
    [plotDisabled]="form.invalid"
    [serviceCallInfo]="serviceCallInfo()"
    [resetDisabled]="form.pristine"
    (resetClick)="service.resetControlPanel()"
  />
</form>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""