Skip to content
Snippets Groups Projects
Commit fd54955f authored by Mathias Chouet's avatar Mathias Chouet
Browse files

PreBarrage: update wall creation modal

can now create upstream to downstream direct connections
unrelevant list elements are grayed-out
parent 781ae75d
No related branches found
No related tags found
1 merge request!96WIP: Resolve "Simplifier les composants de résultats"
......@@ -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>
......
......@@ -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) {
......
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