Commit 34fff8d8 authored by Alexander.Trofimov's avatar Alexander.Trofimov

fix inset rows/columns before pivot table

parent 566891c3
......@@ -2675,6 +2675,10 @@ CT_pivotTableDefinition.prototype.init = function () {
CT_pivotTableDefinition.prototype.intersection = function (range) {
return (this.location && this.location.intersection(range)) || this.pageFieldsIntersection(range);
};
CT_pivotTableDefinition.prototype.isIntersectForShift = function (range, offset) {
var ref = this.location && (this.location.refWithPage || this.location.ref);
return (ref && range.isIntersectForShift(ref, offset));
};
CT_pivotTableDefinition.prototype.pageFieldsIntersection = function (range) {
return this.pageFieldsPositions && this.pageFieldsPositions.some(function (element) {
return Array.isArray(range) ? range.some(function (elementRange) {
......@@ -4157,6 +4161,8 @@ function CT_Location() {
this.firstDataCol = null;
this.rowPageCount = null;//0
this.colPageCount = null;//0
// private
this.refWithPage = null;
}
CT_Location.prototype.readAttributes = function(attr, uq) {
if (attr()) {
......@@ -4220,8 +4226,19 @@ CT_Location.prototype.contains = function (col, row) {
return this.ref && this.ref.contains(col, row);
};
CT_Location.prototype.setPageCount = function (row, col) {
var c2;
this.rowPageCount = row;
this.colPageCount = col;
if (this.ref) {
this.refWithPage = this.ref.clone();
if (this.rowPageCount) {
this.refWithPage.setOffsetFirst(new AscCommonExcel.CRangeOffset(0, - (this.rowPageCount + 1)));
}
c2 = this.colPageCount * 3 - 1 - 1;
if (c2 > this.refWithPage.c2) {
this.refWithPage.setOffsetLast(new AscCommonExcel.CRangeOffset(c2 - this.refWithPage.c2, 0));
}
}
};
function CT_PivotFields() {
//Attributes
......
......@@ -3494,6 +3494,7 @@
//renameDependencyNodes before move cells to store current location in history
var changedFormulas = this.renameDependencyNodes(offset, oActualRange);
var redrawTablesArr = this.autoFilters.insertRows("delCell", oActualRange, c_oAscDeleteOptions.DeleteRows);
this.updatePivotOffset(oActualRange, offset);
var oDefRowPr = new AscCommonExcel.UndoRedoData_RowProp();
this.getRange3(start,0,stop,0)._foreachRowNoEmpty(function(row){
......@@ -3533,6 +3534,7 @@
//renameDependencyNodes before move cells to store current location in history
var changedFormulas = this.renameDependencyNodes(offset, oActualRange);
var redrawTablesArr = this.autoFilters.insertRows("insCell", oActualRange, c_oAscInsertOptions.InsertColumns);
this.updatePivotOffset(oActualRange, offset);
this._updateFormulasParents(index + count, 0, gc_nMaxRow0, gc_nMaxCol0, offset);
//insert new row/cell
......@@ -3586,13 +3588,13 @@
this.workbook.dependencyFormulas.lockRecal();
History.Create_NewPoint();
//start, stop 0 based
var nDif = -(stop - start + 1), i, j, length, nIndex;
var nDif = -(stop - start + 1), i, j, length;
var oActualRange = new Asc.Range(start, 0, stop, gc_nMaxRow0);
var offset = { offsetRow: 0, offsetCol: nDif };
//renameDependencyNodes before move cells to store current location in history
var changedFormulas = this.renameDependencyNodes(offset, oActualRange);
var redrawTablesArr = this.autoFilters.insertColumn(oActualRange, nDif);
this.updatePivotOffset(oActualRange, offset);
var oDefColPr = new AscCommonExcel.UndoRedoData_ColProp();
this.getRange3(start,0,stop,0)._foreachColNoEmpty(function(col){
......@@ -3635,6 +3637,7 @@
//renameDependencyNodes before move cells to store current location in history
var changedFormulas = this.renameDependencyNodes(offset, oActualRange);
var redrawTablesArr = this.autoFilters.insertColumn(oActualRange, count);
this.updatePivotOffset(oActualRange, offset);
this._updateFormulasParents(0, index + count, gc_nMaxRow0, gc_nMaxCol0, offset);
var prevCellsByCol = index > 0 ? this.cellsByCol[index - 1] : null;
......@@ -4540,7 +4543,7 @@
var offset = {offsetRow: dif, offsetCol: 0};
//renameDependencyNodes before move cells to store current location in history
var changedFormulas = this.renameDependencyNodes(offset, oBBox);
var redrawTablesArr = this.autoFilters.insertRows( "delCell", oBBox, c_oAscDeleteOptions.DeleteCellsAndShiftTop );
var redrawTablesArr = this.autoFilters.insertRows("delCell", oBBox, c_oAscDeleteOptions.DeleteCellsAndShiftTop);
this.getRange3(oBBox.r1, oBBox.c1, oBBox.r2, oBBox.c2)._foreachNoEmpty(function(cell){
t._removeCell(null, null, cell);
......@@ -4561,7 +4564,6 @@
//todo проверить не уменьшились ли границы таблицы
};
Worksheet.prototype._shiftCellsRight=function(oBBox, displayNameFormatTable){
var t = this;
var nLeft = oBBox.c1;
var nRight = oBBox.c2;
var dif = nRight - nLeft + 1;
......@@ -4610,11 +4612,9 @@
this.autoFilters.redrawStylesTables(redrawTablesArr);
};
Worksheet.prototype._shiftCellsBottom=function(oBBox, displayNameFormatTable){
var t = this;
var nTop = oBBox.r1;
var nBottom = oBBox.r2;
var dif = nBottom - nTop + 1;
var aIndexes = [];
var oActualRange = new Asc.Range(oBBox.c1, oBBox.r1, oBBox.c2, gc_nMaxRow0);
var offset = {offsetRow: dif, offsetCol: 0};
//renameDependencyNodes before move cells to store current location in history
......@@ -5413,11 +5413,32 @@
}
}
};
Worksheet.prototype.updatePivotOffset = function (range, offset) {
var pivotTable, pivotRange, cells;
for (var i = 0; i < this.pivotTables.length; ++i) {
pivotTable = this.pivotTables[i];
pivotRange = pivotTable.getRange();
if ((0 < offset.offsetCol && range.c1 <= pivotRange.c2) ||
(0 < offset.offsetRow && range.r1 <= pivotRange.r2)) {
cells = this.getRange3(pivotRange.r1, pivotRange.c1, pivotRange.r2, pivotRange.c2);
cells.clearTableStyle();
pivotRange.setOffset(offset);
pivotTable.init();
this.updatePivotTablesStyle(pivotRange);
}
}
};
Worksheet.prototype.inPivotTable = function (range) {
return this.pivotTables.some(function (element) {
return element.intersection(range);
});
};
Worksheet.prototype.checkShiftPivotTable = function (range, offset) {
return this.pivotTables.some(function (element) {
return AscCommonExcel.c_oAscShiftType.Change === element.isIntersectForShift(range, offset);
});
};
Worksheet.prototype.getPivotTable = function (col, row) {
var res = null;
for (var i = 0; i < this.pivotTables.length; ++i) {
......
......@@ -45,6 +45,12 @@
var c_oAscSelectionType = Asc.c_oAscSelectionType;
var c_oAscShiftType = {
None : 0,
Move : 1,
Change: 2
};
/** @const */
var kLeftLim1 = .999999999999999;
......@@ -367,29 +373,28 @@
};
Range.prototype.isIntersectForShift = function(range, offset) {
var isHor = offset && 0 != offset.offsetCol;
var isHor = offset && offset.offsetCol;
var toDelete = offset && (offset.offsetCol < 0 || offset.offsetRow < 0);
if (isHor) {
if (this.r1 <= range.r1 && range.r2 <= this.r2 && this.c1 <= range.c2) {
return true;
return (this.c1 < range.c1 || (this.c1 === range.c1 && this.c2 === range.c1)) ?
c_oAscShiftType.Move : c_oAscShiftType.Change;
} else if (toDelete && this.c1 <= range.c1 && range.c2 <= this.c2) {
var topIn = this.r1 <= range.r1 && range.r1 <= this.r2;
var bottomIn = this.r1 <= range.r2 && range.r2 <= this.r2;
return topIn || bottomIn;
} else {
return false;
}
} else {
if (this.c1 <= range.c1 && range.c2 <= this.c2 && this.r1 <= range.r2) {
return true;
return (this.r1 < range.r1 || (this.r1 === range.r1 && this.r2 === range.r1)) ?
c_oAscShiftType.Move : c_oAscShiftType.Change;
} else if (toDelete && this.r1 <= range.r1 && range.r2 <= this.r2) {
var leftIn = this.c1 <= range.c1 && range.c1 <= this.c2;
var rightIn = this.c1 <= range.c2 && range.c2 <= this.c2;
return leftIn || rightIn;
} else {
return false;
}
}
return c_oAscShiftType.None;
};
Range.prototype.isIntersectForShiftCell = function(col, row, offset) {
......@@ -2308,6 +2313,7 @@
var prot;
window['Asc'] = window['Asc'] || {};
window['AscCommonExcel'] = window['AscCommonExcel'] || {};
window["AscCommonExcel"].c_oAscShiftType = c_oAscShiftType;
window["AscCommonExcel"].recalcType = recalcType;
window["AscCommonExcel"].applyFunction = applyFunction;
window["Asc"].typeOf = typeOf;
......
......@@ -10290,7 +10290,7 @@
var arn = this.model.selectionRange.getLast().clone();
var checkRange = arn.getAllRange();
var range;
var range, count;
var oRecalcType = AscCommonExcel.recalcType.recalc;
var reinitRanges = false;
var updateDrawingObjectsInfo = null;
......@@ -10471,42 +10471,49 @@
c_oAscError.ID.AutoFilterChangeFormatTableError, c_oAscError.Level.NoCritical);
return;
}
lockRange = new asc_Range(arn.c1, 0, arn.c2, gc_nMaxRow0);
count = arn.c2 - arn.c1 + 1;
if (this.model.checkShiftPivotTable(lockRange,
new AscCommonExcel.CRangeOffset(count, 0))) {
this.model.workbook.handlers.trigger("asc_onError", c_oAscError.ID.LockedCellPivot,
c_oAscError.Level.NoCritical);
return;
}
functionModelAction = function () {
History.Create_NewPoint();
History.StartTransaction();
oRecalcType = AscCommonExcel.recalcType.full;
reinitRanges = true;
t.model.insertColsBefore(arn.c1, arn.c2 - arn.c1 + 1);
t.model.insertColsBefore(arn.c1, count);
updateDrawingObjectsInfo2 = {bInsert: true, operType: val, updateRange: arn};
t.cellCommentator.updateCommentsDependencies(true, val, arn);
History.EndTransaction();
};
arrChangedRanges.push(lockRange = new asc_Range(arn.c1, 0, arn.c2, gc_nMaxRow0));
if (this.model.inPivotTable(lockRange)) {
this.model.workbook.handlers.trigger("asc_onError", c_oAscError.ID.LockedCellPivot,
c_oAscError.Level.NoCritical);
return;
}
arrChangedRanges.push(lockRange);
this._isLockedCells(lockRange, c_oAscLockTypeElemSubType.InsertColumns,
onChangeWorksheetCallback);
break;
case c_oAscInsertOptions.InsertRows:
lockRange = new asc_Range(0, arn.r1, gc_nMaxCol0, arn.r2);
count = arn.r2 - arn.r1 + 1;
if (this.model.checkShiftPivotTable(lockRange,
new AscCommonExcel.CRangeOffset(0, count))) {
this.model.workbook.handlers.trigger("asc_onError", c_oAscError.ID.LockedCellPivot,
c_oAscError.Level.NoCritical);
return;
}
functionModelAction = function () {
oRecalcType = AscCommonExcel.recalcType.full;
reinitRanges = true;
t.model.insertRowsBefore(arn.r1, arn.r2 - arn.r1 + 1);
t.model.insertRowsBefore(arn.r1, count);
updateDrawingObjectsInfo2 = {bInsert: true, operType: val, updateRange: arn};
t.cellCommentator.updateCommentsDependencies(true, val, arn);
};
arrChangedRanges.push(lockRange = new asc_Range(0, arn.r1, gc_nMaxCol0, arn.r2));
if (this.model.inPivotTable(lockRange)) {
this.model.workbook.handlers.trigger("asc_onError", c_oAscError.ID.LockedCellPivot,
c_oAscError.Level.NoCritical);
return;
}
arrChangedRanges.push(lockRange);
this._isLockedCells(lockRange, c_oAscLockTypeElemSubType.InsertRows, onChangeWorksheetCallback);
break;
}
......
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