Skip to content
Snippets Groups Projects
Commit 6e6f899f authored by francois.grand's avatar francois.grand
Browse files

ajout du bouton de fermeture d'une calculette

closes #21
parent 87b0da68
No related branches found
No related tags found
No related merge requests found
......@@ -113,10 +113,62 @@ export class AppComponent implements OnInit, OnDestroy, Observer {
case "invalidid":
this.toList();
break;
case "close":
const uid: number = data["formid"];
this.closeCalculator(uid);
break;
}
}
}
private closeCalculator(formId: number) {
// recherche de la calculette correspondante à formId
const closedIndex = this._calculators.reduce((resultIndex, calc, currIndex) => {
if (resultIndex == -1 && calc["uid"] == formId)
resultIndex = currIndex;
return resultIndex;
}, -1);
/*
* détermination de la nouvelle calculette à afficher :
* - celle après celle supprimée
* - ou celle avant celle supprimée si on supprime la dernière
*/
let newId: number = -1;
const l = this._calculators.length;
if (l > 1) {
if (closedIndex == l - 1)
newId = +this._calculators[closedIndex - 1]["uid"];
else
newId = +this._calculators[closedIndex + 1]["uid"];
}
// suppression
this._calculators = this._calculators.filter(calc => {
return formId != +calc["uid"]
});
// MAJ affichage
if (newId == -1)
this.toList();
else
this.toCalc(newId);
}
private toList() {
this.router.navigate(['/list']);
}
private toCalc(id: number) {
this.router.navigate(['/calculator', id]);
}
// sidenav
private openNav() {
......@@ -132,9 +184,5 @@ export class AppComponent implements OnInit, OnDestroy, Observer {
this.toList();
}
private toList() {
this.router.navigate(['/list']);
}
// sidenav
}
<div *ngIf="hasData()" class="row">
<div class="col">
<div class="col-10">
<h1>{{uitextTitre}}</h1>
</div>
<div class="col-2">
<button type="button" class="btn btn-primary float-right black" (click)="onCloseForm()">×</button>
</div>
</div>
<field-set *ngFor="let fs of fieldSets" [style.display]="getFieldsetStyleDisplay(fs.id)" [fieldSet]=fs (onRadio)=onRadioClick($event)
(onSelectChange)=onSelectChanged($event)></field-set>
......
......@@ -128,6 +128,10 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, OnDestroy, O
this._formulaire.resetRadiosAndResults(symbol, option);
}
private onCloseForm() {
this.formulaireService.requestCloseForm(this._formulaire.uid);
}
/**
* met à jour l'interface
*/
......
......@@ -179,4 +179,16 @@ export class FormulaireService extends Observable {
throw "FormulaireService.getConfigPathPrefix() : valeur de CalculatorType " + ct + " non implémentée"
}
}
public requestCloseForm(uid: number) {
const form = this.getFormulaireFromId(uid);
if (form != undefined) {
this._formulaires = this._formulaires.filter(f => f.uid !== uid);
this.notifyObservers({
"action": "close",
"formid": uid
});
}
}
}
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