Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/bug 48994 #1653

Merged
merged 7 commits into from
Mar 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 30 additions & 86 deletions cell/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2700,92 +2700,33 @@ var editor;
}
};

spreadsheet_api.prototype.asc_groupPivot = function (opt_rangePr, opt_dateTypes) {
var t = this;
var ws = this.wbModel.getActiveWs();
var activeCell = ws.selectionRange.activeCell;
var pivotTable = ws.getPivotTable(activeCell.col, activeCell.row);
if (pivotTable && ws.selectionRange.inContains(pivotTable.getReportRanges())) {
var layout = pivotTable.getLayoutsForGroup(ws.selectionRange);
if (null !== layout.fld) {
var fieldGroupType = pivotTable.getFieldGroupType(layout.fld);
var rangePrRes = pivotTable.getGroupRangePr(layout.fld);
if (opt_rangePr && opt_rangePr.getFieldGroupType() === fieldGroupType) {
this._changePivotAndConnectedByPivotCacheWithLock(pivotTable, false, function (confirmation, pivotTables) {
var changeRes = t._changePivot(pivotTable, confirmation, true, function () {
var oldPivot = new AscCommonExcel.UndoRedoData_BinaryWrapper(pivotTable.cloneForHistory(true, false));

pivotTable.groupRangePr(layout.fld, opt_rangePr, opt_dateTypes);

var newPivot = new AscCommonExcel.UndoRedoData_BinaryWrapper(pivotTable.cloneForHistory(true, false));
History.Add(AscCommonExcel.g_oUndoRedoWorksheet, AscCH.historyitem_Worksheet_PivotReplaceKeepRecords, ws.getId(),
null, new AscCommonExcel.UndoRedoData_PivotTableRedo(pivotTable.Get_Id(), oldPivot, newPivot));

pivotTable._updateCacheDataUpdateSlicersPost();
});
return changeRes;
});
} else if (rangePrRes) {
//todo dialog
//this.handlers.trigger("setAutoFiltersDialog", rangePrRes.rangePrRes, rangePrRes.dateTypes);
this.asc_groupPivot(rangePrRes.rangePr, rangePrRes.dateTypes);
} else if (1 === layout.getGroupSize() && c_oAscGroupType.Text !== pivotTable.getFieldGroupType(layout.fld)) {
rangePrRes = pivotTable.createGroupRangePr(layout.fld);
//todo dialog
this.asc_groupPivot(rangePrRes.rangePr, rangePrRes.dateTypes);
} else if (layout.getGroupSize() > 1) {
this._changePivotAndConnectedByPivotCacheWithLock(pivotTable, false, function(confirmation, pivotTables) {
var changeRes = t._changePivot(pivotTable, confirmation, true, function(){
var oldPivot = new AscCommonExcel.UndoRedoData_BinaryWrapper(pivotTable.cloneForHistory(true, false));

var groupRes = pivotTable.groupDiscreteCache(layout);
pivotTable.groupDiscrete(layout, groupRes);

var newPivot = new AscCommonExcel.UndoRedoData_BinaryWrapper(pivotTable.cloneForHistory(true, false));
History.Add(AscCommonExcel.g_oUndoRedoWorksheet, AscCH.historyitem_Worksheet_PivotReplaceKeepRecords, ws.getId(),
null, new AscCommonExcel.UndoRedoData_PivotTableRedo(pivotTable.Get_Id(), oldPivot, newPivot));

pivotTable._updateCacheDataUpdateSlicersPost();
});
return changeRes;
});
} else {
this.sendEvent('asc_onError', c_oAscError.ID.PivotGroup, c_oAscError.Level.Critical);
}
}
}
};
spreadsheet_api.prototype.asc_ungroupPivot = function () {
var t = this;
var ws = this.wbModel.getActiveWs();
var activeCell = ws.selectionRange.activeCell;
var pivotTable = ws.getPivotTable(activeCell.col, activeCell.row);
if (pivotTable && ws.selectionRange.inContains(pivotTable.getReportRanges())) {
var layout = pivotTable.getLayoutsForGroup(ws.selectionRange);
if (null !== layout.fld) {
if (layout.getGroupSize() > 0) {
this._changePivotAndConnectedByPivotCacheWithLock(pivotTable, false, function(confirmation, pivotTables) {
var groupRes;
var changeRes = t._changePivot(pivotTable, confirmation, true, function(){
var oldPivot = new AscCommonExcel.UndoRedoData_BinaryWrapper(pivotTable.cloneForHistory(true, false));

groupRes = pivotTable.ungroupDiscreteCache(layout);
pivotTable.ungroupDiscrete(layout, groupRes);

var newPivot = new AscCommonExcel.UndoRedoData_BinaryWrapper(pivotTable.cloneForHistory(true, false));
History.Add(AscCommonExcel.g_oUndoRedoWorksheet, AscCH.historyitem_Worksheet_PivotReplaceKeepRecords, ws.getId(),
null, new AscCommonExcel.UndoRedoData_PivotTableRedo(pivotTable.Get_Id(), oldPivot, newPivot));

pivotTable._updateCacheDataUpdateSlicersPost();
});
return changeRes;
});
} else {
this.sendEvent('asc_onError', c_oAscError.ID.PivotGroup, c_oAscError.Level.Critical);
}
}
}
};
spreadsheet_api.prototype._canGroupPivot = function () {
var ws = this.wbModel.getActiveWs();
var activeCell = ws.selectionRange.activeCell;
var pivotTable = ws.getPivotTable(activeCell.col, activeCell.row);
if (pivotTable && ws.selectionRange.inContains(pivotTable.getReportRanges())) {
var layout = pivotTable.getLayoutsForGroup(ws.selectionRange);
if (null !== layout.fld) {
return {pivotTable: pivotTable, layout: layout};
}
}
return null;
};
spreadsheet_api.prototype.asc_canGroupPivot = function () {
return !!this._canGroupPivot();
};
spreadsheet_api.prototype.asc_groupPivot = function (opt_rangePr, opt_dateTypes) {
var canGroupRes = this._canGroupPivot();
if(canGroupRes) {
canGroupRes.pivotTable.groupPivot(this, canGroupRes.layout, opt_rangePr, opt_dateTypes);
}
};
spreadsheet_api.prototype.asc_ungroupPivot = function () {
var canGroupRes = this._canGroupPivot();
if(canGroupRes) {
canGroupRes.pivotTable.ungroupPivot(this, canGroupRes.layout);
}
};

spreadsheet_api.prototype.asc_ungroup = function(val) {
if(val) {
Expand Down Expand Up @@ -5398,6 +5339,9 @@ var editor;
//Group data
prot["asc_group"] = prot.asc_group;
prot["asc_ungroup"] = prot.asc_ungroup;
prot["asc_canGroupPivot"] = prot.asc_canGroupPivot;
prot["asc_groupPivot"] = prot.asc_groupPivot;
prot["asc_ungroupPivot"] = prot.asc_ungroupPivot;
prot["asc_clearOutline"] = prot.asc_clearOutline;
prot["asc_changeGroupDetails"] = prot.asc_changeGroupDetails;
prot["asc_checkAddGroup"] = prot.asc_checkAddGroup;
Expand Down
Loading