components/path-parameters/path-parameters.component.ts
Control panel form fields for GMM path parameters.
OnInit
OnDestroy
selector | app-path-parameters |
imports |
MatLabel
MatFormField
MatInput
MatError
MatCheckbox
MatButtonToggleGroup
MatButtonToggle
ReactiveFormsModule
|
templateUrl | ./path-parameters.component.html |
styleUrl | ./path-parameters.component.scss |
Properties |
|
Methods |
|
constructor(service: AppService)
|
||||||
Parameters :
|
ngOnDestroy |
ngOnDestroy()
|
Returns :
void
|
ngOnInit |
ngOnInit()
|
Returns :
void
|
Private onDerivePathParams |
onDerivePathParams()
|
Returns :
void
|
Private onHangingWall |
onHangingWall()
|
Returns :
void
|
Private onRx |
onRx()
|
Returns :
void
|
Private controls |
Default value : this.form.controls
|
form |
Default value : this.service.formGroup
|
Control panel form field state |
parameters |
Default value : computed(() => this.service.usage()?.response.parameters)
|
Usage parameters |
subs |
Type : Subscription[]
|
Default value : []
|
import {Component, computed, OnDestroy, OnInit} 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 {Subscription} from 'rxjs';
import {AppService} from '../../services/app.service';
/**
* Control panel form fields for GMM path parameters.
*/
@Component({
imports: [
MatLabel,
MatFormField,
MatInput,
MatError,
MatCheckbox,
MatButtonToggleGroup,
MatButtonToggle,
ReactiveFormsModule,
],
selector: 'app-path-parameters',
styleUrl: './path-parameters.component.scss',
templateUrl: './path-parameters.component.html',
})
export class PathParametersComponent implements OnInit, OnDestroy {
/** Control panel form field state */
form = this.service.formGroup;
/** Usage parameters */
parameters = computed(() => this.service.usage()?.response.parameters);
subs: Subscription[] = [];
private controls = this.form.controls;
constructor(private service: AppService) {}
ngOnInit(): void {
this.subs.push(this.controls.rX.valueChanges.subscribe(() => this.onRx()));
this.subs.push(
this.controls.derivePathParams.valueChanges.subscribe(() =>
this.onDerivePathParams(),
),
);
this.subs.push(
this.controls.hangingWall.valueChanges.subscribe(() =>
this.onHangingWall(),
),
);
}
ngOnDestroy(): void {
this.subs.forEach(sub => sub.unsubscribe());
}
private onDerivePathParams(): void {
const {derivePathParams, hangingWall, rX} = this.form.getRawValue();
if (derivePathParams) {
if (rX >= 0 !== hangingWall) {
this.controls.hangingWall.setValue(rX >= 0);
}
this.controls.hangingWall.enable();
this.controls.rJB.disable();
this.controls.rRup.disable();
this.service.calcPathParameters(this.form);
} else {
this.controls.hangingWall.setValue(null);
this.controls.hangingWall.disable();
this.controls.rJB.enable();
this.controls.rRup.enable();
}
this.service.resetState();
}
private onHangingWall(): void {
const values = this.form.getRawValue();
const rX = values.hangingWall ? Math.abs(values.rX) : -Math.abs(values.rX);
if (values.rX !== rX) {
this.controls.rX.setValue(rX);
}
this.service.calcPathParameters(this.form);
this.service.resetState();
}
private onRx(): void {
const {derivePathParams, hangingWall, rX} = this.form.getRawValue();
if (derivePathParams && rX >= 0 !== hangingWall) {
this.controls.hangingWall.patchValue(rX >= 0);
}
this.service.calcPathParameters(this.form);
this.service.resetState();
}
}
<!-- Path Parameters -->
<div class="settings-subsection control-panel">
<mat-label class="settings-subsection--label">Path Parameters</mat-label>
<div class="settings-subsection--section">
<div class="grid-row grid-gap-sm">
<!-- Path Parameters: rX input -->
<mat-form-field class="grid-col-4 rx-input">
<mat-label>R<sub>X</sub> (km)</mat-label>
<input
matInput
[max]="parameters()?.rX?.max"
[min]="parameters()?.rX?.min"
[formControl]="form.controls.rX"
step="0.5"
type="number"
/>
<mat-error>
[
{{ parameters()?.rX?.min }},
{{ parameters()?.rX?.max }}
]
</mat-error>
</mat-form-field>
<!-- Path Parameters: rRup input -->
<mat-form-field class="grid-col-4 rrup-input">
<mat-label>R<sub>RUP</sub> (km)</mat-label>
<input
matInput
[max]="parameters()?.rRup?.max"
[min]="parameters()?.rRup?.min"
[formControl]="form.controls.rRup"
step="0.5"
type="number"
/>
<mat-error>
[
{{ parameters()?.rRup?.min }},
{{ parameters()?.rRup?.max }}
]
</mat-error>
</mat-form-field>
<!-- Path Parameters: rJB input -->
<mat-form-field class="grid-col-4 rjb-input">
<mat-label>R<sub>JB</sub> (km)</mat-label>
<input
matInput
[max]="parameters()?.rJB?.max"
[min]="parameters()?.rJB?.min"
[formControl]="form.controls.rJB"
step="0.5"
type="number"
/>
<mat-error>
[
{{ parameters()?.rJB?.min }},
{{ parameters()?.rJB?.max }}
]
</mat-error>
</mat-form-field>
</div>
<!-- Path Parameters: Derive rJB and rRup -->
<div class="grid-row">
<mat-checkbox
class="grid-col-12 rjb-rrup-checkbox"
color="primary"
[formControl]="form.controls.derivePathParams"
>
Derive R<sub>JB</sub> and R<sub>RUP</sub>
</mat-checkbox>
</div>
<!-- Path Parameters: Hanging wall or footwall -->
<mat-button-toggle-group
class="grid-col-12 hanging-wall-button"
[formControl]="form.controls.hangingWall"
>
<mat-button-toggle class="grid-col-6" [value]="true">
Hanging Wall
</mat-button-toggle>
<mat-button-toggle class="grid-col-6" [value]="false">
Footwall
</mat-button-toggle>
</mat-button-toggle-group>
</div>
</div>