From 4aa3780ebd3dccf36e282052d4596883c6b8c8be Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Tue, 31 Jan 2023 23:40:04 +0300 Subject: [PATCH] [SSE] For Bug 50888: add Show As options for pivot context menu --- .../main/app/controller/DocumentHolder.js | 28 ++++- .../main/app/view/DocumentHolder.js | 102 +++++++++++++++++- .../main/app/view/ValueFieldSettingsDialog.js | 8 +- apps/spreadsheeteditor/main/locale/en.json | 8 +- 4 files changed, 139 insertions(+), 7 deletions(-) diff --git a/apps/spreadsheeteditor/main/app/controller/DocumentHolder.js b/apps/spreadsheeteditor/main/app/controller/DocumentHolder.js index 906e2b9de1..518ceb0171 100644 --- a/apps/spreadsheeteditor/main/app/controller/DocumentHolder.js +++ b/apps/spreadsheeteditor/main/app/controller/DocumentHolder.js @@ -223,6 +223,7 @@ define([ view.mnuDeleteField.on('click', _.bind(me.onDeleteField, me)); view.mnuSubtotalField.on('click', _.bind(me.onSubtotalField, me)); view.mnuSummarize.menu.on('item:click', _.bind(me.onSummarize, me)); + view.mnuShowAs.menu.on('item:click', _.bind(me.onShowAs, me)); view.pmiClear.menu.on('item:click', _.bind(me.onClear, me)); view.pmiSelectTable.menu.on('item:click', _.bind(me.onSelectTable, me)); view.pmiInsertTable.menu.on('item:click', _.bind(me.onInsertTable, me)); @@ -647,6 +648,7 @@ define([ { props: props, field: field, + showAsValue: me.propsPivot.showAsValue, api: me.api, handler: function(result, value) { if (result === 'ok' && me.api && value) { @@ -719,6 +721,21 @@ define([ } }, + onShowAs: function(menu, item, e) { + if (!this.propsPivot.originalProps) return; + + if (item.value===-1 || item.options.showMore) { + if (item.options.showMore) + this.propsPivot.showAsValue = item.value; + this.onFieldSettings(); + } else if (item.value!==undefined && item.value!==null) { + var field = new Asc.CT_DataField(); + field.asc_setShowDataAs(item.value); + this.propsPivot.field.asc_set(this.api, this.propsPivot.originalProps, this.propsPivot.index, field); + Common.NotificationCenter.trigger('edit:complete', this.documentHolder); + } + }, + fillPivotProps: function(pageFieldIndex, rowFieldIndex, colFieldIndex, dataFieldIndex, rowTotal, colTotal) { var props = this.propsPivot.originalProps; if (!props) return; @@ -2513,7 +2530,7 @@ define([ documentHolder.pmiAddNamedRange.setVisible(iscellmenu && !iscelledit && !internaleditor); var needshow = iscellmenu && !iscelledit && !diagramOrMergeEditor && inPivot, - pageFieldIndex, rowFieldIndex, colFieldIndex = 0, dataFieldIndex, rowTotal, colTotal; + pageFieldIndex, rowFieldIndex, colFieldIndex, dataFieldIndex, rowTotal, colTotal; needshow && this.fillPivotProps(pageFieldIndex, rowFieldIndex, colFieldIndex, dataFieldIndex, rowTotal, colTotal); documentHolder.mnuRefreshPivot.setVisible(needshow); @@ -2528,6 +2545,7 @@ define([ documentHolder.mnuPivotSettings.setVisible(needshow); documentHolder.mnuFieldSettings.setVisible(!!this.propsPivot.field); documentHolder.mnuSummarize.setVisible(!!this.propsPivot.field && (this.propsPivot.fieldType===2)); + documentHolder.mnuShowAs.setVisible(!!this.propsPivot.field && (this.propsPivot.fieldType===2) && !rowTotal && !colTotal); documentHolder.mnuPivotValueSeparator.setVisible(!!this.propsPivot.field && (this.propsPivot.fieldType===2)); if (this.propsPivot.field) { documentHolder.mnuDeleteField.setCaption(documentHolder.txtDelField + ' ' + (rowTotal || colTotal ? documentHolder.txtGrandTotal : '"' + Common.Utils.String.htmlEncode(this.propsPivot.fieldName) + '"'), true); @@ -2539,6 +2557,13 @@ define([ var item = documentHolder.mnuSummarize.menu.items[i]; (item.value!==undefined) && item.setChecked(item.value===sumval, true); } + if (!rowTotal && !colTotal) { + sumval = this.propsPivot.field.asc_getShowDataAs(); + for (var i = 0; i < documentHolder.mnuShowAs.menu.items.length; i++) { + var item = documentHolder.mnuShowAs.menu.items[i]; + (item.value!==undefined) && item.setChecked(item.value===sumval, true); + } + } } else { documentHolder.mnuSubtotalField.setChecked(!!this.propsPivot.field.asc_getDefaultSubtotal(), true); } @@ -2644,6 +2669,7 @@ define([ documentHolder.mnuDeleteField.setDisabled(isPivotLocked || this._state.wsLock); documentHolder.mnuSubtotalField.setDisabled(isPivotLocked || this._state.wsLock); documentHolder.mnuSummarize.setDisabled(isPivotLocked || this._state.wsLock); + documentHolder.mnuShowAs.setDisabled(isPivotLocked || this._state.wsLock); } if (showMenu) this.showPopupMenu(documentHolder.ssMenu, {}, event); diff --git a/apps/spreadsheeteditor/main/app/view/DocumentHolder.js b/apps/spreadsheeteditor/main/app/view/DocumentHolder.js index 3bdd128608..a3748707ac 100644 --- a/apps/spreadsheeteditor/main/app/view/DocumentHolder.js +++ b/apps/spreadsheeteditor/main/app/view/DocumentHolder.js @@ -407,6 +407,90 @@ define([ }) }); + me.mnuShowAs = new Common.UI.MenuItem({ + caption : this.txtShowAs, + menu : new Common.UI.Menu({ + cls: 'shifted-right', + menuAlign : 'tl-tr', + items: [ + { + caption : me.txtNormal, + value : Asc.c_oAscShowDataAs.Normal, + checkable: true + },{ + caption : me.txtPercentOfGrand, + value : Asc.c_oAscShowDataAs.PercentOfTotal, + checkable: true + },{ + caption : me.txtPercentOfCol, + value : Asc.c_oAscShowDataAs.PercentOfCol, + checkable: true + },{ + caption : me.txtPercentOfTotal, + value : Asc.c_oAscShowDataAs.PercentOfRow, + checkable: true + },{ + caption : me.txtPercent, + value : Asc.c_oAscShowDataAs.Percent, + showMore: true, + checkable: true + },{ + caption : me.txtPercentOfParentRow, + value : Asc.c_oAscShowDataAs.PercentOfParentRow, + checkable: true + },{ + caption : me.txtPercentOfParentCol, + value : Asc.c_oAscShowDataAs.PercentOfParentCol, + checkable: true + },{ + caption : me.txtPercentOfParent, + value : Asc.c_oAscShowDataAs.PercentOfParent, + showMore: true, + checkable: true + },{ + caption : me.txtDifference, + value : Asc.c_oAscShowDataAs.Difference, + showMore: true, + checkable: true + },{ + caption : me.txtPercentDiff, + value : Asc.c_oAscShowDataAs.PercentDiff, + showMore: true, + checkable: true + },{ + caption : me.txtRunTotal, + value : Asc.c_oAscShowDataAs.RunTotal, + showMore: true, + checkable: true + },{ + caption : me.txtPercentOfRunTotal, + value : Asc.c_oAscShowDataAs.PercentOfRunningTotal, + showMore: true, + checkable: true + },{ + caption : me.txtRankAscending, + value : Asc.c_oAscShowDataAs.RankAscending, + showMore: true, + checkable: true + },{ + caption : me.txtRankDescending, + value : Asc.c_oAscShowDataAs.RankDescending, + showMore: true, + checkable: true + },{ + caption : me.txtIndex, + value : Asc.c_oAscShowDataAs.Index, + checkable: true + },{ + caption : '--' + },{ + caption : me.txtMoreOptions, + value: -1 + } + ] + }) + }); + me.mnuPivotRefreshSeparator = new Common.UI.MenuItem({caption: '--'}); me.mnuPivotSubtotalSeparator = new Common.UI.MenuItem({caption: '--'}); me.mnuPivotSettingsSeparator = new Common.UI.MenuItem({caption: '--'}); @@ -663,6 +747,7 @@ define([ me.mnuDeleteField, me.mnuPivotValueSeparator, me.mnuSummarize, + me.mnuShowAs, me.mnuPivotSettingsSeparator, me.mnuFieldSettings, me.mnuPivotSettings, @@ -1487,7 +1572,22 @@ define([ txtCount: 'Count', txtMax: 'Max', txtMin: 'Min', - txtProduct: 'Product' + txtProduct: 'Product', + txtNormal: 'No calculation', + txtDifference: 'The difference from', + txtPercent: '% of', + txtPercentDiff: '% difference from', + txtRunTotal: 'Running total in', + txtPercentOfRunTotal: '% running total in', + txtPercentOfCol: '% of column total', + txtPercentOfTotal: '% of row total', + txtPercentOfGrand: '% of grand total', + txtIndex: 'Index', + txtPercentOfParentRow: '% of parent row total', + txtPercentOfParentCol: '% of parent column total', + txtPercentOfParent: '% of parent total', + txtRankAscending: 'Rank smallest to largest', + txtRankDescending: 'Rank largest to smallest' }, SSE.Views.DocumentHolder || {})); }); \ No newline at end of file diff --git a/apps/spreadsheeteditor/main/app/view/ValueFieldSettingsDialog.js b/apps/spreadsheeteditor/main/app/view/ValueFieldSettingsDialog.js index 51059d1f04..cf2891316e 100644 --- a/apps/spreadsheeteditor/main/app/view/ValueFieldSettingsDialog.js +++ b/apps/spreadsheeteditor/main/app/view/ValueFieldSettingsDialog.js @@ -107,6 +107,7 @@ define([ this.handler = options.handler; this.props = options.props; this.field = options.field || 0; + this.showAsValue = options.showAsValue; Common.Views.AdvancedSettingsWindow.prototype.initialize.call(this, this.options); }, @@ -244,6 +245,11 @@ define([ this.cmbBaseItem.setDisabled(data.length<1 || show_as !== Asc.c_oAscShowDataAs.Difference && show_as !== Asc.c_oAscShowDataAs.Percent && show_as !== Asc.c_oAscShowDataAs.PercentDiff); this.cmbBaseItem.setValue((data.length>0) && (show_as === Asc.c_oAscShowDataAs.Difference || show_as === Asc.c_oAscShowDataAs.Percent || show_as === Asc.c_oAscShowDataAs.PercentDiff) ? field.asc_getBaseItem() : '', ''); } + + if (this.showAsValue!==undefined) { + this.cmbShowAs.setValue(this.showAsValue); + this.onShowAsSelect(this.cmbShowAs, this.cmbShowAs.getSelectedRecord()); + } }, getSettings: function () { @@ -300,7 +306,7 @@ define([ this.cmbBaseItem.setData(data); var show_as = this.cmbShowAs.getValue(); this.cmbBaseItem.setDisabled(data.length<1 || show_as !== Asc.c_oAscShowDataAs.Difference && show_as !== Asc.c_oAscShowDataAs.Percent && show_as !== Asc.c_oAscShowDataAs.PercentDiff); - this.cmbBaseItem.setValue((show_as === Asc.c_oAscShowDataAs.Difference || show_as === Asc.c_oAscShowDataAs.Percent || show_as === Asc.Asc.c_oAscShowDataAs.PercentDiff) && data.length>0 ? + this.cmbBaseItem.setValue((show_as === Asc.c_oAscShowDataAs.Difference || show_as === Asc.c_oAscShowDataAs.Percent || show_as === Asc.c_oAscShowDataAs.PercentDiff) && data.length>0 ? this.cmbBaseItem.store.at(0).get('value') : '', ''); }, diff --git a/apps/spreadsheeteditor/main/locale/en.json b/apps/spreadsheeteditor/main/locale/en.json index 7582baaa40..cb4057771a 100644 --- a/apps/spreadsheeteditor/main/locale/en.json +++ b/apps/spreadsheeteditor/main/locale/en.json @@ -3932,15 +3932,15 @@ "SSE.Views.ValueFieldSettingsDialog.txtMax": "Max", "SSE.Views.ValueFieldSettingsDialog.txtMin": "Min", "SSE.Views.ValueFieldSettingsDialog.txtNormal": "No calculation", - "SSE.Views.ValueFieldSettingsDialog.txtPercent": "Percent of", - "SSE.Views.ValueFieldSettingsDialog.txtPercentDiff": "Percent difference from", - "SSE.Views.ValueFieldSettingsDialog.txtPercentOfCol": "Percent of column", + "SSE.Views.ValueFieldSettingsDialog.txtPercent": "% of", + "SSE.Views.ValueFieldSettingsDialog.txtPercentDiff": "% difference from", + "SSE.Views.ValueFieldSettingsDialog.txtPercentOfCol": "% of column", "SSE.Views.ValueFieldSettingsDialog.txtPercentOfGrand": "% of grand total", "SSE.Views.ValueFieldSettingsDialog.txtPercentOfParent": "% of parent total", "SSE.Views.ValueFieldSettingsDialog.txtPercentOfParentCol": "% of parent column total", "SSE.Views.ValueFieldSettingsDialog.txtPercentOfParentRow": "% of parent row total", "SSE.Views.ValueFieldSettingsDialog.txtPercentOfRunTotal": "% running total in", - "SSE.Views.ValueFieldSettingsDialog.txtPercentOfTotal": "Percent of row", + "SSE.Views.ValueFieldSettingsDialog.txtPercentOfTotal": "% of row", "SSE.Views.ValueFieldSettingsDialog.txtProduct": "Product", "SSE.Views.ValueFieldSettingsDialog.txtRankAscending": "Rank smallest to largest", "SSE.Views.ValueFieldSettingsDialog.txtRankDescending": "Rank largest to smallest",