[PE][SSE] Optimize equation loading

This commit is contained in:
Julia Radzhabova 2019-08-15 17:09:26 +03:00
parent 781950c412
commit 35e00505b4
2 changed files with 114 additions and 146 deletions

View file

@ -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,55 +1716,19 @@ 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 equationGroup = equationsStore.at(i);
var menuItem = new Common.UI.MenuItem({
caption: equationGroup.get('groupName'),
menu: new Common.UI.Menu({
menuAlign: 'tl-tr',
items: [
{ template: _.template('<div id="id-toolbar-menu-equationgroup' + i +
'" class="menu-shape" style="width:' + (equationGroup.get('groupWidth') + 8) + 'px; ' +
equationGroup.get('groupHeight') + 'margin-left:5px;"></div>') }
]
})
});
me.toolbar.btnInsertEquation.menu.addItem(menuItem);
var equationPicker = new Common.UI.DataView({
var equationPicker = new Common.UI.DataViewSimple({
el: $('#id-toolbar-menu-equationgroup' + i),
store: equationGroup.get('groupStore'),
parentMenu: menuItem.menu,
showLast: false,
parentMenu: menu.items[i].menu,
store: equationsStore.at(i).get('groupStore'),
scrollAlwaysVisible: true,
itemTemplate: _.template('<div class="item-equation" '+
'style="background-position:<%= posX %>px <%= posY %>px;" >' +
'<div style="width:<%= width %>px;height:<%= height %>px;" id="<%= id %>">')
'<div style="width:<%= width %>px;height:<%= height %>px;" id="<%= id %>"></div>' +
'</div>')
});
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)
@ -1784,6 +1748,25 @@ define([
}
});
}
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({
menuAlign: 'tl-tr',
items: [
{ template: _.template('<div id="id-toolbar-menu-equationgroup' + i +
'" class="menu-shape" style="width:' + (equationGroup.get('groupWidth') + 8) + 'px; ' +
equationGroup.get('groupHeight') + 'margin-left:5px;"></div>') }
]
})
});
me.toolbar.btnInsertEquation.menu.addItem(menuItem);
}
},
onInsertEquationClick: function() {
@ -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();
}
}

View file

@ -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,55 +2632,19 @@ 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 equationGroup = equationsStore.at(i);
var menuItem = new Common.UI.MenuItem({
caption: equationGroup.get('groupName'),
menu: new Common.UI.Menu({
menuAlign: 'tl-tr',
items: [
{ template: _.template('<div id="id-toolbar-menu-equationgroup' + i +
'" class="menu-shape" style="width:' + (equationGroup.get('groupWidth') + 8) + 'px; ' +
equationGroup.get('groupHeight') + 'margin-left:5px;"></div>') }
]
})
});
me.toolbar.btnInsertEquation.menu.addItem(menuItem);
var equationPicker = new Common.UI.DataView({
var equationPicker = new Common.UI.DataViewSimple({
el: $('#id-toolbar-menu-equationgroup' + i),
store: equationGroup.get('groupStore'),
parentMenu: menuItem.menu,
showLast: false,
parentMenu: menu.items[i].menu,
store: equationsStore.at(i).get('groupStore'),
scrollAlwaysVisible: true,
itemTemplate: _.template('<div class="item-equation" '+
'style="background-position:<%= posX %>px <%= posY %>px;" >' +
'<div style="width:<%= width %>px;height:<%= height %>px;" id="<%= id %>">')
'<div style="width:<%= width %>px;height:<%= height %>px;" id="<%= id %>"></div>' +
'</div>')
});
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)
@ -2700,6 +2664,25 @@ define([
}
});
}
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({
menuAlign: 'tl-tr',
items: [
{ template: _.template('<div id="id-toolbar-menu-equationgroup' + i +
'" class="menu-shape" style="width:' + (equationGroup.get('groupWidth') + 8) + 'px; ' +
equationGroup.get('groupHeight') + 'margin-left:5px;"></div>') }
]
})
});
me.toolbar.btnInsertEquation.menu.addItem(menuItem);
}
},
onInsertEquationClick: function() {
@ -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();
}
}