From 7d4cdabdb37af107cd6497de2aee2eb9f778824e Mon Sep 17 00:00:00 2001 From: Sergey Konovalov Date: Mon, 30 Sep 2019 18:54:37 +0300 Subject: [PATCH] [SSE] Add processing of some pivot settings --- .../main/app/controller/PivotTable.js | 50 +++++- .../main/app/view/FieldSettingsDialog.js | 146 ++++++++++++------ .../main/app/view/PivotSettings.js | 34 +++- .../main/app/view/PivotSettingsAdvanced.js | 4 + .../main/app/view/PivotTable.js | 42 ++--- 5 files changed, 202 insertions(+), 74 deletions(-) diff --git a/apps/spreadsheeteditor/main/app/controller/PivotTable.js b/apps/spreadsheeteditor/main/app/controller/PivotTable.js index 2e8e33f82..c19a0a39e 100644 --- a/apps/spreadsheeteditor/main/app/controller/PivotTable.js +++ b/apps/spreadsheeteditor/main/app/controller/PivotTable.js @@ -136,11 +136,32 @@ define([ Common.NotificationCenter.trigger('edit:complete', this); }, + createSheetName: function() { + var items = [], wc = this.api.asc_getWorksheetsCount(); + while (wc--) { + items.push(this.api.asc_getWorksheetName(wc).toLowerCase()); + } + + var index = 0, name; + while(++index < 1000) { + name = this.strSheet + index; + if (items.indexOf(name.toLowerCase()) < 0) break; + } + + return name; + }, + onCreateClick: function(btn, opts){ + if (this.api) { + this.api.asc_insertPivot("Sheet1!B2:H13", this.createSheetName()); + } Common.NotificationCenter.trigger('edit:complete', this); }, onRefreshClick: function(btn, opts){ + if (this.api) { + this._originalProps.asc_refresh(this.api); + } Common.NotificationCenter.trigger('edit:complete', this); }, @@ -160,29 +181,37 @@ define([ onPivotBlankRows: function(type){ if (this.api) { - if (type === 'insert'){ - - } else { - - } + var props = new Asc.CT_pivotTableDefinition(); + props.asc_setInsertBlankRow(type === 'insert'); + this._originalProps.asc_set(this.api, props); } Common.NotificationCenter.trigger('edit:complete', this); }, onPivotLayout: function(type){ if (this.api) { + var props = new Asc.CT_pivotTableDefinition(); switch (type){ case 0: + props.asc_setCompact(true); + props.asc_setOutline(true); break; case 1: + props.asc_setCompact(false); + props.asc_setOutline(true); break; case 2: + props.asc_setCompact(false); + props.asc_setOutline(false); break; case 3: + props.asc_setFillDownLabelsDefault(true); break; case 4: + props.asc_setFillDownLabelsDefault(false); break; } + this._originalProps.asc_set(this.api, props); } Common.NotificationCenter.trigger('edit:complete', this); }, @@ -199,14 +228,21 @@ define([ onPivotSubtotals: function(type){ if (this.api) { + var props = new Asc.CT_pivotTableDefinition(); switch (type){ case 0: + props.asc_setDefaultSubtotal(false); break; case 1: + props.asc_setDefaultSubtotal(true); + props.asc_setSubtotalTop(false); break; case 2: + props.asc_setDefaultSubtotal(true); + props.asc_setSubtotalTop(true); break; } + this._originalProps.asc_set(this.api, props); } Common.NotificationCenter.trigger('edit:complete', this); }, @@ -348,7 +384,9 @@ define([ resolve(); })).then(function () { }); - } + }, + + strSheet : 'Sheet' }, SSE.Controllers.PivotTable || {})); }); \ No newline at end of file diff --git a/apps/spreadsheeteditor/main/app/view/FieldSettingsDialog.js b/apps/spreadsheeteditor/main/app/view/FieldSettingsDialog.js index 06a871571..132b617fd 100644 --- a/apps/spreadsheeteditor/main/app/view/FieldSettingsDialog.js +++ b/apps/spreadsheeteditor/main/app/view/FieldSettingsDialog.js @@ -227,59 +227,119 @@ define([ 'text!spreadsheeteditor/main/app/template/FieldSettingsDialog.templa _setDefaults: function (props) { if (props) { var me = this, - cache_names = props.asc_getCacheFields(), field = props.asc_getPivotFields()[this.fieldIndex]; - this.lblSourceName.html(Common.Utils.String.htmlEncode(cache_names[this.fieldIndex].asc_getName())); - this.inputCustomName.setValue(Common.Utils.String.htmlEncode((field || cache_names[this.fieldIndex]).asc_getName())); + this.lblSourceName.html(Common.Utils.String.htmlEncode(props.getCacheFieldName(this.fieldIndex))); + this.inputCustomName.setValue(Common.Utils.String.htmlEncode(props.getPivotFieldName(this.fieldIndex))); + (field.asc_getOutline()) ? this.radioOutline.setValue(true) : this.radioTabular.setValue(true); + this.chCompact.setValue(field.asc_getOutline() && field.asc_getCompact()); + + this.chRepeat.setValue(field.asc_getFillDownLabelsDefault()); + this.chBlank.setValue(field.asc_getInsertBlankRow()); + + this.chSubtotals.setValue(field.asc_getDefaultSubtotal()); (field.asc_getSubtotalTop()) ? this.radioTop.setValue(true) : this.radioBottom.setValue(true); - var arr = field.asc_getSubtotals(); - if (arr) { - _.each(arr, function(item) { - switch(item) { - case Asc.c_oAscItemType.Sum: - me.chSum.setValue(true); - break; - case Asc.c_oAscItemType.Count: - me.chCount.setValue(true); - break; - case Asc.c_oAscItemType.Avg: - me.chAve.setValue(true); - break; - case Asc.c_oAscItemType.Max: - me.chMax.setValue(true); - break; - case Asc.c_oAscItemType.Min: - me.chMin.setValue(true); - break; - case Asc.c_oAscItemType.Product: - me.chProduct.setValue(true); - break; - case Asc.c_oAscItemType.CountA: - me.chNum.setValue(true); - break; - case Asc.c_oAscItemType.StdDev: - me.chDev.setValue(true); - break; - case Asc.c_oAscItemType.StdDevP: - me.chDevp.setValue(true); - break; - case Asc.c_oAscItemType.Var: - me.chVar.setValue(true); - break; - case Asc.c_oAscItemType.VarP: - me.chVarp.setValue(true); - break; - } - }); + this.chEmpty.setValue(field.asc_getShowAll()); + if (field.asc_getDefaultSubtotal()) { + var arr = field.asc_getSubtotals(); + if (arr) { + _.each(arr, function(item) { + switch(item) { + case Asc.c_oAscItemType.Sum: + me.chSum.setValue(true); + break; + case Asc.c_oAscItemType.Count: + me.chCount.setValue(true); + break; + case Asc.c_oAscItemType.Avg: + me.chAve.setValue(true); + break; + case Asc.c_oAscItemType.Max: + me.chMax.setValue(true); + break; + case Asc.c_oAscItemType.Min: + me.chMin.setValue(true); + break; + case Asc.c_oAscItemType.Product: + me.chProduct.setValue(true); + break; + case Asc.c_oAscItemType.CountA: + me.chNum.setValue(true); + break; + case Asc.c_oAscItemType.StdDev: + me.chDev.setValue(true); + break; + case Asc.c_oAscItemType.StdDevP: + me.chDevp.setValue(true); + break; + case Asc.c_oAscItemType.Var: + me.chVar.setValue(true); + break; + case Asc.c_oAscItemType.VarP: + me.chVarp.setValue(true); + break; + } + }); + } } } }, getSettings: function () { - return {}; + var field = new Asc.CT_PivotField(); + field.asc_setName(this.inputCustomName.getValue()); + + field.asc_setOutline(this.radioOutline.getValue()); + field.asc_setCompact(this.radioOutline.getValue() && this.chCompact.getValue() == 'checked'); + + field.asc_setFillDownLabelsDefault(this.chRepeat.getValue() == 'checked'); + field.asc_setInsertBlankRow(this.chBlank.getValue() == 'checked'); + + field.asc_setDefaultSubtotal(this.chSubtotals.getValue() == 'checked'); + field.asc_setSubtotalTop(this.radioTop.getValue()); + + field.asc_setShowAll(this.chEmpty.getValue() == 'checked'); + if (field.asc_getDefaultSubtotal()) { + var arr = []; + if (this.chSum.getValue() == 'checked') { + arr.push(Asc.c_oAscItemType.Sum); + } + if (this.chCount.getValue() == 'checked') { + arr.push(Asc.c_oAscItemType.Count); + } + if (this.chAve.getValue() == 'checked') { + arr.push(Asc.c_oAscItemType.Avg); + } + if (this.chMax.getValue() == 'checked') { + arr.push(Asc.c_oAscItemType.Max); + } + if (this.chMin.getValue() == 'checked') { + arr.push(Asc.c_oAscItemType.Min); + } + if (this.chProduct.getValue() == 'checked') { + arr.push(Asc.c_oAscItemType.Product); + } + if (this.chNum.getValue() == 'checked') { + arr.push(Asc.c_oAscItemType.CountA); + } + if (this.chDev.getValue() == 'checked') { + arr.push(Asc.c_oAscItemType.StdDev); + } + if (this.chDevp.getValue() == 'checked') { + arr.push(Asc.c_oAscItemType.StdDevP); + } + if (this.chVar.getValue() == 'checked') { + arr.push(Asc.c_oAscItemType.Var); + } + if (this.chVarp.getValue() == 'checked') { + arr.push(Asc.c_oAscItemType.VarP); + } + field.asc_setSubtotals(arr); + } + + return field; }, onDlgBtnClick: function(event) { diff --git a/apps/spreadsheeteditor/main/app/view/PivotSettings.js b/apps/spreadsheeteditor/main/app/view/PivotSettings.js index 24b4168f2..0b92a35f6 100644 --- a/apps/spreadsheeteditor/main/app/view/PivotSettings.js +++ b/apps/spreadsheeteditor/main/app/view/PivotSettings.js @@ -344,17 +344,17 @@ define([ caption : this.txtAddRow, checkable : false }); - // this.miAddRow.on('click', _.bind(this.onAddRow, this)); + this.miAddRow.on('click', _.bind(this.onAddRow, this)); this.miAddColumn = new Common.UI.MenuItem({ caption : this.txtAddColumn, checkable : false }); - // this.miAddColumn.on('click', _.bind(this.onAddColumn, this)); + this.miAddColumn.on('click', _.bind(this.onAddColumn, this)); this.miAddValues = new Common.UI.MenuItem({ caption : this.txtAddValues, checkable : false }); - // this.miAddValues.on('click', _.bind(this.onAddValues, this)); + this.miAddValues.on('click', _.bind(this.onAddValues, this)); this.pivotFieldsMenu = new Common.UI.Menu({ menuAlign: 'tr-br', @@ -435,6 +435,13 @@ define([ listView.isSuspendEvents = true; record.set('check', !record.get('check')); + if (this.api && !this._locked){ + if (record.get('check')) { + this._originalProps.asc_addField(this.api, record.get('index')); + } else { + this._originalProps.asc_removeField(this.api, record.get('index')); + } + } listView.isSuspendEvents = false; listView.scroller.update({minScrollbarLength : 40, alwaysVisibleY: true, suppressScrollX: true}); @@ -602,6 +609,7 @@ define([ } })).show(); } else { + var pivotField = me._originalProps.asc_getPivotFields()[me._state.field.record.get('pivotIndex')]; (new SSE.Views.FieldSettingsDialog( { props: me._originalProps, @@ -611,7 +619,7 @@ define([ type: me._state.field.type, handler: function(result, value) { if (result == 'ok' && me.api && value) { - // me.api.asc_changeFormatTableInfo(me._state.TableName, Asc.c_oAscChangeTableStyleInfo.advancedSettings, value); + pivotField.asc_set(me.api, me._originalProps, value); } Common.NotificationCenter.trigger('edit:complete', me); @@ -627,6 +635,24 @@ define([ } }, + onAddRow: function() { + if (this.api && !this._locked && this._state.field){ + this._originalProps.asc_addRowField(this.api, this._state.field.record.get('index')); + } + }, + + onAddColumn: function() { + if (this.api && !this._locked && this._state.field){ + this._originalProps.asc_addColField(this.api, this._state.field.record.get('index')); + } + }, + + onAddValues: function() { + if (this.api && !this._locked && this._state.field){ + this._originalProps.asc_addDataField(this.api, this._state.field.record.get('index')); + } + }, + onRemove: function() { if (this.api && !this._locked && this._state.field){ this._originalProps.asc_removeField(this.api, this._state.field.record.get('pivotIndex')); diff --git a/apps/spreadsheeteditor/main/app/view/PivotSettingsAdvanced.js b/apps/spreadsheeteditor/main/app/view/PivotSettingsAdvanced.js index 053887819..95fc39a47 100644 --- a/apps/spreadsheeteditor/main/app/view/PivotSettingsAdvanced.js +++ b/apps/spreadsheeteditor/main/app/view/PivotSettingsAdvanced.js @@ -217,8 +217,12 @@ define([ 'text!spreadsheeteditor/main/app/template/PivotSettingsAdvanced.temp getSettings: function () { var props = new Asc.CT_pivotTableDefinition(); + props.asc_setName(this.inputName.getValue()); props.asc_setRowGrandTotals(this.chCols.getValue() == 'checked'); props.asc_setColGrandTotals(this.chRows.getValue() == 'checked'); + props.asc_setPageOverThenDown(this.radioOver.getValue()); + props.asc_setPageWrap(this.numWrap.getNumberValue()); + props.asc_setShowHeaders(this.chHeaders.getValue() == 'checked'); return props; }, diff --git a/apps/spreadsheeteditor/main/app/view/PivotTable.js b/apps/spreadsheeteditor/main/app/view/PivotTable.js index 057329caf..9733b6f08 100644 --- a/apps/spreadsheeteditor/main/app/view/PivotTable.js +++ b/apps/spreadsheeteditor/main/app/view/PivotTable.js @@ -52,21 +52,21 @@ define([ SSE.Views.PivotTable = Common.UI.BaseView.extend(_.extend((function(){ var template = '
' + - // '
' + - // '' + - // '
' + - // '
' + - // '
' + - // '' + - // '' + - // '' + - // '' + - // '
' + - // '
' + - // '
' + - // '' + - // '
' + - // '
' + + '
' + + '' + + '
' + + '
' + + '
' + + '' + + '' + + '' + + '' + + '
' + + '
' + + '
' + + '' + + '
' + + '
' + '
' + '' + '
' + @@ -176,7 +176,7 @@ define([ cls: 'btn-toolbar x-huge icon-top', iconCls: 'btn-add-pivot', caption: this.txtCreate, - disabled : true + disabled : false }); // this.lockedControls.push(this.btnAddPivot); @@ -196,7 +196,7 @@ define([ ] }) }); - // this.lockedControls.push(this.btnPivotLayout); // remove commentings after enabled option + this.lockedControls.push(this.btnPivotLayout); this.btnPivotBlankRows = new Common.UI.Button({ cls : 'btn-toolbar x-huge icon-top', @@ -210,7 +210,7 @@ define([ ] }) }); - // this.lockedControls.push(this.btnPivotBlankRows); // remove commentings after enabled option + this.lockedControls.push(this.btnPivotBlankRows); this.btnPivotSubtotals = new Common.UI.Button({ cls : 'btn-toolbar x-huge icon-top', @@ -225,7 +225,7 @@ define([ ] }) }); - // this.lockedControls.push(this.btnPivotSubtotals); // remove commentings after enabled option + this.lockedControls.push(this.btnPivotSubtotals); this.btnPivotGrandTotals = new Common.UI.Button({ cls : 'btn-toolbar x-huge icon-top', @@ -241,7 +241,7 @@ define([ ] }) }); - // this.lockedControls.push(this.btnPivotGrandTotals); // remove commentings after enabled option + this.lockedControls.push(this.btnPivotGrandTotals); this.btnRefreshPivot = new Common.UI.Button({ cls: 'btn-toolbar x-huge icon-top', @@ -249,7 +249,7 @@ define([ caption: this.txtRefresh, disabled : true }); - // this.lockedControls.push(this.btnRefreshPivot); + this.lockedControls.push(this.btnRefreshPivot); this.btnSelectPivot = new Common.UI.Button({ cls: 'btn-toolbar x-huge icon-top',