From 21102bf1d8f0b102fbffa3494324ab94c8f68cfd Mon Sep 17 00:00:00 2001 From: JuliaSvinareva Date: Wed, 11 Oct 2023 18:25:37 +0300 Subject: [PATCH] [SSE] Goal seek: add handlers, fix validation --- .../main/app/controller/DataTab.js | 18 +++---- .../main/app/view/ChangingCellSelectionDlg.js | 30 ++++-------- .../main/app/view/GoalSeekDlg.js | 49 ++++++++++++++++++- 3 files changed, 64 insertions(+), 33 deletions(-) diff --git a/apps/spreadsheeteditor/main/app/controller/DataTab.js b/apps/spreadsheeteditor/main/app/controller/DataTab.js index 399a1770bc..fa6d0bc827 100644 --- a/apps/spreadsheeteditor/main/app/controller/DataTab.js +++ b/apps/spreadsheeteditor/main/app/controller/DataTab.js @@ -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_onChangingCellSelection',_.bind(this.onUpdateChangingCellSelection, this)); + this.api.asc_registerCallback('asc_onGoalSeekUpdate', _.bind(this.onUpdateChangingCellSelection, 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)); @@ -542,8 +542,7 @@ define([ api: me.api, handler: function(result, settings) { if (result == 'ok' && settings) { - me.api.asc_FormulaGoalSeek(settings.formulaCell, settings.expectedValue, settings.changingCell); - //me.onUpdateChangingCellSelection(0, 1, 0); // only for test + me.api.asc_StartGoalSeek(settings.formulaCell, settings.expectedValue, settings.changingCell); } Common.NotificationCenter.trigger('edit:complete'); } @@ -555,24 +554,19 @@ define([ if (!this.ChangingCellSelectionDlg) { this.ChangingCellSelectionDlg = new SSE.Views.ChangingCellSelectionDlg({ api: me.api, - handler: function (result, settings) { - if (result == 'ok' && settings) { - // save changes - } else { - // cancel changes - } + handler: function (result) { + me.api.asc_CloseGoalClose(result == 'ok'); me.ChangingCellSelectionDlg = undefined; Common.NotificationCenter.trigger('edit:complete'); } }); this.ChangingCellSelectionDlg.on('close', function() { + me.api.asc_CloseGoalClose(false); me.ChangingCellSelectionDlg = undefined; }); this.ChangingCellSelectionDlg.show(); - this.ChangingCellSelectionDlg.setSettings({targetValue: targetValue, currentValue: currentValue, iteration: iteration, formulaCell: 'E3'}); - } else { - this.ChangingCellSelectionDlg.updateSettings({targetValue: targetValue, currentValue: currentValue, iteration: iteration}); } + this.ChangingCellSelectionDlg.setSettings({targetValue: targetValue, currentValue: currentValue, iteration: iteration, formulaCell: 'E3'}); }, onUpdateExternalReference: function(arr, callback) { diff --git a/apps/spreadsheeteditor/main/app/view/ChangingCellSelectionDlg.js b/apps/spreadsheeteditor/main/app/view/ChangingCellSelectionDlg.js index 078b827ca5..f07699c3b6 100644 --- a/apps/spreadsheeteditor/main/app/view/ChangingCellSelectionDlg.js +++ b/apps/spreadsheeteditor/main/app/view/ChangingCellSelectionDlg.js @@ -94,10 +94,7 @@ define([ this.props = options.props; this._state = { - isPause: false, - iteration: undefined, - currentValue: undefined, - targetValue: undefined + isPause: false } this.options.handler = function(result, value) { @@ -106,7 +103,7 @@ define([ return; }; - //this.api.asc_registerCallback('asc_onChangingCellSelection',_.bind(this.onStopSelection, this)); + this.api.asc_registerCallback('asc_onGoalSeekStop',_.bind(this.onStopSelection, this)); Common.Views.AdvancedSettingsWindow.prototype.initialize.call(this, this.options); }, @@ -158,30 +155,23 @@ define([ var me = this; }, - updateSettings: function (props) { - this._state.targetValue = props.targetValue; - this._state.currentValue = props.currentValue; - this._state.iteration = props.iteration; - this.$targetValue.text(this._state.targetValue); - this.$currentValue.text(this._state.currentValue); - }, - setSettings: function (props) { if (props) { - this.updateSettings(props); - this.$formulaSolutionLabel.text(Common.Utils.String.format(this.textFoundSolution, props.formulaCell)); + this.$targetValue.text(props.targetValue); + this.$currentValue.text(props.currentValue); + this.$formulaSolutionLabel.text(Common.Utils.String.format(this.textFoundSolution, props.formulaCell, props.iteration)); } }, onBtnPause: function () { - this.btnPause.setCaption(this._state.isPause ? this.textContinue : this.textPause); - this.btnStep.setDisabled(this._state.isPause); // always? or only !last iteration? - // call api method this._state.isPause = !this._state.isPause; + this.btnPause.setCaption(this._state.isPause ? this.textContinue : this.textPause); + this.btnStep.setDisabled(!this._state.isPause); + this._state.isPause ? this.api.asc_PauseGoalSeek() : this.api.asc_ContinueGoalSeek(); }, onBtnStep: function () { - // call api method + this.api.asc_StepGoalSeek(); }, onStopSelection: function () { @@ -201,7 +191,7 @@ define([ }, textTitle: 'Changing Cell Selection', - textFoundSolution: 'The search for the target using cell {0} has found a solution.', + textFoundSolution: 'The search for the target using cell {0} has found a solution. Iteration №{1}.', textTargetValue: 'Target value:', textCurrenttValue: 'Current value:', textStep: 'Step', diff --git a/apps/spreadsheeteditor/main/app/view/GoalSeekDlg.js b/apps/spreadsheeteditor/main/app/view/GoalSeekDlg.js index 046ca8835f..2cf4daf649 100644 --- a/apps/spreadsheeteditor/main/app/view/GoalSeekDlg.js +++ b/apps/spreadsheeteditor/main/app/view/GoalSeekDlg.js @@ -197,7 +197,54 @@ define([ }, isRangeValid: function() { - return true; + var isvalid = true, + txtError = '', + value; + + if (_.isEmpty(this.txtFormulaCell.getValue())) { + isvalid = false; + txtError = this.txtEmpty; + } 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); + isvalid = false; + } + } + if (!isvalid) { + this.txtFormulaCell.showError([txtError]); + this.txtFormulaCell.cmpEl.find('input').focus(); + return isvalid; + } + + if (_.isEmpty(this.txtExpectVal.getValue())) { + isvalid = false; + txtError = this.txtEmpty; + } + if (!isvalid) { + this.txtExpectVal.showError([txtError]); + this.txtExpectVal.cmpEl.find('input').focus(); + return isvalid; + } + + if (_.isEmpty(this.txtChangeCell.getValue())) { + isvalid = false; + txtError = this.txtEmpty; + } 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; + isvalid = false; + } + } + if (!isvalid) { + this.txtChangeCell.showError([txtError]); + this.txtChangeCell.cmpEl.find('input').focus(); + return isvalid; + } + + return isvalid; }, onSelectData: function(type) {