Commit 747addfc authored by Alexander.Trofimov's avatar Alexander.Trofimov

add change pivot table style to undo/redo

parent 0a38bc51
......@@ -142,6 +142,8 @@ function (window, undefined) {
window['AscCH'].historyitem_AutoFilter_ChangeColumnName = 16;
window['AscCH'].historyitem_AutoFilter_ChangeTotalRow = 17;
window['AscCH'].historyitem_PivotTable_StyleName = 1;
function CHistory()
......
......@@ -2002,6 +2002,7 @@ function CT_pivotTableDefinition() {
//editor
this.cacheDefinition = null;
this.isInit = false;
this.pageFieldsPositions = null;
this.clearGrid = false;
this.hasCompact = true;
......@@ -2675,6 +2676,7 @@ CT_pivotTableDefinition.prototype.toXml = function(writer) {
writer.WriteXmlNodeEnd("pivotTableDefinition");
};
CT_pivotTableDefinition.prototype.init = function () {
this.isInit = true;
this.pageFieldsPositions = [];
var rowPageCount = null, colPageCount = null;
......@@ -4975,7 +4977,7 @@ CT_PivotTableStyle.prototype.asc_getShowColStripes = function() {
CT_PivotTableStyle.prototype.asc_setName = function(api, pivot, newVal) {
if (newVal !== this.name) {
var t = this;
api._changePivotStyle(pivot, function() {t._setName(newVal)});
api._changePivotStyle(pivot, function(ws) {t._setName(newVal, pivot, ws)});
}
};
CT_PivotTableStyle.prototype.asc_setShowRowHeaders = function(api, pivot, newVal) {
......@@ -5002,7 +5004,12 @@ CT_PivotTableStyle.prototype.asc_setShowColStripes = function(api, pivot, newVal
api._changePivotStyle(pivot, function() {t._setShowColStripes(newVal)});
}
};
CT_PivotTableStyle.prototype._setName = function(newVal) {
CT_PivotTableStyle.prototype._setName = function (newVal, pivot, ws) {
if (History.Is_On() && this.name !== newVal) {
History.Add(AscCommonExcel.g_oUndoRedoPivotTables, AscCH.historyitem_PivotTable_StyleName,
ws ? ws.getId() : null, null,
new AscCommonExcel.UndoRedoData_PivotTable(pivot && pivot.asc_getName(), this.name, newVal));
}
this.name = newVal;
};
CT_PivotTableStyle.prototype._setShowRowHeaders = function(newVal) {
......
......@@ -460,8 +460,7 @@ var UndoRedoDataTypes = new function() {
this.DynamicFilter = 75;
this.Top10 = 76;
this.PropertyChanges = 79;
this.SparklineProps = 80;
this.PivotTable = 80;
this.Create = function(nType)
{
......@@ -532,6 +531,8 @@ var UndoRedoDataTypes = new function() {
case this.ParagraphParaItemAdd: return new UndoRedoData_historyitem_Paragraph_AddItem();
case this.DefinedName: return new UndoRedoData_DefinedNames();
case this.PivotTable: return new UndoRedoData_PivotTable();
}
return null;
};
......@@ -1083,6 +1084,50 @@ UndoRedoData_SortData.prototype = {
}
};
function UndoRedoData_PivotTable(pivot, from, to) {
this.pivot = pivot;
this.from = from;
this.to = to;
}
UndoRedoData_PivotTable.prototype.Properties = {
pivot: 0,
from: 1,
to: 2
};
UndoRedoData_PivotTable.prototype.getType = function () {
return UndoRedoDataTypes.PivotTable;
};
UndoRedoData_PivotTable.prototype.getProperties = function () {
return this.Properties;
};
UndoRedoData_PivotTable.prototype.getProperty = function (nType) {
switch (nType) {
case this.Properties.pivot:
return this.pivot;
break;
case this.Properties.from:
return this.from;
break;
case this.Properties.to:
return this.to;
break;
}
return null;
};
UndoRedoData_PivotTable.prototype.setProperty = function (nType, value) {
switch (nType) {
case this.Properties.pivot:
this.pivot = value;
break;
case this.Properties.from:
this.from = value;
break;
case this.Properties.to:
this.to = value;
break;
}
};
function UndoRedoData_GTableIdAdd(object, id)
{
......@@ -2972,11 +3017,7 @@ UndoRedoCell.prototype = {
this.wb.aCollaborativeChangeElements.push(oLockInfo);
}
ws._getCell(nRow, nCol, function(cell) {
var Val;
if(bUndo)
Val = Data.oOldVal;
else
Val = Data.oNewVal;
var Val = bUndo ? Data.oOldVal : Data.oNewVal;
if(AscCH.historyitem_Cell_Fontname == Type)
cell.setFontname(Val);
else if(AscCH.historyitem_Cell_Fontsize == Type)
......@@ -3812,10 +3853,28 @@ UndoRedoAutoFilters.prototype = {
this.UndoRedo(Type, Data, nSheetId, false);
};
UndoRedoPivotTables.prototype.UndoRedo = function (Type, Data, nSheetId, bUndo) {
var wb = opt_wb ? opt_wb : this.wb;
var ws = wb.getWorksheetById(nSheetId);
if (ws) {
var ws = this.wb.getWorksheetById(nSheetId);
if (!ws) {
return;
}
var pivotTable = ws.getPivotTableByName(Data.pivot);
if (!pivotTable) {
return;
}
var value = bUndo ? Data.from : Data.to;
switch (Type) {
case AscCH.historyitem_PivotTable_StyleName:
pivotTable.asc_getStyleInfo()._setName(value);
break;
}
// ToDo not the best way to update
if (pivotTable.isInit) {
var pivotRange = pivotTable.getRange();
ws.updatePivotTablesStyle(pivotRange);
var api = window["Asc"]["editor"];
api.wb.getWorksheet()._onUpdateFormatTable(pivotRange);
}
};
......@@ -3834,6 +3893,7 @@ UndoRedoAutoFilters.prototype = {
window['AscCommonExcel'].UndoRedoData_RowProp = UndoRedoData_RowProp;
window['AscCommonExcel'].UndoRedoData_BBox = UndoRedoData_BBox;
window['AscCommonExcel'].UndoRedoData_SortData = UndoRedoData_SortData;
window['AscCommonExcel'].UndoRedoData_PivotTable = UndoRedoData_PivotTable;
window['AscCommonExcel'].UndoRedoData_SheetAdd = UndoRedoData_SheetAdd;
window['AscCommonExcel'].UndoRedoData_SheetRemove = UndoRedoData_SheetRemove;
window['AscCommonExcel'].UndoRedoData_DefinedNames = UndoRedoData_DefinedNames;
......
......@@ -5262,7 +5262,7 @@
pivotTable = this.pivotTables[i];
pivotRange = pivotTable.getRange();
styleInfo = pivotTable.asc_getStyleInfo();
if (!styleInfo || (range && !pivotTable.intersection(range))) {
if (!pivotTable.isInit || !styleInfo || (range && !pivotTable.intersection(range))) {
continue;
}
style = this.workbook.TableStyles.AllStyles[styleInfo.asc_getName()];
......@@ -5533,6 +5533,16 @@
}
return res;
};
Worksheet.prototype.getPivotTableByName = function (name) {
var res = null;
for (var i = 0; i < this.pivotTables.length; ++i) {
if (this.pivotTables[i].asc_getName() === name) {
res = this.pivotTables[i];
break;
}
}
return res;
};
Worksheet.prototype.getPivotTableButtons = function (range) {
var res = [];
var pivotTable, pivotRange, j, pos, countC, countCWValues, countR, cell;
......
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