From 274f56291a1faba6357bd1ee973373b4ce4b05de Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Thu, 4 Mar 2021 23:15:29 +0300 Subject: [PATCH 1/5] [SSE] Group/ungroup pivot table --- .../main/app/controller/DocumentHolder.js | 59 ++- .../main/app/view/DocumentHolder.js | 12 + .../main/app/view/PivotGroupDialog.js | 364 ++++++++++++++++++ apps/spreadsheeteditor/main/locale/en.json | 15 + 4 files changed, 437 insertions(+), 13 deletions(-) create mode 100644 apps/spreadsheeteditor/main/app/view/PivotGroupDialog.js diff --git a/apps/spreadsheeteditor/main/app/controller/DocumentHolder.js b/apps/spreadsheeteditor/main/app/controller/DocumentHolder.js index 02881cd2a3..bb257aa75e 100644 --- a/apps/spreadsheeteditor/main/app/controller/DocumentHolder.js +++ b/apps/spreadsheeteditor/main/app/controller/DocumentHolder.js @@ -72,7 +72,8 @@ define([ 'spreadsheeteditor/main/app/view/SetValueDialog', 'spreadsheeteditor/main/app/view/AutoFilterDialog', 'spreadsheeteditor/main/app/view/SpecialPasteDialog', - 'spreadsheeteditor/main/app/view/SlicerSettingsAdvanced' + 'spreadsheeteditor/main/app/view/SlicerSettingsAdvanced', + 'spreadsheeteditor/main/app/view/PivotGroupDialog' ], function () { 'use strict'; @@ -196,6 +197,8 @@ define([ view.pmiSortCells.menu.on('item:click', _.bind(me.onSortCells, me)); view.pmiFilterCells.menu.on('item:click', _.bind(me.onFilterCells, me)); view.pmiReapply.on('click', _.bind(me.onReapply, me)); + view.mnuGroupPivot.on('click', _.bind(me.onGroupPivot, me)); + view.mnuUnGroupPivot.on('click', _.bind(me.onGroupPivot, 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)); @@ -323,6 +326,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_onShowPivotGroupDialog', _.bind(this.onShowPivotGroupDialog, this)); } return this; }, @@ -474,6 +478,27 @@ define([ this.api.asc_reapplyAutoFilter(this.documentHolder.ssMenu.formatTableName); }, + onGroupPivot: function(item) { + item.value=='grouping' ? this.api.asc_groupPivot() : this.api.asc_ungroupPivot(); + }, + + onShowPivotGroupDialog: function(rangePr, dateTypes) { + var win, props, + me = this; + win = new SSE.Views.PivotGroupDialog({ + date: !!dateTypes, + handler: function(dlg, result) { + if (result == 'ok') { + props = dlg.getSettings(); + me.api.asc_groupPivot(props[0], props[1]); + Common.NotificationCenter.trigger('edit:complete', me.documentHolder); + } + } + }); + win.show(); + win.setSettings(rangePr, dateTypes, me.permissions.lang); + }, + onClear: function(menu, item) { if (this.api) { this.api.asc_emptyCells(item.value); @@ -1657,6 +1682,7 @@ define([ seltype = cellinfo.asc_getSelectionType(), isCellLocked = cellinfo.asc_getLocked(), isTableLocked = cellinfo.asc_getLockedTable()===true, + isPivotLocked = cellinfo.asc_getLockedPivotTable()===true, isObjLocked = false, commentsController = this.getApplication().getController('Common.Controllers.Comments'), internaleditor = this.permissions.isEditMailMerge || this.permissions.isEditDiagram, @@ -1861,7 +1887,8 @@ define([ formatTableInfo = cellinfo.asc_getFormatTableInfo(), isinsparkline = (cellinfo.asc_getSparklineInfo()!==null), isintable = (formatTableInfo !== null), - ismultiselect = cellinfo.asc_getMultiselect(); + ismultiselect = cellinfo.asc_getMultiselect(), + inPivot = !!cellinfo.asc_getPivotTableInfo(); documentHolder.ssMenu.formatTableName = (isintable) ? formatTableInfo.asc_getTableName() : null; documentHolder.ssMenu.cellColor = xfs.asc_getFillColor(); documentHolder.ssMenu.fontColor = xfs.asc_getFontColor(); @@ -1869,20 +1896,22 @@ define([ documentHolder.pmiInsertEntire.setVisible(isrowmenu||iscolmenu); documentHolder.pmiInsertEntire.setCaption((isrowmenu) ? this.textInsertTop : this.textInsertLeft); documentHolder.pmiDeleteEntire.setVisible(isrowmenu||iscolmenu); - documentHolder.pmiInsertCells.setVisible(iscellmenu && !iscelledit && !isintable); - documentHolder.pmiDeleteCells.setVisible(iscellmenu && !iscelledit && !isintable); + documentHolder.pmiInsertCells.setVisible(iscellmenu && !iscelledit && !isintable && !inPivot); + documentHolder.pmiDeleteCells.setVisible(iscellmenu && !iscelledit && !isintable && !inPivot); documentHolder.pmiSelectTable.setVisible(iscellmenu && !iscelledit && isintable); documentHolder.pmiInsertTable.setVisible(iscellmenu && !iscelledit && isintable); documentHolder.pmiDeleteTable.setVisible(iscellmenu && !iscelledit && isintable); documentHolder.pmiSparklines.setVisible(isinsparkline); - documentHolder.pmiSortCells.setVisible((iscellmenu||isallmenu) && !iscelledit); + documentHolder.pmiSortCells.setVisible((iscellmenu||isallmenu) && !iscelledit && !inPivot); documentHolder.pmiSortCells.menu.items[2].setVisible(!internaleditor); documentHolder.pmiSortCells.menu.items[3].setVisible(!internaleditor); documentHolder.pmiSortCells.menu.items[4].setVisible(!internaleditor); - documentHolder.pmiFilterCells.setVisible(iscellmenu && !iscelledit && !internaleditor); - documentHolder.pmiReapply.setVisible((iscellmenu||isallmenu) && !iscelledit && !internaleditor); + documentHolder.pmiFilterCells.setVisible(iscellmenu && !iscelledit && !internaleditor && !inPivot); + documentHolder.pmiReapply.setVisible((iscellmenu||isallmenu) && !iscelledit && !internaleditor && !inPivot); + documentHolder.mnuGroupPivot.setVisible(iscellmenu && !iscelledit && !internaleditor && inPivot); + documentHolder.mnuUnGroupPivot.setVisible(iscellmenu && !iscelledit && !internaleditor && inPivot); documentHolder.ssMenu.items[12].setVisible((iscellmenu||isallmenu||isinsparkline) && !iscelledit); - documentHolder.pmiInsFunction.setVisible(iscellmenu && !iscelledit); + documentHolder.pmiInsFunction.setVisible(iscellmenu && !iscelledit && !inPivot); documentHolder.pmiAddNamedRange.setVisible(iscellmenu && !iscelledit && !internaleditor); if (isintable) { @@ -1898,8 +1927,8 @@ define([ } var hyperinfo = cellinfo.asc_getHyperlink(); - documentHolder.menuHyperlink.setVisible(iscellmenu && hyperinfo && !iscelledit && !ismultiselect && !internaleditor); - documentHolder.menuAddHyperlink.setVisible(iscellmenu && !hyperinfo && !iscelledit && !ismultiselect && !internaleditor); + documentHolder.menuHyperlink.setVisible(iscellmenu && hyperinfo && !iscelledit && !ismultiselect && !internaleditor && !inPivot); + documentHolder.menuAddHyperlink.setVisible(iscellmenu && !hyperinfo && !iscelledit && !ismultiselect && !internaleditor && !inPivot); documentHolder.pmiRowHeight.setVisible(isrowmenu||isallmenu); documentHolder.pmiColumnWidth.setVisible(iscolmenu||isallmenu); @@ -1910,7 +1939,7 @@ define([ /** coauthoring begin **/ var count = cellinfo.asc_getComments().length; - documentHolder.ssMenu.items[17].setVisible(iscellmenu && !iscelledit && this.permissions.canCoAuthoring && this.permissions.canComments && count < 1); + documentHolder.ssMenu.items[19].setVisible(iscellmenu && !iscelledit && this.permissions.canCoAuthoring && this.permissions.canComments && count < 1); documentHolder.pmiAddComment.setVisible(iscellmenu && !iscelledit && this.permissions.canCoAuthoring && this.permissions.canComments && count < 1); /** coauthoring end **/ documentHolder.pmiCellMenuSeparator.setVisible(iscellmenu && !iscelledit || isrowmenu || iscolmenu || isallmenu); @@ -1936,8 +1965,6 @@ define([ documentHolder.pmiInsertCells.menu.items[1].setDisabled(isApplyAutoFilter); documentHolder.pmiDeleteCells.menu.items[1].setDisabled(isApplyAutoFilter); - var inPivot = !!cellinfo.asc_getPivotTableInfo(); - documentHolder.pmiEntriesList.setVisible(!iscelledit && !inPivot); documentHolder.pmiNumFormat.setVisible(!iscelledit); @@ -1965,6 +1992,12 @@ define([ documentHolder.pmiInsFunction.setDisabled(isCellLocked || inPivot); documentHolder.pmiFreezePanes.setDisabled(this.api.asc_isWorksheetLockedOrDeleted(this.api.asc_getActiveWorksheetIndex())); + if (inPivot) { + var canGroup = this.api.asc_canGroupPivot(); + documentHolder.mnuGroupPivot.setDisabled(isPivotLocked || !canGroup); + documentHolder.mnuUnGroupPivot.setDisabled(isPivotLocked || !canGroup); + } + if (showMenu) this.showPopupMenu(documentHolder.ssMenu, {}, event); } else if (this.permissions.isEditDiagram && seltype == Asc.c_oAscSelectionType.RangeChartText) { if (!showMenu && !documentHolder.textInShapeMenu.isVisible()) return; diff --git a/apps/spreadsheeteditor/main/app/view/DocumentHolder.js b/apps/spreadsheeteditor/main/app/view/DocumentHolder.js index 4e10255dca..db859a2900 100644 --- a/apps/spreadsheeteditor/main/app/view/DocumentHolder.js +++ b/apps/spreadsheeteditor/main/app/view/DocumentHolder.js @@ -338,6 +338,16 @@ define([ caption : me.txtReapply }); + me.mnuGroupPivot = new Common.UI.MenuItem({ + caption : this.txtGroup, + value : 'grouping' + }); + + me.mnuUnGroupPivot = new Common.UI.MenuItem({ + caption : this.txtUngroup, + value : 'ungrouping' + }); + me.pmiInsFunction = new Common.UI.MenuItem({ iconCls: 'menu__icon btn-function', caption : me.txtFormula @@ -560,6 +570,8 @@ define([ me.pmiSortCells, me.pmiFilterCells, me.pmiReapply, + me.mnuGroupPivot, + me.mnuUnGroupPivot, {caption: '--'}, me.pmiAddComment, me.pmiCellMenuSeparator, diff --git a/apps/spreadsheeteditor/main/app/view/PivotGroupDialog.js b/apps/spreadsheeteditor/main/app/view/PivotGroupDialog.js new file mode 100644 index 0000000000..aab79bc2e4 --- /dev/null +++ b/apps/spreadsheeteditor/main/app/view/PivotGroupDialog.js @@ -0,0 +1,364 @@ +/* + * + * (c) Copyright Ascensio System SIA 2010-2021 + * + * 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-12 Ernesta Birznieka-Upisha + * 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 + * + */ +/** + * PivotGroupDialog.js + * + * Created by Julia Radzhabova 04.03.2021 + * Copyright (c) 2021 Ascensio System SIA. All rights reserved. + * + */ + +define([ + 'common/main/lib/component/Window' +], function () { + 'use strict'; + + SSE.Views.PivotGroupDialog = Common.UI.Window.extend(_.extend({ + options: { + width: 250, + header: true, + cls: 'modal-dlg', + buttons: ['ok', 'cancel'] + }, + + initialize : function (options) { + var t = this, + height = options.date ? 335 : 195; + + _.extend(this.options, { + title: this.txtTitle + }, options || {}); + + this.template = options.template || [ + '
', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '
', + '', + '
', + '
', + '
', + '
', + '
', + '
', + '
', + '
', + '
', + '', + '', + '
', + '
', + '', + '
', + '
', + '
', + '', + '', + '
', + '
', + '
' + ].join(''); + + this.api = options.api; + this.handler = options.handler; + + this.options.tpl = _.template(this.template)(this.options); + Common.UI.Window.prototype.initialize.call(this, this.options); + }, + render: function () { + Common.UI.Window.prototype.render.call(this); + + this.$window.find('.dlg-btn').on('click', _.bind(this.onBtnClick, this)); + + var me = this; + + this.chStart = new Common.UI.CheckBox({ + el: $('#pivot-group-dlg-chk-start', this.$window), + labelText: this.textStart + }); + this.chStart.on('change', function (field, newValue, oldValue, eOpts) { + + }); + + this.chEnd = new Common.UI.CheckBox({ + el: $('#pivot-group-dlg-chk-end', this.$window), + labelText: this.textEnd + }); + this.chEnd.on('change', function (field, newValue, oldValue, eOpts) { + + }); + + this.inputStart = new Common.UI.InputField({ + el : $('#pivot-group-dlg-txt-start', this.$window), + style : 'width: 100px;', + allowBlank : true, + validateOnChange : true, + validation : function () { return true; } + }).on ('changing', function (input, value) { + me.chStart.setValue(false, true); + }); + + this.inputEnd = new Common.UI.InputField({ + el : $('#pivot-group-dlg-txt-end', this.$window), + style : 'width: 100px;', + allowBlank : true, + validateOnChange : true, + validation : function () { return true; } + }).on ('changing', function (input, value) { + me.chEnd.setValue(false, true); + }); + + this.inputBy = new Common.UI.InputField({ + el : $('#pivot-group-dlg-txt-by', this.$window), + style : 'width: 100px;', + allowBlank : true, + validateOnChange : true, + validation : function () { return true; } + }).on ('changing', function (input, value) { + if (value.length) { + } + }); + + this.spnDays = new Common.UI.MetricSpinner({ + el: $('#pivot-group-dlg-spn-days', this.$window), + step: 1, + width: 100, + defaultUnit : "", + value: '1', + maxValue: 32767, + minValue: 1 + }); + this.spnDays.on('change', _.bind(function(field, newValue, oldValue, eOpts){ + }, this)); + + var arr = [ + { value: this.textSec, type: Asc.c_oAscGroupBy.Seconds}, + { value: this.textMin, type: Asc.c_oAscGroupBy.Minutes}, + { value: this.textHour, type: Asc.c_oAscGroupBy.Hours}, + { value: this.textDays, type: Asc.c_oAscGroupBy.Days}, + { value: this.textMonth, type: Asc.c_oAscGroupBy.Months}, + { value: this.textQuart, type: Asc.c_oAscGroupBy.Quarters}, + { value: this.textYear, type: Asc.c_oAscGroupBy.Years} + ]; + this.listDate = new Common.UI.ListView({ + el: $('#pivot-group-dlg-list', this.$window), + store: new Common.UI.DataViewStore(arr), + multiSelect: true, + tabindex: 1, + itemTemplate: _.template('
<%= value %>
') + }); + + this.listDate.on('item:select', _.bind(this.onSelectDate, this)); + this.listDate.on('item:deselect', _.bind(this.onSelectDate, this)); + this.listDate.on('entervalue', _.bind(this.onPrimary, this)); + + this.btnOk = new Common.UI.Button({ + el: $('.dlg-btn.primary', this.$window) + }); + }, + + getFocusedComponents: function() { + return [this.inputStart, this.inputEnd, this.inputBy, {cmp: this.listDate, selector: '.listview'}, this.spnDays]; + }, + + getDefaultFocusableComponent: function () { + return this.inputStart; + }, + + onBtnClick: function (event) { + this._handleInput(event.currentTarget.attributes['result'].value); + }, + + onSelectDate: function (listView, itemView, record) { + if (!record || record.length<1) return; + if (record.get('type')==Asc.c_oAscGroupBy.Days) + this.isDays = record.get('selected'); + var selected = this.listDate.getSelectedRec().length; + this.spnDays.setDisabled(!this.isDays || selected>1); + this.btnOk.setDisabled(selected<1); + }, + + setSettings: function (rangePr, dateTypes, lang) { + this.$window.find('.group-number').toggleClass('hidden', !!dateTypes); + this.$window.find('.group-date').toggleClass('hidden', !dateTypes); + if (rangePr) { + this.chStart.setValue(rangePr.asc_getAutoStart(), true); + this.chEnd.setValue(rangePr.asc_getAutoEnd(), true); + this.inputStart.setValue((dateTypes ? new Date(rangePr.asc_getStartDate()).toLocaleDateString(lang) : rangePr.asc_getStartNum()) || ''); + this.inputEnd.setValue((dateTypes ? new Date(rangePr.asc_getEndDate()).toLocaleDateString(lang) : rangePr.asc_getEndNum()) || ''); + !dateTypes && this.inputBy.setValue(rangePr.asc_getGroupInterval() || ''); + this.rangePr = rangePr; + } + if (dateTypes) { + var me = this, + isDays; + _.each(dateTypes, function(item) { + var rec = me.listDate.store.findWhere({type: item}); + rec && me.listDate.selectRecord(rec); + if (item == Asc.c_oAscGroupBy.Days) + isDays = true; + }); + this.spnDays.setValue(rangePr.asc_getGroupInterval() || ''); + this.spnDays.setDisabled(!isDays || dateTypes.length>1); + this.btnOk.setDisabled(dateTypes.length<1); + this.dateTypes = dateTypes; + this.isDays = isDays; + } + }, + + getSettings: function() { + if (this.rangePr) { + this.rangePr.asc_setAutoStart(this.chStart.getValue()=='checked'); + this.rangePr.asc_setAutoEnd(this.chEnd.getValue()=='checked'); + if (this.dateTypes) { + this.dateTypes = this.listDate.getSelectedRec().map(function(item){return item.get('type');}); + this.rangePr.asc_setGroupInterval(this.spnDays.getNumberValue()); + this.rangePr.asc_setStartDate(new Date(this.inputStart.getValue()).getTime()); + this.rangePr.asc_setEndDate(new Date(this.inputEnd.getValue()).getTime()); + } else { + this.rangePr.asc_setStartNum(parseFloat(this.inputStart.getValue())); + this.rangePr.asc_setEndNum(parseFloat(this.inputEnd.getValue())); + this.rangePr.asc_setGroupInterval(parseFloat(this.inputBy.getValue())); + } + } + + return [this.rangePr, this.dateTypes]; + }, + + isRangeValid: function() { + if (this.dateTypes) { + var res1 = new Date(this.inputStart.getValue()).getTime(); + if (isNaN(res1)) { + this.inputStart.showError([this.textError]); + this.inputStart.focus(); + return false; + } + var res2 = new Date(this.inputEnd.getValue()).getTime(); + if (isNaN(res2)) { + this.inputEnd.showError([this.textError]); + this.inputEnd.focus(); + return false; + } + if (res2 Date: Thu, 4 Mar 2021 23:20:12 +0300 Subject: [PATCH 2/5] [SSE] Add Asc.c_oAscError.ID.PivotGroup error --- apps/spreadsheeteditor/main/app/controller/Main.js | 7 ++++++- apps/spreadsheeteditor/main/locale/en.json | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/spreadsheeteditor/main/app/controller/Main.js b/apps/spreadsheeteditor/main/app/controller/Main.js index 85fa18d165..552b674ec7 100644 --- a/apps/spreadsheeteditor/main/app/controller/Main.js +++ b/apps/spreadsheeteditor/main/app/controller/Main.js @@ -1610,6 +1610,10 @@ define([ config.msg = this.errorSetPassword; break; + case Asc.c_oAscError.ID.PivotGroup : + config.msg = this.errorPivotGroup; + break; + default: config.msg = (typeof id == 'string') ? id : this.errorDefaultMessage.replace('%1', id); break; @@ -2813,7 +2817,8 @@ define([ textRenameLabel: 'Enter a name to be used for collaboration', textRenameError: 'User name must not be empty.', textLongName: 'Enter a name that is less than 128 characters.', - textGuest: 'Guest' + textGuest: 'Guest', + errorPivotGroup: 'Cannot group that selection.' } })(), SSE.Controllers.Main || {})) }); diff --git a/apps/spreadsheeteditor/main/locale/en.json b/apps/spreadsheeteditor/main/locale/en.json index 5343be3d2c..cb7e751e11 100644 --- a/apps/spreadsheeteditor/main/locale/en.json +++ b/apps/spreadsheeteditor/main/locale/en.json @@ -610,6 +610,7 @@ "SSE.Controllers.Main.errorViewerDisconnect": "Connection is lost. You can still view the document,
but will not be able to download or print it until the connection is restored and page is reloaded.", "SSE.Controllers.Main.errorWrongBracketsCount": "An error in the entered formula.
Wrong number of brackets is used.", "SSE.Controllers.Main.errorWrongOperator": "An error in the entered formula. Wrong operator is used.
Please correct the error.", + "SSE.Controllers.Main.errorPivotGroup": "Cannot group that selection.", "SSE.Controllers.Main.errRemDuplicates": "Duplicate values found and deleted: {0}, unique values left: {1}.", "SSE.Controllers.Main.leavePageText": "You have unsaved changes in this spreadsheet. Click 'Stay on this Page' then 'Save' to save them. Click 'Leave this Page' to discard all the unsaved changes.", "SSE.Controllers.Main.loadFontsTextText": "Loading data...", From 9d18c8ce132bc89b90c85903c6d5ba18d5b83e61 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Fri, 5 Mar 2021 11:49:58 +0300 Subject: [PATCH 3/5] [SSE] Apply auto values for pivot groups --- .../main/app/controller/DocumentHolder.js | 4 +-- .../main/app/view/PivotGroupDialog.js | 27 ++++++++++++------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/apps/spreadsheeteditor/main/app/controller/DocumentHolder.js b/apps/spreadsheeteditor/main/app/controller/DocumentHolder.js index bb257aa75e..5934e19834 100644 --- a/apps/spreadsheeteditor/main/app/controller/DocumentHolder.js +++ b/apps/spreadsheeteditor/main/app/controller/DocumentHolder.js @@ -482,7 +482,7 @@ define([ item.value=='grouping' ? this.api.asc_groupPivot() : this.api.asc_ungroupPivot(); }, - onShowPivotGroupDialog: function(rangePr, dateTypes) { + onShowPivotGroupDialog: function(rangePr, dateTypes, defRangePr) { var win, props, me = this; win = new SSE.Views.PivotGroupDialog({ @@ -496,7 +496,7 @@ define([ } }); win.show(); - win.setSettings(rangePr, dateTypes, me.permissions.lang); + win.setSettings(rangePr, dateTypes, defRangePr, me.permissions.lang); }, onClear: function(menu, item) { diff --git a/apps/spreadsheeteditor/main/app/view/PivotGroupDialog.js b/apps/spreadsheeteditor/main/app/view/PivotGroupDialog.js index aab79bc2e4..0d04c25099 100644 --- a/apps/spreadsheeteditor/main/app/view/PivotGroupDialog.js +++ b/apps/spreadsheeteditor/main/app/view/PivotGroupDialog.js @@ -131,7 +131,9 @@ define([ labelText: this.textStart }); this.chStart.on('change', function (field, newValue, oldValue, eOpts) { - + if (newValue=='checked' && !me.dateTypes && me.defRangePr) { + me.inputStart.setValue(me.defRangePr.start); + } }); this.chEnd = new Common.UI.CheckBox({ @@ -139,7 +141,9 @@ define([ labelText: this.textEnd }); this.chEnd.on('change', function (field, newValue, oldValue, eOpts) { - + if (newValue=='checked' && !me.dateTypes && me.defRangePr) { + me.inputEnd.setValue(me.defRangePr.end); + } }); this.inputStart = new Common.UI.InputField({ @@ -232,7 +236,7 @@ define([ this.btnOk.setDisabled(selected<1); }, - setSettings: function (rangePr, dateTypes, lang) { + setSettings: function (rangePr, dateTypes, defRangePr, lang) { this.$window.find('.group-number').toggleClass('hidden', !!dateTypes); this.$window.find('.group-date').toggleClass('hidden', !dateTypes); if (rangePr) { @@ -242,6 +246,9 @@ define([ this.inputEnd.setValue((dateTypes ? new Date(rangePr.asc_getEndDate()).toLocaleDateString(lang) : rangePr.asc_getEndNum()) || ''); !dateTypes && this.inputBy.setValue(rangePr.asc_getGroupInterval() || ''); this.rangePr = rangePr; + if (defRangePr) { + this.defRangePr = {start: defRangePr.asc_getStartNum(), end: defRangePr.asc_getEndNum()}; + } } if (dateTypes) { var me = this, @@ -270,8 +277,8 @@ define([ this.rangePr.asc_setStartDate(new Date(this.inputStart.getValue()).getTime()); this.rangePr.asc_setEndDate(new Date(this.inputEnd.getValue()).getTime()); } else { - this.rangePr.asc_setStartNum(parseFloat(this.inputStart.getValue())); - this.rangePr.asc_setEndNum(parseFloat(this.inputEnd.getValue())); + this.rangePr.asc_setStartNum(parseFloat(this.inputStart.getValue().toString().replace(',','.'))); + this.rangePr.asc_setEndNum(parseFloat(this.inputEnd.getValue().toString().replace(',','.'))); this.rangePr.asc_setGroupInterval(parseFloat(this.inputBy.getValue())); } } @@ -281,13 +288,13 @@ define([ isRangeValid: function() { if (this.dateTypes) { - var res1 = new Date(this.inputStart.getValue()).getTime(); + var res1 = new Date(this.inputStart.getValue().toString()).getTime(); if (isNaN(res1)) { this.inputStart.showError([this.textError]); this.inputStart.focus(); return false; } - var res2 = new Date(this.inputEnd.getValue()).getTime(); + var res2 = new Date(this.inputEnd.getValue().toString()).getTime(); if (isNaN(res2)) { this.inputEnd.showError([this.textError]); this.inputEnd.focus(); @@ -300,19 +307,19 @@ define([ } } else { var regstr = new RegExp('^\s*[0-9]+[,.]?[0-9]*\s*$'); - var res1 = this.inputStart.getValue(); + var res1 = this.inputStart.getValue().toString(); if (!regstr.test(res1)) { this.inputStart.showError([this.textError]); this.inputStart.focus(); return false; } - var res2 = this.inputEnd.getValue(); + var res2 = this.inputEnd.getValue().toString(); if (!regstr.test(res2)) { this.inputEnd.showError([this.textError]); this.inputEnd.focus(); return false; } - if (parseFloat(res2) Date: Fri, 5 Mar 2021 16:30:32 +0300 Subject: [PATCH 4/5] [SSE] Refactoring --- apps/spreadsheeteditor/main/app/view/PivotGroupDialog.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/spreadsheeteditor/main/app/view/PivotGroupDialog.js b/apps/spreadsheeteditor/main/app/view/PivotGroupDialog.js index 0d04c25099..7fd944f9a3 100644 --- a/apps/spreadsheeteditor/main/app/view/PivotGroupDialog.js +++ b/apps/spreadsheeteditor/main/app/view/PivotGroupDialog.js @@ -279,7 +279,7 @@ define([ } else { this.rangePr.asc_setStartNum(parseFloat(this.inputStart.getValue().toString().replace(',','.'))); this.rangePr.asc_setEndNum(parseFloat(this.inputEnd.getValue().toString().replace(',','.'))); - this.rangePr.asc_setGroupInterval(parseFloat(this.inputBy.getValue())); + this.rangePr.asc_setGroupInterval(parseFloat(this.inputBy.getValue().toString().replace(',','.'))); } } @@ -324,7 +324,7 @@ define([ this.inputEnd.focus(); return false; } - if (!regstr.test(this.inputBy.getValue())) { + if (!regstr.test(this.inputBy.getValue().toString())) { this.inputBy.showError([this.textError]); this.inputBy.focus(); return false; From 3a0c941d73d44b015551a4abb9be44bce0d72e3a Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Tue, 9 Mar 2021 14:43:05 +0300 Subject: [PATCH 5/5] [SSE] Fix pivot groups --- .../main/app/controller/DocumentHolder.js | 2 +- .../main/app/view/PivotGroupDialog.js | 52 ++++++++++--------- 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/apps/spreadsheeteditor/main/app/controller/DocumentHolder.js b/apps/spreadsheeteditor/main/app/controller/DocumentHolder.js index 5934e19834..d16bbe35f6 100644 --- a/apps/spreadsheeteditor/main/app/controller/DocumentHolder.js +++ b/apps/spreadsheeteditor/main/app/controller/DocumentHolder.js @@ -496,7 +496,7 @@ define([ } }); win.show(); - win.setSettings(rangePr, dateTypes, defRangePr, me.permissions.lang); + win.setSettings(rangePr, dateTypes, defRangePr); }, onClear: function(menu, item) { diff --git a/apps/spreadsheeteditor/main/app/view/PivotGroupDialog.js b/apps/spreadsheeteditor/main/app/view/PivotGroupDialog.js index 7fd944f9a3..83fba93dde 100644 --- a/apps/spreadsheeteditor/main/app/view/PivotGroupDialog.js +++ b/apps/spreadsheeteditor/main/app/view/PivotGroupDialog.js @@ -131,7 +131,7 @@ define([ labelText: this.textStart }); this.chStart.on('change', function (field, newValue, oldValue, eOpts) { - if (newValue=='checked' && !me.dateTypes && me.defRangePr) { + if (newValue=='checked' && me.defRangePr) { me.inputStart.setValue(me.defRangePr.start); } }); @@ -141,7 +141,7 @@ define([ labelText: this.textEnd }); this.chEnd.on('change', function (field, newValue, oldValue, eOpts) { - if (newValue=='checked' && !me.dateTypes && me.defRangePr) { + if (newValue=='checked' && me.defRangePr) { me.inputEnd.setValue(me.defRangePr.end); } }); @@ -236,18 +236,18 @@ define([ this.btnOk.setDisabled(selected<1); }, - setSettings: function (rangePr, dateTypes, defRangePr, lang) { + setSettings: function (rangePr, dateTypes, defRangePr) { this.$window.find('.group-number').toggleClass('hidden', !!dateTypes); this.$window.find('.group-date').toggleClass('hidden', !dateTypes); if (rangePr) { this.chStart.setValue(rangePr.asc_getAutoStart(), true); this.chEnd.setValue(rangePr.asc_getAutoEnd(), true); - this.inputStart.setValue((dateTypes ? new Date(rangePr.asc_getStartDate()).toLocaleDateString(lang) : rangePr.asc_getStartNum()) || ''); - this.inputEnd.setValue((dateTypes ? new Date(rangePr.asc_getEndDate()).toLocaleDateString(lang) : rangePr.asc_getEndNum()) || ''); + this.inputStart.setValue((dateTypes ? rangePr.asc_getStartDateText() : rangePr.asc_getStartNum()) || ''); + this.inputEnd.setValue((dateTypes ? rangePr.asc_getEndDateText() : rangePr.asc_getEndNum()) || ''); !dateTypes && this.inputBy.setValue(rangePr.asc_getGroupInterval() || ''); this.rangePr = rangePr; if (defRangePr) { - this.defRangePr = {start: defRangePr.asc_getStartNum(), end: defRangePr.asc_getEndNum()}; + this.defRangePr = {start: dateTypes ? defRangePr.asc_getStartDateText() : defRangePr.asc_getStartNum(), end: dateTypes ? defRangePr.asc_getEndDateText() : defRangePr.asc_getEndNum()}; } } if (dateTypes) { @@ -274,8 +274,8 @@ define([ if (this.dateTypes) { this.dateTypes = this.listDate.getSelectedRec().map(function(item){return item.get('type');}); this.rangePr.asc_setGroupInterval(this.spnDays.getNumberValue()); - this.rangePr.asc_setStartDate(new Date(this.inputStart.getValue()).getTime()); - this.rangePr.asc_setEndDate(new Date(this.inputEnd.getValue()).getTime()); + this.rangePr.asc_setStartDateText(this.inputStart.getValue()); + this.rangePr.asc_setEndDateText(this.inputEnd.getValue()); } else { this.rangePr.asc_setStartNum(parseFloat(this.inputStart.getValue().toString().replace(',','.'))); this.rangePr.asc_setEndNum(parseFloat(this.inputEnd.getValue().toString().replace(',','.'))); @@ -288,22 +288,26 @@ define([ isRangeValid: function() { if (this.dateTypes) { - var res1 = new Date(this.inputStart.getValue().toString()).getTime(); - if (isNaN(res1)) { - this.inputStart.showError([this.textError]); - this.inputStart.focus(); - return false; - } - var res2 = new Date(this.inputEnd.getValue().toString()).getTime(); - if (isNaN(res2)) { - this.inputEnd.showError([this.textError]); - this.inputEnd.focus(); - return false; - } - if (res2