From 96f73f97c0f879e9643333f5bf960c130eaf6fa7 Mon Sep 17 00:00:00 2001 From: Alexei Koshelev Date: Wed, 29 Mar 2023 03:13:21 +0300 Subject: [PATCH 1/3] [SSE] Sort by ASC in table templates lists --- .../main/app/controller/PivotTable.js | 13 +++++++++++++ .../main/app/controller/Toolbar.js | 12 ++++++++++++ .../main/app/view/TableSettings.js | 12 ++++++++++++ 3 files changed, 37 insertions(+) diff --git a/apps/spreadsheeteditor/main/app/controller/PivotTable.js b/apps/spreadsheeteditor/main/app/controller/PivotTable.js index 390486a08b..1fab2535a0 100644 --- a/apps/spreadsheeteditor/main/app/controller/PivotTable.js +++ b/apps/spreadsheeteditor/main/app/controller/PivotTable.js @@ -421,6 +421,19 @@ define([ tip : tip }); }); + + var reverseArr = function(arr, indexStart) { + for(var i = 0; i < Math.floor((arr.length-indexStart)/2); i++) { + var temp = arr[indexStart + i]; + arr[indexStart + i] = arr[arr.length-1 - i]; + arr[arr.length-1 - i] = temp; + } + }; + + reverseArr(groups[1].templates, groups[1].templates[0].tip == 'None' ? 1 : 0); + reverseArr(groups[2].templates, 0); + reverseArr(groups[3].templates, 0); + groups = groups.filter(function(item, index){ return item.templates.length > 0 }); diff --git a/apps/spreadsheeteditor/main/app/controller/Toolbar.js b/apps/spreadsheeteditor/main/app/controller/Toolbar.js index e7ba55791b..08b8d3094f 100644 --- a/apps/spreadsheeteditor/main/app/controller/Toolbar.js +++ b/apps/spreadsheeteditor/main/app/controller/Toolbar.js @@ -2311,6 +2311,18 @@ define([ }); }); + var reverseArr = function(arr, indexStart) { + for(var i = 0; i < Math.floor((arr.length-indexStart)/2); i++) { + var temp = arr[indexStart + i]; + arr[indexStart + i] = arr[arr.length-1 - i]; + arr[arr.length-1 - i] = temp; + } + }; + + reverseArr(groups[1].templates, groups[1].templates[0].tip == 'None' ? 1 : 0); + reverseArr(groups[2].templates, 0); + reverseArr(groups[3].templates, 0); + groups = groups.filter(function(item, index){ return item.templates.length > 0 }); diff --git a/apps/spreadsheeteditor/main/app/view/TableSettings.js b/apps/spreadsheeteditor/main/app/view/TableSettings.js index af5e90d93c..3fbfa7b085 100644 --- a/apps/spreadsheeteditor/main/app/view/TableSettings.js +++ b/apps/spreadsheeteditor/main/app/view/TableSettings.js @@ -637,6 +637,18 @@ define([ }); }); + var reverseArr = function(arr, indexStart) { + for(var i = 0; i < Math.floor((arr.length-indexStart)/2); i++) { + var temp = arr[indexStart + i]; + arr[indexStart + i] = arr[arr.length-1 - i]; + arr[arr.length-1 - i] = temp; + } + }; + + reverseArr(groups[1].templates, groups[1].templates[0].tip == 'None' ? 1 : 0); + reverseArr(groups[2].templates, 0); + reverseArr(groups[3].templates, 0); + groups = groups.filter(function(item, index){ return item.templates.length > 0 }); From f6cb9bddb5ab35b211141dc20608296dce71b55b Mon Sep 17 00:00:00 2001 From: Alexei Koshelev Date: Thu, 30 Mar 2023 00:06:16 +0300 Subject: [PATCH 2/3] [SSE] Refactoring previous commit --- .../main/app/controller/PivotTable.js | 31 +++++++++-------- .../main/app/controller/Toolbar.js | 34 ++++++++++--------- .../main/app/view/TableSettings.js | 31 +++++++++-------- 3 files changed, 50 insertions(+), 46 deletions(-) diff --git a/apps/spreadsheeteditor/main/app/controller/PivotTable.js b/apps/spreadsheeteditor/main/app/controller/PivotTable.js index 1fab2535a0..74d80ae809 100644 --- a/apps/spreadsheeteditor/main/app/controller/PivotTable.js +++ b/apps/spreadsheeteditor/main/app/controller/PivotTable.js @@ -385,12 +385,13 @@ define([ {id: 'menu-table-group-no-name', caption: ' ', templates: []}, ]; _.each(Templates, function(template, index){ - var tip = template.asc_getDisplayName(); - var groupItem = ''; + var tip = template.asc_getDisplayName(), + groupItem = '', + lastWordInTip = null; if (template.asc_getType()==0) { - var arr = tip.split(' '), - last = arr.pop(); + var arr = tip.split(' '); + lastWordInTip = arr.pop(); if(tip == 'None'){ groupItem = 'menu-table-group-light'; @@ -404,7 +405,8 @@ define([ } } arr = 'txtTable_' + arr.join(''); - tip = self.view.__proto__[arr] ? self.view.__proto__[arr] + ' ' + last : tip; + tip = self.view.__proto__[arr] ? self.view.__proto__[arr] + ' ' + lastWordInTip : tip; + lastWordInTip = parseInt(lastWordInTip); } else { groupItem = 'menu-table-group-custom' @@ -418,21 +420,20 @@ define([ group : groupItem, allowSelected : true, selected : false, - tip : tip + tip : tip, + numInGroup : (lastWordInTip != null && !isNaN(lastWordInTip) ? lastWordInTip : null) }); }); - var reverseArr = function(arr, indexStart) { - for(var i = 0; i < Math.floor((arr.length-indexStart)/2); i++) { - var temp = arr[indexStart + i]; - arr[indexStart + i] = arr[arr.length-1 - i]; - arr[arr.length-1 - i] = temp; - } + var sortFunc = function(a, b) { + var aNum = a.numInGroup, + bNum = b.numInGroup; + return aNum - bNum; }; - reverseArr(groups[1].templates, groups[1].templates[0].tip == 'None' ? 1 : 0); - reverseArr(groups[2].templates, 0); - reverseArr(groups[3].templates, 0); + groups[1].templates.sort(sortFunc); + groups[2].templates.sort(sortFunc); + groups[3].templates.sort(sortFunc); groups = groups.filter(function(item, index){ return item.templates.length > 0 diff --git a/apps/spreadsheeteditor/main/app/controller/Toolbar.js b/apps/spreadsheeteditor/main/app/controller/Toolbar.js index 08b8d3094f..d09effef89 100644 --- a/apps/spreadsheeteditor/main/app/controller/Toolbar.js +++ b/apps/spreadsheeteditor/main/app/controller/Toolbar.js @@ -2275,12 +2275,13 @@ define([ {id: 'menu-table-group-no-name', caption: ' ', templates: []}, ]; _.each(images, function(item) { - var tip = item.asc_getDisplayName(); - var groupItem = ''; - + var tip = item.asc_getDisplayName(), + groupItem = '', + lastWordInTip = null; + if (item.asc_getType()==0) { - var arr = tip.split(' '), - last = arr.pop(); + var arr = tip.split(' '); + lastWordInTip = arr.pop(); if(tip == 'None'){ groupItem = 'menu-table-group-light'; @@ -2294,7 +2295,8 @@ define([ } } arr = 'txtTable_' + arr.join(''); - tip = me[arr] ? me[arr] + ' ' + last : tip; + tip = me[arr] ? me[arr] + ' ' + lastWordInTip : tip; + lastWordInTip = parseInt(lastWordInTip); } else { groupItem = 'menu-table-group-custom' @@ -2307,21 +2309,21 @@ define([ group : groupItem, allowSelected : true, selected : false, - tip : tip + tip : tip, + numInGroup : (lastWordInTip != null && !isNaN(lastWordInTip) ? lastWordInTip : null) }); }); - var reverseArr = function(arr, indexStart) { - for(var i = 0; i < Math.floor((arr.length-indexStart)/2); i++) { - var temp = arr[indexStart + i]; - arr[indexStart + i] = arr[arr.length-1 - i]; - arr[arr.length-1 - i] = temp; - } + var sortFunc = function(a, b) { + var aNum = a.numInGroup, + bNum = b.numInGroup; + return aNum - bNum; }; - reverseArr(groups[1].templates, groups[1].templates[0].tip == 'None' ? 1 : 0); - reverseArr(groups[2].templates, 0); - reverseArr(groups[3].templates, 0); + + groups[1].templates.sort(sortFunc); + groups[2].templates.sort(sortFunc); + groups[3].templates.sort(sortFunc); groups = groups.filter(function(item, index){ return item.templates.length > 0 diff --git a/apps/spreadsheeteditor/main/app/view/TableSettings.js b/apps/spreadsheeteditor/main/app/view/TableSettings.js index 3fbfa7b085..7f6a67ed02 100644 --- a/apps/spreadsheeteditor/main/app/view/TableSettings.js +++ b/apps/spreadsheeteditor/main/app/view/TableSettings.js @@ -600,12 +600,13 @@ define([ {id: 'menu-table-group-no-name', caption: ' ', templates: []}, ]; _.each(Templates, function(item){ - var tip = item.asc_getDisplayName(); - var groupItem = ''; + var tip = item.asc_getDisplayName(), + groupItem = '', + lastWordInTip = null; if (item.asc_getType()==0) { - var arr = tip.split(' '), - last = arr.pop(); + var arr = tip.split(' '); + lastWordInTip = arr.pop(); if(tip == 'None'){ groupItem = 'menu-table-group-light'; @@ -619,7 +620,8 @@ define([ } } arr = 'txtTable_' + arr.join(''); - tip = self[arr] ? self[arr] + ' ' + last : tip; + tip = self[arr] ? self[arr] + ' ' + lastWordInTip : tip; + lastWordInTip = parseInt(lastWordInTip); } else { groupItem = 'menu-table-group-custom' @@ -633,21 +635,20 @@ define([ group : groupItem, allowSelected : true, selected : false, - tip : tip + tip : tip, + numInGroup : (lastWordInTip != null && !isNaN(lastWordInTip) ? lastWordInTip : null) }); }); - var reverseArr = function(arr, indexStart) { - for(var i = 0; i < Math.floor((arr.length-indexStart)/2); i++) { - var temp = arr[indexStart + i]; - arr[indexStart + i] = arr[arr.length-1 - i]; - arr[arr.length-1 - i] = temp; - } + var sortFunc = function(a, b) { + var aNum = a.numInGroup, + bNum = b.numInGroup; + return aNum - bNum; }; - reverseArr(groups[1].templates, groups[1].templates[0].tip == 'None' ? 1 : 0); - reverseArr(groups[2].templates, 0); - reverseArr(groups[3].templates, 0); + groups[1].templates.sort(sortFunc); + groups[2].templates.sort(sortFunc); + groups[3].templates.sort(sortFunc); groups = groups.filter(function(item, index){ return item.templates.length > 0 From 15fc66fd07c59a1887134a38016e54c8f2077f9c Mon Sep 17 00:00:00 2001 From: Alexei Koshelev Date: Fri, 31 Mar 2023 23:23:16 +0300 Subject: [PATCH 3/3] [SSE] Refactoring in PivotTable --- .../main/app/controller/PivotTable.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/spreadsheeteditor/main/app/controller/PivotTable.js b/apps/spreadsheeteditor/main/app/controller/PivotTable.js index 74d80ae809..f1ce0b92c6 100644 --- a/apps/spreadsheeteditor/main/app/controller/PivotTable.js +++ b/apps/spreadsheeteditor/main/app/controller/PivotTable.js @@ -378,11 +378,11 @@ define([ styles.menuPicker.store.reset([]); var templates = []; var groups = [ - {id: 'menu-table-group-custom', caption: self.view.__proto__.txtGroupPivot_Custom, templates: []}, - {id: 'menu-table-group-light', caption: self.view.__proto__.txtGroupPivot_Light, templates: []}, - {id: 'menu-table-group-medium', caption: self.view.__proto__.txtGroupPivot_Medium, templates: []}, - {id: 'menu-table-group-dark', caption: self.view.__proto__.txtGroupPivot_Dark, templates: []}, - {id: 'menu-table-group-no-name', caption: ' ', templates: []}, + {id: 'menu-table-group-custom', caption: self.view.txtGroupPivot_Custom, templates: []}, + {id: 'menu-table-group-light', caption: self.view.txtGroupPivot_Light, templates: []}, + {id: 'menu-table-group-medium', caption: self.view.txtGroupPivot_Medium, templates: []}, + {id: 'menu-table-group-dark', caption: self.view.txtGroupPivot_Dark, templates: []}, + {id: 'menu-table-group-no-name', caption: ' ', templates: []}, ]; _.each(Templates, function(template, index){ var tip = template.asc_getDisplayName(), @@ -405,7 +405,7 @@ define([ } } arr = 'txtTable_' + arr.join(''); - tip = self.view.__proto__[arr] ? self.view.__proto__[arr] + ' ' + lastWordInTip : tip; + tip = self.view[arr] ? self.view[arr] + ' ' + lastWordInTip : tip; lastWordInTip = parseInt(lastWordInTip); } else {