From f02dcad3f79103e0041f23e15c4c7dee0f3476a5 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Wed, 10 Mar 2021 19:53:38 +0300 Subject: [PATCH] [SSE] Check data ranges in conditional formatting --- .../main/app/view/CellRangeDialog.js | 2 +- .../main/app/view/FormatRulesEditDlg.js | 199 ++++++++++++++++-- .../main/app/view/FormatRulesManagerDlg.js | 2 +- 3 files changed, 185 insertions(+), 18 deletions(-) diff --git a/apps/spreadsheeteditor/main/app/view/CellRangeDialog.js b/apps/spreadsheeteditor/main/app/view/CellRangeDialog.js index d3a03020d..cf83fb442 100644 --- a/apps/spreadsheeteditor/main/app/view/CellRangeDialog.js +++ b/apps/spreadsheeteditor/main/app/view/CellRangeDialog.js @@ -168,7 +168,7 @@ define([ this.settings.argvalues[this.settings.argindex] = val; this.api.asc_insertArgumentsInFormula(this.settings.argvalues); - } else if (this.settings.type == Asc.c_oAscSelectionDialogType.DataValidation) { + } else if (this.settings.type == Asc.c_oAscSelectionDialogType.DataValidation || this.settings.type == Asc.c_oAscSelectionDialogType.ConditionalFormattingRule) { this.inputRange.setValue('=' + name); } else this.inputRange.setValue(name); diff --git a/apps/spreadsheeteditor/main/app/view/FormatRulesEditDlg.js b/apps/spreadsheeteditor/main/app/view/FormatRulesEditDlg.js index 49c5e95a2..59a516221 100644 --- a/apps/spreadsheeteditor/main/app/view/FormatRulesEditDlg.js +++ b/apps/spreadsheeteditor/main/app/view/FormatRulesEditDlg.js @@ -90,13 +90,13 @@ define([ '', '', '
', - '
', + '
', '
','
', '
','
', // '
','
', '
','
', '
', - '
', + '
', '
', '', '', @@ -1214,7 +1214,7 @@ define([ }); range.setValue(''); this.iconsControls[i].value = range; - // range.on('button:click', _.bind(this.onSelectIconData, this)); + range.on('button:click', _.bind(this.onSelectData, this)); this.iconsControls[i].label = $('#format-rules-txt-icon-' + (i+1)); } @@ -1684,7 +1684,8 @@ define([ win.setSettings({ api : me.api, range : (!_.isEmpty(cmp.getValue()) && (cmp.checkValidate()==true)) ? cmp.getValue() : '', - type : Asc.c_oAscSelectionDialogType.Chart + type : Asc.c_oAscSelectionDialogType.ConditionalFormattingRule, + validation: function() {return true;} }); } }, @@ -1986,6 +1987,163 @@ define([ formcontrol.css('background-image', record ? 'url(' + record.get('imgUrl') + ')' : ''); }, + isRangeValid: function() { + var rec = this.ruleStore.findWhere({index: this.cmbCategory.getValue()}), + res; + + if (rec) { + var type = rec.get('type'), + arr = [], + msg, + focusedInput; + switch (type) { + case Asc.c_oAscCFType.containsText: + case Asc.c_oAscCFType.expression: + if (this.txtRange1.getValue()==='') + msg = (type==Asc.c_oAscCFType.containsText ? this.textEmptyText: this.textEmptyFormulaExt); + else { + res = this.api.asc_isValidDataRefCf(type, [[this.txtRange1.getValue()]]); + res && (res = res[0]); + } + (res || msg) && (focusedInput = this.txtRange1); + break; + case Asc.c_oAscCFType.cellIs: + var subtype = this.cmbRule.getValue(); + if (this.txtRange1.getValue()==='') { + msg = this.textEmptyValue; + focusedInput = this.txtRange1; + } else if ((subtype == Asc.c_oAscCFOperator.notBetween || subtype == Asc.c_oAscCFOperator.between) && (this.txtRange2.getValue()==='')) { + msg = this.textEmptyValue; + focusedInput = this.txtRange2; + } else { + arr = [[this.txtRange1.getValue()]]; + if (subtype == Asc.c_oAscCFOperator.notBetween || subtype == Asc.c_oAscCFOperator.between) + arr.push([this.txtRange2.getValue()]); + res = this.api.asc_isValidDataRefCf(type, arr); + if (res) { + focusedInput = res[1] ? this.txtRange2 : this.txtRange1; + res = res[0]; + } + } + break; + case Asc.c_oAscCFType.top10: + var isPercent = !!this.cmbPercent.getValue(); + res = this.api.asc_isValidDataRefCf(type, [[this.numRank.getNumberValue(), isPercent]]); + res && (res = res[0]); + if (res == Asc.c_oAscError.ID.ErrorTop10Between) + msg = Common.Utils.String.format(this.textErrorTop10Between, isPercent ? 0 : 1, isPercent ? 100 : 1000); + break; + case Asc.c_oAscCFType.colorScale: + var scalesCount = rec.get('num'); + var scaleControls = (scalesCount==2) ? [this.scaleControls[0], this.scaleControls[2]] : this.scaleControls; + for (var i=0; iAdjust icon data range values so that the ranges do not overlap.', + textSingleRef: 'This type of reference cannot be used in a conditional formatting formula.
Change the reference to a single cell, or use the reference with a worksheet function, such as =SUM(A1:B5).', + textRelativeRef: 'You cannot use relative references in conditional formatting criteria for color scales, data bars, and icon sets.', + textErrorGreater: 'The value for the {0} must be greater than the value for the {1}.', + textInvalid: 'Invalid data range.' }, SSE.Views.FormatRulesEditDlg || {})); }); \ No newline at end of file diff --git a/apps/spreadsheeteditor/main/app/view/FormatRulesManagerDlg.js b/apps/spreadsheeteditor/main/app/view/FormatRulesManagerDlg.js index b4669ee4b..0f527a254 100644 --- a/apps/spreadsheeteditor/main/app/view/FormatRulesManagerDlg.js +++ b/apps/spreadsheeteditor/main/app/view/FormatRulesManagerDlg.js @@ -513,7 +513,7 @@ define([ 'text!spreadsheeteditor/main/app/template/FormatRulesManagerDlg.templa win.setSettings({ api : me.api, range : (!_.isEmpty(rule.txtDataRange.getValue()) && (rule.txtDataRange.checkValidate()==true)) ? rule.txtDataRange.getValue() : rule.dataRangeValid, - type : Asc.c_oAscSelectionDialogType.Chart + type : Asc.c_oAscSelectionDialogType.ConditionalFormattingRule }); } },