Skip to content

Commit

Permalink
[SSE] Goal seek: make changing cell selection dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
JuliaSvinareva committed Oct 9, 2023
1 parent 12d2b97 commit 7bfa477
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 30 deletions.
18 changes: 9 additions & 9 deletions apps/spreadsheeteditor/main/app/controller/DataTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ define([
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_onChangingCellSelection',_.bind(this.onStopChangingCellSelection, 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 @@ -543,8 +542,8 @@ 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_FormulaGoalSeek(settings.formulaCell, settings.expectedValue, settings.changingCell);
//me.onUpdateChangingCellSelection(0, 1, 0); // only for test
}
Common.NotificationCenter.trigger('edit:complete');
}
Expand All @@ -562,17 +561,18 @@ define([
} else {
// cancel changes
}
this.ChangingCellSelectionDlg = undefined;
me.ChangingCellSelectionDlg = undefined;
Common.NotificationCenter.trigger('edit:complete');
}
});
this.ChangingCellSelectionDlg.on('close', function() {
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'});
},

onStopChangingCellSelection: function () {

},

onUpdateExternalReference: function(arr, callback) {
Expand Down
69 changes: 55 additions & 14 deletions apps/spreadsheeteditor/main/app/view/ChangingCellSelectionDlg.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,21 @@ define([
this.api = options.api;
this.props = options.props;

this._state = {
isPause: false,
iteration: undefined,
currentValue: undefined,
targetValue: undefined
}

this.options.handler = function(result, value) {
if ( result != 'ok' || this.isRangeValid() ) {
if (options.handler)
options.handler.call(this, result, value);
return;
}
return true;
if (options.handler)
options.handler.call(this, result, value);
return;
};

//this.api.asc_registerCallback('asc_onChangingCellSelection',_.bind(this.onStopSelection, this));

Common.Views.AdvancedSettingsWindow.prototype.initialize.call(this, this.options);
},

Expand All @@ -116,16 +122,20 @@ define([
this.btnStep = new Common.UI.Button({
parentEl: $('#changing-cell-stop'),
caption: this.textStep,
cls: 'normal dlg-btn'
cls: 'normal dlg-btn',
disabled: true
});
this.btnStep.on('click', _.bind(this.onBtnStep, this));

this.btnPause = new Common.UI.Button({
parentEl: $('#changing-cell-pause'),
caption: this.textPause,
disabled: true,
cls: 'normal dlg-btn'
});
//this.btnPause.setCaption(status ? this.textPause : this.textContinue);
this.btnPause.on('click', _.bind(this.onBtnPause, this));

this.btnOk = this.getChild().find('.primary');
this.setDisabledOkButton(true);

this.afterRender();
},
Expand All @@ -148,17 +158,48 @@ 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.targetValue = props.targetValue;
this.currentValue = props.currentValue;
this.iteration = props.iteration;
this.$targetValue.text(this.targetValue);
this.$currentValue.text(this.currentValue);
this.updateSettings(props);
this.$formulaSolutionLabel.text(Common.Utils.String.format(this.textFoundSolution, props.formulaCell));
}
},

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;
},

onBtnStep: function () {
// call api method
},

onStopSelection: function () {
this.btnPause.setDisabled(true);
this.btnStep.setDisabled(true);
this.setDisabledOkButton(false);
},

setDisabledOkButton: function (disabled) {
if (disabled !== this.btnOk.hasClass('disabled')) {
var decorateBtn = function(button) {
button.toggleClass('disabled', disabled);
(disabled) ? button.attr({disabled: disabled}) : button.removeAttr('disabled');
};
decorateBtn(this.btnOk);
}
},

textTitle: 'Changing Cell Selection',
textFoundSolution: 'The search for the target using cell {0} has found a solution.',
textTargetValue: 'Target value:',
Expand Down
21 changes: 18 additions & 3 deletions apps/spreadsheeteditor/main/app/view/GoalSeekDlg.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,27 @@ define([
var me = this;
this.txtFormulaCell.validation = function(value) {
var isvalid = me.api.asc_checkDataRange(Asc.c_oAscSelectionDialogType.GoalSeek_Cell, value, true);
return (isvalid==Asc.c_oAscError.ID.MustContainFormula) ? me.textInvalidFormula : 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;
}
};
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);
return (isvalid==Asc.c_oAscError.ID.DataRangeError) ? me.textInvalidRange : 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;
}
};
},

Expand Down Expand Up @@ -225,7 +239,8 @@ define([
textChangingCell: 'By changing cell',
txtEmpty: 'This field is required',
textSelectData: 'Select data',
textInvalidRange: 'Invalid cells range',
textMissingRange: 'The formula is missing a range',
textSingleCell: 'Reference must be to a single cell',
textInvalidFormula: 'The cell must contain a formula'
}, SSE.Views.GoalSeekDlg || {}))
});
Original file line number Diff line number Diff line change
Expand Up @@ -602,10 +602,8 @@
display: flex;
justify-content: start;
.cell-1 {
min-width: 120px;
}
.cell-2 {
width: 100%;
min-width: 114px;
.margin-right(6px);
}
}
}
Expand Down

0 comments on commit 7bfa477

Please sign in to comment.