From 35e00505b4db06101d8f403298181d5ed049216e Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Thu, 15 Aug 2019 17:09:26 +0300 Subject: [PATCH] [PE][SSE] Optimize equation loading --- .../main/app/controller/Toolbar.js | 130 ++++++++---------- .../main/app/controller/Toolbar.js | 130 ++++++++---------- 2 files changed, 114 insertions(+), 146 deletions(-) diff --git a/apps/presentationeditor/main/app/controller/Toolbar.js b/apps/presentationeditor/main/app/controller/Toolbar.js index 953e05705..8abd184b4 100644 --- a/apps/presentationeditor/main/app/controller/Toolbar.js +++ b/apps/presentationeditor/main/app/controller/Toolbar.js @@ -360,7 +360,7 @@ define([ this.api.asc_registerCallback('asc_onInitEditorStyles', _.bind(this.onApiInitEditorStyles, this)); this.api.asc_registerCallback('asc_onCountPages', _.bind(this.onApiCountPages, this)); - this.api.asc_registerCallback('asc_onMathTypes', _.bind(this.onMathTypes, this)); + this.api.asc_registerCallback('asc_onMathTypes', _.bind(this.onApiMathTypes, this)); this.api.asc_registerCallback('asc_onContextMenu', _.bind(this.onContextMenu, this)); this.api.asc_registerCallback('asc_onTextLanguage', _.bind(this.onTextLanguage, this)); }, @@ -1716,12 +1716,44 @@ define([ var me = this, equationsStore = this.getApplication().getCollection('EquationGroups'); - me.equationPickers = []; me.toolbar.btnInsertEquation.menu.removeAll(); + var onShowAfter = function(menu) { + for (var i = 0; i < equationsStore.length; ++i) { + var equationPicker = new Common.UI.DataViewSimple({ + el: $('#id-toolbar-menu-equationgroup' + i), + parentMenu: menu.items[i].menu, + store: equationsStore.at(i).get('groupStore'), + scrollAlwaysVisible: true, + itemTemplate: _.template('
' + + '
' + + '
') + }); + equationPicker.on('item:click', function(picker, item, record, e) { + if (me.api) { + if (record) + me.api.asc_AddMath(record.get('data').equationType); + + if (me.toolbar.btnsInsertText.pressed()) { + me.toolbar.btnsInsertText.toggle(false, true); + } + if (me.toolbar.btnsInsertShape.pressed()) { + me.toolbar.btnsInsertShape.toggle(false, true); + } + + if (e.type !== 'click') + me.toolbar.btnInsertEquation.menu.hide(); + Common.NotificationCenter.trigger('edit:complete', me.toolbar, me.toolbar.btnInsertEquation); + Common.component.Analytics.trackEvent('ToolBar', 'Add Equation'); + } + }); + } + me.toolbar.btnInsertEquation.menu.off('show:after', onShowAfter); + }; + me.toolbar.btnInsertEquation.menu.on('show:after', onShowAfter); for (var i = 0; i < equationsStore.length; ++i) { var equationGroup = equationsStore.at(i); - var menuItem = new Common.UI.MenuItem({ caption: equationGroup.get('groupName'), menu: new Common.UI.Menu({ @@ -1733,56 +1765,7 @@ define([ ] }) }); - me.toolbar.btnInsertEquation.menu.addItem(menuItem); - - var equationPicker = new Common.UI.DataView({ - el: $('#id-toolbar-menu-equationgroup' + i), - store: equationGroup.get('groupStore'), - parentMenu: menuItem.menu, - showLast: false, - itemTemplate: _.template('
' + - '
') - }); - if (equationGroup.get('groupHeight').length) { - - me.equationPickers.push(equationPicker); - me.toolbar.btnInsertEquation.menu.on('show:after', function () { - - if (me.equationPickers.length) { - var element = $(this.el).find('.over').find('.menu-shape'); - if (element.length) { - for (var i = 0; i < me.equationPickers.length; ++i) { - if (element[0].id == me.equationPickers[i].el.id) { - me.equationPickers[i].scroller.update({alwaysVisibleY: true}); - me.equationPickers.splice(i, 1); - return; - } - } - } - } - }); - } - - equationPicker.on('item:click', function(picker, item, record, e) { - if (me.api) { - if (record) - me.api.asc_AddMath(record.get('data').equationType); - - if (me.toolbar.btnsInsertText.pressed()) { - me.toolbar.btnsInsertText.toggle(false, true); - } - if (me.toolbar.btnsInsertShape.pressed()) { - me.toolbar.btnsInsertShape.toggle(false, true); - } - - if (e.type !== 'click') - me.toolbar.btnInsertEquation.menu.hide(); - Common.NotificationCenter.trigger('edit:complete', me.toolbar, me.toolbar.btnInsertEquation); - Common.component.Analytics.trackEvent('ToolBar', 'Add Equation'); - } - }); } }, @@ -1794,6 +1777,16 @@ define([ Common.NotificationCenter.trigger('edit:complete', this.toolbar, this.toolbar.btnInsertEquation); }, + onApiMathTypes: function(equation) { + this._equationTemp = equation; + var me = this; + var onShowBefore = function(menu) { + me.onMathTypes(me._equationTemp); + me.toolbar.btnInsertEquation.menu.off('show:before', onShowBefore); + }; + me.toolbar.btnInsertEquation.menu.on('show:before', onShowBefore); + }, + onMathTypes: function(equation) { var equationgrouparray = [], equationsStore = this.getCollection('EquationGroups'); @@ -1834,35 +1827,29 @@ define([ translationTable[Common.define.c_oAscMathType[name]] = this[translate]; } } - - var i,id = 0, count = 0, length = 0, width = 0, height = 0, store = null, list = null, eqStore = null, eq = null; + var i,id = 0, count = 0, length = 0, width = 0, height = 0, store = null, list = null, eqStore = null, eq = null, data; if (equation) { - - count = equation.get_Data().length; - + data = equation.get_Data(); + count = data.length; if (count) { for (var j = 0; j < count; ++j) { - id = equation.get_Data()[j].get_Id(); - width = equation.get_Data()[j].get_W(); - height = equation.get_Data()[j].get_H(); + var group = data[j]; + id = group.get_Id(); + width = group.get_W(); + height = group.get_H(); store = new Backbone.Collection([], { model: PE.Models.EquationModel }); if (store) { - - var allItemsCount = 0, itemsCount = 0, ids = 0; - - length = equation.get_Data()[j].get_Data().length; - + var allItemsCount = 0, itemsCount = 0, ids = 0, arr = []; + length = group.get_Data().length; for (i = 0; i < length; ++i) { - eqStore = equation.get_Data()[j].get_Data()[i]; - + eqStore = group.get_Data()[i]; itemsCount = eqStore.get_Data().length; for (var p = 0; p < itemsCount; ++p) { - eq = eqStore.get_Data()[p]; ids = eq.get_Id(); @@ -1871,8 +1858,7 @@ define([ if (translationTable.hasOwnProperty(ids)) { translate = translationTable[ids]; } - - store.add({ + arr.push({ data : {equationType: ids}, tip : translate, allowSelected : true, @@ -1886,7 +1872,7 @@ define([ allItemsCount += itemsCount; } - + store.add(arr); width = c_oAscMathMainTypeStrings[id][1] * (width + 10); // 4px margin + 4px margin + 1px border + 1px border var normHeight = parseInt(370 / (height + 10)) * (height + 10); @@ -1898,9 +1884,7 @@ define([ }); } } - equationsStore.add(equationgrouparray); - this.fillEquations(); } } diff --git a/apps/spreadsheeteditor/main/app/controller/Toolbar.js b/apps/spreadsheeteditor/main/app/controller/Toolbar.js index 1c1aedbe2..8e333b7ac 100644 --- a/apps/spreadsheeteditor/main/app/controller/Toolbar.js +++ b/apps/spreadsheeteditor/main/app/controller/Toolbar.js @@ -376,7 +376,7 @@ define([ var config = SSE.getController('Main').appOptions; if ( !config.isEditDiagram && !config.isEditMailMerge ) { this.api.asc_registerCallback('asc_onSendThemeColors', _.bind(this.onSendThemeColors, this)); - this.api.asc_registerCallback('asc_onMathTypes', _.bind(this.onMathTypes, this)); + this.api.asc_registerCallback('asc_onMathTypes', _.bind(this.onApiMathTypes, this)); this.api.asc_registerCallback('asc_onContextMenu', _.bind(this.onContextMenu, this)); } @@ -2632,12 +2632,44 @@ define([ var me = this, equationsStore = this.getApplication().getCollection('EquationGroups'); - me.equationPickers = []; me.toolbar.btnInsertEquation.menu.removeAll(); + var onShowAfter = function(menu) { + for (var i = 0; i < equationsStore.length; ++i) { + var equationPicker = new Common.UI.DataViewSimple({ + el: $('#id-toolbar-menu-equationgroup' + i), + parentMenu: menu.items[i].menu, + store: equationsStore.at(i).get('groupStore'), + scrollAlwaysVisible: true, + itemTemplate: _.template('
' + + '
' + + '
') + }); + equationPicker.on('item:click', function(picker, item, record, e) { + if (me.api) { + if (record) + me.api.asc_AddMath(record.get('data').equationType); + + if (me.toolbar.btnInsertText.pressed) { + me.toolbar.btnInsertText.toggle(false, true); + } + if (me.toolbar.btnInsertShape.pressed) { + me.toolbar.btnInsertShape.toggle(false, true); + } + + if (e.type !== 'click') + me.toolbar.btnInsertEquation.menu.hide(); + Common.NotificationCenter.trigger('edit:complete', me.toolbar, me.toolbar.btnInsertEquation); + Common.component.Analytics.trackEvent('ToolBar', 'Add Equation'); + } + }); + } + me.toolbar.btnInsertEquation.menu.off('show:after', onShowAfter); + }; + me.toolbar.btnInsertEquation.menu.on('show:after', onShowAfter); for (var i = 0; i < equationsStore.length; ++i) { var equationGroup = equationsStore.at(i); - var menuItem = new Common.UI.MenuItem({ caption: equationGroup.get('groupName'), menu: new Common.UI.Menu({ @@ -2649,56 +2681,7 @@ define([ ] }) }); - me.toolbar.btnInsertEquation.menu.addItem(menuItem); - - var equationPicker = new Common.UI.DataView({ - el: $('#id-toolbar-menu-equationgroup' + i), - store: equationGroup.get('groupStore'), - parentMenu: menuItem.menu, - showLast: false, - itemTemplate: _.template('
' + - '
') - }); - if (equationGroup.get('groupHeight').length) { - - me.equationPickers.push(equationPicker); - me.toolbar.btnInsertEquation.menu.on('show:after', function () { - - if (me.equationPickers.length) { - var element = $(this.el).find('.over').find('.menu-shape'); - if (element.length) { - for (var i = 0; i < me.equationPickers.length; ++i) { - if (element[0].id == me.equationPickers[i].el.id) { - me.equationPickers[i].scroller.update({alwaysVisibleY: true}); - me.equationPickers.splice(i, 1); - return; - } - } - } - } - }); - } - - equationPicker.on('item:click', function(picker, item, record, e) { - if (me.api) { - if (record) - me.api.asc_AddMath(record.get('data').equationType); - - if (me.toolbar.btnInsertText.pressed) { - me.toolbar.btnInsertText.toggle(false, true); - } - if (me.toolbar.btnInsertShape.pressed) { - me.toolbar.btnInsertShape.toggle(false, true); - } - - if (e.type !== 'click') - me.toolbar.btnInsertEquation.menu.hide(); - Common.NotificationCenter.trigger('edit:complete', me.toolbar, me.toolbar.btnInsertEquation); - Common.component.Analytics.trackEvent('ToolBar', 'Add Equation'); - } - }); } }, @@ -2710,6 +2693,16 @@ define([ Common.NotificationCenter.trigger('edit:complete', this.toolbar, this.toolbar.btnInsertEquation); }, + onApiMathTypes: function(equation) { + this._equationTemp = equation; + var me = this; + var onShowBefore = function(menu) { + me.onMathTypes(me._equationTemp); + me.toolbar.btnInsertEquation.menu.off('show:before', onShowBefore); + }; + me.toolbar.btnInsertEquation.menu.on('show:before', onShowBefore); + }, + onMathTypes: function(equation) { var equationgrouparray = [], equationsStore = this.getCollection('EquationGroups'); @@ -2750,35 +2743,29 @@ define([ translationTable[Common.define.c_oAscMathType[name]] = this[translate]; } } - - var i,id = 0, count = 0, length = 0, width = 0, height = 0, store = null, list = null, eqStore = null, eq = null; + var i,id = 0, count = 0, length = 0, width = 0, height = 0, store = null, list = null, eqStore = null, eq = null, data; if (equation) { - - count = equation.get_Data().length; - + data = equation.get_Data(); + count = data.length; if (count) { for (var j = 0; j < count; ++j) { - id = equation.get_Data()[j].get_Id(); - width = equation.get_Data()[j].get_W(); - height = equation.get_Data()[j].get_H(); + var group = data[j]; + id = group.get_Id(); + width = group.get_W(); + height = group.get_H(); store = new Backbone.Collection([], { model: SSE.Models.EquationModel }); if (store) { - - var allItemsCount = 0, itemsCount = 0, ids = 0; - - length = equation.get_Data()[j].get_Data().length; - + var allItemsCount = 0, itemsCount = 0, ids = 0, arr = []; + length = group.get_Data().length; for (i = 0; i < length; ++i) { - eqStore = equation.get_Data()[j].get_Data()[i]; - + eqStore = group.get_Data()[i]; itemsCount = eqStore.get_Data().length; for (var p = 0; p < itemsCount; ++p) { - eq = eqStore.get_Data()[p]; ids = eq.get_Id(); @@ -2787,8 +2774,7 @@ define([ if (translationTable.hasOwnProperty(ids)) { translate = translationTable[ids]; } - - store.add({ + arr.push({ data : {equationType: ids}, tip : translate, allowSelected : true, @@ -2802,7 +2788,7 @@ define([ allItemsCount += itemsCount; } - + store.add(arr); width = c_oAscMathMainTypeStrings[id][1] * (width + 10); // 4px margin + 4px margin + 1px border + 1px border var normHeight = parseInt(370 / (height + 10)) * (height + 10); @@ -2814,9 +2800,7 @@ define([ }); } } - equationsStore.add(equationgrouparray); - this.fillEquations(); } }