Skip to content

Commit

Permalink
Merge pull request 'feature/pivot-calculated-items' (#193) from featu…
Browse files Browse the repository at this point in the history
…re/pivot-calculated-items into release/v8.3.0
  • Loading branch information
Julia Radzhabova committed Dec 19, 2024
2 parents a932343 + 0a32b47 commit 0bccc80
Show file tree
Hide file tree
Showing 57 changed files with 1,887 additions and 2 deletions.
8 changes: 8 additions & 0 deletions apps/spreadsheeteditor/main/app/controller/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2256,6 +2256,14 @@ define([
config.msg = this.errorSaveWatermark;
break;

case Asc.c_oAscError.ID.CalculatedItemInPageField:
config.msg = this.errorCalculatedItemInPageField;
break;

case Asc.c_oAscError.ID.NotUniqueFieldWithCalculated:
config.msg = this.errorNotUniqueFieldWithCalculated;
break;

default:
config.msg = (typeof id == 'string') ? id : this.errorDefaultMessage.replace('%1', id);
break;
Expand Down
61 changes: 60 additions & 1 deletion apps/spreadsheeteditor/main/app/controller/PivotTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ define([
'pivottable:create': _.bind(this.onCreateClick, this),
'pivottable:refresh': _.bind(this.onRefreshClick, this),
'pivottable:select': _.bind(this.onSelectClick, this),
'pivottable:calculated': _.bind(this.onCalculatedClick, this),
'pivottable:expand': _.bind(this.onExpandClick, this),
'pivottable:collapse': _.bind(this.onCollapseClick, this),
'pivottable:style': _.bind(this.onPivotStyleSelect, this),
Expand Down Expand Up @@ -195,6 +196,57 @@ define([
Common.NotificationCenter.trigger('edit:complete', this);
},

onCalculatedClick: function(btn, opts){
var me = this;
var pivotInfo = this.api.asc_getCellInfo().asc_getPivotTableInfo();
var pivotFieldIndex = pivotInfo.asc_getFieldIndexByActiveCell();
var error = pivotInfo.asc_hasTablesErrorForCalculatedItems(pivotFieldIndex);

function getWarningMessage(error) {
var message = '';
switch (error) {
case Asc.c_oAscError.ID.PivotItemNameNotFound:
message = me.txtPivotItemNameNotFound;
break;
case Asc.c_oAscError.ID.CalculatedItemInPageField:
message = me.txtCalculatedItemInPageField;
break;
case Asc.c_oAscError.ID.NotUniqueFieldWithCalculated:
message = me.txtNotUniqueFieldWithCalculated;
break;
case Asc.c_oAscError.ID.WrongDataFieldSubtotalForCalculatedItems:
message = me.txtWrongDataFieldSubtotalForCalculatedItems;
break;
case Asc.c_oAscError.ID.PivotFieldCustomSubtotalsWithCalculatedItems:
message = me.txtPivotFieldCustomSubtotalsWithCalculatedItems;
break;
default:
message = me.txtCalculatedItemWarningDefault;
}
return message;
};

function showWarningDialog(error) {
Common.UI.warning({
msg: getWarningMessage(error),
maxwidth: 600
});
};

if(error) {
showWarningDialog(error);
} else {
var winList = new SSE.Views.PivotCalculatedItemsDialog({
api: this.api,
handlerWarning: function(error) {
showWarningDialog(error);
},
getWarningMessage: getWarningMessage,
});
winList.show();
}
},

onExpandClick: function(){
if (this.api) {
this._originalProps.asc_setExpandCollapseByActiveCell(this.api, true, true);
Expand Down Expand Up @@ -481,6 +533,7 @@ define([
Common.Utils.lockControls(Common.enumLock.pivotLock, pivotInfo && (info.asc_getLockedPivotTable()===true), {array: this.view.lockedControls});
Common.Utils.lockControls(Common.enumLock.editPivot, !!pivotInfo, {array: this.view.btnsAddPivot});
Common.Utils.lockControls(Common.enumLock.pivotExpandLock, !(pivotInfo && pivotInfo.asc_canExpandCollapseByActiveCell(this.api)), {array: [this.view.btnExpandField, this.view.btnCollapseField]});
Common.Utils.lockControls(Common.enumLock.pivotCalcItemsLock, !(pivotInfo && pivotInfo.asc_canChangeCalculatedItemByActiveCell()), {array: [this.view.btnCalculatedItems]});

if (pivotInfo)
this.ChangeSettings(pivotInfo);
Expand Down Expand Up @@ -518,7 +571,13 @@ define([
}
},

strSheet : 'Sheet'
strSheet : 'Sheet',
txtPivotItemNameNotFound: 'An item name cannot be found. Check that you\'ve typed name correctly and the item is present in the PivotTable report.',
txtCalculatedItemInPageField: 'The item cannot be added or modified. PivotTable report has this field in Filters.',
txtNotUniqueFieldWithCalculated: 'If one or more PivotTable have calculated items, no fields can be used in data area two or more times, or in the data area and another area at the same time.',
txtWrongDataFieldSubtotalForCalculatedItems: 'Averages, standard deviations, and variances are not supported when a PivotTable report has calculated items.',
txtPivotFieldCustomSubtotalsWithCalculatedItems: 'Calculated items do not work with custom subtotals.',
txtCalculatedItemWarningDefault: 'No actions with calculated items are allowed for this active cell.'

}, SSE.Controllers.PivotTable || {}));
});
Loading

0 comments on commit 0bccc80

Please sign in to comment.