From 0fa44aa21db1655473624ddbfcc637b14b4b2273 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Tue, 22 Jan 2019 11:29:24 +0300 Subject: [PATCH 1/6] [DE] Add formula to table cell --- .../main/app/template/TableSettings.template | 10 + .../main/app/view/TableFormulaDialog.js | 227 ++++++++++++++++++ .../main/app/view/TableSettings.js | 31 ++- apps/documenteditor/main/locale/en.json | 8 + 4 files changed, 274 insertions(+), 2 deletions(-) create mode 100644 apps/documenteditor/main/app/view/TableFormulaDialog.js diff --git a/apps/documenteditor/main/app/template/TableSettings.template b/apps/documenteditor/main/app/template/TableSettings.template index 19e649186..c840cf208 100644 --- a/apps/documenteditor/main/app/template/TableSettings.template +++ b/apps/documenteditor/main/app/template/TableSettings.template @@ -137,6 +137,16 @@
+ + + + + + + +
+ +
diff --git a/apps/documenteditor/main/app/view/TableFormulaDialog.js b/apps/documenteditor/main/app/view/TableFormulaDialog.js new file mode 100644 index 000000000..d1d9e06db --- /dev/null +++ b/apps/documenteditor/main/app/view/TableFormulaDialog.js @@ -0,0 +1,227 @@ +/* + * + * (c) Copyright Ascensio System SIA 2010-2019 + * + * 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 + * + */ +/** + * TableFormulaDialog.js + * + * Created by Julia Radzhabova on 1/21/19 + * Copyright (c) 2019 Ascensio System SIA. All rights reserved. + * + */ + +define([ + 'common/main/lib/component/InputField', + 'common/main/lib/component/Window' +], function () { 'use strict'; + + DE.Views.TableFormulaDialog = Common.UI.Window.extend(_.extend({ + options: { + width: 300, + style: 'min-width: 230px;', + cls: 'modal-dlg' + }, + + initialize : function(options) { + _.extend(this.options, { + title: this.textTitle + }, options || {}); + + this.template = [ + '
', + '
', + '', + '
', + '
', + '
', + '', + '
', + '
', + '
', + '
', + '
', + '
', + '
', + '' + ].join(''); + + this.options.tpl = _.template(this.template)(this.options); + this.bookmarks = this.options.bookmarks; + + Common.UI.Window.prototype.initialize.call(this, this.options); + }, + + render: function() { + Common.UI.Window.prototype.render.call(this); + + var me = this, + $window = this.getChild(); + + this.inputFormula = new Common.UI.InputField({ + el : $('#id-dlg-formula-formula'), + allowBlank : true, + validateOnChange: true, + style : 'width: 100%;' + }).on('changing', _.bind(this.checkFormulaInput, this)); + + this.cmbFormat = new Common.UI.ComboBox({ + el : $('#id-dlg-formula-format'), + cls : 'input-group-nr', + menuStyle : 'min-width: 100%; max-heigh: 200px;' + }); + + this.cmbFunction = new Common.UI.ComboBox({ + el : $('#id-dlg-formula-function'), + cls : 'input-group-nr', + menuStyle : 'min-width: 100%; max-heigh: 100px;', + editable : false, + data: [ + {displayValue: 'ABS', value: 1}, + {displayValue: 'AND', value: 1}, + {displayValue: 'AVERAGE', value: 1}, + {displayValue: 'SUM', value: 0} + ] + }); + this.cmbFunction.on('selected', _.bind(function(combo, record) { + combo.setValue(this.textInsertFunction); + var _input = me.inputFormula._input, + end = _input[0].selectionEnd; + _input.val(_input.val().substring(0, end) + record.displayValue + '()' + _input.val().substring(end)); + _input.focus(); + _input[0].selectionStart = _input[0].selectionEnd = end + record.displayValue.length+1; + this.btnOk.setDisabled(false); + }, this)); + this.cmbFunction.setValue(this.textInsertFunction); + + this.cmbBookmark = new Common.UI.ComboBox({ + el : $('#id-dlg-formula-bookmark'), + cls : 'input-group-nr', + menuStyle : 'min-width: 100%; max-heigh: 100px;', + editable : false + }); + this.cmbBookmark.on('selected', _.bind(function(combo, record) { + combo.setValue(this.textBookmark); + var _input = me.inputFormula._input, + end = _input[0].selectionEnd; + _input.val(_input.val().substring(0, end) + record.displayValue + _input.val().substring(end)); + _input.focus(); + _input[0].selectionStart = _input[0].selectionEnd = end + record.displayValue.length; + this.btnOk.setDisabled(false); + }, this)); + this.cmbBookmark.setValue(this.textBookmark); + + me.btnOk = new Common.UI.Button({ + el: $window.find('.primary') + }); + + $window.find('.dlg-btn').on('click', _.bind(this.onBtnClick, this)); + this.afterRender(); + }, + + onSelectItem: function(picker, item, record, e){ + this.btnOk.setDisabled(record.get('level')==0 && record.get('index')>0); + }, + + show: function() { + Common.UI.Window.prototype.show.apply(this, arguments); + + var me = this; + _.delay(function(){ + me.inputFormula.cmpEl.find('input').focus(); + },500); + }, + + afterRender: function() { + this.refreshBookmarks(); + this._setDefaults(this.props); + }, + + _setDefaults: function (props) { + if (props) { + + } + this.checkFormulaInput(this.inputFormula, this.inputFormula.getValue()); + }, + + refreshBookmarks: function() { + var arr = []; + if (this.bookmarks) { + var count = this.bookmarks.asc_GetCount(); + for (var i=0; i Date: Wed, 27 Feb 2019 13:19:07 +0300 Subject: [PATCH 2/6] [DE] Get/set formula text --- apps/documenteditor/main/app/view/TableFormulaDialog.js | 9 ++++----- apps/documenteditor/main/app/view/TableSettings.js | 3 ++- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/documenteditor/main/app/view/TableFormulaDialog.js b/apps/documenteditor/main/app/view/TableFormulaDialog.js index d1d9e06db..f48cce59f 100644 --- a/apps/documenteditor/main/app/view/TableFormulaDialog.js +++ b/apps/documenteditor/main/app/view/TableFormulaDialog.js @@ -78,6 +78,7 @@ define([ this.options.tpl = _.template(this.template)(this.options); this.bookmarks = this.options.bookmarks; + this.api = this.options.api; Common.UI.Window.prototype.initialize.call(this, this.options); }, @@ -164,13 +165,11 @@ define([ afterRender: function() { this.refreshBookmarks(); - this._setDefaults(this.props); + this._setDefaults(); }, - _setDefaults: function (props) { - if (props) { - - } + _setDefaults: function () { + this.inputFormula.setValue(this.api.asc_GetTableFormula()); this.checkFormulaInput(this.inputFormula, this.inputFormula.getValue()); }, diff --git a/apps/documenteditor/main/app/view/TableSettings.js b/apps/documenteditor/main/app/view/TableSettings.js index 6dd79bc2a..128ccf110 100644 --- a/apps/documenteditor/main/app/view/TableSettings.js +++ b/apps/documenteditor/main/app/view/TableSettings.js @@ -771,11 +771,12 @@ define([ if (me.api && !this._locked){ (new DE.Views.TableFormulaDialog( { + api: me.api, bookmarks: me.api.asc_GetBookmarksManager(), handler: function(result, value) { if (result == 'ok') { if (me.api) { - // me.api.addFormula(value.tableProps); + me.api.asc_AddTableFormula(value); } } me.fireEvent('editcomplete', me); From 7e4f76e41d92f7a554ee9dedced55c2ffd4165d2 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Tue, 5 Mar 2019 13:03:13 +0300 Subject: [PATCH 3/6] [DE] Set formula formats, functions --- .../main/app/view/TableFormulaDialog.js | 39 +++++++++++++++---- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/apps/documenteditor/main/app/view/TableFormulaDialog.js b/apps/documenteditor/main/app/view/TableFormulaDialog.js index f48cce59f..2887511dd 100644 --- a/apps/documenteditor/main/app/view/TableFormulaDialog.js +++ b/apps/documenteditor/main/app/view/TableFormulaDialog.js @@ -99,28 +99,42 @@ define([ this.cmbFormat = new Common.UI.ComboBox({ el : $('#id-dlg-formula-format'), cls : 'input-group-nr', - menuStyle : 'min-width: 100%; max-heigh: 200px;' + menuStyle : 'min-width: 100%; max-height: 200px;' }); this.cmbFunction = new Common.UI.ComboBox({ el : $('#id-dlg-formula-function'), cls : 'input-group-nr', - menuStyle : 'min-width: 100%; max-heigh: 100px;', + menuStyle : 'min-width: 100%; max-height: 150px;', editable : false, + scrollAlwaysVisible: true, data: [ {displayValue: 'ABS', value: 1}, {displayValue: 'AND', value: 1}, {displayValue: 'AVERAGE', value: 1}, - {displayValue: 'SUM', value: 0} + {displayValue: 'COUNT', value: 1}, + {displayValue: 'DEFINED', value: 1}, + {displayValue: 'FALSE', value: 0}, + {displayValue: 'INT', value: 1}, + {displayValue: 'MAX', value: 1}, + {displayValue: 'MIN', value: 1}, + {displayValue: 'MOD', value: 1}, + {displayValue: 'NOT', value: 1}, + {displayValue: 'OR', value: 1}, + {displayValue: 'PRODUCT', value: 1}, + {displayValue: 'ROUND', value: 1}, + {displayValue: 'SIGN', value: 1}, + {displayValue: 'SUM', value: 1}, + {displayValue: 'TRUE', value: 0} ] }); this.cmbFunction.on('selected', _.bind(function(combo, record) { combo.setValue(this.textInsertFunction); var _input = me.inputFormula._input, end = _input[0].selectionEnd; - _input.val(_input.val().substring(0, end) + record.displayValue + '()' + _input.val().substring(end)); + _input.val(_input.val().substring(0, end) + record.displayValue + (record.value ? '()' : '') + _input.val().substring(end)); _input.focus(); - _input[0].selectionStart = _input[0].selectionEnd = end + record.displayValue.length+1; + _input[0].selectionStart = _input[0].selectionEnd = end + record.displayValue.length + record.value; this.btnOk.setDisabled(false); }, this)); this.cmbFunction.setValue(this.textInsertFunction); @@ -128,7 +142,7 @@ define([ this.cmbBookmark = new Common.UI.ComboBox({ el : $('#id-dlg-formula-bookmark'), cls : 'input-group-nr', - menuStyle : 'min-width: 100%; max-heigh: 100px;', + menuStyle : 'min-width: 100%; max-heigh: 150px;', editable : false }); this.cmbBookmark.on('selected', _.bind(function(combo, record) { @@ -169,7 +183,16 @@ define([ }, _setDefaults: function () { - this.inputFormula.setValue(this.api.asc_GetTableFormula()); + var arr = []; + _.each(this.api.asc_GetTableFormulaFormats(), function(item) { + arr.push({value: item, displayValue: item}); + }); + this.cmbFormat.setData(arr); + var formula = this.api.asc_GetTableFormula(), + idx = formula.lastIndexOf('/\#'); + this.inputFormula.setValue(formula.substring(0, (idx>-1) ? idx : formula.length)); + if (idx>-1) + this.cmbFormat.setValue(formula.substring(idx+2, formula.length)); this.checkFormulaInput(this.inputFormula, this.inputFormula.getValue()); }, @@ -195,7 +218,7 @@ define([ }, getSettings: function () { - return this.inputFormula.getValue(); + return (this.inputFormula.getValue() + '/\#' + this.cmbFormat.getValue()); }, onBtnClick: function(event) { From 6da70788daae7c63f686388d93a083458f94147a Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Tue, 5 Mar 2019 14:29:29 +0300 Subject: [PATCH 4/6] [DE] Fix formula string --- apps/documenteditor/main/app/view/TableFormulaDialog.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/documenteditor/main/app/view/TableFormulaDialog.js b/apps/documenteditor/main/app/view/TableFormulaDialog.js index 2887511dd..1cf41da8e 100644 --- a/apps/documenteditor/main/app/view/TableFormulaDialog.js +++ b/apps/documenteditor/main/app/view/TableFormulaDialog.js @@ -189,7 +189,7 @@ define([ }); this.cmbFormat.setData(arr); var formula = this.api.asc_GetTableFormula(), - idx = formula.lastIndexOf('/\#'); + idx = formula.lastIndexOf('\\#'); this.inputFormula.setValue(formula.substring(0, (idx>-1) ? idx : formula.length)); if (idx>-1) this.cmbFormat.setValue(formula.substring(idx+2, formula.length)); @@ -218,7 +218,7 @@ define([ }, getSettings: function () { - return (this.inputFormula.getValue() + '/\#' + this.cmbFormat.getValue()); + return (this.inputFormula.getValue() + '\\#' + this.cmbFormat.getValue()); }, onBtnClick: function(event) { From a957cfcaca8556d140ee73cfed5694a92616eaad Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Tue, 5 Mar 2019 16:28:01 +0300 Subject: [PATCH 5/6] [DE] Fix applying formula --- .../documenteditor/main/app/view/TableFormulaDialog.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/apps/documenteditor/main/app/view/TableFormulaDialog.js b/apps/documenteditor/main/app/view/TableFormulaDialog.js index 1cf41da8e..3fbce2ae2 100644 --- a/apps/documenteditor/main/app/view/TableFormulaDialog.js +++ b/apps/documenteditor/main/app/view/TableFormulaDialog.js @@ -188,11 +188,9 @@ define([ arr.push({value: item, displayValue: item}); }); this.cmbFormat.setData(arr); - var formula = this.api.asc_GetTableFormula(), - idx = formula.lastIndexOf('\\#'); - this.inputFormula.setValue(formula.substring(0, (idx>-1) ? idx : formula.length)); - if (idx>-1) - this.cmbFormat.setValue(formula.substring(idx+2, formula.length)); + var formula = this.api.asc_ParseTableFormulaInstrLine(this.api.asc_GetTableFormula()); + this.inputFormula.setValue(formula[0]); + this.cmbFormat.setValue(formula[1]); this.checkFormulaInput(this.inputFormula, this.inputFormula.getValue()); }, @@ -218,7 +216,7 @@ define([ }, getSettings: function () { - return (this.inputFormula.getValue() + '\\#' + this.cmbFormat.getValue()); + return this.api.asc_CreateInstructionLine(this.inputFormula.getValue(), this.cmbFormat.getValue()); }, onBtnClick: function(event) { From 6eaab69d3c336edc2e6c9eec2aa2f63837fb3526 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Wed, 6 Mar 2019 11:16:21 +0300 Subject: [PATCH 6/6] [DE] Add translation for formula errors --- .../main/app/controller/Main.js | 66 ++++++++++++------- apps/documenteditor/main/locale/en.json | 11 ++++ 2 files changed, 55 insertions(+), 22 deletions(-) diff --git a/apps/documenteditor/main/app/controller/Main.js b/apps/documenteditor/main/app/controller/Main.js index e516475a2..c037839a9 100644 --- a/apps/documenteditor/main/app/controller/Main.js +++ b/apps/documenteditor/main/app/controller/Main.js @@ -130,27 +130,38 @@ define([ var styleNames = ['Normal', 'No Spacing', 'Heading 1', 'Heading 2', 'Heading 3', 'Heading 4', 'Heading 5', 'Heading 6', 'Heading 7', 'Heading 8', 'Heading 9', 'Title', 'Subtitle', 'Quote', 'Intense Quote', 'List Paragraph', 'footnote text'], - translate = { - 'Series': this.txtSeries, - 'Diagram Title': this.txtDiagramTitle, - 'X Axis': this.txtXAxis, - 'Y Axis': this.txtYAxis, - 'Your text here': this.txtArt, - "Error! Bookmark not defined.": this.txtBookmarkError, - "above": this.txtAbove, - "below": this.txtBelow, - "on page ": this.txtOnPage, - "Header": this.txtHeader, - "Footer": this.txtFooter, - " -Section ": this.txtSection, - "First Page ": this.txtFirstPage, - "Even Page ": this.txtEvenPage, - "Odd Page ": this.txtOddPage, - "Same as Previous": this.txtSameAsPrev, - "Current Document": this.txtCurrentDocument, - "No table of contents entries found.": this.txtNoTableOfContents, - "Table of Contents": this.txtTableOfContents - }; + translate = { + 'Series': this.txtSeries, + 'Diagram Title': this.txtDiagramTitle, + 'X Axis': this.txtXAxis, + 'Y Axis': this.txtYAxis, + 'Your text here': this.txtArt, + "Error! Bookmark not defined.": this.txtBookmarkError, + "above": this.txtAbove, + "below": this.txtBelow, + "on page ": this.txtOnPage, + "Header": this.txtHeader, + "Footer": this.txtFooter, + " -Section ": this.txtSection, + "First Page ": this.txtFirstPage, + "Even Page ": this.txtEvenPage, + "Odd Page ": this.txtOddPage, + "Same as Previous": this.txtSameAsPrev, + "Current Document": this.txtCurrentDocument, + "No table of contents entries found.": this.txtNoTableOfContents, + "Table of Contents": this.txtTableOfContents, + "Syntax Error": this.txtSyntaxError, + "Missing Operator": this.txtMissOperator, + "Missing Argument": this.txtMissArg, + "Number Too Large To Format": this.txtTooLarge, + "Zero Divide": this.txtZeroDivide, + "Is Not In Table": this.txtNotInTable, + "Index Too Large": this.txtIndTooLarge, + "The Formula Not In Table": this.txtFormulaNotInTable, + "Table Index Cannot be Zero": this.txtTableInd, + "Undefined Bookmark": this.txtUndefBookmark, + "Unexpected End of Formula": this.txtEndOfFormula + }; styleNames.forEach(function(item){ translate[item] = me.translationTable[item] = me['txtStyle_' + item.replace(/ /g, '_')] || item; }); @@ -2525,7 +2536,18 @@ define([ txtShape_curvedConnector3WithTwoArrows: 'Curved Double-Arrow Connector', txtShape_spline: 'Curve', txtShape_polyline1: 'Scribble', - txtShape_polyline2: 'Freeform' + txtShape_polyline2: 'Freeform', + txtSyntaxError: 'Syntax Error', + txtMissOperator: 'Missing Operator', + txtMissArg: 'Missing Argument', + txtTooLarge: 'Number Too Large To Format', + txtZeroDivide: 'Zero Divide', + txtNotInTable: 'Is Not In Table', + txtIndTooLarge: 'Index Too Large', + txtFormulaNotInTable: 'The Formula Not In Table', + txtTableInd: 'Table Index Cannot be Zero', + txtUndefBookmark: 'Undefined Bookmark', + txtEndOfFormula: 'Unexpected End of Formula' } })(), DE.Controllers.Main || {})) }); \ No newline at end of file diff --git a/apps/documenteditor/main/locale/en.json b/apps/documenteditor/main/locale/en.json index 18e40edad..cd21b38af 100644 --- a/apps/documenteditor/main/locale/en.json +++ b/apps/documenteditor/main/locale/en.json @@ -643,6 +643,17 @@ "DE.Controllers.Main.warnNoLicense": "This version of ONLYOFFICE Editors has certain limitations for concurrent connections to the document server.
If you need more please consider purchasing a commercial license.", "DE.Controllers.Main.warnNoLicenseUsers": "This version of ONLYOFFICE Editors has certain limitations for concurrent users.
If you need more please consider purchasing a commercial license.", "DE.Controllers.Main.warnProcessRightsChange": "You have been denied the right to edit the file.", + "DE.Controllers.Main.txtSyntaxError": "Syntax Error", + "DE.Controllers.Main.txtMissOperator": "Missing Operator", + "DE.Controllers.Main.txtMissArg": "Missing Argument", + "DE.Controllers.Main.txtTooLarge": "Number Too Large To Format", + "DE.Controllers.Main.txtZeroDivide": "Zero Divide", + "DE.Controllers.Main.txtNotInTable": "Is Not In Table", + "DE.Controllers.Main.txtIndTooLarge": "Index Too Large", + "DE.Controllers.Main.txtFormulaNotInTable": "The Formula Not In Table", + "DE.Controllers.Main.txtTableInd": "Table Index Cannot be Zero", + "DE.Controllers.Main.txtUndefBookmark": "Undefined Bookmark", + "DE.Controllers.Main.txtEndOfFormula": "Unexpected End of Formula", "DE.Controllers.Navigation.txtBeginning": "Beginning of document", "DE.Controllers.Navigation.txtGotoBeginning": "Go to the beginning of the document", "DE.Controllers.Statusbar.textHasChanges": "New changes have been tracked",