Commit 0d6d44d6 authored by Mathias Chouet's avatar Mathias Chouet 🍝
Browse files

Fix #293 - help links for results

parent a8e2aa81
......@@ -28,8 +28,8 @@ export class FormResultRemous extends FormResult {
}
public get results(): CalculatorResults[] {
const res: CalculatorResults[] = [];
res.push(this._remousResults);
return res;
// ensure help links are propagated
this._remousResults.helpLinks = this.helpLinks;
return [ this._remousResults ];
}
}
......@@ -60,6 +60,10 @@ export class FormResultSection extends FormResult {
public get results(): CalculatorResults[] {
const res: CalculatorResults[] = [];
// ensure help links are propagated
this._fixedResults.helpLinks = this.helpLinks;
this._varResults.helpLinks = this.helpLinks;
this._sectionResults.helpLinks = this.helpLinks;
res.push(this._fixedResults);
res.push(this._varResults);
res.push(this._sectionResults);
......
import { CalculatorResults } from "../../results/calculator-results";
export abstract class FormResult {
/** copy of options.resultsHelp read by FormDefinition.parseOptions() */
public helpLinks: { [key: string]: string };
public abstract resetResults();
public abstract get hasResults(): boolean;
......
......@@ -8,29 +8,19 @@ export abstract class FormulaireNode implements IObservable {
/** aide en ligne */
protected _helpLink: string;
/**
* identifiant dans le fichier de conf
*/
/** identifiant dans le fichier de conf */
protected _confId: string;
/**
* id numérique unique
*/
/** id numérique unique */
private _uid: string;
/**
* parent direct
*/
/** parent direct */
private _parentNode: FormulaireNode;
/**
* enfants (utilisé entre autres pour FormulaireDefinition, FieldSet et FieldsetContainer)
*/
/** enfants (utilisé entre autres pour FormulaireDefinition, FieldSet et FieldsetContainer) */
private _kids: FormulaireNode[];
/**
* implémentation par délégation de IObservable
*/
/** implémentation par délégation de IObservable */
private _observable: Observable;
constructor(parent: FormulaireNode) {
......
......@@ -7,6 +7,9 @@ import { sprintf } from "sprintf-js";
export abstract class CalculatorResults {
/** help links by result symbol, read from calculator config */
public helpLinks: { [key: string]: string };
/**
* @param p parameter to generate label for
* @param displaySymbol if true, will prefix label with parameter symbol (ex: "ZDV")
......@@ -51,4 +54,17 @@ export abstract class CalculatorResults {
* indique si il existe des résultats à afficher
*/
public abstract get hasResults(): boolean;
public getHelpLink(symbol: string): string {
// add help link if any
if (this.helpLinks !== undefined && this.helpLinks[symbol] !== undefined) {
// important: no ".html" is added after the link, to allow using anchors in config file
const helpURL = "assets/docs-fr/calculators/" + this.helpLinks[symbol];
// pseudo-<mat-icon> dirty trick because <mat-icon> renderer cannot be
// triggered when code is set through innerHTML
return `<a href="${helpURL}" target="_blank"><span class="material-icons mat-accent">help</span></a>`;
} else {
return "";
}
}
}
......@@ -46,7 +46,7 @@ export class MacrorugoCompoundResults extends MultiDimensionResults {
if (sn.parent) {
ct = sn.parent.calcType;
}
let unit;
let unit: string;
// is h a parameter ? If so, extract its unit
try {
const p = sn.getParameter(h);
......@@ -54,7 +54,9 @@ export class MacrorugoCompoundResults extends MultiDimensionResults {
unit = p.unit;
}
} catch (e) { /* silent fail */ }
return ServiceFactory.instance.formulaireService.expandVariableNameAndUnit(ct , h, unit);
let label = ServiceFactory.instance.formulaireService.expandVariableNameAndUnit(ct , h, unit);
label += this.getHelpLink(h);
return label;
});
}
......
......@@ -52,7 +52,9 @@ export class PabResults extends MultiDimensionResults {
if (sn.parent) {
ct = sn.parent.calcType;
}
return ServiceFactory.instance.formulaireService.expandVariableNameAndUnit(ct , h);
let label = ServiceFactory.instance.formulaireService.expandVariableNameAndUnit(ct , h);
label += this.getHelpLink(h);
return label;
});
}
......
......@@ -7,19 +7,14 @@ import { Result, cLog } from "jalhyd";
* les autres étant tous fixés ou avec un paramètre varié
*/
export abstract class CalculatedParamResults extends CalculatorResults {
/**
* paramètre calculé
*/
/** paramètre calculé */
protected _calculatedParam: NgParameter;
/**
* titre de la colonne
*/
/** titre de la colonne du paramètre calculé */
public calculatedParameterHeader: string;
/**
* résultat du calcul sur le paramètre calculé
*/
/** résultat du calcul sur le paramètre calculé */
public result: Result;
/** custom variables order for results tables */
......
......@@ -151,6 +151,7 @@ export class RemousResults extends CalculatorResults {
keys.push(this.extraParamSymbol);
}
this._varResults.resultKeys = keys;
this._varResults.helpLinks = this.helpLinks;
this._varResults.update();
}
......
......@@ -312,7 +312,9 @@ export class VarResults extends CalculatedParamResults implements PlottableData
public update() {
// refresh param headers
this._variableParamHeaders = this._variatedParams.map((v) => {
return CalculatorResults.paramLabel(v, true, this.result.sourceNub);
let h = CalculatorResults.paramLabel(v, true, this.result.sourceNub);
h += this.getHelpLink(v.symbol);
return h;
});
// liste la plus longue
......@@ -364,9 +366,9 @@ export class VarResults extends CalculatedParamResults implements PlottableData
unit = p.unit;
}
} catch (e) { /* silent fail */ }
this._resultHeaders.push(
ServiceFactory.instance.formulaireService.expandVariableNameAndUnit(ct, k, unit)
);
let rh = ServiceFactory.instance.formulaireService.expandVariableNameAndUnit(ct, k, unit);
rh += this.getHelpLink(k);
this._resultHeaders.push(rh);
}
// entêtes des résultats des enfants
for (const c of sn.getChildren()) {
......@@ -374,11 +376,11 @@ export class VarResults extends CalculatedParamResults implements PlottableData
const cn = capitalize(ServiceFactory.instance.i18nService.childName(sn));
// using latest ResultElement; results count / types are supposed to be the same on every iteration
for (const k of c.result.resultElement.keys) {
this._resultHeaders.push(
sprintf(ServiceFactory.instance.i18nService.localizeText("INFO_STUFF_N"), cn)
+ (c.findPositionInParent() + 1) + " : "
+ ServiceFactory.instance.formulaireService.expandVariableNameAndUnit(ct, k)
);
let rh = sprintf(ServiceFactory.instance.i18nService.localizeText("INFO_STUFF_N"), cn)
+ (c.findPositionInParent() + 1) + " : "
+ ServiceFactory.instance.formulaireService.expandVariableNameAndUnit(ct, k);
rh += this.getHelpLink(k);
this._resultHeaders.push(rh);
}
}
}
......
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