diff --git a/jalhyd_branch b/jalhyd_branch index 626e97d71d9e3364f9abe16f7e3c8d70dea5a7fa..f6d80c358063b6549a42b2aa1f515dbad81f5c9a 100644 --- a/jalhyd_branch +++ b/jalhyd_branch @@ -1 +1 @@ -devel \ No newline at end of file +306-gerer-un-flag-modified-dans-paramdefinition \ No newline at end of file diff --git a/src/app/components/base-param-input/base-param-input.component.ts b/src/app/components/base-param-input/base-param-input.component.ts index 25573571b021a64a06672559fa919981d00f8d8a..883fa077213c7a069a3942c163faceecdcf97e41 100644 --- a/src/app/components/base-param-input/base-param-input.component.ts +++ b/src/app/components/base-param-input/base-param-input.component.ts @@ -15,7 +15,7 @@ export class NgBaseParam extends Observable { constructor(symb: string, d: ParamDomain | ParamDomainValue, val: number, unit?: string) { super(); - this._param = new ParamDefinition(null, symb, d, unit, val); + this._param = new ParamDefinition(null, symb, d, unit, val, undefined, undefined, false); } public get param() { diff --git a/src/app/components/calculator-list/calculator-list.component.ts b/src/app/components/calculator-list/calculator-list.component.ts index fcc96d90f5b96ff89aa806113a1e161274abdacb..cd37dad302aa6a325990cc70e314b5a7eeccbb69 100644 --- a/src/app/components/calculator-list/calculator-list.component.ts +++ b/src/app/components/calculator-list/calculator-list.component.ts @@ -181,10 +181,6 @@ export class CalculatorListComponent implements OnInit { } } } - - if (this.appSetupService.enableEmptyFieldsOnFormInit) { - f.emptyFields(); - } } public get nbOpenCalculators() { diff --git a/src/app/components/pb-schema/pb-schema.component.ts b/src/app/components/pb-schema/pb-schema.component.ts index e1e74c9e6fcf715c1a11c1da7dbf121960ea5801..1862a8dcfaa85a2986de87a53c311f5af73a630b 100644 --- a/src/app/components/pb-schema/pb-schema.component.ts +++ b/src/app/components/pb-schema/pb-schema.component.ts @@ -492,35 +492,10 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni return this.i18nService.localizeText("INFO_FIELDSET_COPY"); } - /** - * Set value of all single parameters to undefined, except for the given parameter ids - */ - private emptyFields(basin: PbBassin, except: string[] = FormulaireNode.NeverEmptyFields) { - // save current calculated param, as setting value on a CALC param will - // change its mode and choose another calculated param by default - let calcP: ParamDefinition; - for (const p of basin.parameterIterator) { - if ( - [ParamValueMode.SINGLE, ParamValueMode.CALCUL].includes(p.valueMode) - && !except.includes(p.symbol) - ) { - if (p.valueMode === ParamValueMode.CALCUL) { - calcP = p; - } - p.setValue(undefined); - } - } - // restore original calculated param - if (calcP !== undefined) { - calcP.setCalculated(); - } - } - /** Adds a new lone basin */ public onAddBasinClick() { const newBasin = new PbBassin(new PbBassinParams(20, 99)); this.model.addChild(newBasin); - this.emptyFields(newBasin); this.clearResults(); this.refreshWithSelection(newBasin.uid); this.calculatorComponent.showPBInputData = true; diff --git a/src/app/formulaire/definition/form-prebarrage.ts b/src/app/formulaire/definition/form-prebarrage.ts index ebe3ea8ffdda5ae94f096a9dd6c0a3ceefa1089f..811007d2c1966bc071dc1b9739e3a9485c3ae4ec 100644 --- a/src/app/formulaire/definition/form-prebarrage.ts +++ b/src/app/formulaire/definition/form-prebarrage.ts @@ -322,21 +322,6 @@ export class FormulairePrebarrage extends FormulaireFixedVar { } } - /** - * Set value of all single parameters to undefined, except for the given parameter ids - */ - public emptyFields(except: string[] = FormulaireNode.NeverEmptyFields) { - // save current calculated param, as setting value on a CALC param will - // change its mode and choose another calculated param by default - const paramCalculated = this.currentNub.calculatedParam; - for (const p of this.currentNub.parameterIterator) { - if (! except.includes(p.symbol)) { - p.setValue(undefined); - } - } - this.currentNub.calculatedParam = paramCalculated; - } - /** * Check validity of all model parameters * @param withChildren check parameters of child nub as well diff --git a/src/app/formulaire/definition/form-section.ts b/src/app/formulaire/definition/form-section.ts index fd45ceb50c782c50436c52886767f4abbba236c0..c408e572abe092e6454ee1395e052bc0bfdaac18 100644 --- a/src/app/formulaire/definition/form-section.ts +++ b/src/app/formulaire/definition/form-section.ts @@ -20,11 +20,6 @@ export class FormulaireSection extends FormulaireFixedVar { } // show / hide dependent fields this.refreshFieldsets(); - // empty fields ? only those belonging to the specific section type - if (ServiceFactory.applicationSetupService.enableEmptyFieldsOnFormInit) { - // "LargeurBerge" is hackily used as LargeurFond in Rectangular and Trapez sections, omit it here - this.emptyFields([ "Ks", "Q", "If", "YB", "iPrec", "Y" ]); - } this.reset(); } } diff --git a/src/app/formulaire/elements/fieldset.ts b/src/app/formulaire/elements/fieldset.ts index e5a9ca15af20c8281d7652b8c609727f324f4653..4081f824133ac596b38848c2e926a0793580713e 100644 --- a/src/app/formulaire/elements/fieldset.ts +++ b/src/app/formulaire/elements/fieldset.ts @@ -73,23 +73,13 @@ export class FieldSet extends FormulaireElement implements Observer { * @param backup list of NgParameter object representation * @see backupParameters */ - public restoreParameters(backup: any[], except: string[] = FormulaireNode.NeverEmptyFields) { + public restoreParameters(backup: any[]) { // for (const p of this.allFormElements) { for (const p of this._kids) { if (p instanceof NgParameter) { for (const bp of backup) { if (p.symbol === bp.prmDef.symbol) { - // if source parameter has been user modified, copy value - if (bp.modified) { - p.loadObjectRepresentation(bp); - } - else { - // can parameter be emptied ? - if (ServiceFactory.applicationSetupService.enableEmptyFieldsOnFormInit && !except.includes(bp.prmDef.symbol)) { - p.resetValue(this, undefined); - } - // else let parameter to default value - } + p.loadObjectRepresentation(bp); break; } } @@ -421,10 +411,6 @@ export class FieldSet extends FormulaireElement implements Observer { } } - if (ServiceFactory.applicationSetupService.enableEmptyFieldsOnFormInit) { - const f = this.parentForm; - f.emptyFields(); - } break; // switch (data.action) } } diff --git a/src/app/formulaire/elements/formulaire-node.ts b/src/app/formulaire/elements/formulaire-node.ts index 0ab8a88dfd64f0fd0ec52037fea428d3d701506c..b57bec770d2d128fc76e2fcd53a43370f0efd667 100644 --- a/src/app/formulaire/elements/formulaire-node.ts +++ b/src/app/formulaire/elements/formulaire-node.ts @@ -9,11 +9,6 @@ import { NgParameter } from "./ngparam"; */ export abstract class FormulaireNode implements IObservable { - /** - * fields in fieldset that must not be empty due to enableEmptyFieldsOnFormInit option - */ - public static readonly NeverEmptyFields = ["Cd0", "CdWS", "CdGR", "CdGRS", "CdCunge", "CdWR", "CdO", "CdT"]; - /** aide en ligne */ protected _helpLink: string; @@ -145,32 +140,6 @@ export abstract class FormulaireNode implements IObservable { return new DeepFormulaireElementIterator(this); } - /** - * Set value of all single parameters to undefined, except for the given parameter ids - */ - public emptyFields(except: string[] = FormulaireNode.NeverEmptyFields) { - // save current calculated param, as setting value on a CALC param will - // change its mode and choose another calculated param by default - let calcP: NgParameter; - for (const p of this.allFormElements) { - if (p instanceof NgParameter) { - if ( - [ParamValueMode.SINGLE, ParamValueMode.CALCUL].includes(p.valueMode) - && !except.includes(p.id) && !p.isValueModified - ) { - if (p.valueMode === ParamValueMode.CALCUL) { - calcP = p; - } - p.resetValue(this, undefined); - } - } - } - // restore original calculated param - if (calcP !== undefined) { - calcP.setCalculated(); - } - } - /** * notifie un événement aux observateurs */ diff --git a/src/app/services/app-setup.service.ts b/src/app/services/app-setup.service.ts index d1f01b2af7fbc411487f2e8045bd337299b842b6..193b32aaf05d3c353cd2d019393e15cf6ada4bb1 100644 --- a/src/app/services/app-setup.service.ts +++ b/src/app/services/app-setup.service.ts @@ -24,7 +24,6 @@ export class ApplicationSetupService extends Observable { private _maxIterations = 100; // tied to model public enableNotifications = true; public enableHotkeys = false; - public enableEmptyFieldsOnFormInit = true; public set computePrecision(p: number) { this._computePrecision = p; @@ -46,6 +45,14 @@ export class ApplicationSetupService extends Observable { return this._maxIterations; } + public get enableEmptyFieldsOnFormInit() { + return !SessionSettings.useDefaultParamValue; + } + + public set enableEmptyFieldsOnFormInit(b: boolean) { + SessionSettings.useDefaultParamValue = !b; + } + /** * just stores the current language preference, does not transmit it to I18nService, that is * not available here. @@ -71,6 +78,9 @@ export class ApplicationSetupService extends Observable { // related to @HostListener("window:beforeunload") in AppComponent this.warnBeforeTabClose = true; + // by default, create empty fields for new calculators + this.enableEmptyFieldsOnFormInit = true; + // load JSON config this.readValuesFromConfig().then((data) => { const configLanguage = this.language;