components/disagg-summary/disagg-summary.component.ts
Lists of disaggregation summaries from service response.
selector | app-disagg-summary |
imports |
MatButton
MatDivider
MatList
MatListItem
|
templateUrl | ./disagg-summary.component.html |
styleUrl | ./disagg-summary.component.scss |
Properties |
|
Methods |
Inputs |
constructor(service: AppService)
|
||||||
Parameters :
|
componentData | |
Required : true | |
Disaggregation component data state |
showExportButton | |
Default value : true
|
|
dataValue | ||||||||
dataValue(data: number | string)
|
||||||||
Format data.
Parameters :
Returns :
string | number
|
Readonly componentData |
Disaggregation component data state |
form |
Default value : this.service.formGroup
|
Form field state |
Public service |
Type : AppService
|
Readonly showExportButton |
Default value : true
|
import {Component, input} from '@angular/core';
import {MatButton} from '@angular/material/button';
import {MatDivider} from '@angular/material/divider';
import {MatList, MatListItem} from '@angular/material/list';
import {DisaggComponentData} from '@ghsc/nshmp-utils-ts/libs/nshmp-haz/www/disagg-service';
import {AppService} from '../../services/app.service';
/**
* Lists of disaggregation summaries from service response.
*/
@Component({
imports: [MatButton, MatDivider, MatList, MatListItem],
selector: 'app-disagg-summary',
styleUrl: './disagg-summary.component.scss',
templateUrl: './disagg-summary.component.html',
})
export class DisaggSummaryComponent {
/** Disaggregation component data state */
readonly componentData = input.required<DisaggComponentData>();
readonly showExportButton = input(true);
/** Form field state */
form = this.service.formGroup;
constructor(public service: AppService) {}
/**
* Format data.
*
* @param data The data
*/
dataValue(data: number | string) {
if (typeof data === 'number' && data.toString().includes('.')) {
const split = data.toString().split('.');
if (split[0].length === 1 && split[1].length > 4) {
data = data.toExponential(3);
}
}
return data;
}
}
@if (componentData()) {
<div class="disagg-summaries">
<!-- Summaries -->
<div class="summary-group">
@if (showExportButton()) {
<div class="print-display-none">
<button
mat-raised-button
color="primary"
(click)="service.saveSummary(componentData(), form.getRawValue())"
>
Export as Text
</button>
</div>
<mat-divider />
}
<div class="grid-row">
@for (summary of componentData()?.summary; track summary) {
<div
class="grid-col-12 mobile:grid-col-6 desktop-lg:grid-col-4 widescreen:grid-col-3 summary-values print-flex-basis-half"
>
<h4>{{ summary.name }}</h4>
<mat-divider />
<mat-list>
@for (data of summary.data; track data) {
<mat-list-item>
<div class="list-item">
<span class="data-name">{{ data.name }}</span>
: {{ dataValue(data.value) }} {{ data.units }}
</div>
</mat-list-item>
}
</mat-list>
</div>
}
</div>
</div>
</div>
}