Commit dffc35d9 authored by Mathias Chouet's avatar Mathias Chouet :spaghetti:
Browse files

Patch lifecycle issue when switching from a PreBarrage to another

Showing with 14 additions and 13 deletions
+14 -13
...@@ -81,9 +81,13 @@ ...@@ -81,9 +81,13 @@
fxFlex.lt-md="1 0 500px" fxFlex.lt-md="1 0 500px"
fxFlex.lt-sm="1 0 300px"> fxFlex.lt-sm="1 0 300px">
<pb-schema [pbSchema]="formElements[0]" (radio)=onRadioClick($event) <!-- without this loop, injecting formElements[0] in <pb-schema> makes it not
(validChange)=onElementValid() (nodeSelected)="onPBNodeSelected($event)"> trigger lifecycle hooks when switching from a PreBarrage module to another… -->
</pb-schema> <ng-template ngFor let-fe [ngForOf]="formElements">
<pb-schema *ngIf="isPbSchema(fe)" [pbSchema]="fe" (radio)=onRadioClick($event)
(validChange)=onElementValid() (nodeSelected)="onPBNodeSelected($event)">
</pb-schema>
</ng-template>
<div fxHide.sm fxFlex.gt-sm="0 0 16px"></div> <div fxHide.sm fxFlex.gt-sm="0 0 16px"></div>
</div> </div>
......
...@@ -2,12 +2,12 @@ import { Component, Input, Output, EventEmitter, OnInit, AfterViewInit, ViewChil ...@@ -2,12 +2,12 @@ import { Component, Input, Output, EventEmitter, OnInit, AfterViewInit, ViewChil
import { MatDialog } from "@angular/material/dialog"; import { MatDialog } from "@angular/material/dialog";
import { import {
PreBarrage, PbBassin, PbBassinParams, PbCloison, CreateStructure, LoiDebit, Structure, Observer, IObservable PreBarrage, PbBassin, PbBassinParams, PbCloison, Observer, IObservable
} from "jalhyd"; } from "jalhyd";
import * as mermaid from "mermaid"; import * as mermaid from "mermaid";
import { HotkeysService, Hotkey } from 'angular2-hotkeys'; import { HotkeysService, Hotkey } from "angular2-hotkeys";
import { I18nService } from "../../services/internationalisation.service"; import { I18nService } from "../../services/internationalisation.service";
import { PbSchema } from "../../formulaire/elements/pb-schema"; import { PbSchema } from "../../formulaire/elements/pb-schema";
...@@ -115,10 +115,12 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni ...@@ -115,10 +115,12 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni
} }
public ngAfterViewInit(): void { public ngAfterViewInit(): void {
this.refreshEventListeners();
this.updateValidity();
// subscribe to "refresh" event passed indirectly by FormulairePbCloison (change upstream/downstream basin) // subscribe to "refresh" event passed indirectly by FormulairePbCloison (change upstream/downstream basin)
this.pbSchema.addObserver(this); this.pbSchema.addObserver(this);
// @WARNING clodo trick to prevent blank diagram when switching from a PreBarrage to another
setTimeout(() => {
this.refresh();
}, 10);
} }
/** Add click listener on every node and link in the graph */ /** Add click listener on every node and link in the graph */
...@@ -360,6 +362,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni ...@@ -360,6 +362,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni
public onCopyClick() { public onCopyClick() {
const wall = this._selectedItem as PbCloison; const wall = this._selectedItem as PbCloison;
const wallCopy = new PbCloison(wall.bassinAmont, wall.bassinAval); const wallCopy = new PbCloison(wall.bassinAmont, wall.bassinAval);
wallCopy.loadObjectRepresentation(wall.objectRepresentation());
this.model.addChild(wallCopy); this.model.addChild(wallCopy);
this.unselect(); this.unselect();
this.refresh(); this.refresh();
......
...@@ -446,12 +446,6 @@ export abstract class FormulaireDefinition extends FormulaireNode implements Obs ...@@ -446,12 +446,6 @@ export abstract class FormulaireDefinition extends FormulaireNode implements Obs
return new TopFormulaireElementIterator(this); return new TopFormulaireElementIterator(this);
} }
/**
* Appelé par CalculatorComponent lorsque le Formulaire est chargé dans la vue,
* c'est à dire lorsqu'on affiche un module de calcul à l'écran
*/
public onCalculatorInit() {}
// interface Observer // interface Observer
public update(sender: any, data: any) { public update(sender: any, data: any) {
......
Supports Markdown
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