Skip to content

Commit

Permalink
[SSE] Add show detail dialog for pivot table
Browse files Browse the repository at this point in the history
  • Loading branch information
Basher0303 committed Aug 13, 2023
1 parent 0a5fa2d commit 710e7af
Show file tree
Hide file tree
Showing 2 changed files with 187 additions and 1 deletion.
40 changes: 39 additions & 1 deletion apps/spreadsheeteditor/main/app/controller/DocumentHolder.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ define([
'spreadsheeteditor/main/app/view/MacroDialog',
'spreadsheeteditor/main/app/view/FieldSettingsDialog',
'spreadsheeteditor/main/app/view/ValueFieldSettingsDialog',
'spreadsheeteditor/main/app/view/PivotSettingsAdvanced'
'spreadsheeteditor/main/app/view/PivotSettingsAdvanced',
'spreadsheeteditor/main/app/view/PivotShowDetailDialog',
], function () {
'use strict';

Expand Down Expand Up @@ -396,6 +397,7 @@ define([
this.api.asc_registerCallback('asc_ChangeCropState', _.bind(this.onChangeCropState, this));
this.api.asc_registerCallback('asc_onInputMessage', _.bind(this.onInputMessage, this));
this.api.asc_registerCallback('asc_onTableTotalMenu', _.bind(this.onTableTotalMenu, this));
this.api.asc_registerCallback('asc_onShowPivotHeaderDetailsDialog', _.bind(this.onShowPivotHeaderDetailsDialog, this));
this.api.asc_registerCallback('asc_onShowPivotGroupDialog', _.bind(this.onShowPivotGroupDialog, this));
if (!this.permissions.isEditMailMerge && !this.permissions.isEditDiagram && !this.permissions.isEditOle) {
this.api.asc_registerCallback('asc_doubleClickOnTableOleObject', _.bind(this.onDoubleClickOnTableOleObject, this));
Expand Down Expand Up @@ -612,6 +614,42 @@ define([
item.value=='grouping' ? this.api.asc_groupPivot() : this.api.asc_ungroupPivot();
},

onShowPivotHeaderDetailsDialog: function(isRow, isAll) {
var me = this,
pivotInfo = this.api.asc_getCellInfo().asc_getPivotTableInfo(),
cacheFields = pivotInfo.asc_getCacheFields(),
pivotFields = pivotInfo.asc_getPivotFields(),
fieldsNames = _.map(pivotFields, function(item, index) {
return {
index: index,
name: item.asc_getName() || cacheFields[index].asc_getName()
}
}),
excludedFields = [];

if(isRow) excludedFields = pivotInfo.asc_getRowFields();
else excludedFields = pivotInfo.asc_getColumnFields();

excludedFields && (excludedFields = _.filter(excludedFields, function(item){
var pivotIndex = item.asc_getIndex();
return (pivotIndex>-1 || pivotIndex == -2);
}));

excludedFields.forEach(function(excludedItem) {
var indexInFieldsNames = _.findIndex(fieldsNames, function(item) { return excludedItem.asc_getIndex() == item.index});
fieldsNames.splice(indexInFieldsNames, 1);
});

new SSE.Views.PivotShowDetailDialog({
handler: function(result, value) {
if (result == 'ok' && value) {
me.api.asc_pivotShowDetailsHeader(value.index, isAll) ;
}
},
items: fieldsNames,
}).show();
},

onShowPivotGroupDialog: function(rangePr, dateTypes, defRangePr) {
var win, props,
me = this;
Expand Down
148 changes: 148 additions & 0 deletions apps/spreadsheeteditor/main/app/view/PivotShowDetailDialog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
/*
* (c) Copyright Ascensio System SIA 2010-2023
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
/**
*
* PivotShowDetailDialog.js
*
* Created by Alexey.Koshelev on 13.08.23
* Copyright (c) 2023 Ascensio System SIA. All rights reserved.
*
*/

define([
'common/main/lib/view/AdvancedSettingsWindow',
'common/main/lib/component/ListView'
], function () {
'use strict';

SSE.Views = SSE.Views || {};

SSE.Views.PivotShowDetailDialog = Common.Views.AdvancedSettingsWindow.extend(_.extend({
options: {
alias: 'PivotShowDetailDialog',
contentWidth: 300,
height: 282
},

initialize: function (options) {
var me = this;

_.extend(this.options, {
title: this.txtTitle,
template: [
'<div class="box" style="height:' + (me.options.height - 85) + 'px;">',
'<div class="content-panel" style="padding: 0;"><div class="inner-content">',
'<div class="settings-panel active">',
'<table cols="1" style="width: 100%;">',
'<tr>',
'<td class="padding-small">',
'<label class="input-label">', me.textDescription,'</label>',
'<div id="pivot-show-detail-list" class="range-tableview" style="width:100%; height: 165px;"></div>',
'</td>',
'</tr>',
'</table>',
'</div></div>',
'</div>',
'</div>'
].join('')
}, options);

this.handler = options.handler;
this.items = options.items || [];

Common.Views.AdvancedSettingsWindow.prototype.initialize.call(this, this.options);
},
render: function () {
Common.Views.AdvancedSettingsWindow.prototype.render.call(this);

this.rangeList = new Common.UI.ListView({
el: $('#pivot-show-detail-list', this.$window),
store: new Common.UI.DataViewStore(),
simpleAddMode: true,
cls: 'dbl-clickable',
itemTemplate: _.template([
'<div style="pointer-events:none;">',
'<div id="<%= id %>" class="list-item" style="width: 100%;display:inline-block;">',
'<div class="padding-right-5" style="width:186px;"><%= Common.Utils.String.htmlEncode(name) %></div>',
'</div>',
'</div>'
].join(''))
});
this.rangeList.on('item:dblclick', _.bind(this.onDblClickFunction, this));
this.rangeList.on('entervalue', _.bind(this.onPrimary, this));

this.afterRender();
},

afterRender: function() {
this._setDefaults();
},

_setDefaults: function () {
if(this.items) {
var me = this;
this.rangeList.store.reset(this.items);
if (this.rangeList.store.length>0)
this.rangeList.selectByIndex(0);
this.rangeList.scroller.update({alwaysVisibleY: true});
_.delay(function () {
me.rangeList.focus();
}, 100, this);
}
},

getSettings: function() {
var rec = this.rangeList.getSelectedRec();
return (rec) ? {index: rec.get('index'), name: rec.get('name')}: null;
},

onPrimary: function() {
this.handler && this.handler.call(this, 'ok', this.getSettings());
this.close();
return false;
},

onDlgBtnClick: function(event) {
var state = event.currentTarget.attributes['result'].value;
this.handler && this.handler.call(this, state, (state == 'ok') ? this.getSettings() : undefined);
this.close();
},

onDblClickFunction: function () {
this.handler && this.handler.call(this, 'ok', this.getSettings());
this.close();
},

txtTitle: 'Show Detail',
textDescription: 'Choose the field containing the detail you want to show:'
}, SSE.Views.PivotShowDetailDialog || {}));
});

0 comments on commit 710e7af

Please sign in to comment.