[SSE] Formula dialog: add 10 last used functions. Refactoring.

This commit is contained in:
Julia Radzhabova 2019-05-27 16:19:48 +03:00
parent 2e16e770e8
commit 1acd9be0d8
3 changed files with 78 additions and 23 deletions

View file

@ -82,6 +82,8 @@ define([
this.api = api; this.api = api;
if (this.formulasGroups && this.api) { if (this.formulasGroups && this.api) {
Common.Utils.InternalSettings.set("sse-settings-func-last", Common.localStorage.getItem("sse-settings-func-last"));
this.reloadTranslations( this.reloadTranslations(
Common.localStorage.getItem("sse-settings-func-locale") || this.appOptions.lang ); Common.localStorage.getItem("sse-settings-func-locale") || this.appOptions.lang );
@ -93,7 +95,8 @@ define([
formulasGroups : this.formulasGroups, formulasGroups : this.formulasGroups,
handler : function (func) { handler : function (func) {
if (func) { if (func) {
me.api.asc_insertFormula(func, Asc.c_oAscPopUpSelectorType.Func); me.api.asc_insertFormula(func.name, Asc.c_oAscPopUpSelectorType.Func);
me.updateLast10Formulas(func.origin);
} }
} }
}); });
@ -180,7 +183,6 @@ define([
if (this.formulas.$window) { if (this.formulas.$window) {
this.formulas.fillFormulasGroups(); this.formulas.fillFormulasGroups();
this.formulas.fillFunctions('All');
} }
} }
this.formulas.show(); this.formulas.show();
@ -192,6 +194,40 @@ define([
} }
}, },
updateLast10Formulas: function(formula) {
var arr = Common.Utils.InternalSettings.get("sse-settings-func-last") || 'SUM;AVERAGE;IF;HYPERLINK;COUNT;MAX;SIN;SUMIF;PMT;STDEV';
arr = arr.split(';');
var idx = _.indexOf(arr, formula);
arr.splice((idx<0) ? arr.length-1 : idx, 1);
arr.unshift(formula);
var val = arr.join(';');
Common.localStorage.setItem("sse-settings-func-last", val);
Common.Utils.InternalSettings.set("sse-settings-func-last", val);
if (this.formulasGroups) {
var group = this.formulasGroups.findWhere({name : 'Last10'});
group && group.set('functions', this.loadingLast10Formulas(this.getDescription(Common.Utils.InternalSettings.get("sse-settings-func-locale"))));
}
},
loadingLast10Formulas: function(descrarr) {
var arr = (Common.Utils.InternalSettings.get("sse-settings-func-last") || 'SUM;AVERAGE;IF;HYPERLINK;COUNT;MAX;SIN;SUMIF;PMT;STDEV').split(';'),
separator = this.api.asc_getFunctionArgumentSeparator(),
functions = [];
for (var j = 0; j < arr.length; j++) {
var funcname = arr[j];
functions.push(new SSE.Models.FormulaModel({
index : j,
group : 'Last10',
name : this.api.asc_getFormulaLocaleName(funcname),
origin: funcname,
args : ((descrarr && descrarr[funcname]) ? descrarr[funcname].a : '').replace(/[,;]/g, separator),
desc : (descrarr && descrarr[funcname]) ? descrarr[funcname].d : ''
}));
}
return functions;
},
loadingFormulas: function (descrarr) { loadingFormulas: function (descrarr) {
var i = 0, j = 0, var i = 0, j = 0,
ascGroupName, ascGroupName,
@ -204,20 +240,33 @@ define([
info = null, info = null,
allFunctions = [], allFunctions = [],
allFunctionsGroup = null, allFunctionsGroup = null,
last10FunctionsGroup = null,
separator = this.api.asc_getFunctionArgumentSeparator(); separator = this.api.asc_getFunctionArgumentSeparator();
if (store) { if (store) {
ascGroupName = 'Last10';
last10FunctionsGroup = new SSE.Models.FormulaGroup ({
name : ascGroupName,
index : index,
store : store
});
if (last10FunctionsGroup) {
last10FunctionsGroup.set('functions', this.loadingLast10Formulas(descrarr));
store.push(last10FunctionsGroup);
index += 1;
}
allFunctionsGroup = new SSE.Models.FormulaGroup ({ allFunctionsGroup = new SSE.Models.FormulaGroup ({
name : 'All', name : 'All',
index : index, index : index,
store : store store : store
}); });
if (allFunctionsGroup) {
store.push(allFunctionsGroup);
index += 1;
}
if (allFunctionsGroup) { if (allFunctionsGroup) {
index += 1;
store.push(allFunctionsGroup);
info = this.api.asc_getFormulasInfo(); info = this.api.asc_getFormulasInfo();
for (i = 0; i < info.length; i += 1) { for (i = 0; i < info.length; i += 1) {
@ -240,6 +289,7 @@ define([
index : funcInd, index : funcInd,
group : ascGroupName, group : ascGroupName,
name : ascFunctions[j].asc_getLocaleName(), name : ascFunctions[j].asc_getLocaleName(),
origin: funcname,
args : ((descrarr && descrarr[funcname]) ? descrarr[funcname].a : '').replace(/[,;]/g, separator), args : ((descrarr && descrarr[funcname]) ? descrarr[funcname].a : '').replace(/[,;]/g, separator),
desc : (descrarr && descrarr[funcname]) ? descrarr[funcname].d : '' desc : (descrarr && descrarr[funcname]) ? descrarr[funcname].d : ''
}); });

View file

@ -54,6 +54,7 @@ define([
index : 0, index : 0,
group : null, group : null,
name : null, name : null,
origin : null,
args : null args : null
} }
} }

View file

@ -107,7 +107,7 @@ define([
var name = '', translate = '', var name = '', translate = '',
descriptions = ['All', 'Cube', 'Database', 'DateAndTime', 'Engineering', 'Financial', 'Information', descriptions = ['All', 'Cube', 'Database', 'DateAndTime', 'Engineering', 'Financial', 'Information',
'Logical', 'LookupAndReference', 'Mathematic', 'Statistical', 'TextAndData' ]; 'Logical', 'LookupAndReference', 'Mathematic', 'Statistical', 'TextAndData', 'Last10' ];
for (var i=0; i<descriptions.length; i++) { for (var i=0; i<descriptions.length; i++) {
name = descriptions[i]; name = descriptions[i];
translate = 'sCategory' + name; translate = 'sCategory' + name;
@ -122,7 +122,6 @@ define([
} }
this.fillFormulasGroups(); this.fillFormulasGroups();
this.fillFunctions('All');
}, },
show: function () { show: function () {
if (this.$window) { if (this.$window) {
@ -149,6 +148,9 @@ define([
this.mask.on('mousedown',_.bind(this.onUpdateFocus, this)); this.mask.on('mousedown',_.bind(this.onUpdateFocus, this));
this.$window.on('mousedown',_.bind(this.onUpdateFocus, this)); this.$window.on('mousedown',_.bind(this.onUpdateFocus, this));
if (this.cmbFuncGroup.getValue() == 0)
this.fillFunctions('Last10');
if (this.cmbListFunctions) { if (this.cmbListFunctions) {
_.delay(function (me) { _.delay(function (me) {
me.cmbListFunctions.$el.find('.listview').focus(); me.cmbListFunctions.$el.find('.listview').focus();
@ -197,18 +199,9 @@ define([
var funcId, functions, func; var funcId, functions, func;
if (this.formulasGroups) { if (this.formulasGroups) {
funcId = record.get('id'); this.applyFunction = {name: record.get('value'), origin: record.get('origin')};
if (!_.isUndefined(funcId)) { this.syntaxLabel.text(this.applyFunction.name + record.get('args'));
functions = this.formulasGroups.at(0).get('functions'); this.descLabel.text(record.get('desc'));
if (functions) {
func = _.find(functions, function (f) { if (f.get('index') === funcId) { return f; } return null; });
if (func) {
this.applyFunction = func.get('name');
this.syntaxLabel.text(this.applyFunction + func.get('args'));
this.descLabel.text(func.get('desc'));
}
}
}
} }
}, },
onPrimary: function(list, record, event) { onPrimary: function(list, record, event) {
@ -258,6 +251,8 @@ define([
this.cmbFuncGroup.setData(groupsListItems); this.cmbFuncGroup.setData(groupsListItems);
} }
this.cmbFuncGroup.setValue(0); this.cmbFuncGroup.setValue(0);
this.fillFunctions('Last10');
} }
}, },
fillFunctions: function (name) { fillFunctions: function (name) {
@ -297,13 +292,16 @@ define([
id : functions[i].get('index'), id : functions[i].get('index'),
selected : i < 1, selected : i < 1,
allowSelected : true, allowSelected : true,
value : functions[i].get('name') value : functions[i].get('name'),
args : functions[i].get('args'),
desc : functions[i].get('desc'),
origin : functions[i].get('origin')
})); }));
} }
this.applyFunction = functions[0].get('name'); this.applyFunction = {name: functions[0].get('name'), origin: functions[0].get('origin')};
this.syntaxLabel.text(this.applyFunction + functions[0].get('args')); this.syntaxLabel.text(this.applyFunction.name + functions[0].get('args'));
this.descLabel.text(functions[0].get('desc')); this.descLabel.text(functions[0].get('desc'));
this.cmbListFunctions.scroller.update({ this.cmbListFunctions.scroller.update({
minScrollbarLength : 40, minScrollbarLength : 40,
@ -401,6 +399,7 @@ define([
cancelButtonText: 'Cancel', cancelButtonText: 'Cancel',
okButtonText: 'Ok', okButtonText: 'Ok',
sCategoryAll: 'All', sCategoryAll: 'All',
sCategoryLast10: '10 last used',
sCategoryLogical: 'Logical', sCategoryLogical: 'Logical',
sCategoryCube: 'Cube', sCategoryCube: 'Cube',
sCategoryDatabase: 'Database', sCategoryDatabase: 'Database',
@ -416,6 +415,7 @@ define([
textListDescription: 'Select Function', textListDescription: 'Select Function',
sDescription: 'Description', sDescription: 'Description',
sCategoryAll_de: 'Alle', sCategoryAll_de: 'Alle',
sCategoryLast10_de: '10 zuletzt verwendete',
sCategoryCube_de: 'Cube', sCategoryCube_de: 'Cube',
sCategoryDatabase_de: 'Datenbank', sCategoryDatabase_de: 'Datenbank',
sCategoryDateAndTime_de: 'Datum und Uhrzeit', sCategoryDateAndTime_de: 'Datum und Uhrzeit',
@ -428,6 +428,7 @@ define([
sCategoryStatistical_de: 'Statistik', sCategoryStatistical_de: 'Statistik',
sCategoryTextAndData_de: 'Text und Daten', sCategoryTextAndData_de: 'Text und Daten',
sCategoryAll_ru: 'Все', sCategoryAll_ru: 'Все',
sCategoryLast10_ru: '10 недавно использовавшихся',
sCategoryCube_ru: 'Кубические', sCategoryCube_ru: 'Кубические',
sCategoryDatabase_ru: 'Базы данных', sCategoryDatabase_ru: 'Базы данных',
sCategoryDateAndTime_ru: 'Дата и время', sCategoryDateAndTime_ru: 'Дата и время',
@ -441,6 +442,7 @@ define([
sCategoryTextAndData_ru: 'Текст и данные', sCategoryTextAndData_ru: 'Текст и данные',
txtTitle: 'Insert Function', txtTitle: 'Insert Function',
sCategoryAll_es: 'Todo', sCategoryAll_es: 'Todo',
sCategoryLast10_es: '10 últimas utilizadas',
sCategoryLogical_es: 'Lógico', sCategoryLogical_es: 'Lógico',
sCategoryCube_es: 'Cubo', sCategoryCube_es: 'Cubo',
sCategoryDatabase_es: 'Base de Datos', sCategoryDatabase_es: 'Base de Datos',
@ -453,6 +455,7 @@ define([
sCategoryStatistical_es: 'Estadístico', sCategoryStatistical_es: 'Estadístico',
sCategoryTextAndData_es: 'Texto y datos', sCategoryTextAndData_es: 'Texto y datos',
sCategoryAll_fr: 'Tout', sCategoryAll_fr: 'Tout',
sCategoryLast10_fr: '10 dernières utilisées',
sCategoryLogical_fr: 'Logique', sCategoryLogical_fr: 'Logique',
sCategoryCube_fr: 'Cube', sCategoryCube_fr: 'Cube',
sCategoryDatabase_fr: 'Base de données', sCategoryDatabase_fr: 'Base de données',
@ -465,6 +468,7 @@ define([
sCategoryStatistical_fr: 'Statistiques', sCategoryStatistical_fr: 'Statistiques',
sCategoryTextAndData_fr: 'Texte et données', sCategoryTextAndData_fr: 'Texte et données',
sCategoryAll_pl: 'Wszystko', sCategoryAll_pl: 'Wszystko',
sCategoryLast10_pl: '10 ostatnio używanych',
sCategoryLogical_pl: 'Logiczny', sCategoryLogical_pl: 'Logiczny',
sCategoryCube_pl: 'Sześcian', sCategoryCube_pl: 'Sześcian',
sCategoryDatabase_pl: 'Baza danych', sCategoryDatabase_pl: 'Baza danych',