diff --git a/src/app/components/pb-schema/pb-schema.component.html b/src/app/components/pb-schema/pb-schema.component.html index f8bb9bbc0bc1c4e0f85a1edab06b49f528d99a84..b9314c653190799eee8a29ec3d40acae2f9002e2 100644 --- a/src/app/components/pb-schema/pb-schema.component.html +++ b/src/app/components/pb-schema/pb-schema.component.html @@ -21,13 +21,20 @@ {{ prefixedItemDescription }} </span> <button type="button" mat-icon-button color="primary" [disabled]="! enableCopyButton" (click)="onCopyClick()" - [title]="uitextCopy"> - <mat-icon>content_copy</mat-icon> - </button> + [title]="uitextCopy"> + <mat-icon>content_copy</mat-icon> + </button> + | <button type="button" mat-icon-button color="primary" [disabled]="! enableRemoveButton" (click)="onRemoveClick()" [title]="uitextRemove"> <mat-icon>delete</mat-icon> </button> + <button type="button" mat-icon-button [disabled]="! enableUpButton" (click)="onMoveBasinUpClick()" [title]="uitextMoveBasinUp"> + <mat-icon>arrow_upward</mat-icon> + </button> + <button type="button" mat-icon-button [disabled]="! enableDownButton" (click)="onMoveBasinDownClick()" [title]="uitextMoveBasinDown"> + <mat-icon>arrow_downward</mat-icon> + </button> <!-- | <button type="button" mat-icon-button color="primary" (click)="exportAsSpreadsheet()" diff --git a/src/app/components/pb-schema/pb-schema.component.ts b/src/app/components/pb-schema/pb-schema.component.ts index 7249b69291fc8d99500eca26084ba07f2c654e2d..695243eab4044d186936191efb631198885b7a4f 100644 --- a/src/app/components/pb-schema/pb-schema.component.ts +++ b/src/app/components/pb-schema/pb-schema.component.ts @@ -480,11 +480,64 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni }); } - public get uitextAddWall() { return this.i18nService.localizeText("INFO_PB_ADD_WALL"); } + public get enableUpButton() { + return ( + this._selectedItem instanceof PbBassin + && this.findBasinPosition(this._selectedItem) !== 0 + && this.isStandaloneBasin(this._selectedItem) + ); + } + + public onMoveBasinUpClick() { + if (this._selectedItem instanceof PbBassin) { + this.model.moveBasin(this._selectedItem.uid, this.findBasinPosition(this._selectedItem) - 1); + } + this.refresh(); + } + + public get uitextMoveBasinUp() { + return this.i18nService.localizeText("INFO_PB_MOVE_BASIN_UP"); + } + + public get enableDownButton() { + return ( + this._selectedItem instanceof PbBassin + && this.findBasinPosition(this._selectedItem) !== this.model.bassins.length - 1 + && this.isStandaloneBasin(this._selectedItem) + ); + } + + public onMoveBasinDownClick() { + if (this._selectedItem instanceof PbBassin) { + this.model.moveBasin(this._selectedItem.uid, this.findBasinPosition(this._selectedItem) + 1); + } + this.refresh(); + } + + public get uitextMoveBasinDown() { + return this.i18nService.localizeText("INFO_PB_MOVE_BASIN_DOWN"); + } + + /** + * Returns true if given basin is either connected to nothing, or only to + * river upstream or downstream + */ + private isStandaloneBasin(basin: PbBassin) { + return ( + ( + basin.cloisonsAmont.length === 0 + || basin.cloisonsAmont.map(c => c.bassinAmont).every(e => e === undefined) + ) && ( + basin.cloisonsAval.length === 0 + || basin.cloisonsAval.map(c => c.bassinAval).every(e => e === undefined) + ) + ); + } + /** * Computes the global Pab validity : validity of every cell of every row */ diff --git a/src/locale/messages.en.json b/src/locale/messages.en.json index b5004bf82c16a54406cd0ffb903fcca113ce1129..fe62870ceb63374231945e8b2a0dfcaa1cba8ac9 100644 --- a/src/locale/messages.en.json +++ b/src/locale/messages.en.json @@ -520,6 +520,8 @@ "INFO_PB_ADD_WALL": "Add new wall", "INFO_PB_BASSIN_N": "Basin #", "INFO_PB_CLOISON": "Wall", + "INFO_PB_MOVE_BASIN_UP": "Move basin up", + "INFO_PB_MOVE_BASIN_DOWN": "Move basin down", "INFO_PB_NEW_WALL_SELECT_BASINS": "Select basins to connect", "INFO_PB_NEW_WALL_UP_BASIN": "upstream basin", "INFO_PB_NEW_WALL_DOWN_BASIN": "Downstream basin", diff --git a/src/locale/messages.fr.json b/src/locale/messages.fr.json index 1f2e4117ca2ac0ad89c0cbce6870fcdf55c62b09..2eb5001d832574c648bffe48bd2c2533ebb422eb 100644 --- a/src/locale/messages.fr.json +++ b/src/locale/messages.fr.json @@ -521,6 +521,8 @@ "INFO_PB_ADD_WALL": "Ajouter une cloison", "INFO_PB_BASSIN_N": "Bassin n°", "INFO_PB_CLOISON": "Cloison", + "INFO_PB_MOVE_BASIN_UP": "Déplacer le bassin vers le haut", + "INFO_PB_MOVE_BASIN_DOWN": "Déplacer le bassin vers le bas", "INFO_PB_NEW_WALL_SELECT_BASINS": "Choisir les bassins à connecter", "INFO_PB_NEW_WALL_UP_BASIN": "Bassin amont", "INFO_PB_NEW_WALL_DOWN_BASIN": "Bassin aval",