Skip to content
This repository has been archived by the owner on Mar 28, 2024. It is now read-only.

Commit

Permalink
feat(condition format): formula condition
Browse files Browse the repository at this point in the history
formula condition

fix #186
  • Loading branch information
wpxp123456 committed Dec 15, 2020
1 parent 2c6b1c2 commit 6c98bde
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 7 deletions.
133 changes: 128 additions & 5 deletions src/controllers/conditionformat.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ const conditionformat = {
<span class="icon iconfont luckysheet-iconfont-youjiantou"></span>
<span>${conditionformat_Text.ruleTypeItem5}</span>
</div>
<div class="ruleTypeItem">
<span class="icon iconfont luckysheet-iconfont-youjiantou"></span>
<span>${conditionformat_Text.ruleTypeItem6}</span>
</div>
</div>`;
},
textCellColorHtml: function(){
Expand Down Expand Up @@ -510,6 +514,19 @@ const conditionformat = {
conditionName = "duplicateValue";
conditionValue.push(type1);
}
else if(index == 5){ //公式
conditionName = "formula";

//条件值
let v = $("#luckysheet-newConditionRule-dialog #formulaConditionVal input").val().trim();

if(v == ""){
_this.infoDialog("Condition value cannot be empty!", "");
return;
}

conditionValue.push(v);
}

//格式颜色
let textcolor;
Expand Down Expand Up @@ -882,6 +899,19 @@ const conditionformat = {
conditionName = "duplicateValue";
conditionValue.push(type1);
}
else if(index == 5){ //公式
conditionName = "formula";

//条件值
let v = $("#luckysheet-editorConditionRule-dialog #formulaConditionVal input").val().trim();
console.log(v)
if(v == ""){
_this.infoDialog("Condition value cannot be empty!", "");
return;
}

conditionValue.push(v);
}

//格式颜色
let textcolor;
Expand Down Expand Up @@ -1232,24 +1262,37 @@ const conditionformat = {
$("#" + id).hide();
//入口
let source;

if(id == "luckysheet-conditionformat-dialog"){
if($(this).siblings("input").attr("id") == "conditionVal"){
let $id = $(this).siblings("input").attr("id");

if($id == "conditionVal"){
source = "0_1";
}
else{
source = "0_2";
}
}
else if(id == "luckysheet-newConditionRule-dialog"){
if($(this).parents(".range").attr("id") == "conditionVal"){
let $id = $(this).parents(".range").attr("id");

if($id == "formulaConditionVal"){
source = "1_0";
}
else if($id == "conditionVal"){
source = "1_1";
}
else{
source = "1_2";
}
}
else if(id == "luckysheet-editorConditionRule-dialog"){
if($(this).parents(".range").attr("id") == "conditionVal"){
let $id = $(this).parents(".range").attr("id");

if($id == "formulaConditionVal"){
source = "2_0";
}
else if($id == "conditionVal"){
source = "2_1";
}
else{
Expand Down Expand Up @@ -1277,6 +1320,10 @@ const conditionformat = {
$("#luckysheet-conditionformat-dialog").show();
$("#luckysheet-conditionformat-dialog #conditionVal2").val(v);
}
else if(source == "1_0"){
$("#luckysheet-newConditionRule-dialog").show();
$("#luckysheet-newConditionRule-dialog #formulaConditionVal input").val(v);
}
else if(source == "1_1"){
$("#luckysheet-newConditionRule-dialog").show();
$("#luckysheet-newConditionRule-dialog #conditionVal input").val(v);
Expand All @@ -1285,6 +1332,10 @@ const conditionformat = {
$("#luckysheet-newConditionRule-dialog").show();
$("#luckysheet-newConditionRule-dialog #conditionVal2 input").val(v);
}
else if(source == "2_0"){
$("#luckysheet-editorConditionRule-dialog").show();
$("#luckysheet-editorConditionRule-dialog #formulaConditionVal input").val(v);
}
else if(source == "2_1"){
$("#luckysheet-editorConditionRule-dialog").show();
$("#luckysheet-editorConditionRule-dialog #conditionVal input").val(v);
Expand All @@ -1305,10 +1356,10 @@ const conditionformat = {
if(source == "0_1" || source == "0_2"){
$("#luckysheet-conditionformat-dialog").show();
}
else if(source == "1_1" || source == "1_2"){
else if(source == "1_0" || source == "1_1" || source == "1_2"){
$("#luckysheet-newConditionRule-dialog").show();
}
else if(source == "2_1" || source == "2_2"){
else if(source == "2_0" || source == "2_1" || source == "2_2"){
$("#luckysheet-editorConditionRule-dialog").show();
}

Expand Down Expand Up @@ -1909,6 +1960,13 @@ const conditionformat = {
else if(conditionName == "SubAverage"){
return conditionformat_Text.belowAverage;
}
else if(conditionName == "formula"){
if(v.slice(0, 1) != '='){
v = '=' + v;
}

return conditionformat_Text.formula + ': ' + v;
}
},
newConditionRuleDialog: function(source){
let _this = this;
Expand Down Expand Up @@ -2011,6 +2069,9 @@ const conditionformat = {
index = 4;
type1 = rule["conditionValue"];
}
else if(conditionName == "formula"){
index = 5;
}
}

//规则说明
Expand Down Expand Up @@ -2174,6 +2235,12 @@ const conditionformat = {
$("#luckysheet-editorConditionRule-dialog #isPercent").attr("checked", "checked");
}
}
else{
if(conditionName == "formula"){
let val1 = rule.conditionValue[0];
$("#luckysheet-editorConditionRule-dialog #formulaConditionVal input").val(val1);
}
}

$("#luckysheet-editorConditionRule-dialog #textcolorshow").spectrum("set", ruleFormat.textColor);
$("#luckysheet-editorConditionRule-dialog #cellcolorshow").spectrum("set", ruleFormat.cellColor);
Expand Down Expand Up @@ -2367,6 +2434,16 @@ const conditionformat = {
</div>
<div class="title">${conditionformat_Text.setFormat}:</div>${textCellColorHtml}`;
break;
case 5: //使用公式确定要设置格式的单元格
ruleExplainHtml = `<div class="title">${conditionformat_Text.ruleTypeItem2_title}:</div>
<div style="height: 30px;margin-bottom: 10px;">
<div class="inpbox range" id="formulaConditionVal" style="width: 250px;">
<input class="formulaInputFocus" style="width: 200px;"/>
<i class="fa fa-table" aria-hidden="true" title="${conditionformat_Text.selectCell}"></i>
</div>
</div>
<div class="title">${conditionformat_Text.setFormat}: </div>${textCellColorHtml}`;
break;
}

return ruleExplainHtml;
Expand Down Expand Up @@ -3640,6 +3717,52 @@ const conditionformat = {
}
}
}
else if(conditionName == "formula"){
let str = cellrange[s].row[0],
edr = cellrange[s].row[1],
stc = cellrange[s].column[0],
edc = cellrange[s].column[1];

let formulaTxt = conditionValue0;
if(conditionValue0.toString().slice(0, 1) != '='){
formulaTxt = '=' + conditionValue0;
}

for(let r = str; r <= edr; r++){
for(let c = stc; c <= edc; c++){
let func = formulaTxt;
let offsetRow = r - str;
let offsetCol = c - stc;

if(offsetRow > 0){
func = "=" + formula.functionCopy(func, "down", offsetRow);
}

if(offsetCol > 0){
func = "=" + formula.functionCopy(func, "right", offsetCol);
}

let funcV = formula.execfunction(func);
let v = funcV[1];

if(typeof v != 'boolean'){
v = !!Number(v);
}

if(!v){
continue;
}

if((r + "_" + c) in computeMap){
computeMap[r + "_" + c]["textColor"] = textColor;
computeMap[r + "_" + c]["cellColor"] = cellColor;
}
else{
computeMap[r + "_" + c] = { "textColor": textColor, "cellColor": cellColor };
}
}
}
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/global/formula.js
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,7 @@ const luckysheetformula = {
$("#luckysheet-formula-search-c, #luckysheet-formula-help-c").hide();
_this.helpFunctionExe($editer, currSelection);

console.log(currSelection, $(currSelection).closest(".luckysheet-formula-functionrange-cell").length);
// console.log(currSelection, $(currSelection).closest(".luckysheet-formula-functionrange-cell").length);
if ($(currSelection).closest(".luckysheet-formula-functionrange-cell").length == 0) {
_this.searchFunction($editer);
return;
Expand Down Expand Up @@ -5619,7 +5619,7 @@ const luckysheetformula = {
Store.calculateSheetIndex = index;

let fp = $.trim(_this.functionParserExe(txt));

console.log(fp)
if ((fp.substr(0, 20) == "luckysheet_function." || fp.substr(0, 22) == "luckysheet_compareWith") ) {
_this.functionHTMLIndex = 0;
}
Expand Down
2 changes: 2 additions & 0 deletions src/locale/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -9591,6 +9591,8 @@ export default {
ruleTypeItem4: 'Format only values above or below the average',
ruleTypeItem4_title: 'Is a value that satisfies the following conditions',
ruleTypeItem5: 'Format only unique or repeated values',
ruleTypeItem6: 'Use formulas to determine which cells to format',
formula: 'Formula',
textColor: 'Text color',
cellColor: 'Cell color',
confirm: 'Confirm',
Expand Down
2 changes: 2 additions & 0 deletions src/locale/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -9589,6 +9589,8 @@ export default {
ruleTypeItem4: 'Aplicar formato solo a los valores superiores o inferiores al promedio',
ruleTypeItem4_title: 'Es un valor que cumple las siguientes condiciones',
ruleTypeItem5: 'Aplicar formato solo a valores únicos o repetidos',
ruleTypeItem6: 'Use fórmulas para determinar qué celdas formatear',
formula: 'fórmula',
textColor: 'Color Texto',
cellColor: 'Color Celda',
confirm: 'Confirma',
Expand Down
2 changes: 2 additions & 0 deletions src/locale/zh.js
Original file line number Diff line number Diff line change
Expand Up @@ -9833,6 +9833,8 @@ export default {
ruleTypeItem4: '仅对高于或低于平均值的数值设置格式',
ruleTypeItem4_title: '为满足以下条件的值',
ruleTypeItem5: '仅对唯一值或重复值设置格式',
ruleTypeItem6: '使用公式确定要设置格式的单元格',
formula: '公式',
textColor: '文本颜色',
cellColor: '单元格颜色',
confirm: '确定',
Expand Down
2 changes: 2 additions & 0 deletions src/locale/zh_tw.js
Original file line number Diff line number Diff line change
Expand Up @@ -9826,6 +9826,8 @@ export default {
ruleTypeItem4 : '僅對高於或低於平均值的數值設定格式',
ruleTypeItem4_title : '為滿足以下條件的值',
ruleTypeItem5 : '僅對唯一值或重複值設定格式',
ruleTypeItem6 : '使用公式確定要設置格式的單元格',
formula : '公式',
textColor : '文字顏色',
cellColor : '儲存格顏色',
confirm : '確定',
Expand Down

0 comments on commit 6c98bde

Please sign in to comment.