Skip to content

Commit

Permalink
[SSE] Fix goal seek dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
JuliaSvinareva committed Oct 12, 2023
1 parent 21102bf commit 492afe3
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 64 deletions.
24 changes: 13 additions & 11 deletions apps/spreadsheeteditor/main/app/controller/DataTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ define([
'spreadsheeteditor/main/app/view/ExternalLinksDlg',
'spreadsheeteditor/main/app/view/ImportFromXmlDialog',
'spreadsheeteditor/main/app/view/GoalSeekDlg',
'spreadsheeteditor/main/app/view/ChangingCellSelectionDlg',
'spreadsheeteditor/main/app/view/GoalSeekStatusDlg',
'common/main/lib/view/OptionsDialog'
], function () {
'use strict';
Expand Down Expand Up @@ -85,7 +85,7 @@ define([
this.api.asc_registerCallback('asc_onSelectionChanged', _.bind(this.onSelectionChanged, this));
this.api.asc_registerCallback('asc_onWorksheetLocked', _.bind(this.onWorksheetLocked, this));
this.api.asc_registerCallback('asc_onChangeProtectWorkbook',_.bind(this.onChangeProtectWorkbook, this));
this.api.asc_registerCallback('asc_onGoalSeekUpdate', _.bind(this.onUpdateChangingCellSelection, this));
this.api.asc_registerCallback('asc_onGoalSeekUpdate', _.bind(this.onUpdateGoalSeekStatus, this));
this.api.asc_registerCallback('asc_onCoAuthoringDisconnect',_.bind(this.onCoAuthoringDisconnect, this));
Common.NotificationCenter.on('api:disconnect', _.bind(this.onCoAuthoringDisconnect, this));
Common.NotificationCenter.on('protect:wslock', _.bind(this.onChangeProtectSheet, this));
Expand Down Expand Up @@ -549,24 +549,26 @@ define([
})).show();
},

onUpdateChangingCellSelection: function (targetValue, currentValue, iteration) {
onUpdateGoalSeekStatus: function (targetValue, currentValue, iteration, cellName) {
var me = this;
if (!this.ChangingCellSelectionDlg) {
this.ChangingCellSelectionDlg = new SSE.Views.ChangingCellSelectionDlg({
if (!this.GoalSeekStatusDlg) {
this.GoalSeekStatusDlg = new SSE.Views.GoalSeekStatusDlg({
api: me.api,
handler: function (result) {
me.api.asc_CloseGoalClose(result == 'ok');
me.ChangingCellSelectionDlg = undefined;
me.GoalSeekStatusDlg = undefined;
Common.NotificationCenter.trigger('edit:complete');
}
});
this.ChangingCellSelectionDlg.on('close', function() {
me.api.asc_CloseGoalClose(false);
me.ChangingCellSelectionDlg = undefined;
this.GoalSeekStatusDlg.on('close', function() {
if (me.GoalSeekStatusDlg !== undefined) {
me.api.asc_CloseGoalClose(false);
me.GoalSeekStatusDlg = undefined;
}
});
this.ChangingCellSelectionDlg.show();
this.GoalSeekStatusDlg.show();
}
this.ChangingCellSelectionDlg.setSettings({targetValue: targetValue, currentValue: currentValue, iteration: iteration, formulaCell: 'E3'});
this.GoalSeekStatusDlg.setSettings({targetValue: targetValue, currentValue: currentValue, iteration: iteration, cellName: cellName});
},

onUpdateExternalReference: function(arr, callback) {
Expand Down
61 changes: 30 additions & 31 deletions apps/spreadsheeteditor/main/app/view/GoalSeekDlg.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ define([

render: function() {
Common.Views.AdvancedSettingsWindow.prototype.render.call(this);
var me = this;

this.txtFormulaCell= new Common.UI.InputFieldBtn({
el : $('#goal-seek-formula-cell'),
Expand All @@ -141,10 +140,10 @@ define([

this.txtExpectVal = new Common.UI.InputField({
el : $('#goal-seek-expect-val'),
allowBlank : false,
blankError : this.txtEmpty,
style : 'width: 100%;',
maskExp : /[0-9,\-]/
maskExp : /[0-9,\-]/,
allowBlank : true,
validateOnChange: true
});

this.afterRender();
Expand All @@ -165,31 +164,16 @@ define([
},

_setDefaults: function (props) {
var me = this;
this.txtFormulaCell.validation = function(value) {
var isvalid = me.api.asc_checkDataRange(Asc.c_oAscSelectionDialogType.GoalSeek_Cell, value, true);
if (isvalid == Asc.c_oAscError.ID.DataRangeError) {
return me.textMissingRange;
} else if (isvalid == Asc.c_oAscError.ID.MustSingleCell) {
return me.textSingleCell;
} else if (isvalid==Asc.c_oAscError.ID.MustContainFormula) {
return me.textInvalidFormula;
} else {
return true;
}
return true;
};
this.txtFormulaCell.setValue(this.api.asc_getActiveRangeStr(Asc.referenceType.A));
this.txtFormulaCell.checkValidate();
this.txtChangeCell.validation = function(value) {
var isvalid = me.api.asc_checkDataRange(Asc.c_oAscSelectionDialogType.GoalSeek_ChangingCell, value, true);
if (isvalid == Asc.c_oAscError.ID.DataRangeError) {
return me.textMissingRange;
} else if (isvalid == Asc.c_oAscError.ID.MustSingleCell) {
return me.textSingleCell;
} else {
return true;
}
return true;
};
this.txtExpectVal.validation = function(value) {
return true;
};
this.txtFormulaCell.setValue(this.api.asc_getActiveRangeStr(Asc.referenceType.A));
},

getSettings: function () {
Expand All @@ -207,8 +191,15 @@ define([
} else {
value = this.api.asc_checkDataRange(Asc.c_oAscSelectionDialogType.GoalSeek_Cell, this.txtFormulaCell.getValue(), true);
if (value != Asc.c_oAscError.ID.No) {
txtError = isvalid == Asc.c_oAscError.ID.DataRangeError ? this.textMissingRange :
(isvalid == Asc.c_oAscError.ID.MustSingleCell ? this.textSingleCell : this.textInvalidFormula);
if (value == Asc.c_oAscError.ID.DataRangeError) {
txtError = this.textDataRangeError;
} else if (value == Asc.c_oAscError.ID.MustSingleCell) {
txtError = this.textMustSingleCell;
} else if (value == Asc.c_oAscError.ID.MustContainFormula) {
txtError = this.textMustContainFormula;
} else if (value == Asc.c_oAscError.ID.MustFormulaResultNumber) {
txtError = this.textMustFormulaResultNumber;
}
isvalid = false;
}
}
Expand All @@ -234,7 +225,13 @@ define([
} else {
value = this.api.asc_checkDataRange(Asc.c_oAscSelectionDialogType.GoalSeek_ChangingCell, this.txtChangeCell.getValue(), true);
if (value != Asc.c_oAscError.ID.No) {
txtError = isvalid == Asc.c_oAscError.ID.DataRangeError ? this.textMissingRange : this.textSingleCell;
if (value == Asc.c_oAscError.ID.DataRangeError) {
txtError = this.textDataRangeError;
} else if (value == Asc.c_oAscError.ID.MustSingleCell) {
txtError = this.textMustSingleCell;
} else if (value == Asc.c_oAscError.ID.MustContainValue) {
txtError = this.textMustContainValue;
}
isvalid = false;
}
}
Expand Down Expand Up @@ -286,8 +283,10 @@ define([
textChangingCell: 'By changing cell',
txtEmpty: 'This field is required',
textSelectData: 'Select data',
textMissingRange: 'The formula is missing a range',
textSingleCell: 'Reference must be to a single cell',
textInvalidFormula: 'The cell must contain a formula'
textDataRangeError: 'The formula is missing a range',
textMustSingleCell: 'Reference must be to a single cell',
textMustContainFormula: 'The cell must contain a formula',
textMustFormulaResultNumber: 'Formula in cell must result in a number',
textMustContainValue: 'Cell must contain a value'
}, SSE.Views.GoalSeekDlg || {}))
});
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ define([
'common/main/lib/view/AdvancedSettingsWindow'
], function () { 'use strict';

SSE.Views.ChangingCellSelectionDlg = Common.Views.AdvancedSettingsWindow.extend(_.extend({
SSE.Views.GoalSeekStatusDlg = Common.Views.AdvancedSettingsWindow.extend(_.extend({
options: {
contentWidth: 330,
height: 220,
id: 'window-changing-cell'
id: 'window-goal-seek-status'
},

initialize : function(options) {
Expand All @@ -61,27 +61,27 @@ define([
'<div class="settings-panel active">',
'<div class="row-1 padding-large" style="width: 100%;">',
'<div class="cell-1">',
'<label class="input-label" id="changing-cell-label">' + me.textFoundSolution + '</label>',
'<label class="input-label" id="goal-seek-status-label">' + me.textSearchIteration + '</label>',
'</div>',
'<div class="cell-2">',
'<div id="changing-cell-stop" class="padding-small"></div>',
'<div id="changing-cell-pause"></div>',
'<div id="goal-seek-stop" class="padding-small"></div>',
'<div id="goal-seek-pause"></div>',
'</div>',
'</div>',
'<div class="row-2 padding-small">',
'<div class="cell-1">',
'<label class="input-label">' + me.textTargetValue + '</label>',
'</div>',
'<div class="cell-2">',
'<div id="changing-cell-target-value"></div>',
'<div id="goal-seek-target-value"></div>',
'</div>',
'</div>',
'<div class="row-2 padding-small">',
'<div class="cell-1">',
'<label class="input-label">' + me.textCurrenttValue + '</label>',
'<label class="input-label">' + me.textCurrentValue + '</label>',
'</div>',
'<div class="cell-2">',
'<div id="changing-cell-current-value"></div>',
'<div id="goal-seek-current-value"></div>',
'</div',
'</div>',
'</div></div>',
Expand All @@ -94,7 +94,8 @@ define([
this.props = options.props;

this._state = {
isPause: false
isPause: false,
cellName: undefined
}

this.options.handler = function(result, value) {
Expand All @@ -112,20 +113,20 @@ define([
Common.Views.AdvancedSettingsWindow.prototype.render.call(this);
var me = this;

this.$targetValue = $('#changing-cell-target-value');
this.$currentValue = $('#changing-cell-current-value');
this.$formulaSolutionLabel = $('#changing-cell-label');
this.$targetValue = $('#goal-seek-target-value');
this.$currentValue = $('#goal-seek-current-value');
this.$statusLabel = $('#goal-seek-status-label');

this.btnStep = new Common.UI.Button({
parentEl: $('#changing-cell-stop'),
parentEl: $('#goal-seek-stop'),
caption: this.textStep,
cls: 'normal dlg-btn',
disabled: true
});
this.btnStep.on('click', _.bind(this.onBtnStep, this));

this.btnPause = new Common.UI.Button({
parentEl: $('#changing-cell-pause'),
parentEl: $('#goal-seek-pause'),
caption: this.textPause,
cls: 'normal dlg-btn'
});
Expand Down Expand Up @@ -157,9 +158,11 @@ define([

setSettings: function (props) {
if (props) {
if (this._state.cellName === undefined)
this._state.cellName = props.cellName;
this.$targetValue.text(props.targetValue);
this.$currentValue.text(props.currentValue);
this.$formulaSolutionLabel.text(Common.Utils.String.format(this.textFoundSolution, props.formulaCell, props.iteration));
this.$statusLabel.text(Common.Utils.String.format(this.textSearchIteration, props.cellName, props.iteration));
}
},

Expand All @@ -174,10 +177,11 @@ define([
this.api.asc_StepGoalSeek();
},

onStopSelection: function () {
onStopSelection: function (isFound) {
this.btnPause.setDisabled(true);
this.btnStep.setDisabled(true);
this.setDisabledOkButton(false);
this.$statusLabel.text(Common.Utils.String.format(isFound ? this.textFoundSolution : this.textNotFoundSolution, this._state.cellName));
},

setDisabledOkButton: function (disabled) {
Expand All @@ -190,12 +194,14 @@ define([
}
},

textTitle: 'Changing Cell Selection',
textFoundSolution: 'The search for the target using cell {0} has found a solution. Iteration №{1}.',
textTitle: 'Goal Seek Status',
textFoundSolution: 'Goal Seeking with Cell {0} found a solution.',
textNotFoundSolution: 'Goal Seeking with Cell {0} may not have found a solution.',
textSearchIteration: 'Goal Seeking with Cell {0} on iteration #{1}.',
textTargetValue: 'Target value:',
textCurrenttValue: 'Current value:',
textCurrentValue: 'Current value:',
textStep: 'Step',
textPause: 'Pause',
textContinue: 'Continue'
}, SSE.Views.ChangingCellSelectionDlg || {}))
}, SSE.Views.GoalSeekStatusDlg || {}))
});
24 changes: 23 additions & 1 deletion apps/spreadsheeteditor/main/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2153,6 +2153,8 @@
"SSE.Views.DataTab.tipRemDuplicates": "Remove duplicate rows from a sheet",
"SSE.Views.DataTab.tipToColumns": "Separate cell text into columns",
"SSE.Views.DataTab.tipUngroup": "Ungroup range of cells",
"SSE.Views.DataTab.capGoalSeek": "Goal Seek",
"SSE.Views.DataTab.tipGoalSeek": "Find the right input for the value you want",
"SSE.Views.DataValidationDialog.errorFormula": "The value currently evaluates to an error. Do you want to continue?",
"SSE.Views.DataValidationDialog.errorInvalid": "The value you entered for the field \"{0}\" is invalid.",
"SSE.Views.DataValidationDialog.errorInvalidDate": "The date you entered for the field \"{0}\" is invalid.",
Expand Down Expand Up @@ -4269,5 +4271,25 @@
"SSE.Views.WBProtection.txtSheetUnlockDescription": "Enter a password to unprotect sheet",
"SSE.Views.WBProtection.txtSheetUnlockTitle": "Unprotect Sheet",
"SSE.Views.WBProtection.txtWBUnlockDescription": "Enter a password to unprotect workbook",
"SSE.Views.WBProtection.txtWBUnlockTitle": "Unprotect Workbook"
"SSE.Views.WBProtection.txtWBUnlockTitle": "Unprotect Workbook",
"SSE.Views.GoalSeekDlg.textTitle": "Goal Seek",
"SSE.Views.GoalSeekDlg.textSetCell": "Set cell",
"SSE.Views.GoalSeekDlg.textToValue": "To value",
"SSE.Views.GoalSeekDlg.textChangingCell": "By changing cell",
"SSE.Views.GoalSeekDlg.txtEmpty": "This field is required",
"SSE.Views.GoalSeekDlg.textSelectData": "Select data",
"SSE.Views.GoalSeekDlg.textDataRangeError": "The formula is missing a range",
"SSE.Views.GoalSeekDlg.textMustSingleCell": "Reference must be to a single cell",
"SSE.Views.GoalSeekDlg.textMustContainFormula": "The cell must contain a formula",
"SSE.Views.GoalSeekDlg.textMustFormulaResultNumber": "Formula in cell must result in a number",
"SSE.Views.GoalSeekDlg.textMustContainValue": "Cell must contain a value",
"SSE.Views.GoalSeekStatusDlg.textTitle": "Goal Seek Status",
"SSE.Views.GoalSeekStatusDlg.textFoundSolution": "Goal Seeking with Cell {0} found a solution.",
"SSE.Views.GoalSeekStatusDlg.textNotFoundSolution": "Goal Seeking with Cell {0} may not have found a solution.",
"SSE.Views.GoalSeekStatusDlg.textSearchIteration": "Goal Seeking with Cell {0} on iteration #{1}.",
"SSE.Views.GoalSeekStatusDlg.textTargetValue": "Target value:",
"SSE.Views.GoalSeekStatusDlg.textCurrentValue": "Current value:",
"SSE.Views.GoalSeekStatusDlg.textStep": "Step",
"SSE.Views.GoalSeekStatusDlg.textPause": "Pause",
"SSE.Views.GoalSeekStatusDlg.textContinue": "Continue"
}
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@
}
}

#window-changing-cell {
#window-goal-seek-status {
.settings-panel {
margin-top: 16px;
.row-1 {
Expand Down

0 comments on commit 492afe3

Please sign in to comment.