Skip to content
Snippets Groups Projects
Commit d7a3199f authored by François Grand's avatar François Grand
Browse files

feat: predam: add missing implemention of add/copy buttons/icons

refs #522
parent 3aab1ff2
No related branches found
No related tags found
1 merge request!166Resolve "Prébarrages: Regroupement de la saisie des bassins"
......@@ -3,6 +3,9 @@ import { Component } from "@angular/core";
import { I18nService } from "../../services/internationalisation.service";
import { ApplicationSetupService } from "../../services/app-setup.service";
import { FieldsetContainerComponent } from "../fieldset-container/fieldset-container.component";
import { PrebarrageService } from "app/services/prebarrage.service";
import { ServiceFactory } from "app/services/service-factory";
import { FieldSet } from "app/formulaire/elements/fieldset";
@Component({
selector: "basin-fieldset-container",
......@@ -13,7 +16,7 @@ import { FieldsetContainerComponent } from "../fieldset-container/fieldset-conta
})
export class BasinFieldsetContainerComponent extends FieldsetContainerComponent {
constructor(i18nService: I18nService, appSetupService: ApplicationSetupService) {
constructor(i18nService: I18nService, appSetupService: ApplicationSetupService, private predamService: PrebarrageService) {
super(i18nService, appSetupService);
}
......@@ -24,4 +27,8 @@ export class BasinFieldsetContainerComponent extends FieldsetContainerComponent
fs.showMoveArrows = false;
});
}
protected addSubNub(after: FieldSet, clone?: boolean): void {
this.predamService.copySelectedBasin(ServiceFactory.applicationSetupService.enableEmptyFieldsOnFormInit);
}
}
......@@ -21,7 +21,7 @@ import { AppComponent } from "../../app.component";
import { fv } from "app/util";
import { ServiceFactory } from "app/services/service-factory";
import { DefinedBoolean } from "app/definedvalue/definedboolean";
import { PrebarrageService } from "app/services/prebarrage.service";
import { PrebarrageService, PrebarrageServiceEvents } from "app/services/prebarrage.service";
/**
* The interactive schema for calculator type "PreBarrage" (component)
......@@ -70,6 +70,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni
) {
this.hotkeysService.add(new Hotkey("del", AppComponent.onHotkey(this.removeOnHotkey, this)));
this._isValid = new DefinedBoolean();
this.predamService.changeEventEmitter.subscribe(event => this.onPredamServiceEvent(event));
}
/** tracks the fullscreen state */
......@@ -482,16 +483,12 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni
/** Copies a wall or a basin */
public onCopyClick() {
let copy: PbCloison | PbBassin;
if (this._selectedItem instanceof PbCloison) {
copy = this.predamService.copySelectedWall(ServiceFactory.applicationSetupService.enableEmptyFieldsOnFormInit);
this.predamService.copySelectedWall(ServiceFactory.applicationSetupService.enableEmptyFieldsOnFormInit);
}
else {
copy = this.predamService.copySelectedBasin(ServiceFactory.applicationSetupService.enableEmptyFieldsOnFormInit);
this.predamService.copySelectedBasin(ServiceFactory.applicationSetupService.enableEmptyFieldsOnFormInit);
}
this.clearResults();
this.refreshWithSelection(copy.uid);
this.calculatorComponent.showPBInputData = true;
}
public get uitextCopy() {
......@@ -500,10 +497,22 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni
/** Adds a new lone basin */
public onAddBasinClick() {
const newBasin = this.predamService.addBasin(ServiceFactory.applicationSetupService.enableEmptyFieldsOnFormInit);
this.clearResults();
this.refreshWithSelection(newBasin.uid);
this.calculatorComponent.showPBInputData = true;
this.predamService.addBasin(ServiceFactory.applicationSetupService.enableEmptyFieldsOnFormInit);
}
/**
* process events from PrebarrageService
*/
private onPredamServiceEvent(event: any) {
const nub = event.data;
switch (event.id) {
case PrebarrageServiceEvents.BASIN_WALL_ADDED:
case PrebarrageServiceEvents.BASIN_WALL_COPIED:
this.clearResults();
this.refreshWithSelection(nub.uid);
this.calculatorComponent.showPBInputData = true;
break;
}
}
public get uitextAddBasin() {
......@@ -529,10 +538,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni
// apply modifications
dialogRef.afterClosed().subscribe(result => {
if (result.up !== undefined && result.down !== undefined) {
const wall = this.predamService.addWall(result.up, result.down, ServiceFactory.applicationSetupService.enableEmptyFieldsOnFormInit);
this.clearResults();
this.refreshWithSelection(wall.uid);
this.calculatorComponent.showPBInputData = true;
this.predamService.addWall(result.up, result.down, ServiceFactory.applicationSetupService.enableEmptyFieldsOnFormInit);
}
});
}
......
import { Injectable } from "@angular/core";
import { EventEmitter, Injectable } from "@angular/core";
import { MermaidUtil, PbBassin, PbBassinParams, PbCloison, PreBarrage } from "jalhyd";
export enum PrebarrageServiceEvents {
BASIN_WALL_ADDED, // a wall has been added
BASIN_WALL_COPIED, // a basin or wall has been copied
}
/**
* service relatif au schéma de prébarrage
*/
......@@ -16,6 +20,8 @@ export class PrebarrageService {
/** Latest clicked item: a PbCloison, a PbBassin or undefined if river "Upstream" or "Downstream" was clicked */
private _selectedNub: PbCloison | PbBassin;
private _changeEventEmitter = new EventEmitter();
public get model(): PreBarrage {
return this._model;
}
......@@ -24,6 +30,10 @@ export class PrebarrageService {
this._model = pb;
}
public get changeEventEmitter() {
return this._changeEventEmitter;
}
/**
* return upstream (and downstream) basin object
*/
......@@ -66,26 +76,41 @@ export class PrebarrageService {
return wallCopy;
}
public copySelectedWall(emptyFields: boolean): PbCloison {
public copySelectedWall(emptyFields: boolean) {
const wall = this._selectedNub as PbCloison;
const wallCopy = new PbCloison(wall.bassinAmont, wall.bassinAval, undefined, emptyFields);
wallCopy.loadObjectRepresentation(wall.objectRepresentation());
this._model.addChild(wallCopy);
return wallCopy;
this._changeEventEmitter.emit(
{
id: PrebarrageServiceEvents.BASIN_WALL_COPIED,
data: wallCopy
}
);
}
public addBasin(emptyFields: boolean): PbBassin {
public addBasin(emptyFields: boolean) {
const newBasin = new PbBassin(new PbBassinParams(20, 99, emptyFields));
this._model.addChild(newBasin);
return newBasin;
this._changeEventEmitter.emit(
{
id: PrebarrageServiceEvents.BASIN_WALL_ADDED,
data: newBasin
}
);
}
public copySelectedBasin(emptyFields: boolean): PbBassin {
public copySelectedBasin(emptyFields: boolean) {
const basin = this._selectedNub as PbBassin;
const basinCopy = new PbBassin(new PbBassinParams(20, 99, emptyFields));
basinCopy.loadObjectRepresentation(basin.objectRepresentation());
this._model.addChild(basinCopy);
return basinCopy;
this._changeEventEmitter.emit(
{
id: PrebarrageServiceEvents.BASIN_WALL_COPIED,
data: basinCopy
}
);
}
public get hasBasins(): boolean {
......@@ -96,7 +121,7 @@ export class PrebarrageService {
return this._model.bassins;
}
public addWall(upstreamIndex: number, downstreamIndex: number, emptyFields: boolean): PbCloison {
public addWall(upstreamIndex: number, downstreamIndex: number, emptyFields: boolean) {
const wall = new PbCloison(
upstreamIndex === 0 ? undefined : this._model.bassins[upstreamIndex - 1],
downstreamIndex === 0 ? undefined : this._model.bassins[downstreamIndex - 1],
......@@ -104,7 +129,12 @@ export class PrebarrageService {
emptyFields
);
this._model.addChild(wall);
return wall;
this._changeEventEmitter.emit(
{
id: PrebarrageServiceEvents.BASIN_WALL_ADDED,
data: wall
}
);
}
/**
......
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