diff --git a/src/app/components/field-set/field-set.component.html b/src/app/components/field-set/field-set.component.html index f99f507db7c13994937281220a2bfa133b033996..c80e4c991ea81b64bdf5f055f9df07cee58a6b46 100644 --- a/src/app/components/field-set/field-set.component.html +++ b/src/app/components/field-set/field-set.component.html @@ -3,9 +3,18 @@ {{ title }} </mat-card-title> <div *ngIf="showButtons" class="hyd-window-btns"> + <mat-select id="add-many-children" [(value)]="childrenToAdd"> + <mat-option *ngFor="let i of addManyOptionsList" [value]="i"> + {{ i }} + </mat-option> + </mat-select> <button type="button" mat-icon-button (click)="onAddClick()" class="add-structure"> <mat-icon>add_box</mat-icon> </button> + <button type="button" mat-icon-button (click)="onCopyClick()" class="copy-structure"> + <mat-icon>content_copy</mat-icon> + </button> + | <button type="button" mat-icon-button [disabled]="! enableRemoveButton" (click)="onRemoveClick()"> <mat-icon>delete</mat-icon> </button> diff --git a/src/app/components/field-set/field-set.component.scss b/src/app/components/field-set/field-set.component.scss index ca8706d74552a7dbbd37d32e4ebfc5f997b590cb..72defe6dfabdb049b9cc0d132dae6076bea1e47d 100644 --- a/src/app/components/field-set/field-set.component.scss +++ b/src/app/components/field-set/field-set.component.scss @@ -73,6 +73,12 @@ mat-card-actions { margin-right: 0; transform: scale(1); } + + &.copy-structure { + mat-icon { + transform: scale(0.9); // this one is slightly bigger + } + } } } } @@ -82,3 +88,25 @@ mat-card-actions { } } } + +.copy-structure { + > mat-icon { + transform: scale(0.9); + } +} + +#add-many-children { + width: 3em; + + ::ng-deep .mat-select-value, ::ng-deep .mat-select-arrow { + color: #fff !important; + } + + ::ng-deep .mat-form-field-infix { + border-bottom: 2px solid #fff !important; + } + + /* ::ng-deep .mat-focused .mat-form-field-underline .mat-form-field-ripple { + background: none; + } */ +} diff --git a/src/app/components/field-set/field-set.component.ts b/src/app/components/field-set/field-set.component.ts index e1e2eb9b6e589541d128b7c18db8432d237695b3..a2e401208134928536e246fd276dcb2a57891bfe 100644 --- a/src/app/components/field-set/field-set.component.ts +++ b/src/app/components/field-set/field-set.component.ts @@ -18,6 +18,9 @@ import { FieldsetContainer } from "../../formulaire/fieldset-container"; }) export class FieldSetComponent implements DoCheck { + /** number of children to add when clicking "add" or "clone" button */ + public childrenToAdd = 1; + @Input() private set fieldSet(fs: FieldSet) { this._fieldSet = fs; @@ -27,9 +30,9 @@ export class FieldSetComponent implements DoCheck { return this._fieldSet.kids; } - /* public set fieldsetNumber(n: number) { - this._fieldSet.labelNumber = n; - } */ + public get addManyOptionsList() { + return Array(20).fill(0).map((value, index) => index + 1); + } public get title(): string { if (! this._fieldSet) { @@ -316,7 +319,26 @@ export class FieldSetComponent implements DoCheck { * clic sur le bouton ajouter */ private onAddClick() { - this.addFieldset.emit(this._fieldSet); + for (let i = 0; i < this.childrenToAdd; i++) { + this.addFieldset.emit({ + fs: this._fieldSet, + clone: false + }); + } + this.childrenToAdd = 1; // reinit to avoid confusion + } + + /** + * clic sur le bouton copier + */ + private onCopyClick() { + for (let i = 0; i < this.childrenToAdd; i++) { + this.addFieldset.emit({ + fs: this._fieldSet, + clone: true + }); + } + this.childrenToAdd = 1; // reinit to avoid confusion } /** diff --git a/src/app/components/fieldset-container/fieldset-container.component.ts b/src/app/components/fieldset-container/fieldset-container.component.ts index ede0fd363ba56ffcf1e680e576ebfe99c09ebf7c..2c161f764a0282e86771fa7bc5c20d70d0787b51 100644 --- a/src/app/components/fieldset-container/fieldset-container.component.ts +++ b/src/app/components/fieldset-container/fieldset-container.component.ts @@ -68,22 +68,24 @@ export class FieldsetContainerComponent implements DoCheck, AfterViewInit { * Ajoute un nouveau sous-nub (Structure, PabCloisons selon le cas) * dans un nouveau fieldset */ - private addSubNub(after?: FieldSet) { + private addSubNub(after?: FieldSet, clone: boolean = false) { if (after) { - this._container.addFromTemplate(0, after.indexAsKid()); + const newFs = this._container.addFromTemplate(0, after.indexAsKid()); + if (clone) { + // replace in-place to change properties (overkill) + newFs.setPropValue("structureType", after.properties.getPropValue("structureType")); + newFs.setPropValue("loiDebit", after.properties.getPropValue("loiDebit")); + // after.nub.properties + for (const p of after.nub.prms) { + newFs.nub.getParameter(p.symbol).singleValue = p.singleValue; + } + } } else { this._container.addFromTemplate(0); } } private onFieldsetListChange() { - // renumérotation - /* let n = 1; - this._fieldsetComponents.forEach(fsc => { - fsc.fieldsetNumber = n; - n++; - } - ); */ } public ngAfterViewInit() { @@ -164,8 +166,8 @@ export class FieldsetContainerComponent implements DoCheck, AfterViewInit { /** * réception d'un événement de demande d'ajout d'un FieldSet */ - private onAddFieldset(fs: FieldSet) { - this.addSubNub(fs); + private onAddFieldset(evt: { fs: FieldSet, clone: boolean }) { + this.addSubNub(evt.fs, evt.clone); } /** diff --git a/src/app/formulaire/definition/concrete/form-parallel-structures.ts b/src/app/formulaire/definition/concrete/form-parallel-structures.ts index ada70cc185602a61e84820967a6daffda892319d..2c7ab712506805bd8a9b4f3d0abd3407e6564398 100644 --- a/src/app/formulaire/definition/concrete/form-parallel-structures.ts +++ b/src/app/formulaire/definition/concrete/form-parallel-structures.ts @@ -64,7 +64,9 @@ export class FormulaireParallelStructure extends FormulaireBase { } /** - * Replaces the current Nub in the current calculator module, with a new one built with properties "params" + * Replaces the geiven Structure sn in the current calculator module, + * with a new one built with properties "params" + * @param sn Structure to replace * @param params properties to build the new Nub (calcType, loiDebit...) */ protected replaceNub(sn: Structure, params: Props): Nub { diff --git a/src/app/formulaire/fieldset.ts b/src/app/formulaire/fieldset.ts index 2f21b31fee492d90971a3a45e4bb483102ce4103..a1eb7b57d4f7b8d49864fad5e3c97f80147b64d0 100644 --- a/src/app/formulaire/fieldset.ts +++ b/src/app/formulaire/fieldset.ts @@ -47,7 +47,6 @@ export class FieldSet extends FormulaireElement implements Observer { public setNub(sn: Nub, update: boolean = true) { this._nub = sn; this.setParentNubForAllFields(); - // this._props.setProps(sn.properties || new Props({}), this); if (update) { this.updateFields(); }