Commit 8e970924 authored by konovalovsergey's avatar konovalovsergey

TablePart with custom formula

parent 3447b823
...@@ -3756,7 +3756,6 @@ function parserFormula( formula, parent, _ws ) { ...@@ -3756,7 +3756,6 @@ function parserFormula( formula, parent, _ws ) {
this.parenthesesNotEnough = false; this.parenthesesNotEnough = false;
this.f = []; this.f = [];
this.reRowCol = /^(ROW|ROWS|COLUMN|COLUMNS)$/gi this.reRowCol = /^(ROW|ROWS|COLUMN|COLUMNS)$/gi
this.regSpace = /\$/g;
this.countRef = 0; this.countRef = 0;
this.listenerId = lastListenerId++; this.listenerId = lastListenerId++;
...@@ -3764,6 +3763,7 @@ function parserFormula( formula, parent, _ws ) { ...@@ -3764,6 +3763,7 @@ function parserFormula( formula, parent, _ws ) {
this.isDirty = false; this.isDirty = false;
this.isCalculate = false; this.isCalculate = false;
this.isTable = false; this.isTable = false;
this.isInDependencies = false;
this.parent = parent; this.parent = parent;
} }
parserFormula.prototype.getWs = function() { parserFormula.prototype.getWs = function() {
...@@ -3881,7 +3881,9 @@ parserFormula.prototype.clone = function(formula, parent, ws) { ...@@ -3881,7 +3881,9 @@ parserFormula.prototype.clone = function(formula, parent, ws) {
oRes.isParsed = this.isParsed; oRes.isParsed = this.isParsed;
return oRes; return oRes;
}; };
parserFormula.prototype.getFormula = function() {
return this.Formula;
}
parserFormula.prototype.setFormula = function(formula) { parserFormula.prototype.setFormula = function(formula) {
this.Formula = formula; this.Formula = formula;
this.is3D = false; this.is3D = false;
...@@ -5100,7 +5102,10 @@ parserFormula.prototype.assembleLocale = function(locale, digitDelim) { ...@@ -5100,7 +5102,10 @@ parserFormula.prototype.assembleLocale = function(locale, digitDelim) {
} }
}; };
parserFormula.prototype.buildDependencies = function() { parserFormula.prototype.buildDependencies = function() {
if (this.isInDependencies) {
return;
}
this.isInDependencies = true;
var ref, wsR; var ref, wsR;
var isTable = this.isTable; var isTable = this.isTable;
var bbox; var bbox;
...@@ -5160,6 +5165,10 @@ parserFormula.prototype.assembleLocale = function(locale, digitDelim) { ...@@ -5160,6 +5165,10 @@ parserFormula.prototype.assembleLocale = function(locale, digitDelim) {
} }
}; };
parserFormula.prototype.removeDependencies = function() { parserFormula.prototype.removeDependencies = function() {
if (!this.isInDependencies) {
return;
}
this.isInDependencies = false;
var ref; var ref;
var wsR; var wsR;
var isTable = this.isTable; var isTable = this.isTable;
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -5673,7 +5673,7 @@ function TablePart(handlers) { ...@@ -5673,7 +5673,7 @@ function TablePart(handlers) {
this.result = null; this.result = null;
this.handlers = handlers; this.handlers = handlers;
} }
TablePart.prototype.clone = function(ws, tableName) { TablePart.prototype.clone = function() {
var i, res = new TablePart(this.handlers); var i, res = new TablePart(this.handlers);
res.Ref = this.Ref ? this.Ref.clone() : null; res.Ref = this.Ref ? this.Ref.clone() : null;
res.HeaderRowCount = this.HeaderRowCount; res.HeaderRowCount = this.HeaderRowCount;
...@@ -5695,17 +5695,7 @@ TablePart.prototype.clone = function(ws, tableName) { ...@@ -5695,17 +5695,7 @@ TablePart.prototype.clone = function(ws, tableName) {
for (i = 0; i < this.result.length; ++i) for (i = 0; i < this.result.length; ++i)
res.result.push(this.result[i].clone()); res.result.push(this.result[i].clone());
} }
if(tableName)
{
res.DisplayName = tableName;
}
else
{
res.DisplayName = this.DisplayName; res.DisplayName = this.DisplayName;
}
if(ws !== null)
res.recalc(ws, tableName);
return res; return res;
}; };
TablePart.prototype.renameSheetCopy = function(ws, renameParams) { TablePart.prototype.renameSheetCopy = function(ws, renameParams) {
...@@ -5726,10 +5716,6 @@ TablePart.prototype.clone = function(ws, tableName) { ...@@ -5726,10 +5716,6 @@ TablePart.prototype.clone = function(ws, tableName) {
this.TableColumns[i].buildDependencies(); this.TableColumns[i].buildDependencies();
} }
}; };
TablePart.prototype.recalc = function(ws, tableName) {
this.DisplayName = ws.workbook.dependencyFormulas.getNextTableName();
ws.workbook.dependencyFormulas.addTableName(ws, this);
};
TablePart.prototype.moveRef = function(col, row) { TablePart.prototype.moveRef = function(col, row) {
var ref = this.Ref.clone(); var ref = this.Ref.clone();
ref.setOffset({offsetCol: col ? col : 0, offsetRow: row ? row : 0}); ref.setOffset({offsetCol: col ? col : 0, offsetRow: row ? row : 0});
...@@ -6318,8 +6304,8 @@ function TableColumn() { ...@@ -6318,8 +6304,8 @@ function TableColumn() {
} else if (AscCommon.c_oNotifyParentType.ChangeFormula === type) { } else if (AscCommon.c_oNotifyParentType.ChangeFormula === type) {
if (eventData.isRebuild) { if (eventData.isRebuild) {
var ws = this.TotalsRowFormula.ws; var ws = this.TotalsRowFormula.ws;
this.TotalsRowFormula = null;//to prevent removeDependencies in _setTotalRowFormula this.TotalsRowFormula = null;//to prevent removeDependencies in applyTotalRowFormula
this._setTotalRowFormula(eventData.assemble, ws, true); this.applyTotalRowFormula(eventData.assemble, ws, true);
} else { } else {
this.TotalsRowFormula.Formula = eventData.assemble; this.TotalsRowFormula.Formula = eventData.assemble;
this.TotalsRowFormula.buildDependencies(); this.TotalsRowFormula.buildDependencies();
...@@ -6328,12 +6314,14 @@ function TableColumn() { ...@@ -6328,12 +6314,14 @@ function TableColumn() {
}; };
TableColumn.prototype.renameSheetCopy = function(ws, renameParams) { TableColumn.prototype.renameSheetCopy = function(ws, renameParams) {
if (this.TotalsRowFormula) { if (this.TotalsRowFormula) {
this.buildDependencies();
this.TotalsRowFormula.renameSheetCopy(renameParams); this.TotalsRowFormula.renameSheetCopy(renameParams);
this._setTotalRowFormula(this.TotalsRowFormula.assemble(true), ws, true); this.applyTotalRowFormula(this.TotalsRowFormula.assemble(true), ws, true);
} }
}; };
TableColumn.prototype.buildDependencies = function() { TableColumn.prototype.buildDependencies = function() {
if (this.TotalsRowFormula) { if (this.TotalsRowFormula) {
this.TotalsRowFormula.parse();
this.TotalsRowFormula.buildDependencies(); this.TotalsRowFormula.buildDependencies();
} }
}; };
...@@ -6349,7 +6337,7 @@ TableColumn.prototype.clone = function() { ...@@ -6349,7 +6337,7 @@ TableColumn.prototype.clone = function() {
res.TotalsRowFunction = this.TotalsRowFunction; res.TotalsRowFunction = this.TotalsRowFunction;
if (this.TotalsRowFormula) { if (this.TotalsRowFormula) {
res._setTotalRowFormula(this.TotalsRowFormula.Formula, this.TotalsRowFormula.ws, false); res.applyTotalRowFormula(this.TotalsRowFormula.Formula, this.TotalsRowFormula.ws, false);
} }
if (this.dxf) if (this.dxf)
res.dxf = this.dxf.clone; res.dxf = this.dxf.clone;
...@@ -6395,9 +6383,7 @@ TableColumn.prototype.getTotalRowFormula = function(tablePart){ ...@@ -6395,9 +6383,7 @@ TableColumn.prototype.getTotalRowFormula = function(tablePart){
} }
case Asc.ETotalsRowFunction.totalrowfunctionCustom: case Asc.ETotalsRowFunction.totalrowfunctionCustom:
{ {
if (this.TotalsRowFormula) { res = this.getTotalsRowFormula();
res = this.TotalsRowFormula.Formula;
}
break; break;
} }
case Asc.ETotalsRowFunction.totalrowfunctionMax: case Asc.ETotalsRowFunction.totalrowfunctionMax:
...@@ -6437,18 +6423,20 @@ TableColumn.prototype.getTotalRowFormula = function(tablePart){ ...@@ -6437,18 +6423,20 @@ TableColumn.prototype.getTotalRowFormula = function(tablePart){
TableColumn.prototype.cleanTotalsData = function(){ TableColumn.prototype.cleanTotalsData = function(){
this.CalculatedColumnFormula = null; this.CalculatedColumnFormula = null;
this._setTotalRowFormula(null, null, false); this.applyTotalRowFormula(null, null, false);
this.TotalsRowFunction = null; this.TotalsRowFunction = null;
this.TotalsRowLabel = null; this.TotalsRowLabel = null;
}; };
TableColumn.prototype.getTotalsRowFormula = function(){
return this.TotalsRowFormula ? this.TotalsRowFormula.getFormula() : null;
};
TableColumn.prototype.setTotalsRowFormula = function(val, ws){ TableColumn.prototype.setTotalsRowFormula = function(val, ws){
this.cleanTotalsData(); this.cleanTotalsData();
if("=" === val[0]) if("=" === val[0])
{ {
val = val.substring(1); val = val.substring(1);
} }
this._setTotalRowFormula(val, ws, true); this.applyTotalRowFormula(val, ws, true);
this.TotalsRowFunction = Asc.ETotalsRowFunction.totalrowfunctionCustom; this.TotalsRowFunction = Asc.ETotalsRowFunction.totalrowfunctionCustom;
}; };
...@@ -6465,22 +6453,20 @@ TableColumn.prototype.checkTotalRowFormula = function(ws, tablePart){ ...@@ -6465,22 +6453,20 @@ TableColumn.prototype.checkTotalRowFormula = function(ws, tablePart){
if(null !== totalRowFormula) if(null !== totalRowFormula)
{ {
this._setTotalRowFormula(totalRowFormula, ws, true); this.applyTotalRowFormula(totalRowFormula, ws, true);
this.TotalsRowFunction = Asc.ETotalsRowFunction.totalrowfunctionCustom; this.TotalsRowFunction = Asc.ETotalsRowFunction.totalrowfunctionCustom;
} }
} }
}; };
TableColumn.prototype._setTotalRowFormula = function(val, opt_ws, opt_buildDep) { TableColumn.prototype.applyTotalRowFormula = function(val, opt_ws, opt_buildDep) {
if (this.TotalsRowFormula) { this.removeDependencies();
this.TotalsRowFormula.removeDependencies();
this.TotalsRowFormula = null;
}
if (val) { if (val) {
this.TotalsRowFormula = new AscCommonExcel.parserFormula(val, this, opt_ws); this.TotalsRowFormula = new AscCommonExcel.parserFormula(val, this, opt_ws);
this.TotalsRowFormula.parse();
if (opt_buildDep) { if (opt_buildDep) {
this.TotalsRowFormula.buildDependencies(); this.buildDependencies();
} }
} else {
this.TotalsRowFormula = null;
} }
}; };
......
...@@ -962,9 +962,6 @@ ...@@ -962,9 +962,6 @@
if (undoData.clone) { if (undoData.clone) {
cloneData = undoData.clone(null); cloneData = undoData.clone(null);
if (cloneData.buildDependencies) {
cloneData.buildDependencies();
}
} else } else
cloneData = undoData; cloneData = undoData;
...@@ -986,10 +983,7 @@ ...@@ -986,10 +983,7 @@
{ {
if(cloneData.TableStyleInfo) if(cloneData.TableStyleInfo)
{ {
if(!worksheet.TableParts) worksheet.addTablePart(cloneData ,true);
worksheet.TableParts = [];
worksheet.TableParts[worksheet.TableParts.length] = cloneData;
worksheet.workbook.dependencyFormulas.addTableName(worksheet, cloneData);
this._setColorStyleTable(cloneData.Ref, cloneData, null, true); this._setColorStyleTable(cloneData.Ref, cloneData, null, true);
} }
else else
...@@ -1005,7 +999,7 @@ ...@@ -1005,7 +999,7 @@
{ {
if(cloneData.newFilterRef && cloneData.oldFilter && cloneData.oldFilter.DisplayName === worksheet.TableParts[l].DisplayName) if(cloneData.newFilterRef && cloneData.oldFilter && cloneData.oldFilter.DisplayName === worksheet.TableParts[l].DisplayName)
{ {
worksheet.TableParts[l] = cloneData.oldFilter.clone(null); worksheet.changeTablePart(l, cloneData.oldFilter.clone(null), false);
//чистим стиль от старой таблицы //чистим стиль от старой таблицы
var clearRange = new AscCommonExcel.Range(worksheet, cloneData.newFilterRef.r1, cloneData.newFilterRef.c1, cloneData.newFilterRef.r2, cloneData.newFilterRef.c2); var clearRange = new AscCommonExcel.Range(worksheet, cloneData.newFilterRef.r1, cloneData.newFilterRef.c1, cloneData.newFilterRef.r2, cloneData.newFilterRef.c2);
...@@ -1032,8 +1026,7 @@ ...@@ -1032,8 +1026,7 @@
{ {
if(oldName === worksheet.TableParts[l].DisplayName) if(oldName === worksheet.TableParts[l].DisplayName)
{ {
worksheet.TableParts[l] = cloneData.oldFilter.clone(null); worksheet.changeTablePart(l, cloneData.oldFilter.clone(null), true);
worksheet.workbook.dependencyFormulas.changeTableName(oldName, worksheet.TableParts[l].DisplayName);
break; break;
} }
} }
...@@ -1048,7 +1041,7 @@ ...@@ -1048,7 +1041,7 @@
{ {
if(cloneData.oldFilter.DisplayName === worksheet.TableParts[l].DisplayName) if(cloneData.oldFilter.DisplayName === worksheet.TableParts[l].DisplayName)
{ {
worksheet.TableParts[l] = cloneData.oldFilter.clone(null); worksheet.changeTablePart(l, cloneData.oldFilter.clone(null), false);
break; break;
} }
} }
...@@ -1064,7 +1057,7 @@ ...@@ -1064,7 +1057,7 @@
//если передавать в redo displaName -> конфликт при совместном ред.(1- ый добавляет ф/т + undo, 2-ой добавляет ф/т, первый делает redo->2 одинаковых имени) //если передавать в redo displaName -> конфликт при совместном ред.(1- ый добавляет ф/т + undo, 2-ой добавляет ф/т, первый делает redo->2 одинаковых имени)
if(cloneData.Ref.isEqual(worksheet.TableParts[l].Ref)) if(cloneData.Ref.isEqual(worksheet.TableParts[l].Ref))
{ {
worksheet.TableParts[l] = cloneData.clone(null); worksheet.changeTablePart(l, cloneData.clone(null), false);
this._setColorStyleTable(cloneData.Ref, cloneData, null, true); this._setColorStyleTable(cloneData.Ref, cloneData, null, true);
break; break;
} }
...@@ -1089,7 +1082,7 @@ ...@@ -1089,7 +1082,7 @@
{ {
if(cloneData.Ref.isEqual(worksheet.TableParts[l].Ref)) if(cloneData.Ref.isEqual(worksheet.TableParts[l].Ref))
{ {
worksheet.TableParts[l] = cloneData; worksheet.changeTablePart(l, cloneData, false);
if(cloneData.AutoFilter && cloneData.AutoFilter.FilterColumns) if(cloneData.AutoFilter && cloneData.AutoFilter.FilterColumns)
this._reDrawCurrentFilter(cloneData.AutoFilter.FilterColumns, worksheet.TableParts[l]); this._reDrawCurrentFilter(cloneData.AutoFilter.FilterColumns, worksheet.TableParts[l]);
else else
...@@ -1109,10 +1102,7 @@ ...@@ -1109,10 +1102,7 @@
{ {
if(cloneData.TableStyleInfo) if(cloneData.TableStyleInfo)
{ {
if(!worksheet.TableParts) worksheet.addTablePart.push(cloneData);
worksheet.TableParts = [];
worksheet.TableParts[worksheet.TableParts.length] = cloneData;
worksheet.workbook.dependencyFormulas.addTableName(worksheet, cloneData);
this._setColorStyleTable(cloneData.Ref, cloneData, null, true); this._setColorStyleTable(cloneData.Ref, cloneData, null, true);
} }
else else
...@@ -1133,11 +1123,7 @@ ...@@ -1133,11 +1123,7 @@
if(cloneData.Ref.isEqual(worksheet.TableParts[l].Ref)) if(cloneData.Ref.isEqual(worksheet.TableParts[l].Ref))
{ {
this._cleanStyleTable(cloneData.Ref); this._cleanStyleTable(cloneData.Ref);
worksheet.workbook.dependencyFormulas.delTableName(worksheet.TableParts[l].DisplayName); worksheet.deleteTablePart(l);
var deleted = worksheet.TableParts.splice(l,1);
for (var delIndex = 0; delIndex < deleted.length; ++delIndex) {
deleted[delIndex].removeDependencies();
}
} }
} }
} }
...@@ -1198,6 +1184,7 @@ ...@@ -1198,6 +1184,7 @@
var changeFilter = function(filter, isTablePart) var changeFilter = function(filter, isTablePart)
{ {
var bRes = false;
var oldFilter = filter.clone(null); var oldFilter = filter.clone(null);
var oRange = AscCommonExcel.Range.prototype.createFromBBox(worksheet, oldFilter.Ref); var oRange = AscCommonExcel.Range.prototype.createFromBBox(worksheet, oldFilter.Ref);
...@@ -1220,11 +1207,9 @@ ...@@ -1220,11 +1207,9 @@
} }
else else
t._addHistoryObj(oldFilter, AscCH.historyitem_AutoFilter_Empty, {activeCells: activeCells}, null, oldFilter.Ref); t._addHistoryObj(oldFilter, AscCH.historyitem_AutoFilter_Empty, {activeCells: activeCells}, null, oldFilter.Ref);
bRes = true;
if(isTablePart) }
worksheet.workbook.dependencyFormulas.delTableName(oldFilter.DisplayName) return bRes;
} else
return filter;
}; };
if(worksheet.AutoFilter) if(worksheet.AutoFilter)
...@@ -1233,19 +1218,13 @@ ...@@ -1233,19 +1218,13 @@
} }
if(worksheet.TableParts) if(worksheet.TableParts)
{ {
var newTableParts = []; for (var i = worksheet.TableParts.length - 1; i >= 0; i--)
for(var i = 0; i < worksheet.TableParts.length; i++)
{ {
var tablePart = worksheet.TableParts[i]; var tablePart = worksheet.TableParts[i];
var filter = changeFilter(tablePart, true); if (!changeFilter(tablePart, true)) {
if(filter){ worksheet.deleteTablePart(i);
newTableParts.push(filter);
} else {
tablePart.removeDependencies();
} }
} }
worksheet.TableParts = newTableParts;
} }
t._setStyleTablePartsAfterOpenRows(activeCells); t._setStyleTablePartsAfterOpenRows(activeCells);
...@@ -3072,7 +3051,7 @@ ...@@ -3072,7 +3051,7 @@
} }
var oldLabel = tableColumn.TotalsRowLabel; var oldLabel = tableColumn.TotalsRowLabel;
var oldFormula = tableColumn.TotalsRowFormula ? tableColumn.TotalsRowFormula.Formula : null; var oldFormula = tableColumn.getTotalsRowFormula();
if(null !== formula) if(null !== formula)
{ {
...@@ -3616,8 +3595,6 @@ ...@@ -3616,8 +3595,6 @@
} }
else else
{ {
if(!worksheet.TableParts)
worksheet.TableParts = [];
//ref = Asc.g_oRangeCache.getAscRange(val[0].id + ':' + val[val.length - 1].idNext).clone(); //ref = Asc.g_oRangeCache.getAscRange(val[0].id + ':' + val[val.length - 1].idNext).clone();
newFilter = worksheet.createTablePart(); newFilter = worksheet.createTablePart();
...@@ -3651,7 +3628,6 @@ ...@@ -3651,7 +3628,6 @@
} }
newFilter.DisplayName = newTableName; newFilter.DisplayName = newTableName;
worksheet.workbook.dependencyFormulas.addTableName(worksheet, newFilter);
var tableColumns; var tableColumns;
if(tablePart && tablePart.TableColumns) if(tablePart && tablePart.TableColumns)
...@@ -3668,7 +3644,7 @@ ...@@ -3668,7 +3644,7 @@
} }
newFilter.TableColumns = tableColumns; newFilter.TableColumns = tableColumns;
worksheet.TableParts[worksheet.TableParts.length] = newFilter; worksheet.addTablePart(newFilter, true);
//TODO возможно дублируется при всавке(ф-ия _pasteFromBinary) - пересмотреть //TODO возможно дублируется при всавке(ф-ия _pasteFromBinary) - пересмотреть
if (tablePart) { if (tablePart) {
var renameParams = {}; var renameParams = {};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment