Commit f0cd5234 authored by Grand Francois's avatar Grand Francois
Browse files

refactor: LogHelper class: use jalhyd for message log statistics

refs #517
parent 7e83cb00
devel
\ No newline at end of file
308-log-ameliorer-la-synthese-de-journal
\ No newline at end of file
import { cLog, Message, MessageCode, MessageSeverity, Result } from "jalhyd";
import { ServiceFactory } from "app/services/service-factory";
import { cLog, Message, MessageCode, Result, ResultElement } from "jalhyd";
import { sprintf } from "sprintf-js";
import { MultiDimensionResults } from "./multidimension-results";
/**
......@@ -31,76 +33,45 @@ export class LogHelper {
* Returns the number of errors, warnings, infos among children logs
*/
private logStats(): any {
const ret = {
info: 0,
warning: 0,
error: 0
};
if (this._mdr.result?.hasLog()) {
for (const re of this._mdr.result.resultElements) {
if (re.hasLog()) {
for (const m of re.log.messages) {
const s = m.getSeverity();
switch (s) {
case MessageSeverity.INFO:
ret.info++;
break;
case MessageSeverity.WARNING:
ret.warning++;
break;
case MessageSeverity.ERROR:
ret.error++;
break;
}
}
}
}
}
for (const cr of this._childrenResults) { // bassins et cloisons
if (cr && cr.hasLog()) {
for (const re of cr.resultElements) {
if (re.hasLog()) {
for (const m of re.log.messages) {
const s = m.getSeverity();
switch (s) {
case MessageSeverity.INFO:
ret.info++;
break;
case MessageSeverity.WARNING:
ret.warning++;
break;
case MessageSeverity.ERROR:
ret.error++;
break;
}
}
}
}
}
return this._mdr.result.sourceNub.resultElementsLogStats();
}
private computeResultElementLogStats(index: number): any {
let res;
const it: Iterator<ResultElement> = this._mdr.result.nthResultElementIterator(index);
let ire = it.next();
while (!ire.done) {
res = ire.value.logStats(res);
ire = it.next();
}
if (this._extraResult?.hasLog()) {
for (const re of this._extraResult.resultElements) {
if (re.hasLog()) {
for (const m of re.log.messages) {
const s = m.getSeverity();
switch (s) {
case MessageSeverity.INFO:
ret.info++;
break;
case MessageSeverity.WARNING:
ret.warning++;
break;
case MessageSeverity.ERROR:
ret.error++;
break;
}
}
return res;
}
private resultElementStatToString(res: any): string {
let ret = "";
function ccat(n: number, code: MessageCode, b: string): string {
if (n > 0) {
const c: string = MessageCode[code];
const m: string = ServiceFactory.i18nService.localizeText(c);
const s = sprintf(m, n);
if (b.length > 0) {
return b + ", " + s;
}
return s;
}
return b;
}
ret = ccat(res.error, MessageCode.WARNING_ERROR_COUNT_SHORT, ret);
ret = ccat(res.warning, MessageCode.WARNING_WARNING_COUNT_SHORT, ret);
ret = ccat(res.info, MessageCode.WARNING_INFO_COUNT_SHORT, ret);
return ret;
}
public resultElementsStats(index: number): string {
const res = this.computeResultElementLogStats(index);
return this.resultElementStatToString(res);
}
/*
* Retourne les logs à afficher dans le composant de log global, au dessus
* du sélecteur d'itération : messages globaux et / ou résumé des messages
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment