From c7635ca193d10dc6f343f9ed8bd161de783ebe1d Mon Sep 17 00:00:00 2001 From: Mathias Chouet <mathias.chouet@irstea.fr> Date: Fri, 29 May 2020 16:50:12 +0200 Subject: [PATCH] PreBarrage: update wall creation modal can now create upstream to downstream direct connections unrelevant list elements are grayed-out --- .../dialog-new-pb-cloison.component.html | 4 +-- .../dialog-new-pb-cloison.component.ts | 36 +++++++++++++++++-- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/app/components/dialog-new-pb-cloison/dialog-new-pb-cloison.component.html b/src/app/components/dialog-new-pb-cloison/dialog-new-pb-cloison.component.html index aa12a4308..a6587c773 100644 --- a/src/app/components/dialog-new-pb-cloison/dialog-new-pb-cloison.component.html +++ b/src/app/components/dialog-new-pb-cloison/dialog-new-pb-cloison.component.html @@ -3,7 +3,7 @@ <form> <mat-form-field> <mat-select [placeholder]="uiTextUpstreambasin" [(value)]="upstreamIndex" required> - <mat-option *ngFor="let b of availableIndexes" [value]="b"> + <mat-option *ngFor="let b of availableUpstreamIndexes" [value]="b" [disabled]="! basinIsSelectable(b, false)"> {{ basinDescription(b, uitextRiverUpstream) }} </mat-option> </mat-select> @@ -11,7 +11,7 @@ <mat-form-field> <mat-select [placeholder]="uiTextDownstreambasin" [(value)]="downstreamIndex" required> - <mat-option *ngFor="let b of availableIndexes" [value]="b"> + <mat-option *ngFor="let b of availableDownstreamIndexes" [value]="b" [disabled]="! basinIsSelectable(b, true)"> {{ basinDescription(b, uitextRiverDownstream) }} </mat-option> </mat-select> diff --git a/src/app/components/dialog-new-pb-cloison/dialog-new-pb-cloison.component.ts b/src/app/components/dialog-new-pb-cloison/dialog-new-pb-cloison.component.ts index f5513751b..d562f03d3 100644 --- a/src/app/components/dialog-new-pb-cloison/dialog-new-pb-cloison.component.ts +++ b/src/app/components/dialog-new-pb-cloison/dialog-new-pb-cloison.component.ts @@ -28,10 +28,10 @@ export class DialogNewPbCloisonComponent implements OnInit { ) { this.availableBasins = data.basins; this.upstreamIndex = 0; - this.downstreamIndex = 1; + this.downstreamIndex = 0; } - public get availableIndexes(): number[] { + public get availableUpstreamIndexes(): number[] { // add river upstream as "0" let ab: number[] = [ 0 ]; for (let i = 0; i < this.availableBasins.length; i++) { @@ -40,6 +40,32 @@ export class DialogNewPbCloisonComponent implements OnInit { return ab; } + public get availableDownstreamIndexes(): number[] { + let ab: number[] = [ ]; + for (let i = 0; i < this.availableBasins.length; i++) { + ab.push(i + 1); + } + // add river downstream as "0" + ab.push(0); + return ab; + } + + /** + * Returns true if a basin is selectable in the possible upstream basins list, + * considering which downstream basin is currently selected + * @param index index of basin + * @param downstream if true, inverts the test + */ + public basinIsSelectable(index: number, downstream: boolean = false): boolean { + let ok = true; + if (downstream) { + return (this.upstreamIndex === 0 || index > this.upstreamIndex) + } else { + return (this.downstreamIndex === 0 || index < this.downstreamIndex) + } + return ok; + } + public basinDescription(i: number, fallback: string): string { if (i === 0) { return fallback; @@ -48,8 +74,12 @@ export class DialogNewPbCloisonComponent implements OnInit { } } + // @TODO redundant with lists filtering, useless public get enableValidate(): boolean { - return (this.upstreamIndex !== this.downstreamIndex); + return ( + this.upstreamIndex !== this.downstreamIndex + || this.upstreamIndex === 0 // river upstream to river downstream direct connection is allowed + ); } public onValidate(close = true) { -- GitLab