Skip to content

Commit

Permalink
[se] For bug 58524
Browse files Browse the repository at this point in the history
  • Loading branch information
konovalovsergey committed Aug 16, 2022
1 parent 25cafc4 commit d0ca9a6
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 10 deletions.
50 changes: 42 additions & 8 deletions cell/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -6220,13 +6220,47 @@ var editor;
History.EndTransaction();
return pivot;
};
spreadsheet_api.prototype.asc_refreshAllPivots = function() {
spreadsheet_api.prototype.asc_refreshAllPivots = function(opt_confirmation) {
var t = this;
let pivotTables = [];
this.wbModel.forEach(function(ws) {
for (var i = 0; i < ws.pivotTables.length; ++i) {
ws.pivotTables[i].asc_refresh(t);
pivotTables.push(ws.pivotTables[i]);
}
});
if (0 === pivotTables.length) {
return;
}
this._isLockedPivotAndConnectedByPivotCache(pivotTables, function(res) {
if (!res) {
t.sendEvent('asc_onError', c_oAscError.ID.PivotOverlap, c_oAscError.Level.NoCritical);
return;
}
History.Create_NewPoint();
History.StartTransaction();
t.wbModel.dependencyFormulas.lockRecal();

let changeRes;
for (let i = pivotTables.length - 1; i >= 0; --i) {
let checkRefresh = pivotTables[i].checkRefresh();
if (c_oAscError.ID.No === checkRefresh) {
changeRes = t._changePivot(pivotTables[i], opt_confirmation, false, function(ws, pivot) {
let error = pivot.refresh();
});
} else {
changeRes = {error: checkRefresh, warning: c_oAscError.ID.No, updateRes: undefined};
}
if (c_oAscError.ID.No !== changeRes.error || c_oAscError.ID.No !== changeRes.warning) {
break;
}
}
t.wbModel.dependencyFormulas.unlockRecal();
History.EndTransaction();
t._changePivotEndCheckError(changeRes, function(){
t.asc_refreshAllPivots(true);
});
});

};
spreadsheet_api.prototype._isLockedPivot = function (pivot, callback) {
var lockInfos = [];
Expand Down Expand Up @@ -6281,7 +6315,7 @@ var editor;
var changeRes = t._changePivot(pivot, confirmation, updateSelection, onAction, doNotCheckUnderlyingData);
t.wbModel.dependencyFormulas.unlockRecal();
History.EndTransaction();
t._changePivotEndCheckError(pivot, changeRes, function () {
t._changePivotEndCheckError(changeRes, function () {
//undo can replace pivot complitly. note: getPivotTableById returns nothing while insert operation
var pivotAfterUndo = t.wbModel.getPivotTableById(pivot.Get_Id()) || pivot;
t._changePivotWithLockExt(pivotAfterUndo, true, updateSelection, onAction);
Expand Down Expand Up @@ -6316,7 +6350,7 @@ var editor;
var changeRes = onAction(confirmation, pivotTables);
t.wbModel.dependencyFormulas.unlockRecal();
History.EndTransaction();
t._changePivotEndCheckError(pivot, changeRes, onRepeat);
t._changePivotEndCheckError(changeRes, onRepeat);
});
};
spreadsheet_api.prototype._changePivot = function(pivot, confirmation, updateSelection, onAction, doNotCheckUnderlyingData) {
Expand Down Expand Up @@ -6360,20 +6394,20 @@ var editor;
}
return {error: error, warning: warning, updateRes: updateRes};
};
spreadsheet_api.prototype._changePivotRevert = function (pivot) {
spreadsheet_api.prototype._changePivotRevert = function () {
History.Undo();
History.Clear_Redo();
this._onUpdateDocumentCanUndoRedo();
};
spreadsheet_api.prototype._changePivotEndCheckError = function (pivot, changeRes, onRepeat) {
spreadsheet_api.prototype._changePivotEndCheckError = function (changeRes, onRepeat) {
if (!changeRes) {
return true;
}
if (c_oAscError.ID.No !== changeRes.error) {
this._changePivotRevert(pivot);
this._changePivotRevert();
this.sendEvent('asc_onError', changeRes.error, c_oAscError.Level.NoCritical);
} else if (c_oAscError.ID.No !== changeRes.warning) {
this._changePivotRevert(pivot);
this._changePivotRevert();
this.handlers.trigger("asc_onConfirmAction", Asc.c_oAscConfirm.ConfirmReplaceRange, function (can) {
if (can) {
//repeate with whole checks because of collaboration changes
Expand Down
11 changes: 9 additions & 2 deletions cell/model/PivotTables.js
Original file line number Diff line number Diff line change
Expand Up @@ -5293,6 +5293,13 @@ CT_pivotTableDefinition.prototype.moveField = function(arr, from, to, addToHisto
}
return false;
};
CT_pivotTableDefinition.prototype.checkRefresh = function() {
let dataRef = this.asc_getDataRef();
return Asc.CT_pivotTableDefinition.prototype.isValidDataRef(dataRef) ? c_oAscError.ID.No : c_oAscError.ID.PivotLabledColumns;
};
CT_pivotTableDefinition.prototype.refresh = function() {
this.updateCacheData(this.asc_getDataRef());
};
CT_pivotTableDefinition.prototype.asc_refresh = function(api) {
var dataRef = this.asc_getDataRef();
if (Asc.CT_pivotTableDefinition.prototype.isValidDataRef(dataRef)) {
Expand Down Expand Up @@ -5784,7 +5791,7 @@ CT_pivotTableDefinition.prototype.filterByFieldIndex = function (api, autoFilter
}
api.wbModel.dependencyFormulas.unlockRecal();
History.EndTransaction();
api._changePivotEndCheckError(t, changeRes, function () {
api._changePivotEndCheckError(changeRes, function () {
var pivot = api.wbModel.getPivotTableById(t.Get_Id());
if (pivot) {
pivot.filterByFieldIndex(api, autoFilterObject, fld, true);
Expand Down Expand Up @@ -5919,7 +5926,7 @@ CT_pivotTableDefinition.prototype.removeFiltersWithLock = function(api, flds, co
}
api.wbModel.dependencyFormulas.unlockRecal();
History.EndTransaction();
api._changePivotEndCheckError(t, changeRes, function() {
api._changePivotEndCheckError(changeRes, function() {
var pivot = api.wbModel.getPivotTableById(t.Get_Id());
if (pivot) {
pivot.removeFiltersWithLock(api, flds, true);
Expand Down

0 comments on commit d0ca9a6

Please sign in to comment.