[SSE] Add processing of some pivot settings

This commit is contained in:
Sergey Konovalov 2019-09-30 18:54:37 +03:00
parent cc05a8ae5b
commit 7d4cdabdb3
No known key found for this signature in database
GPG key ID: 9BC70BEFF12CC5AE
5 changed files with 202 additions and 74 deletions

View file

@ -136,11 +136,32 @@ define([
Common.NotificationCenter.trigger('edit:complete', this); 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){ onCreateClick: function(btn, opts){
if (this.api) {
this.api.asc_insertPivot("Sheet1!B2:H13", this.createSheetName());
}
Common.NotificationCenter.trigger('edit:complete', this); Common.NotificationCenter.trigger('edit:complete', this);
}, },
onRefreshClick: function(btn, opts){ onRefreshClick: function(btn, opts){
if (this.api) {
this._originalProps.asc_refresh(this.api);
}
Common.NotificationCenter.trigger('edit:complete', this); Common.NotificationCenter.trigger('edit:complete', this);
}, },
@ -160,29 +181,37 @@ define([
onPivotBlankRows: function(type){ onPivotBlankRows: function(type){
if (this.api) { if (this.api) {
if (type === 'insert'){ var props = new Asc.CT_pivotTableDefinition();
props.asc_setInsertBlankRow(type === 'insert');
} else { this._originalProps.asc_set(this.api, props);
}
} }
Common.NotificationCenter.trigger('edit:complete', this); Common.NotificationCenter.trigger('edit:complete', this);
}, },
onPivotLayout: function(type){ onPivotLayout: function(type){
if (this.api) { if (this.api) {
var props = new Asc.CT_pivotTableDefinition();
switch (type){ switch (type){
case 0: case 0:
props.asc_setCompact(true);
props.asc_setOutline(true);
break; break;
case 1: case 1:
props.asc_setCompact(false);
props.asc_setOutline(true);
break; break;
case 2: case 2:
props.asc_setCompact(false);
props.asc_setOutline(false);
break; break;
case 3: case 3:
props.asc_setFillDownLabelsDefault(true);
break; break;
case 4: case 4:
props.asc_setFillDownLabelsDefault(false);
break; break;
} }
this._originalProps.asc_set(this.api, props);
} }
Common.NotificationCenter.trigger('edit:complete', this); Common.NotificationCenter.trigger('edit:complete', this);
}, },
@ -199,14 +228,21 @@ define([
onPivotSubtotals: function(type){ onPivotSubtotals: function(type){
if (this.api) { if (this.api) {
var props = new Asc.CT_pivotTableDefinition();
switch (type){ switch (type){
case 0: case 0:
props.asc_setDefaultSubtotal(false);
break; break;
case 1: case 1:
props.asc_setDefaultSubtotal(true);
props.asc_setSubtotalTop(false);
break; break;
case 2: case 2:
props.asc_setDefaultSubtotal(true);
props.asc_setSubtotalTop(true);
break; break;
} }
this._originalProps.asc_set(this.api, props);
} }
Common.NotificationCenter.trigger('edit:complete', this); Common.NotificationCenter.trigger('edit:complete', this);
}, },
@ -348,7 +384,9 @@ define([
resolve(); resolve();
})).then(function () { })).then(function () {
}); });
} },
strSheet : 'Sheet'
}, SSE.Controllers.PivotTable || {})); }, SSE.Controllers.PivotTable || {}));
}); });

View file

@ -227,59 +227,119 @@ define([ 'text!spreadsheeteditor/main/app/template/FieldSettingsDialog.templa
_setDefaults: function (props) { _setDefaults: function (props) {
if (props) { if (props) {
var me = this, var me = this,
cache_names = props.asc_getCacheFields(),
field = props.asc_getPivotFields()[this.fieldIndex]; field = props.asc_getPivotFields()[this.fieldIndex];
this.lblSourceName.html(Common.Utils.String.htmlEncode(cache_names[this.fieldIndex].asc_getName())); this.lblSourceName.html(Common.Utils.String.htmlEncode(props.getCacheFieldName(this.fieldIndex)));
this.inputCustomName.setValue(Common.Utils.String.htmlEncode((field || cache_names[this.fieldIndex]).asc_getName())); 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); (field.asc_getSubtotalTop()) ? this.radioTop.setValue(true) : this.radioBottom.setValue(true);
var arr = field.asc_getSubtotals(); this.chEmpty.setValue(field.asc_getShowAll());
if (arr) { if (field.asc_getDefaultSubtotal()) {
_.each(arr, function(item) { var arr = field.asc_getSubtotals();
switch(item) { if (arr) {
case Asc.c_oAscItemType.Sum: _.each(arr, function(item) {
me.chSum.setValue(true); switch(item) {
break; case Asc.c_oAscItemType.Sum:
case Asc.c_oAscItemType.Count: me.chSum.setValue(true);
me.chCount.setValue(true); break;
break; case Asc.c_oAscItemType.Count:
case Asc.c_oAscItemType.Avg: me.chCount.setValue(true);
me.chAve.setValue(true); break;
break; case Asc.c_oAscItemType.Avg:
case Asc.c_oAscItemType.Max: me.chAve.setValue(true);
me.chMax.setValue(true); break;
break; case Asc.c_oAscItemType.Max:
case Asc.c_oAscItemType.Min: me.chMax.setValue(true);
me.chMin.setValue(true); break;
break; case Asc.c_oAscItemType.Min:
case Asc.c_oAscItemType.Product: me.chMin.setValue(true);
me.chProduct.setValue(true); break;
break; case Asc.c_oAscItemType.Product:
case Asc.c_oAscItemType.CountA: me.chProduct.setValue(true);
me.chNum.setValue(true); break;
break; case Asc.c_oAscItemType.CountA:
case Asc.c_oAscItemType.StdDev: me.chNum.setValue(true);
me.chDev.setValue(true); break;
break; case Asc.c_oAscItemType.StdDev:
case Asc.c_oAscItemType.StdDevP: me.chDev.setValue(true);
me.chDevp.setValue(true); break;
break; case Asc.c_oAscItemType.StdDevP:
case Asc.c_oAscItemType.Var: me.chDevp.setValue(true);
me.chVar.setValue(true); break;
break; case Asc.c_oAscItemType.Var:
case Asc.c_oAscItemType.VarP: me.chVar.setValue(true);
me.chVarp.setValue(true); break;
break; case Asc.c_oAscItemType.VarP:
} me.chVarp.setValue(true);
}); break;
}
});
}
} }
} }
}, },
getSettings: function () { 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) { onDlgBtnClick: function(event) {

View file

@ -344,17 +344,17 @@ define([
caption : this.txtAddRow, caption : this.txtAddRow,
checkable : false checkable : false
}); });
// this.miAddRow.on('click', _.bind(this.onAddRow, this)); this.miAddRow.on('click', _.bind(this.onAddRow, this));
this.miAddColumn = new Common.UI.MenuItem({ this.miAddColumn = new Common.UI.MenuItem({
caption : this.txtAddColumn, caption : this.txtAddColumn,
checkable : false checkable : false
}); });
// this.miAddColumn.on('click', _.bind(this.onAddColumn, this)); this.miAddColumn.on('click', _.bind(this.onAddColumn, this));
this.miAddValues = new Common.UI.MenuItem({ this.miAddValues = new Common.UI.MenuItem({
caption : this.txtAddValues, caption : this.txtAddValues,
checkable : false checkable : false
}); });
// this.miAddValues.on('click', _.bind(this.onAddValues, this)); this.miAddValues.on('click', _.bind(this.onAddValues, this));
this.pivotFieldsMenu = new Common.UI.Menu({ this.pivotFieldsMenu = new Common.UI.Menu({
menuAlign: 'tr-br', menuAlign: 'tr-br',
@ -435,6 +435,13 @@ define([
listView.isSuspendEvents = true; listView.isSuspendEvents = true;
record.set('check', !record.get('check')); 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.isSuspendEvents = false;
listView.scroller.update({minScrollbarLength : 40, alwaysVisibleY: true, suppressScrollX: true}); listView.scroller.update({minScrollbarLength : 40, alwaysVisibleY: true, suppressScrollX: true});
@ -602,6 +609,7 @@ define([
} }
})).show(); })).show();
} else { } else {
var pivotField = me._originalProps.asc_getPivotFields()[me._state.field.record.get('pivotIndex')];
(new SSE.Views.FieldSettingsDialog( (new SSE.Views.FieldSettingsDialog(
{ {
props: me._originalProps, props: me._originalProps,
@ -611,7 +619,7 @@ define([
type: me._state.field.type, type: me._state.field.type,
handler: function(result, value) { handler: function(result, value) {
if (result == 'ok' && me.api && 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); 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() { onRemove: function() {
if (this.api && !this._locked && this._state.field){ if (this.api && !this._locked && this._state.field){
this._originalProps.asc_removeField(this.api, this._state.field.record.get('pivotIndex')); this._originalProps.asc_removeField(this.api, this._state.field.record.get('pivotIndex'));

View file

@ -217,8 +217,12 @@ define([ 'text!spreadsheeteditor/main/app/template/PivotSettingsAdvanced.temp
getSettings: function () { getSettings: function () {
var props = new Asc.CT_pivotTableDefinition(); var props = new Asc.CT_pivotTableDefinition();
props.asc_setName(this.inputName.getValue());
props.asc_setRowGrandTotals(this.chCols.getValue() == 'checked'); props.asc_setRowGrandTotals(this.chCols.getValue() == 'checked');
props.asc_setColGrandTotals(this.chRows.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; return props;
}, },

View file

@ -52,21 +52,21 @@ define([
SSE.Views.PivotTable = Common.UI.BaseView.extend(_.extend((function(){ SSE.Views.PivotTable = Common.UI.BaseView.extend(_.extend((function(){
var template = var template =
'<section id="pivot-table-panel" class="panel" data-tab="pivot">' + '<section id="pivot-table-panel" class="panel" data-tab="pivot">' +
// '<div class="group">' + '<div class="group">' +
// '<span id="slot-btn-add-pivot" class="btn-slot text x-huge"></span>' + '<span id="slot-btn-add-pivot" class="btn-slot text x-huge"></span>' +
// '</div>' + '</div>' +
// '<div class="separator long"/>' + '<div class="separator long"/>' +
// '<div class="group">' + '<div class="group">' +
// '<span id="slot-btn-pivot-report-layout" class="btn-slot text x-huge"></span>' + '<span id="slot-btn-pivot-report-layout" class="btn-slot text x-huge"></span>' +
// '<span id="slot-btn-pivot-blank-rows" class="btn-slot text x-huge"></span>' + '<span id="slot-btn-pivot-blank-rows" class="btn-slot text x-huge"></span>' +
// '<span id="slot-btn-pivot-subtotals" class="btn-slot text x-huge"></span>' + '<span id="slot-btn-pivot-subtotals" class="btn-slot text x-huge"></span>' +
// '<span id="slot-btn-pivot-grand-totals" class="btn-slot text x-huge"></span>' + '<span id="slot-btn-pivot-grand-totals" class="btn-slot text x-huge"></span>' +
// '</div>' + '</div>' +
// '<div class="separator long"/>' + '<div class="separator long"/>' +
// '<div class="group">' + '<div class="group">' +
// '<span id="slot-btn-refresh-pivot" class="btn-slot text x-huge"></span>' + '<span id="slot-btn-refresh-pivot" class="btn-slot text x-huge"></span>' +
// '</div>' + '</div>' +
// '<div class="separator long"/>' + '<div class="separator long"/>' +
'<div class="group">' + '<div class="group">' +
'<span id="slot-btn-select-pivot" class="btn-slot text x-huge"></span>' + '<span id="slot-btn-select-pivot" class="btn-slot text x-huge"></span>' +
'</div>' + '</div>' +
@ -176,7 +176,7 @@ define([
cls: 'btn-toolbar x-huge icon-top', cls: 'btn-toolbar x-huge icon-top',
iconCls: 'btn-add-pivot', iconCls: 'btn-add-pivot',
caption: this.txtCreate, caption: this.txtCreate,
disabled : true disabled : false
}); });
// this.lockedControls.push(this.btnAddPivot); // 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({ this.btnPivotBlankRows = new Common.UI.Button({
cls : 'btn-toolbar x-huge icon-top', 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({ this.btnPivotSubtotals = new Common.UI.Button({
cls : 'btn-toolbar x-huge icon-top', 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({ this.btnPivotGrandTotals = new Common.UI.Button({
cls : 'btn-toolbar x-huge icon-top', 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({ this.btnRefreshPivot = new Common.UI.Button({
cls: 'btn-toolbar x-huge icon-top', cls: 'btn-toolbar x-huge icon-top',
@ -249,7 +249,7 @@ define([
caption: this.txtRefresh, caption: this.txtRefresh,
disabled : true disabled : true
}); });
// this.lockedControls.push(this.btnRefreshPivot); this.lockedControls.push(this.btnRefreshPivot);
this.btnSelectPivot = new Common.UI.Button({ this.btnSelectPivot = new Common.UI.Button({
cls: 'btn-toolbar x-huge icon-top', cls: 'btn-toolbar x-huge icon-top',