Commit 8e970924 authored by konovalovsergey's avatar konovalovsergey

TablePart with custom formula

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