File

components/event-parameters/event-parameters.component.ts

Description

Control panel form fields for GMM event parameters.

Implements

OnInit OnDestroy

Metadata

Index

Properties
Methods

Constructor

constructor(service: AppService)
Parameters :
Name Type Optional
service AppService No

Methods

ngOnDestroy
ngOnDestroy()
Returns : void
ngOnInit
ngOnInit()
Returns : void
Private onZHypCentered
onZHypCentered()
Returns : void

Properties

Private controls
Default value : this.form.controls
form
Default value : this.service.formGroup

Control panel form field state

MwCommonValues
Default value : MW_COMMON_VALUES

Common Vs30 values

MwMultiple$
Default value : this.service.formGroup.controls.multiSelectableParam.valueChanges.pipe( map( multiSelectableParam => multiSelectableParam.toString() === GmmFormControlIds.MW.toString(), ), )

Whether magnitudes are multi-selectable

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

Usage parameters

Private subs
Type : Subscription[]
Default value : []
import {AsyncPipe} from '@angular/common';
import {
  Component,
  computed,
  OnDestroy,
  OnInit,
  ViewEncapsulation,
} from '@angular/core';
import {ReactiveFormsModule} from '@angular/forms';
import {
  MatButtonToggle,
  MatButtonToggleGroup,
} from '@angular/material/button-toggle';
import {MatCheckbox} from '@angular/material/checkbox';
import {MatError, MatFormField, MatLabel} from '@angular/material/form-field';
import {MatInput} from '@angular/material/input';
import {
  GmmFormControlIds,
  MW_COMMON_VALUES,
  NshmpLibNgGmmMultiSelectComponent,
} from '@ghsc/nshmp-lib-ng/gmm';
import {combineLatest, Subscription} from 'rxjs';
import {map} from 'rxjs/operators';

import {AppService} from '../../services/app.service';

/**
 * Control panel form fields for GMM event parameters.
 */
@Component({
  encapsulation: ViewEncapsulation.None,
  imports: [
    NshmpLibNgGmmMultiSelectComponent,
    MatLabel,
    MatFormField,
    MatInput,
    MatError,
    MatButtonToggleGroup,
    MatButtonToggle,
    MatCheckbox,
    AsyncPipe,
    ReactiveFormsModule,
  ],
  selector: 'app-event-parameters',
  styleUrl: './event-parameters.component.scss',
  templateUrl: './event-parameters.component.html',
})
export class EventParametersComponent implements OnInit, OnDestroy {
  /** Common Vs30 values */
  MwCommonValues = MW_COMMON_VALUES;

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

  /** Whether magnitudes are multi-selectable */
  MwMultiple$ =
    this.service.formGroup.controls.multiSelectableParam.valueChanges.pipe(
      map(
        multiSelectableParam =>
          multiSelectableParam.toString() === GmmFormControlIds.MW.toString(),
      ),
    );

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

  private controls = this.form.controls;

  private subs: Subscription[] = [];

  constructor(private service: AppService) {}

  ngOnInit(): void {
    this.subs.push(
      combineLatest([
        this.controls.Mw.valueChanges,
        this.controls.rake.valueChanges,
        this.controls.rakeButton.valueChanges,
        this.controls.zHyp.valueChanges,
      ]).subscribe(() => this.service.resetState()),
    );

    this.subs.push(
      this.controls.zHypCentered.valueChanges.subscribe(() =>
        this.onZHypCentered(),
      ),
    );
  }

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

  private onZHypCentered(): void {
    if (this.form.getRawValue().zHypCentered) {
      this.controls.zHyp.disable();
    } else {
      this.controls.zHyp.enable();
    }

    this.service.calcHypocenterDepth(this.form);
  }
}
<!-- Event parameters -->
<div class="settings-subsection control-panel">
  <mat-label class="settings-subsection--label">Event Parameters</mat-label>

  <div class="settings-subsection--section">
    <div class="grid-row grid-gap-sm">
      <!-- Event parameters: Mw input -->
      <nshmp-lib-ng-gmm-multi-select
        class="grid-col-6 mw-input"
        label="M<sub>W</sub>"
        [multiple]="MwMultiple$ | async"
        [numberControl]="form.controls.Mw"
        [parameter]="parameters()?.Mw"
        placeholder="Select values..."
        [selectControl]="form.controls.MwMulti"
        [selectOptions]="MwCommonValues"
      />

      <!-- Event Parameters: Rake -->
      <mat-form-field class="grid-col-6 rake-input">
        <mat-label>Rake (°)</mat-label>
        <input
          matInput
          [max]="parameters()?.rake?.max"
          [min]="parameters()?.rake?.min"
          [formControl]="form.controls.rake"
          step="5"
          type="number"
          [value]="form?.controls?.rakeButton?.value"
        />
        <mat-error>
          [
          {{ parameters()?.rake?.min }},
          {{ parameters()?.rake?.max }}
          ]
        </mat-error>
      </mat-form-field>
    </div>

    <!-- Event Parameters: Rake Buttons -->
    <mat-button-toggle-group
      class="grid-col-12 rake-buttons"
      [formControl]="form.controls.rakeButton"
      [value]="form.controls.rake.value"
    >
      <mat-button-toggle class="grid-col-4" [value]="0">
        Strike-Slip
      </mat-button-toggle>
      <mat-button-toggle class="grid-col-4" [value]="-90">
        Normal
      </mat-button-toggle>
      <mat-button-toggle class="grid-col-4" [value]="90">
        Reverse
      </mat-button-toggle>
    </mat-button-toggle-group>

    <!-- Event Parameters: zHyp -->
    <div class="grid-row grid-gap-lg zhyp-input">
      <mat-form-field class="grid-col-4">
        <mat-label>Z<sub>HYP</sub> (km)</mat-label>
        <input
          matInput
          [max]="parameters()?.zHyp?.max"
          [min]="parameters()?.zHyp?.min"
          [formControl]="form.controls.zHyp"
          step="0.5"
          type="number"
        />
        <mat-error>
          [
          {{ parameters()?.zHyp?.min }},
          {{ parameters()?.zHyp?.max }}
          ]
        </mat-error>
      </mat-form-field>

      <!-- Event Parameters: centered down dip -->
      <div class="grid-col-8">
        <mat-checkbox
          class="down-dip-checkbox"
          [formControl]="form.controls.zHypCentered"
          color="primary"
        >
          Centered down-dip
        </mat-checkbox>
      </div>
    </div>
  </div>
</div>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""