Skip to content
Snippets Groups Projects
Commit 64262c05 authored by mathias.chouet's avatar mathias.chouet
Browse files

Modules diagram: parent Nub nodes are clickable

parent c0cdbeec
No related branches found
No related tags found
1 merge request!56Resolve "Proposer une représentation graphique de l'enchaînement de modules de calcul (paramètres liés), si possible éditable"
...@@ -12,9 +12,10 @@ ...@@ -12,9 +12,10 @@
<div id="diagram" #diagram></div> <div id="diagram" #diagram></div>
<a class="show-debug" (click)="initSvgPanZoom()">init zoom </a> <!-- <a class="show-debug" (click)="initSvgPanZoom()">init zoom </a> -->
<!-- <a class="show-debug" (click)="showDebug = ! showDebug"> debug</a> -->
<a class="show-debug" (click)="showDebug = ! showDebug"> debug</a>
<div *ngIf="showDebug"> <div *ngIf="showDebug">
<pre>{{ graphDef }}</pre> <pre>{{ graphDef }}</pre>
</div> </div>
......
...@@ -3,14 +3,22 @@ import { ...@@ -3,14 +3,22 @@ import {
ViewChild, ViewChild,
AfterContentInit, AfterContentInit,
OnInit, OnInit,
AfterViewChecked AfterViewChecked,
AfterViewInit
} from "@angular/core"; } from "@angular/core";
import { Router } from "@angular/router"; import { Router } from "@angular/router";
import {
Session,
ParamValueMode,
CalculatorType,
ComputeNodeType,
LoiDebit,
Nub
} from "jalhyd";
import { I18nService } from "../../services/internationalisation/internationalisation.service"; import { I18nService } from "../../services/internationalisation/internationalisation.service";
import { BaseComponent } from "../base/base.component"; import { BaseComponent } from "../base/base.component";
import { Session, ParamValueMode } from "jalhyd";
import { FormulaireService } from "../../services/formulaire/formulaire.service"; import { FormulaireService } from "../../services/formulaire/formulaire.service";
import * as mermaid from "mermaid"; import * as mermaid from "mermaid";
...@@ -22,13 +30,14 @@ import * as SvgPanZoom from "svg-pan-zoom"; ...@@ -22,13 +30,14 @@ import * as SvgPanZoom from "svg-pan-zoom";
templateUrl: "./modules-diagram.component.html", templateUrl: "./modules-diagram.component.html",
styleUrls: ["./modules-diagram.component.scss"] styleUrls: ["./modules-diagram.component.scss"]
}) })
export class ModulesDiagramComponent extends BaseComponent implements AfterContentInit, AfterViewChecked, OnInit { export class ModulesDiagramComponent extends BaseComponent implements AfterContentInit, AfterViewChecked, AfterViewInit, OnInit {
private svgPanZoom: SvgPanZoom.Instance = null; private svgPanZoom: SvgPanZoom.Instance = null;
private needsToInitSvgPanZoom = false; private needsToInitSvgPanZoom = false;
// private readonly externalFunctionName: string = "functionToCallIntoAngular"; /** handle on SVG container */
private nativeElement: any;
@ViewChild("diagram", { static: true }) @ViewChild("diagram", { static: true })
public diagram; public diagram;
...@@ -40,32 +49,12 @@ export class ModulesDiagramComponent extends BaseComponent implements AfterConte ...@@ -40,32 +49,12 @@ export class ModulesDiagramComponent extends BaseComponent implements AfterConte
constructor( constructor(
private intlService: I18nService, private intlService: I18nService,
private router: Router, private router: Router,
private formulaireService: FormulaireService/* , private formulaireService: FormulaireService
zone: NgZone */
) { ) {
super(); super();
this.error = false; this.error = false;
// create a new global variable in the page
// window[this.externalFunctionName] = this.buildPublicCall(zone, this);
} }
/* ngOnDestroy() {
window[this.externalFunctionName] = null;
} */
// generate a function that has the zone and "this"
// captured in a closure.
/* private buildPublicCall(zone: NgZone, diagramComponent: ModulesDiagramComponent): any {
return function angularAppGlobalMethod( nodeId ) {
// you can't call "this.increment( nodeId)" because
// when the code is run on a click, "this" won't be
// the right entity. When the function is constructed
// "this" is the right entity, but it needs to captured
// at the point of construction
zone.run(() => { diagramComponent.openCalc( nodeId ); });
};
} */
public get uitextTitle(): string { public get uitextTitle(): string {
return this.intlService.localizeText("INFO_DIAGRAM_TITLE"); return this.intlService.localizeText("INFO_DIAGRAM_TITLE");
} }
...@@ -100,16 +89,28 @@ export class ModulesDiagramComponent extends BaseComponent implements AfterConte ...@@ -100,16 +89,28 @@ export class ModulesDiagramComponent extends BaseComponent implements AfterConte
} }
} }
public ngAfterViewInit(): void {
// add click listener on every calculator node in the graph, that
// corresponds to an open module
this.nativeElement.querySelectorAll("g.node").forEach(item => {
if (item.id && this.formIsOpen(item.id)) {
item.style.cursor = "pointer";
item.addEventListener("click", () => {
this.openCalc(item.id);
});
}
});
}
public ngAfterContentInit(): void { public ngAfterContentInit(): void {
this.error = false; this.error = false;
mermaid.initialize({ mermaid.initialize({
// theme: "forest", // @TODO thème Irstea ! // theme: "forest", // @TODO thème Irstea !
securityLevel: false, // or "loose" ?
flowchart: { flowchart: {
curve: "basis" // default: "linear" curve: "basis"
} }
}); });
const element: any = this.diagram.nativeElement; this.nativeElement = this.diagram.nativeElement;
if (this.hasModules) { if (this.hasModules) {
// generate graph description // generate graph description
...@@ -117,7 +118,7 @@ export class ModulesDiagramComponent extends BaseComponent implements AfterConte ...@@ -117,7 +118,7 @@ export class ModulesDiagramComponent extends BaseComponent implements AfterConte
// draw // draw
try { try {
mermaid.render("graphDiv", graphDefinition, (svgCode, bindFunctions) => { mermaid.render("graphDiv", graphDefinition, (svgCode, bindFunctions) => {
element.innerHTML = svgCode; this.nativeElement.innerHTML = svgCode;
}); });
} catch (e) { } catch (e) {
console.error(e); console.error(e);
...@@ -154,14 +155,13 @@ export class ModulesDiagramComponent extends BaseComponent implements AfterConte ...@@ -154,14 +155,13 @@ export class ModulesDiagramComponent extends BaseComponent implements AfterConte
def.push("subgraph \"" + f.calculatorName + "\""); def.push("subgraph \"" + f.calculatorName + "\"");
def.push(f.uid + "(\"" + f.calculatorName + "\")"); def.push(f.uid + "(\"" + f.calculatorName + "\")");
for (const c of children) { for (const c of children) {
def.push(c.uid + "[\"" + c.constructor.name + "\"]"); def.push(c.uid + "[\"" + this.describe(c) + "\"]");
def.push(f.uid + " --- " + c.uid); def.push(f.uid + " --- " + c.uid);
} }
def.push("end"); def.push("end");
} else { } else {
// simple Nub (no children) // simple Nub (no children)
def.push(f.uid + "(\"" + f.calculatorName + "\")"); def.push(f.uid + "(\"" + f.calculatorName + "\")");
def.push("click " + f.uid + " openCalc \"open module\"");
} }
// fnid all linked parameters // fnid all linked parameters
for (const p of nub.parameterIterator) { for (const p of nub.parameterIterator) {
...@@ -184,6 +184,37 @@ export class ModulesDiagramComponent extends BaseComponent implements AfterConte ...@@ -184,6 +184,37 @@ export class ModulesDiagramComponent extends BaseComponent implements AfterConte
} }
public openCalc(uid: string) { public openCalc(uid: string) {
console.log("Opening calc", uid); this.router.navigate(["/calculator", uid]);
}
/**
* Returns a very short "description" of the given Nub,
* based on the most specific of its properties
*/
private describe(n: Nub) {
let type = CalculatorType[n.calcType];
const nt = n.properties.getPropValue("nodeType");
if (nt) {
type = ComputeNodeType[nt];
} else {
const ld = n.properties.getPropValue("loiDebit");
if (ld !== undefined) {
type = LoiDebit[ld];
}
}
return type;
}
/**
* Returns true if uid is the id of the main Nub of any
* of the open modules
*/
private formIsOpen(uid: string) {
for (const f of this.formulaireService.formulaires) {
if (f.currentNub.uid === uid) {
return true;
}
}
return false;
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment