Newer
Older
François Grand
committed
import { Component, ViewChild, ElementRef, Input, OnInit } from "@angular/core";
import { MatDialog } from "@angular/material/dialog";
import { VarResults } from "../../results/var-results";
François Grand
committed
import { ResultElement, Message, MessageSeverity, Observer } from "jalhyd";
import { I18nService } from "../../services/internationalisation.service";
import { ResultsComponentDirective } from "./results.component";
import { DialogLogEntriesDetailsComponent } from "../dialog-log-entries-details/dialog-log-entries-details.component";
import { AppComponent } from "../../app.component";
import { longestVarParam } from "../../../app/util/util";
@Component({
selector: "var-results",
templateUrl: "./var-results.component.html",
styleUrls: [
"./var-results.component.scss"
]
François Grand
committed
export class VarResultsComponent extends ResultsComponentDirective implements Observer, OnInit {
@ViewChild("tableContainer")
table: ElementRef;
/** size of the longest variated parameter */
public size: number;
/** résultats non mis en forme */
protected _varResults: VarResults;
/** résultats mis en forme */
/** entêtes des colonnes (param à varier, résultats) */
protected _headers: string[];
/** messages de log issus des résultats variés */
protected _messages: Message[];
protected intlService: I18nService,
protected logEntriesDetailsDialog: MatDialog
) {
super();
François Grand
committed
this.intlService.addObserver(this);
/** Refreshes results and builds the dataset */
public set results(r: VarResults) {
this._varResults = r;
François Grand
committed
this.updateResults();
}
private updateResults() {
this._results = [];
this._headers = [];
if (this._varResults) {
mathias.chouet
committed
const sn = this._varResults.result.sourceNub;
// A. gather messages
for (const re of this._varResults.resultElements) {
this._messages = this._messages.concat(re.log.messages); // es6 concat;
}
// B. build headers
if (this._messages.length > 0) { // has log messages
this._headers.push("logMessagesColumn");
}
this._headers = this._headers.concat(this._varResults.variableParamHeaders);
mathias.chouet
committed
this._headers = this._headers.concat(this._varResults.resultHeaders);
// C. pre-extract variable parameters values
const varValues = [];
// find longest list
const lvp = longestVarParam(this._varResults.variatedParameters);
// get extended values lists for each variable parameter
for (const v of this._varResults.variatedParameters) {
const vv = [];
const iter = v.param.getExtendedValuesIterator(this.size);
while (iter.hasNext) {
const nv = iter.next();
vv.push(this.formattedValue(nv.value));
}
varValues.push(vv);
}
for (let i = 0; i < this._varResults.resultElements.length; i++) {
const re: ResultElement = this._varResults.resultElements[i];
// build ordered list of : variable params values; result; extra results
const list = [];
if (this._messages.length > 0 && re.log.messages.length > 0) {
mathias.chouet
committed
// find highest log level to display
let highest = 100;
for (const lm of re.log.messages) {
highest = Math.min(highest, lm.getSeverity());
}
list.push({
messages: re.log.messages,
isInfo: (highest === MessageSeverity.INFO),
isWarning: (highest === MessageSeverity.WARNING),
isError: (highest === MessageSeverity.ERROR)
});
} else {
list.push({ messages: [] }); // empty log element to preserve row length
}
// 1. variable params values for this computation step
for (const vv of varValues) {
list.push(vv[i]);
}
mathias.chouet
committed
// 2 all results
for (const k of this._varResults.resultKeys) {
list.push(this.intlService.formatResult(k, re.getValue(k)));
}
mathias.chouet
committed
// 3 children results
for (const c of sn.getChildren()) {
if (c.result) {
for (const k of c.result.resultElements[i].keys) {
// console.log("k", k);
const er: number = c.result.resultElements[i].getValue(k);
// console.log("er", er);
public get hasMessages() {
return this._messages.length > 0;
}
public get hasResults(): boolean {
return this._varResults && this._varResults.hasResults;
}
public get headers() {
return this._headers;
}
public get headersWithoutLogColumn() {
if (this.hasMessages) {
return this._headers.slice(1);
} else {
return this._headers;
}
}
* Returns a combination of parameters and results for mat-table
*/
public get dataSet() {
return this._results;
mathias.chouet
committed
public exportAsSpreadsheet() {
AppComponent.exportAsSpreadsheet(this.table.nativeElement);
mathias.chouet
committed
}
public get uitextExportAsSpreadsheet() {
return this.intlService.localizeText("INFO_RESULTS_EXPORT_AS_SPREADSHEET");
}
public get uitextEnterFSTitle() {
return this.intlService.localizeText("INFO_CHART_BUTTON_TITLE_ENTER_FS");
return this.intlService.localizeText("INFO_CHART_BUTTON_TITLE_EXIT_FS");
/** Shows a modal displaying the log messages details for a calcutation step */
public openLogDetails(messages: Message[]) {
if (this.isFullscreen) {
this.exitFullscreen();
}
this.logEntriesDetailsDialog.open(
DialogLogEntriesDetailsComponent,
{
data: {
messages: messages
},
autoFocus: false
}
);
}
François Grand
committed
François Grand
committed
ngOnInit(): void {
this._varResults.updateCalculatedParameterHeader();
}
François Grand
committed
// Observer interface
update(sender: any, data: any): void {
if (sender instanceof I18nService) {
this._varResults.update();
}
}