From 1abcf78b85273eb9bb985eb1e5c57c894e6ad169 Mon Sep 17 00:00:00 2001 From: Serik Ibragimov Date: Thu, 14 Mar 2024 19:08:12 +0500 Subject: [PATCH 01/14] refactor(php): change formats retrieval method on frontend --- .../php/assets/js/format-manager.js | 46 +++++++++++++++++++ .../php/assets/js/format.js | 39 ++++++++++++++++ .../php/assets/js/jscript.js | 27 +++++++++-- web/documentserver-example/php/index.php | 5 ++ web/documentserver-example/php/src/ajax.php | 16 +++++++ .../php/src/views/IndexView.php | 3 -- .../php/templates/index.tpl | 7 +-- 7 files changed, 132 insertions(+), 11 deletions(-) create mode 100644 web/documentserver-example/php/assets/js/format-manager.js create mode 100644 web/documentserver-example/php/assets/js/format.js diff --git a/web/documentserver-example/php/assets/js/format-manager.js b/web/documentserver-example/php/assets/js/format-manager.js new file mode 100644 index 00000000..4602496a --- /dev/null +++ b/web/documentserver-example/php/assets/js/format-manager.js @@ -0,0 +1,46 @@ +/** + * + * (c) Copyright Ascensio System SIA 2024 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +class FormatManager { + formats = []; + + constructor(formats) { + if(Array.isArray(formats)) this.formats = formats; + } + + isAutoConvertible(extension) { + let index = this.formats.findIndex(format => { + return format.name == extension && format.isAutoConvertible(); + }) + return index !== -1; + } + + isEditable(extension) { + let index = this.formats.findIndex(format => { + return format.name == extension && format.isEditable(); + }) + return index !== -1; + } + + isFillable(extension) { + let index = this.formats.findIndex(format => { + return format.name == extension && format.isFillable(); + }) + return index !== -1; + } +} \ No newline at end of file diff --git a/web/documentserver-example/php/assets/js/format.js b/web/documentserver-example/php/assets/js/format.js new file mode 100644 index 00000000..21cd09a1 --- /dev/null +++ b/web/documentserver-example/php/assets/js/format.js @@ -0,0 +1,39 @@ +/** + * + * (c) Copyright Ascensio System SIA 2024 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +class Format { + constructor(name, type, actions, convert, mime) { + this.name = name; + this.type = type; + this.actions = actions; + this.convert = convert; + this.mime = mime; + } + + isAutoConvertible() { + return this.actions.includes('auto-convert'); + } + + isEditable() { + return this.actions.includes('edit') || this.actions.includes('lossy-edit'); + } + + isFillable() { + return this.actions.includes('fill'); + } +} \ No newline at end of file diff --git a/web/documentserver-example/php/assets/js/jscript.js b/web/documentserver-example/php/assets/js/jscript.js index 973580be..97392ed6 100644 --- a/web/documentserver-example/php/assets/js/jscript.js +++ b/web/documentserver-example/php/assets/js/jscript.js @@ -17,6 +17,27 @@ */ var directUrl; +var formatManager; + +window.onload = function () { + fetch('formats') + .then((response) => response.json()) + .then((data) => { + if (data.formats) { + let formats = []; + JSON.parse(data.formats).forEach(format => { + formats.push(new Format( + format.name, + format.type, + format.actions, + format.convert, + format.mime + )); + }); + formatManager = new FormatManager(formats); + } + }) +} if (typeof jQuery != "undefined") { jq = jQuery.noConflict(); @@ -111,7 +132,7 @@ if (typeof jQuery != "undefined") { var posExt = fileName.lastIndexOf('.') + 1; posExt = 0 <= posExt ? fileName.substring(posExt).trim().toLowerCase() : ''; - if (ConverExtList.indexOf(posExt) == -1) { + if (!formatManager.isAutoConvertible(posExt)) { jq("#step2").addClass("done").removeClass("current"); loadScripts(); return; @@ -206,9 +227,9 @@ if (typeof jQuery != "undefined") { var fileName = jq("#hiddenFileName").val(); var posExt = fileName.lastIndexOf('.') + 1; - posExt = 0 <= posExt ? fileName.substring(posExt + 1).trim().toLowerCase() : ''; + posExt = 0 <= posExt ? fileName.substring(posExt).trim().toLowerCase() : ''; - if (EditedExtList.indexOf(posExt) != -1 || FillFormsExtList.indexOf(posExt) != -1) { + if (formatManager.isEditable(posExt) || formatManager.isFillable(posExt)) { jq("#beginEdit").removeClass("disable"); } }; diff --git a/web/documentserver-example/php/index.php b/web/documentserver-example/php/index.php index fa17b217..04b5be69 100755 --- a/web/documentserver-example/php/index.php +++ b/web/documentserver-example/php/index.php @@ -143,6 +143,11 @@ function routers() echo json_encode($response); return; } + if (str_starts_with($path, '/formats')) { + $response = formats(); + echo json_encode($response); + return; + } http_response_code(HTTPStatus::NotFound->value); } diff --git a/web/documentserver-example/php/src/ajax.php b/web/documentserver-example/php/src/ajax.php index 16ebec6b..ee8428b4 100644 --- a/web/documentserver-example/php/src/ajax.php +++ b/web/documentserver-example/php/src/ajax.php @@ -656,3 +656,19 @@ function restore() ]; } } + +function formats() +{ + try { + $formatManager = new FormatManager(); + $formats = $formatManager->all(); + + return [ + 'formats' => json_encode($formats) + ]; + } catch (Exception $error) { + return [ + 'error' => 'Server error' + ]; + } +} diff --git a/web/documentserver-example/php/src/views/IndexView.php b/web/documentserver-example/php/src/views/IndexView.php index 604bb646..e368906c 100644 --- a/web/documentserver-example/php/src/views/IndexView.php +++ b/web/documentserver-example/php/src/views/IndexView.php @@ -44,9 +44,6 @@ final class IndexView extends View "editButton" => $this->getEditButton(), "dataDocs" => $this->getPreloaderUrl(), "date" => date("Y"), - "fillFormsExtList" => implode(",", $formatManager->fillableExtensions()), - "converExtList" => implode(",", $formatManager->convertibleExtensions()), - "editedExtList" => implode(",", $formatManager->editableExtensions()), "serverVersion" => $configManager -> getVersion(), ]; } diff --git a/web/documentserver-example/php/templates/index.tpl b/web/documentserver-example/php/templates/index.tpl index fa221f4d..0a197298 100644 --- a/web/documentserver-example/php/templates/index.tpl +++ b/web/documentserver-example/php/templates/index.tpl @@ -220,11 +220,8 @@ + + - \ No newline at end of file From abab30176fd9fe7dd9d4c696c312641d59f1ef43 Mon Sep 17 00:00:00 2001 From: Serik Ibragimov Date: Thu, 14 Mar 2024 19:11:37 +0500 Subject: [PATCH 02/14] refactor(python): change formats retrieval method on frontend --- web/documentserver-example/python/manage.py | 3 +- .../python/src/views/actions.py | 11 +++++ .../python/src/views/index.py | 5 -- .../python/static/js/format-manager.js | 46 +++++++++++++++++++ .../python/static/js/format.js | 39 ++++++++++++++++ .../python/static/js/jscript.js | 27 +++++++++-- .../python/templates/index.html | 5 +- 7 files changed, 124 insertions(+), 12 deletions(-) create mode 100644 web/documentserver-example/python/static/js/format-manager.js create mode 100644 web/documentserver-example/python/static/js/format.js diff --git a/web/documentserver-example/python/manage.py b/web/documentserver-example/python/manage.py index d861336e..26d762bf 100644 --- a/web/documentserver-example/python/manage.py +++ b/web/documentserver-example/python/manage.py @@ -80,7 +80,8 @@ def routers(): path('restore', actions.restore), path('saveas', actions.saveAs), path('track', actions.track), - path('upload', actions.upload) + path('upload', actions.upload), + path('formats', actions.formats) ] main += static( settings.STATIC_URL, diff --git a/web/documentserver-example/python/src/views/actions.py b/web/documentserver-example/python/src/views/actions.py index 62ef63ce..d8bc8cd0 100755 --- a/web/documentserver-example/python/src/views/actions.py +++ b/web/documentserver-example/python/src/views/actions.py @@ -30,6 +30,8 @@ from src.configuration import ConfigurationManager from src.response import ErrorResponse from src.utils import docManager, fileUtils, serviceConverter, users, jwtManager, historyManager, trackManager from urllib.parse import urlparse, parse_qs +from src.format import FormatManager +import msgspec config_manager = ConfigurationManager() @@ -658,3 +660,12 @@ def restore(request: HttpRequest) -> HttpResponse: message=f'{type(error)}: {error}', status=HTTPStatus.INTERNAL_SERVER_ERROR ) + + +@http.GET() +def formats(request: HttpRequest) -> HttpResponse: + data = { + 'formats': [msgspec.to_builtins(format) for format in FormatManager().all()] + } + + return HttpResponse(json.dumps(data), content_type='application/json') diff --git a/web/documentserver-example/python/src/views/index.py b/web/documentserver-example/python/src/views/index.py index b15cfad6..d4929361 100755 --- a/web/documentserver-example/python/src/views/index.py +++ b/web/documentserver-example/python/src/views/index.py @@ -21,12 +21,10 @@ import json from django.shortcuts import render from src.configuration import ConfigurationManager -from src.format import FormatManager from src.utils import users from src.utils import docManager config_manager = ConfigurationManager() -format_manager = FormatManager() def getDirectUrlParam(request): @@ -41,10 +39,7 @@ def default(request): # default parameters that will be passed to the template 'users': users.USERS, 'languages': config_manager.languages(), 'preloadurl': config_manager.document_server_preloader_url().geturl(), - 'editExt': json.dumps(format_manager.editable_extensions()), # file extensions that can be edited - 'convExt': json.dumps(format_manager.convertible_extensions()), # file extensions that can be converted 'files': docManager.getStoredFiles(request), # information about stored files - 'fillExt': json.dumps(format_manager.fillable_extensions()), 'directUrl': str(getDirectUrlParam(request)).lower, 'serverVersion': config_manager.getVersion() } diff --git a/web/documentserver-example/python/static/js/format-manager.js b/web/documentserver-example/python/static/js/format-manager.js new file mode 100644 index 00000000..4602496a --- /dev/null +++ b/web/documentserver-example/python/static/js/format-manager.js @@ -0,0 +1,46 @@ +/** + * + * (c) Copyright Ascensio System SIA 2024 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +class FormatManager { + formats = []; + + constructor(formats) { + if(Array.isArray(formats)) this.formats = formats; + } + + isAutoConvertible(extension) { + let index = this.formats.findIndex(format => { + return format.name == extension && format.isAutoConvertible(); + }) + return index !== -1; + } + + isEditable(extension) { + let index = this.formats.findIndex(format => { + return format.name == extension && format.isEditable(); + }) + return index !== -1; + } + + isFillable(extension) { + let index = this.formats.findIndex(format => { + return format.name == extension && format.isFillable(); + }) + return index !== -1; + } +} \ No newline at end of file diff --git a/web/documentserver-example/python/static/js/format.js b/web/documentserver-example/python/static/js/format.js new file mode 100644 index 00000000..21cd09a1 --- /dev/null +++ b/web/documentserver-example/python/static/js/format.js @@ -0,0 +1,39 @@ +/** + * + * (c) Copyright Ascensio System SIA 2024 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +class Format { + constructor(name, type, actions, convert, mime) { + this.name = name; + this.type = type; + this.actions = actions; + this.convert = convert; + this.mime = mime; + } + + isAutoConvertible() { + return this.actions.includes('auto-convert'); + } + + isEditable() { + return this.actions.includes('edit') || this.actions.includes('lossy-edit'); + } + + isFillable() { + return this.actions.includes('fill'); + } +} \ No newline at end of file diff --git a/web/documentserver-example/python/static/js/jscript.js b/web/documentserver-example/python/static/js/jscript.js index 4deb1bfb..dd6c7ffb 100644 --- a/web/documentserver-example/python/static/js/jscript.js +++ b/web/documentserver-example/python/static/js/jscript.js @@ -17,6 +17,27 @@ */ var directUrl; +var formatManager; + +window.onload = function () { + fetch('formats') + .then((response) => response.json()) + .then((data) => { + if (data.formats) { + let formats = []; + data.formats.forEach(format => { + formats.push(new Format( + format.name, + format.type, + format.actions, + format.convert, + format.mime + )); + }); + formatManager = new FormatManager(formats); + } + }) +} if (typeof jQuery !== "undefined") { jq = jQuery.noConflict(); @@ -103,7 +124,7 @@ if (typeof jQuery !== "undefined") { var posExt = fileName.lastIndexOf("."); posExt = 0 <= posExt ? fileName.substring(posExt).trim().toLowerCase() : ""; - if (ConverExtList.indexOf(posExt) === -1) { + if (!formatManager.isAutoConvertible(posExt)) { jq("#step2").addClass("done").removeClass("current"); loadScripts(); return; @@ -177,10 +198,10 @@ if (typeof jQuery !== "undefined") { jq("#beginView, #beginEmbedded").removeClass("disable"); var fileName = jq("#hiddenFileName").val(); - var posExt = fileName.lastIndexOf("."); + var posExt = fileName.lastIndexOf(".") + 1; posExt = 0 <= posExt ? fileName.substring(posExt).trim().toLowerCase() : ""; - if (EditedExtList.indexOf(posExt) !== -1 || FillExtList.indexOf(posExt) !== -1) { + if (formatManager.isEditable(posExt) || formatManager.isFillable(posExt)) { jq("#beginEdit").removeClass("disable"); } }; diff --git a/web/documentserver-example/python/templates/index.html b/web/documentserver-example/python/templates/index.html index b885dfb2..bfa9fe95 100644 --- a/web/documentserver-example/python/templates/index.html +++ b/web/documentserver-example/python/templates/index.html @@ -338,12 +338,11 @@ + + From e1e9efa305fbc728b6fb4c91a68e9ed665323e5e Mon Sep 17 00:00:00 2001 From: Serik Ibragimov Date: Fri, 15 Mar 2024 15:29:58 +0500 Subject: [PATCH 03/14] refactor(ruby): change formats retrieval method on frontend --- .../app/assets/javascripts/format-manager.js | 46 +++++++++++++++++++ .../ruby/app/assets/javascripts/format.js | 39 ++++++++++++++++ .../ruby/app/assets/javascripts/jscript.js | 29 ++++++++++-- .../ruby/app/controllers/home_controller.rb | 9 ++++ .../ruby/app/views/home/index.html.erb | 3 -- .../ruby/config/application.rb | 1 + 6 files changed, 120 insertions(+), 7 deletions(-) create mode 100644 web/documentserver-example/ruby/app/assets/javascripts/format-manager.js create mode 100644 web/documentserver-example/ruby/app/assets/javascripts/format.js diff --git a/web/documentserver-example/ruby/app/assets/javascripts/format-manager.js b/web/documentserver-example/ruby/app/assets/javascripts/format-manager.js new file mode 100644 index 00000000..4602496a --- /dev/null +++ b/web/documentserver-example/ruby/app/assets/javascripts/format-manager.js @@ -0,0 +1,46 @@ +/** + * + * (c) Copyright Ascensio System SIA 2024 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +class FormatManager { + formats = []; + + constructor(formats) { + if(Array.isArray(formats)) this.formats = formats; + } + + isAutoConvertible(extension) { + let index = this.formats.findIndex(format => { + return format.name == extension && format.isAutoConvertible(); + }) + return index !== -1; + } + + isEditable(extension) { + let index = this.formats.findIndex(format => { + return format.name == extension && format.isEditable(); + }) + return index !== -1; + } + + isFillable(extension) { + let index = this.formats.findIndex(format => { + return format.name == extension && format.isFillable(); + }) + return index !== -1; + } +} \ No newline at end of file diff --git a/web/documentserver-example/ruby/app/assets/javascripts/format.js b/web/documentserver-example/ruby/app/assets/javascripts/format.js new file mode 100644 index 00000000..21cd09a1 --- /dev/null +++ b/web/documentserver-example/ruby/app/assets/javascripts/format.js @@ -0,0 +1,39 @@ +/** + * + * (c) Copyright Ascensio System SIA 2024 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +class Format { + constructor(name, type, actions, convert, mime) { + this.name = name; + this.type = type; + this.actions = actions; + this.convert = convert; + this.mime = mime; + } + + isAutoConvertible() { + return this.actions.includes('auto-convert'); + } + + isEditable() { + return this.actions.includes('edit') || this.actions.includes('lossy-edit'); + } + + isFillable() { + return this.actions.includes('fill'); + } +} \ No newline at end of file diff --git a/web/documentserver-example/ruby/app/assets/javascripts/jscript.js b/web/documentserver-example/ruby/app/assets/javascripts/jscript.js index 5a5e82e0..e860448b 100644 --- a/web/documentserver-example/ruby/app/assets/javascripts/jscript.js +++ b/web/documentserver-example/ruby/app/assets/javascripts/jscript.js @@ -18,6 +18,27 @@ var directUrl; var userId; +var formatManager; + +window.onload = function () { + fetch('formats') + .then((response) => response.json()) + .then((data) => { + if (data.formats) { + let formats = []; + data.formats.forEach(format => { + formats.push(new Format( + format.name, + format.type, + format.actions, + format.convert, + format.mime + )); + }); + formatManager = new FormatManager(formats); + } + }) +} if (typeof jQuery != "undefined") { jq = jQuery.noConflict(); @@ -111,10 +132,10 @@ if (typeof jQuery != "undefined") { jq("#filePass").val(""); var fileName = jq("#hiddenFileName").val(); - var posExt = fileName.lastIndexOf('.'); + var posExt = fileName.lastIndexOf('.') + 1; posExt = 0 <= posExt ? fileName.substring(posExt).trim().toLowerCase() : ''; - if (ConvertExtList.indexOf(posExt) == -1) { + if (!formatManager.isAutoConvertible(posExt)) { jq("#step2").addClass("done").removeClass("current"); loadScripts(); return; @@ -188,10 +209,10 @@ if (typeof jQuery != "undefined") { jq("#beginView, #beginEmbedded").removeClass("disable"); var fileName = jq("#hiddenFileName").val(); - var posExt = fileName.lastIndexOf('.'); + var posExt = fileName.lastIndexOf('.') + 1; posExt = 0 <= posExt ? fileName.substring(posExt).trim().toLowerCase() : ''; - if (EditedExtList.indexOf(posExt) != -1 || FillExtList.indexOf(posExt) != -1) { + if (formatManager.isEditable(posExt) || formatManager.isFillable(posExt)) { jq("#beginEdit").removeClass("disable"); } }; diff --git a/web/documentserver-example/ruby/app/controllers/home_controller.rb b/web/documentserver-example/ruby/app/controllers/home_controller.rb index a9d11b2b..677d7f37 100755 --- a/web/documentserver-example/ruby/app/controllers/home_controller.rb +++ b/web/documentserver-example/ruby/app/controllers/home_controller.rb @@ -536,4 +536,13 @@ class HomeController < ApplicationController } ) end + + # return all supported formats + def formats + render( + json: JSON.generate({ + formats: FormatManager.new.all.map {|format| format.serialize} + }) + ) + end end diff --git a/web/documentserver-example/ruby/app/views/home/index.html.erb b/web/documentserver-example/ruby/app/views/home/index.html.erb index 3f7b3e90..298721ce 100755 --- a/web/documentserver-example/ruby/app/views/home/index.html.erb +++ b/web/documentserver-example/ruby/app/views/home/index.html.erb @@ -329,9 +329,6 @@ <%= javascript_include_tag "application" %> diff --git a/web/documentserver-example/ruby/config/application.rb b/web/documentserver-example/ruby/config/application.rb index 0034f7dc..751510a9 100644 --- a/web/documentserver-example/ruby/config/application.rb +++ b/web/documentserver-example/ruby/config/application.rb @@ -46,5 +46,6 @@ class Application < Rails::Application match '/saveas', to: 'home#saveas', via: 'post' match '/track', to: 'home#track', via: 'post' match '/upload', to: 'home#upload', via: 'post' + match '/formats', to: 'home#formats', via: 'get' end end From 5217a64e83d6624122a87e34152f69a5b42cadc8 Mon Sep 17 00:00:00 2001 From: Serik Ibragimov Date: Fri, 15 Mar 2024 15:38:14 +0500 Subject: [PATCH 04/14] refactor(java): change formats retrieval method on frontend --- .../main/java/controllers/IndexServlet.java | 14 ++++++ .../java/src/main/webapp/index.jsp | 5 +- .../src/main/webapp/scripts/format-manager.js | 46 +++++++++++++++++++ .../java/src/main/webapp/scripts/format.js | 39 ++++++++++++++++ .../java/src/main/webapp/scripts/jscript.js | 25 +++++++++- 5 files changed, 124 insertions(+), 5 deletions(-) create mode 100644 web/documentserver-example/java/src/main/webapp/scripts/format-manager.js create mode 100644 web/documentserver-example/java/src/main/webapp/scripts/format.js diff --git a/web/documentserver-example/java/src/main/java/controllers/IndexServlet.java b/web/documentserver-example/java/src/main/java/controllers/IndexServlet.java index f925ea18..6d16a6b4 100755 --- a/web/documentserver-example/java/src/main/java/controllers/IndexServlet.java +++ b/web/documentserver-example/java/src/main/java/controllers/IndexServlet.java @@ -29,6 +29,7 @@ import helpers.FileUtility; import helpers.ServiceConverter; import helpers.TrackManager; import helpers.Users; +import format.FormatManager; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; @@ -139,6 +140,9 @@ public class IndexServlet extends HttpServlet { case "historydata": historyData(request, response, writer); break; + case "formats": + formats(request, response, writer); + break; default: break; } @@ -1039,6 +1043,16 @@ public class IndexServlet extends HttpServlet { writer.write("{}"); } + private static void formats(final HttpServletRequest request, + final HttpServletResponse response, + final PrintWriter writer) { + Map data = new HashMap(); + data.put("formats", (new FormatManager()).getFormats()); + response.setContentType("application/json"); + Gson gson = new Gson(); + writer.write(gson.toJson(data)); + } + // process get request @Override protected void doGet(final HttpServletRequest request, diff --git a/web/documentserver-example/java/src/main/webapp/index.jsp b/web/documentserver-example/java/src/main/webapp/index.jsp index 4f4a2c14..dc48ad4c 100755 --- a/web/documentserver-example/java/src/main/webapp/index.jsp +++ b/web/documentserver-example/java/src/main/webapp/index.jsp @@ -365,12 +365,11 @@ + + + + + + - diff --git a/web/documentserver-example/csharp/WebEditor.ashx.cs b/web/documentserver-example/csharp/WebEditor.ashx.cs index b1d37445..cdfc0c74 100644 --- a/web/documentserver-example/csharp/WebEditor.ashx.cs +++ b/web/documentserver-example/csharp/WebEditor.ashx.cs @@ -87,6 +87,9 @@ namespace OnlineEditorsExample case "reference": Reference(context); break; + case "formats": + Formats(context); + break; } } @@ -778,5 +781,25 @@ namespace OnlineEditorsExample + userAddress; return fileUrl.ToString(); } + + // return all the supported formats + private static void Formats(HttpContext context) + { + try + { + Dictionary data = new Dictionary + { + { "formats", FormatManager.All() } + }; + context.Response.ContentType = "application/json"; + var jss = new JavaScriptSerializer(); + + context.Response.Write(jss.Serialize(data)); + } + catch (Exception e) + { + context.Response.Write("{ \"error\": \"" + e.Message + "\"}"); + } + } } } \ No newline at end of file diff --git a/web/documentserver-example/csharp/script/format-manager.js b/web/documentserver-example/csharp/script/format-manager.js new file mode 100755 index 00000000..cd8cfb57 --- /dev/null +++ b/web/documentserver-example/csharp/script/format-manager.js @@ -0,0 +1,46 @@ +/** + * + * (c) Copyright Ascensio System SIA 2024 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +class FormatManager { + formats = []; + + constructor(formats) { + if (Array.isArray(formats)) this.formats = formats; + } + + isAutoConvertible(extension) { + let index = this.formats.findIndex(format => { + return format.name == extension && format.isAutoConvertible(); + }) + return index !== -1; + } + + isEditable(extension) { + let index = this.formats.findIndex(format => { + return format.name == extension && format.isEditable(); + }) + return index !== -1; + } + + isFillable(extension) { + let index = this.formats.findIndex(format => { + return format.name == extension && format.isFillable(); + }) + return index !== -1; + } +} diff --git a/web/documentserver-example/csharp/script/format.js b/web/documentserver-example/csharp/script/format.js new file mode 100755 index 00000000..9ee103a3 --- /dev/null +++ b/web/documentserver-example/csharp/script/format.js @@ -0,0 +1,39 @@ +/** + * + * (c) Copyright Ascensio System SIA 2024 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +class Format { + constructor(name, type, actions, convert, mime) { + this.name = name; + this.type = type; + this.actions = actions; + this.convert = convert; + this.mime = mime; + } + + isAutoConvertible() { + return this.actions.includes('auto-convert'); + } + + isEditable() { + return this.actions.includes('edit') || this.actions.includes('lossy-edit'); + } + + isFillable() { + return this.actions.includes('fill'); + } +} diff --git a/web/documentserver-example/csharp/script/jscript.js b/web/documentserver-example/csharp/script/jscript.js index 2491c400..13cd053f 100644 --- a/web/documentserver-example/csharp/script/jscript.js +++ b/web/documentserver-example/csharp/script/jscript.js @@ -17,6 +17,27 @@ */ var directUrl; +var formatManager; + +window.onload = function () { + fetch("webeditor.ashx?type=formats") + .then((response) => response.json()) + .then((data) => { + if (data.formats) { + let formats = []; + data.formats.forEach(format => { + formats.push(new Format( + format.Name, + format.Type, + format.Actions, + format.Convert, + format.Mime + )); + }); + formatManager = new FormatManager(formats); + } + }) +} if (typeof jQuery != "undefined") { jq = jQuery.noConflict(); @@ -103,7 +124,7 @@ if (typeof jQuery != "undefined") { var posExt = fileName.lastIndexOf('.'); posExt = 0 <= posExt ? fileName.substring(posExt).trim().toLowerCase() : ''; - if (ConverExtList.indexOf(posExt) == -1) { + if (!formatManager.isAutoConvertible(posExt)) { jq("#step2").addClass("done").removeClass("current"); loadScripts(); return; @@ -178,10 +199,10 @@ if (typeof jQuery != "undefined") { jq("#beginView, #beginEmbedded").removeClass("disable"); var fileName = jq("#hiddenFileName").val(); - var posExt = fileName.lastIndexOf('.'); + var posExt = fileName.lastIndexOf('.') + 1; posExt = 0 <= posExt ? fileName.substring(posExt).trim().toLowerCase() : ''; - if (EditedExtList.indexOf(posExt) != -1 || FillFormExtList.indexOf(posExt) != -1) { + if (formatManager.isEditable(posExt) || formatManager.isFillable(posExt)) { jq("#beginEdit").removeClass("disable"); } }; From 0bfb036be61a7200e4e1d29de8ee2dc8efdb26b9 Mon Sep 17 00:00:00 2001 From: Serik Ibragimov Date: Mon, 18 Mar 2024 18:03:10 +0500 Subject: [PATCH 07/14] refactor(csharp-mvc): change formats retrieval method on frontend --- .../csharp-mvc/Scripts/format-manager.js | 46 +++++++++++++++++++ .../csharp-mvc/Scripts/format.js | 39 ++++++++++++++++ .../csharp-mvc/Scripts/jscript.js | 27 +++++++++-- .../csharp-mvc/Views/Home/Index.aspx | 3 -- .../csharp-mvc/WebEditor.ashx.cs | 22 +++++++++ 5 files changed, 131 insertions(+), 6 deletions(-) create mode 100755 web/documentserver-example/csharp-mvc/Scripts/format-manager.js create mode 100755 web/documentserver-example/csharp-mvc/Scripts/format.js diff --git a/web/documentserver-example/csharp-mvc/Scripts/format-manager.js b/web/documentserver-example/csharp-mvc/Scripts/format-manager.js new file mode 100755 index 00000000..cd8cfb57 --- /dev/null +++ b/web/documentserver-example/csharp-mvc/Scripts/format-manager.js @@ -0,0 +1,46 @@ +/** + * + * (c) Copyright Ascensio System SIA 2024 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +class FormatManager { + formats = []; + + constructor(formats) { + if (Array.isArray(formats)) this.formats = formats; + } + + isAutoConvertible(extension) { + let index = this.formats.findIndex(format => { + return format.name == extension && format.isAutoConvertible(); + }) + return index !== -1; + } + + isEditable(extension) { + let index = this.formats.findIndex(format => { + return format.name == extension && format.isEditable(); + }) + return index !== -1; + } + + isFillable(extension) { + let index = this.formats.findIndex(format => { + return format.name == extension && format.isFillable(); + }) + return index !== -1; + } +} diff --git a/web/documentserver-example/csharp-mvc/Scripts/format.js b/web/documentserver-example/csharp-mvc/Scripts/format.js new file mode 100755 index 00000000..9ee103a3 --- /dev/null +++ b/web/documentserver-example/csharp-mvc/Scripts/format.js @@ -0,0 +1,39 @@ +/** + * + * (c) Copyright Ascensio System SIA 2024 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +class Format { + constructor(name, type, actions, convert, mime) { + this.name = name; + this.type = type; + this.actions = actions; + this.convert = convert; + this.mime = mime; + } + + isAutoConvertible() { + return this.actions.includes('auto-convert'); + } + + isEditable() { + return this.actions.includes('edit') || this.actions.includes('lossy-edit'); + } + + isFillable() { + return this.actions.includes('fill'); + } +} diff --git a/web/documentserver-example/csharp-mvc/Scripts/jscript.js b/web/documentserver-example/csharp-mvc/Scripts/jscript.js index 35d82796..fcf4ab29 100644 --- a/web/documentserver-example/csharp-mvc/Scripts/jscript.js +++ b/web/documentserver-example/csharp-mvc/Scripts/jscript.js @@ -17,6 +17,27 @@ */ var directUrl; +var formatManager; + +window.onload = function () { + fetch("webeditor.ashx?type=formats") + .then((response) => response.json()) + .then((data) => { + if (data.formats) { + let formats = []; + data.formats.forEach(format => { + formats.push(new Format( + format.Name, + format.Type, + format.Actions, + format.Convert, + format.Mime + )); + }); + formatManager = new FormatManager(formats); + } + }) +} if (typeof jQuery != "undefined") { jq = jQuery.noConflict(); @@ -103,7 +124,7 @@ if (typeof jQuery != "undefined") { var posExt = fileName.lastIndexOf('.'); posExt = 0 <= posExt ? fileName.substring(posExt).trim().toLowerCase() : ''; - if (ConverExtList.indexOf(posExt) == -1) { + if (!formatManager.isAutoConvertible(posExt)) { jq("#step2").addClass("done").removeClass("current"); loadScripts(); return; @@ -178,10 +199,10 @@ if (typeof jQuery != "undefined") { jq("#beginView, #beginEmbedded").removeClass("disable"); var fileName = jq("#hiddenFileName").val(); - var posExt = fileName.lastIndexOf('.'); + var posExt = fileName.lastIndexOf('.') + 1; posExt = 0 <= posExt ? fileName.substring(posExt).trim().toLowerCase() : ''; - if (EditedExtList.indexOf(posExt) != -1 || FillExtList.indexOf(posExt) != -1) { + if (formatManager.isEditable(posExt) || formatManager.isFillable(posExt)) { jq("#beginEdit").removeClass("disable"); } }; diff --git a/web/documentserver-example/csharp-mvc/Views/Home/Index.aspx b/web/documentserver-example/csharp-mvc/Views/Home/Index.aspx index 080f867f..7df95e35 100644 --- a/web/documentserver-example/csharp-mvc/Views/Home/Index.aspx +++ b/web/documentserver-example/csharp-mvc/Views/Home/Index.aspx @@ -357,9 +357,6 @@ <%: Scripts.Render("~/bundles/jquery", "~/bundles/scripts") %> diff --git a/web/documentserver-example/csharp-mvc/WebEditor.ashx.cs b/web/documentserver-example/csharp-mvc/WebEditor.ashx.cs index 4e69b85c..0697bacb 100644 --- a/web/documentserver-example/csharp-mvc/WebEditor.ashx.cs +++ b/web/documentserver-example/csharp-mvc/WebEditor.ashx.cs @@ -87,6 +87,9 @@ namespace OnlineEditorsExampleMVC case "reference": Reference(context); break; + case "formats": + Formats(context); + break; } } @@ -951,6 +954,25 @@ namespace OnlineEditorsExampleMVC return history; } + // return all the supported formats + private static void Formats(HttpContext context) + { + try + { + Dictionary data = new Dictionary + { + { "formats", FormatManager.All() } + }; + context.Response.ContentType = "application/json"; + var jss = new JavaScriptSerializer(); + + context.Response.Write(jss.Serialize(data)); + } + catch (Exception e) + { + context.Response.Write("{ \"error\": \"" + e.Message + "\"}"); + } + } } } \ No newline at end of file From 601146c847d95b8f4cc9e620757fa31f0272257f Mon Sep 17 00:00:00 2001 From: Serik Ibragimov Date: Tue, 19 Mar 2024 12:59:54 +0500 Subject: [PATCH 08/14] refactor(nodejs): change formats retrieval method on frontend --- web/documentserver-example/nodejs/app.js | 6 +-- .../public/javascripts/format-manager.js | 44 +++++++++++++++++++ .../nodejs/public/javascripts/format.js | 39 ++++++++++++++++ .../nodejs/public/javascripts/jscript.js | 35 ++++++++++----- .../nodejs/views/index.ejs | 5 +-- 5 files changed, 112 insertions(+), 17 deletions(-) create mode 100644 web/documentserver-example/nodejs/public/javascripts/format-manager.js create mode 100644 web/documentserver-example/nodejs/public/javascripts/format.js diff --git a/web/documentserver-example/nodejs/app.js b/web/documentserver-example/nodejs/app.js index 1b2d754a..46dac09e 100755 --- a/web/documentserver-example/nodejs/app.js +++ b/web/documentserver-example/nodejs/app.js @@ -93,8 +93,6 @@ app.get('/', (req, res) => { // define a handler for default page res.render('index', { // render index template with the parameters specified preloaderUrl: siteUrl + configServer.get('preloaderUrl'), - convertExts: fileUtility.getConvertExtensions(), - editedExts: fileUtility.getEditExtensions(), fillExts: fileUtility.getFillExtensions(), storedFiles: req.DocManager.getStoredFiles(), params: req.DocManager.getCustomParams(), @@ -1192,7 +1190,9 @@ app.post('/historyObj', (req, res) => { app.get('/formats', (req, res) => { try { const formats = fileUtility.getFormats(); - res.json(formats); + res.json({ + "formats": formats + }); } catch (ex) { console.log(ex); // display error message in the console res.status(500); // write status parameter to the response diff --git a/web/documentserver-example/nodejs/public/javascripts/format-manager.js b/web/documentserver-example/nodejs/public/javascripts/format-manager.js new file mode 100644 index 00000000..5b167856 --- /dev/null +++ b/web/documentserver-example/nodejs/public/javascripts/format-manager.js @@ -0,0 +1,44 @@ +/** + * + * (c) Copyright Ascensio System SIA 2024 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +class FormatManager { + formats = []; + + constructor(formats) { + if(Array.isArray(formats)) this.formats = formats; + } + + findByExtension(extension) { + return this.formats.find(format => format.name == extension); + } + + isAutoConvertible(extension) { + let format = this.findByExtension(extension); + return format !== undefined && format.isAutoConvertible(); + } + + isEditable(extension) { + let format = this.findByExtension(extension); + return format !== undefined && format.isEditable(); + } + + isFillable(extension) { + let format = this.findByExtension(extension); + return format !== undefined && format.isFillable(); + } +} \ No newline at end of file diff --git a/web/documentserver-example/nodejs/public/javascripts/format.js b/web/documentserver-example/nodejs/public/javascripts/format.js new file mode 100644 index 00000000..21cd09a1 --- /dev/null +++ b/web/documentserver-example/nodejs/public/javascripts/format.js @@ -0,0 +1,39 @@ +/** + * + * (c) Copyright Ascensio System SIA 2024 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +class Format { + constructor(name, type, actions, convert, mime) { + this.name = name; + this.type = type; + this.actions = actions; + this.convert = convert; + this.mime = mime; + } + + isAutoConvertible() { + return this.actions.includes('auto-convert'); + } + + isEditable() { + return this.actions.includes('edit') || this.actions.includes('lossy-edit'); + } + + isFillable() { + return this.actions.includes('fill'); + } +} \ No newline at end of file diff --git a/web/documentserver-example/nodejs/public/javascripts/jscript.js b/web/documentserver-example/nodejs/public/javascripts/jscript.js index 29feae9d..39e4db4c 100644 --- a/web/documentserver-example/nodejs/public/javascripts/jscript.js +++ b/web/documentserver-example/nodejs/public/javascripts/jscript.js @@ -19,13 +19,25 @@ var language; var userid; var directUrl; -var Formats; +var formatManager; window.onload = function () { fetch('formats') .then((response) => response.json()) .then((data) => { - Formats = data; + if (data.formats) { + let formats = []; + data.formats.forEach(format => { + formats.push(new Format( + format.name, + format.type, + format.actions, + format.convert, + format.mime + )); + }); + formatManager = new FormatManager(formats); + } }) } @@ -125,7 +137,7 @@ if (typeof jQuery != "undefined") { var posExt = fileName.lastIndexOf('.') + 1; posExt = 0 <= posExt ? fileName.substring(posExt).trim().toLowerCase() : ''; - if (ConverExtList.indexOf(posExt) == -1) { + if (!formatManager.isAutoConvertible(posExt)) { jq("#step2").addClass("done").removeClass("current"); loadScripts(); return; @@ -215,10 +227,7 @@ if (typeof jQuery != "undefined") { var posExt = fileName.lastIndexOf('.') + 1; posExt = 0 <= posExt ? fileName.substring(posExt).trim().toLowerCase() : ''; - var checkEdited = EditedExtList.split(",").filter(function(ext) { return ext == posExt;}); - var checkFilled = FilledExtList.split(",").filter(function(ext) { return ext == posExt;}); - - if (checkEdited != "" || checkFilled != "") { + if (formatManager.isEditable(posExt) || formatManager.isFillable(posExt)) { jq("#beginEdit").removeClass("disable"); } }; @@ -369,10 +378,14 @@ if (typeof jQuery != "undefined") { jq("#convertFileName").removeClass("word slide cell"); jq("#convertFileName").addClass(type); jq("#convTypes").empty(); - let convExtensions = Formats.find(format => {return format.name == fileName.split('.').pop()}).convert; - convExtensions.forEach(ext => { - jq("#convTypes").append(jq(`${ext}`)); - }); + + let format = formatManager.findByExtension(fileName.split('.').pop()); + if (format) { + format.convert.forEach(ext => { + jq("#convTypes").append(jq(`${ext}`)); + }); + } + jq("#hiddenFileName").val(fileName); jq("#convertStep1").addClass("done"); jq("#convertStep2").addClass("waiting"); diff --git a/web/documentserver-example/nodejs/views/index.ejs b/web/documentserver-example/nodejs/views/index.ejs index 0d707c2c..d4626523 100755 --- a/web/documentserver-example/nodejs/views/index.ejs +++ b/web/documentserver-example/nodejs/views/index.ejs @@ -373,12 +373,11 @@ + + From fadae60e892705ca00a07b492bf133ac5af48faf Mon Sep 17 00:00:00 2001 From: Serik Ibragimov Date: Tue, 19 Mar 2024 13:43:17 +0500 Subject: [PATCH 09/14] fix: linter offenses --- web/documentserver-example/nodejs/app.js | 2 +- .../python/src/views/index.py | 2 -- .../ruby/app/controllers/home_controller.rb | 8 +++--- .../ruby/app/models/file_model.rb | 26 +++++++++---------- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/web/documentserver-example/nodejs/app.js b/web/documentserver-example/nodejs/app.js index 4ebec72a..28ada06d 100755 --- a/web/documentserver-example/nodejs/app.js +++ b/web/documentserver-example/nodejs/app.js @@ -1199,7 +1199,7 @@ app.get('/formats', (req, res) => { try { const formats = fileUtility.getFormats(); res.json({ - "formats": formats + formats, }); } catch (ex) { console.log(ex); // display error message in the console diff --git a/web/documentserver-example/python/src/views/index.py b/web/documentserver-example/python/src/views/index.py index d4929361..4f1b87fd 100755 --- a/web/documentserver-example/python/src/views/index.py +++ b/web/documentserver-example/python/src/views/index.py @@ -16,8 +16,6 @@ """ -import json - from django.shortcuts import render from src.configuration import ConfigurationManager diff --git a/web/documentserver-example/ruby/app/controllers/home_controller.rb b/web/documentserver-example/ruby/app/controllers/home_controller.rb index 0d8545a7..3ec46e78 100755 --- a/web/documentserver-example/ruby/app/controllers/home_controller.rb +++ b/web/documentserver-example/ruby/app/controllers/home_controller.rb @@ -543,9 +543,11 @@ class HomeController < ApplicationController # return all supported formats def formats render( - json: JSON.generate({ - formats: FormatManager.new.all.map {|format| format.serialize} - }) + json: JSON.generate( + { + formats: FormatManager.new.all.map(&:serialize) + } + ) ) end end diff --git a/web/documentserver-example/ruby/app/models/file_model.rb b/web/documentserver-example/ruby/app/models/file_model.rb index be96b7bc..4ce63e8e 100755 --- a/web/documentserver-example/ruby/app/models/file_model.rb +++ b/web/documentserver-example/ruby/app/models/file_model.rb @@ -304,19 +304,19 @@ class FileModel prev = hist_data[(i - 2).to_s] # get the history data from the previous file version # write key and url information about previous file version with optional direct url data_obj['previous'] = if enable_direct_url? == true - { # write key and url information about previous file version with optional directUrl - fileType: prev['fileType'], - key: prev['key'], - url: prev['url'], - directUrl: prev['directUrl'] - } - else - { - fileType: prev['fileType'], - key: prev['key'], - url: prev['url'] - } - end + { # write key and url information about previous file version with optional directUrl + fileType: prev['fileType'], + key: prev['key'], + url: prev['url'], + directUrl: prev['directUrl'] + } + else + { + fileType: prev['fileType'], + key: prev['key'], + url: prev['url'] + } + end diff_path = [hist_dir, (i - 1).to_s, 'diff.zip'].join(File::SEPARATOR) if File.exist?(diff_path) From f3b35a878c4bdfefa869b514f7fcf98f0b70e049 Mon Sep 17 00:00:00 2001 From: Serik Ibragimov Date: Thu, 21 Mar 2024 13:23:31 +0500 Subject: [PATCH 10/14] refactor(java-spring): move formats method to indexcontroller and change return type to responseentity --- .../integration/controllers/FileController.java | 12 ------------ .../integration/controllers/IndexController.java | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/controllers/FileController.java b/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/controllers/FileController.java index deaebba1..854ce1d7 100755 --- a/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/controllers/FileController.java +++ b/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/controllers/FileController.java @@ -41,7 +41,6 @@ import com.onlyoffice.integration.documentserver.util.file.FileUtility; import com.onlyoffice.integration.documentserver.util.service.ServiceConverter; import com.onlyoffice.integration.documentserver.managers.document.DocumentManager; import com.onlyoffice.integration.documentserver.managers.callback.CallbackManager; -import com.onlyoffice.integration.documentserver.util.service.FormatService; import org.json.simple.JSONArray; import org.json.simple.JSONObject; @@ -126,8 +125,6 @@ public class FileController { private CallbackManager callbackManager; @Autowired private HistoryManager historyManager; - @Autowired - private FormatService formatService; // create user metadata private String createUserMetadata(final String uid, final String fullFileName) { @@ -674,13 +671,4 @@ public class FileController { return responseBody.toJSONString(); } } - - @GetMapping("/formats") - @ResponseBody - public String formats() { // return all the supported formats - Map data = new HashMap(); - data.put("formats", formatService.getFormats()); - Gson gson = new Gson(); - return gson.toJson(data); - } } diff --git a/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/controllers/IndexController.java b/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/controllers/IndexController.java index 1f45ddde..097d0231 100755 --- a/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/controllers/IndexController.java +++ b/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/controllers/IndexController.java @@ -22,6 +22,7 @@ import com.onlyoffice.integration.documentserver.storage.FileStorageMutator; import com.onlyoffice.integration.documentserver.storage.FileStoragePathBuilder; import com.onlyoffice.integration.documentserver.util.Misc; import com.onlyoffice.integration.documentserver.util.file.FileUtility; +import com.onlyoffice.integration.documentserver.util.service.FormatService; import com.onlyoffice.integration.entities.User; import com.onlyoffice.integration.services.UserServices; import org.springframework.beans.factory.annotation.Autowired; @@ -33,6 +34,8 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.http.ResponseEntity; +import org.json.simple.JSONObject; import java.util.ArrayList; import java.util.Arrays; @@ -61,6 +64,9 @@ public class IndexController { @Autowired private UserServices userService; + @Autowired + private FormatService formatService; + @Value("${files.docservice.url.site}") private String docserviceSite; @@ -141,4 +147,12 @@ public class IndexController { return configuration; } + + @GetMapping("/formats") + @ResponseBody + public ResponseEntity formats() { // return all the supported formats + JSONObject result = new JSONObject(); + result.put("formats", formatService.getFormats()); + return ResponseEntity.ok(result); + } } From acb9a0e4c9f6c817b01b099ade4d54dd51d134f5 Mon Sep 17 00:00:00 2001 From: Serik Ibragimov Date: Mon, 25 Mar 2024 12:51:13 +0500 Subject: [PATCH 11/14] refactor(java-spring): add formatslist dto object and replace jsonobject with it --- .../controllers/IndexController.java | 9 +++--- .../integration/dto/FormatsList.java | 32 +++++++++++++++++++ 2 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/dto/FormatsList.java diff --git a/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/controllers/IndexController.java b/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/controllers/IndexController.java index 097d0231..dba6bfc1 100755 --- a/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/controllers/IndexController.java +++ b/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/controllers/IndexController.java @@ -25,6 +25,7 @@ import com.onlyoffice.integration.documentserver.util.file.FileUtility; import com.onlyoffice.integration.documentserver.util.service.FormatService; import com.onlyoffice.integration.entities.User; import com.onlyoffice.integration.services.UserServices; +import com.onlyoffice.integration.dto.FormatsList; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Controller; @@ -35,7 +36,6 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.http.ResponseEntity; -import org.json.simple.JSONObject; import java.util.ArrayList; import java.util.Arrays; @@ -150,9 +150,8 @@ public class IndexController { @GetMapping("/formats") @ResponseBody - public ResponseEntity formats() { // return all the supported formats - JSONObject result = new JSONObject(); - result.put("formats", formatService.getFormats()); - return ResponseEntity.ok(result); + public ResponseEntity formats() { // return all the supported formats + FormatsList list = new FormatsList(formatService.getFormats()); + return ResponseEntity.ok(list); } } diff --git a/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/dto/FormatsList.java b/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/dto/FormatsList.java new file mode 100644 index 00000000..daa58983 --- /dev/null +++ b/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/dto/FormatsList.java @@ -0,0 +1,32 @@ +/** + * + * (c) Copyright Ascensio System SIA 2024 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package com.onlyoffice.integration.dto; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Setter; +import com.onlyoffice.integration.documentserver.models.Format; +import java.util.List; + +@Getter +@Setter +@AllArgsConstructor +public class FormatsList { + private List formats; +} From f1f834fb0c64ad72543f93fcfca7df8a6fff619a Mon Sep 17 00:00:00 2001 From: Serik Ibragimov Date: Tue, 26 Mar 2024 17:57:52 +0500 Subject: [PATCH 12/14] refactor: create and use new method for finding formats by extension --- .../csharp-mvc/Scripts/format-manager.js | 26 +++++++++---------- .../csharp/script/format-manager.js | 26 +++++++++---------- .../static/scripts/format-manager.js | 22 +++++++--------- .../src/main/webapp/scripts/format-manager.js | 22 +++++++--------- .../php/assets/js/format-manager.js | 22 +++++++--------- .../python/static/js/format-manager.js | 22 +++++++--------- .../app/assets/javascripts/format-manager.js | 22 +++++++--------- 7 files changed, 74 insertions(+), 88 deletions(-) diff --git a/web/documentserver-example/csharp-mvc/Scripts/format-manager.js b/web/documentserver-example/csharp-mvc/Scripts/format-manager.js index cd8cfb57..fafac66b 100755 --- a/web/documentserver-example/csharp-mvc/Scripts/format-manager.js +++ b/web/documentserver-example/csharp-mvc/Scripts/format-manager.js @@ -20,27 +20,25 @@ class FormatManager { formats = []; constructor(formats) { - if (Array.isArray(formats)) this.formats = formats; + if(Array.isArray(formats)) this.formats = formats; + } + + findByExtension(extension) { + return this.formats.find(format => format.name == extension); } isAutoConvertible(extension) { - let index = this.formats.findIndex(format => { - return format.name == extension && format.isAutoConvertible(); - }) - return index !== -1; + let format = this.findByExtension(extension); + return format !== undefined && format.isAutoConvertible(); } isEditable(extension) { - let index = this.formats.findIndex(format => { - return format.name == extension && format.isEditable(); - }) - return index !== -1; + let format = this.findByExtension(extension); + return format !== undefined && format.isEditable(); } isFillable(extension) { - let index = this.formats.findIndex(format => { - return format.name == extension && format.isFillable(); - }) - return index !== -1; + let format = this.findByExtension(extension); + return format !== undefined && format.isFillable(); } -} +} \ No newline at end of file diff --git a/web/documentserver-example/csharp/script/format-manager.js b/web/documentserver-example/csharp/script/format-manager.js index cd8cfb57..fafac66b 100755 --- a/web/documentserver-example/csharp/script/format-manager.js +++ b/web/documentserver-example/csharp/script/format-manager.js @@ -20,27 +20,25 @@ class FormatManager { formats = []; constructor(formats) { - if (Array.isArray(formats)) this.formats = formats; + if(Array.isArray(formats)) this.formats = formats; + } + + findByExtension(extension) { + return this.formats.find(format => format.name == extension); } isAutoConvertible(extension) { - let index = this.formats.findIndex(format => { - return format.name == extension && format.isAutoConvertible(); - }) - return index !== -1; + let format = this.findByExtension(extension); + return format !== undefined && format.isAutoConvertible(); } isEditable(extension) { - let index = this.formats.findIndex(format => { - return format.name == extension && format.isEditable(); - }) - return index !== -1; + let format = this.findByExtension(extension); + return format !== undefined && format.isEditable(); } isFillable(extension) { - let index = this.formats.findIndex(format => { - return format.name == extension && format.isFillable(); - }) - return index !== -1; + let format = this.findByExtension(extension); + return format !== undefined && format.isFillable(); } -} +} \ No newline at end of file diff --git a/web/documentserver-example/java-spring/src/main/resources/static/scripts/format-manager.js b/web/documentserver-example/java-spring/src/main/resources/static/scripts/format-manager.js index 4602496a..5b167856 100644 --- a/web/documentserver-example/java-spring/src/main/resources/static/scripts/format-manager.js +++ b/web/documentserver-example/java-spring/src/main/resources/static/scripts/format-manager.js @@ -23,24 +23,22 @@ class FormatManager { if(Array.isArray(formats)) this.formats = formats; } + findByExtension(extension) { + return this.formats.find(format => format.name == extension); + } + isAutoConvertible(extension) { - let index = this.formats.findIndex(format => { - return format.name == extension && format.isAutoConvertible(); - }) - return index !== -1; + let format = this.findByExtension(extension); + return format !== undefined && format.isAutoConvertible(); } isEditable(extension) { - let index = this.formats.findIndex(format => { - return format.name == extension && format.isEditable(); - }) - return index !== -1; + let format = this.findByExtension(extension); + return format !== undefined && format.isEditable(); } isFillable(extension) { - let index = this.formats.findIndex(format => { - return format.name == extension && format.isFillable(); - }) - return index !== -1; + let format = this.findByExtension(extension); + return format !== undefined && format.isFillable(); } } \ No newline at end of file diff --git a/web/documentserver-example/java/src/main/webapp/scripts/format-manager.js b/web/documentserver-example/java/src/main/webapp/scripts/format-manager.js index 4602496a..5b167856 100644 --- a/web/documentserver-example/java/src/main/webapp/scripts/format-manager.js +++ b/web/documentserver-example/java/src/main/webapp/scripts/format-manager.js @@ -23,24 +23,22 @@ class FormatManager { if(Array.isArray(formats)) this.formats = formats; } + findByExtension(extension) { + return this.formats.find(format => format.name == extension); + } + isAutoConvertible(extension) { - let index = this.formats.findIndex(format => { - return format.name == extension && format.isAutoConvertible(); - }) - return index !== -1; + let format = this.findByExtension(extension); + return format !== undefined && format.isAutoConvertible(); } isEditable(extension) { - let index = this.formats.findIndex(format => { - return format.name == extension && format.isEditable(); - }) - return index !== -1; + let format = this.findByExtension(extension); + return format !== undefined && format.isEditable(); } isFillable(extension) { - let index = this.formats.findIndex(format => { - return format.name == extension && format.isFillable(); - }) - return index !== -1; + let format = this.findByExtension(extension); + return format !== undefined && format.isFillable(); } } \ No newline at end of file diff --git a/web/documentserver-example/php/assets/js/format-manager.js b/web/documentserver-example/php/assets/js/format-manager.js index 4602496a..5b167856 100644 --- a/web/documentserver-example/php/assets/js/format-manager.js +++ b/web/documentserver-example/php/assets/js/format-manager.js @@ -23,24 +23,22 @@ class FormatManager { if(Array.isArray(formats)) this.formats = formats; } + findByExtension(extension) { + return this.formats.find(format => format.name == extension); + } + isAutoConvertible(extension) { - let index = this.formats.findIndex(format => { - return format.name == extension && format.isAutoConvertible(); - }) - return index !== -1; + let format = this.findByExtension(extension); + return format !== undefined && format.isAutoConvertible(); } isEditable(extension) { - let index = this.formats.findIndex(format => { - return format.name == extension && format.isEditable(); - }) - return index !== -1; + let format = this.findByExtension(extension); + return format !== undefined && format.isEditable(); } isFillable(extension) { - let index = this.formats.findIndex(format => { - return format.name == extension && format.isFillable(); - }) - return index !== -1; + let format = this.findByExtension(extension); + return format !== undefined && format.isFillable(); } } \ No newline at end of file diff --git a/web/documentserver-example/python/static/js/format-manager.js b/web/documentserver-example/python/static/js/format-manager.js index 4602496a..5b167856 100644 --- a/web/documentserver-example/python/static/js/format-manager.js +++ b/web/documentserver-example/python/static/js/format-manager.js @@ -23,24 +23,22 @@ class FormatManager { if(Array.isArray(formats)) this.formats = formats; } + findByExtension(extension) { + return this.formats.find(format => format.name == extension); + } + isAutoConvertible(extension) { - let index = this.formats.findIndex(format => { - return format.name == extension && format.isAutoConvertible(); - }) - return index !== -1; + let format = this.findByExtension(extension); + return format !== undefined && format.isAutoConvertible(); } isEditable(extension) { - let index = this.formats.findIndex(format => { - return format.name == extension && format.isEditable(); - }) - return index !== -1; + let format = this.findByExtension(extension); + return format !== undefined && format.isEditable(); } isFillable(extension) { - let index = this.formats.findIndex(format => { - return format.name == extension && format.isFillable(); - }) - return index !== -1; + let format = this.findByExtension(extension); + return format !== undefined && format.isFillable(); } } \ No newline at end of file diff --git a/web/documentserver-example/ruby/app/assets/javascripts/format-manager.js b/web/documentserver-example/ruby/app/assets/javascripts/format-manager.js index 4602496a..5b167856 100644 --- a/web/documentserver-example/ruby/app/assets/javascripts/format-manager.js +++ b/web/documentserver-example/ruby/app/assets/javascripts/format-manager.js @@ -23,24 +23,22 @@ class FormatManager { if(Array.isArray(formats)) this.formats = formats; } + findByExtension(extension) { + return this.formats.find(format => format.name == extension); + } + isAutoConvertible(extension) { - let index = this.formats.findIndex(format => { - return format.name == extension && format.isAutoConvertible(); - }) - return index !== -1; + let format = this.findByExtension(extension); + return format !== undefined && format.isAutoConvertible(); } isEditable(extension) { - let index = this.formats.findIndex(format => { - return format.name == extension && format.isEditable(); - }) - return index !== -1; + let format = this.findByExtension(extension); + return format !== undefined && format.isEditable(); } isFillable(extension) { - let index = this.formats.findIndex(format => { - return format.name == extension && format.isFillable(); - }) - return index !== -1; + let format = this.findByExtension(extension); + return format !== undefined && format.isFillable(); } } \ No newline at end of file From cc3c640868909045feef4b354a16bb803d50ab46 Mon Sep 17 00:00:00 2001 From: Serik Ibragimov Date: Mon, 1 Apr 2024 12:21:18 +0500 Subject: [PATCH 13/14] refactor: merge format and format-manager files into formats file --- .../csharp-mvc/Scripts/format.js | 39 ------- .../Scripts/{format-manager.js => formats.js} | 108 +++++++++++------- .../csharp/Default.aspx | 3 +- .../csharp/script/format.js | 39 ------- .../script/formats.js} | 22 ++++ .../main/resources/static/scripts/format.js | 39 ------- .../main/resources/static/scripts/formats.js} | 108 +++++++++++------- .../src/main/resources/templates/index.html | 3 +- .../java/src/main/webapp/index.jsp | 3 +- .../java/src/main/webapp/scripts/format.js | 39 ------- .../scripts/{format-manager.js => formats.js} | 22 ++++ .../public/javascripts/format-manager.js | 44 ------- .../nodejs/public/javascripts/format.js | 39 ------- .../nodejs/public/javascripts/formats.js | 66 +++++++++++ .../nodejs/views/index.ejs | 3 +- .../php/assets/js/format-manager.js | 44 ------- .../php/assets/js/format.js | 39 ------- .../php/assets/js/formats.js | 66 +++++++++++ .../php/templates/index.tpl | 3 +- .../python/static/js/format-manager.js | 44 ------- .../python/static/js/format.js | 39 ------- .../python/static/js/formats.js | 66 +++++++++++ .../python/templates/index.html | 3 +- .../app/assets/javascripts/format-manager.js | 44 ------- .../ruby/app/assets/javascripts/format.js | 39 ------- .../ruby/app/assets/javascripts/formats.js | 66 +++++++++++ 26 files changed, 444 insertions(+), 586 deletions(-) delete mode 100755 web/documentserver-example/csharp-mvc/Scripts/format.js rename web/documentserver-example/csharp-mvc/Scripts/{format-manager.js => formats.js} (72%) mode change 100755 => 100644 delete mode 100755 web/documentserver-example/csharp/script/format.js rename web/documentserver-example/{java-spring/src/main/resources/static/scripts/format-manager.js => csharp/script/formats.js} (72%) delete mode 100644 web/documentserver-example/java-spring/src/main/resources/static/scripts/format.js rename web/documentserver-example/{csharp/script/format-manager.js => java-spring/src/main/resources/static/scripts/formats.js} (72%) mode change 100755 => 100644 delete mode 100644 web/documentserver-example/java/src/main/webapp/scripts/format.js rename web/documentserver-example/java/src/main/webapp/scripts/{format-manager.js => formats.js} (72%) delete mode 100644 web/documentserver-example/nodejs/public/javascripts/format-manager.js delete mode 100644 web/documentserver-example/nodejs/public/javascripts/format.js create mode 100644 web/documentserver-example/nodejs/public/javascripts/formats.js delete mode 100644 web/documentserver-example/php/assets/js/format-manager.js delete mode 100644 web/documentserver-example/php/assets/js/format.js create mode 100644 web/documentserver-example/php/assets/js/formats.js delete mode 100644 web/documentserver-example/python/static/js/format-manager.js delete mode 100644 web/documentserver-example/python/static/js/format.js create mode 100644 web/documentserver-example/python/static/js/formats.js delete mode 100644 web/documentserver-example/ruby/app/assets/javascripts/format-manager.js delete mode 100644 web/documentserver-example/ruby/app/assets/javascripts/format.js create mode 100644 web/documentserver-example/ruby/app/assets/javascripts/formats.js diff --git a/web/documentserver-example/csharp-mvc/Scripts/format.js b/web/documentserver-example/csharp-mvc/Scripts/format.js deleted file mode 100755 index 9ee103a3..00000000 --- a/web/documentserver-example/csharp-mvc/Scripts/format.js +++ /dev/null @@ -1,39 +0,0 @@ -/** - * - * (c) Copyright Ascensio System SIA 2024 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -class Format { - constructor(name, type, actions, convert, mime) { - this.name = name; - this.type = type; - this.actions = actions; - this.convert = convert; - this.mime = mime; - } - - isAutoConvertible() { - return this.actions.includes('auto-convert'); - } - - isEditable() { - return this.actions.includes('edit') || this.actions.includes('lossy-edit'); - } - - isFillable() { - return this.actions.includes('fill'); - } -} diff --git a/web/documentserver-example/csharp-mvc/Scripts/format-manager.js b/web/documentserver-example/csharp-mvc/Scripts/formats.js old mode 100755 new mode 100644 similarity index 72% rename from web/documentserver-example/csharp-mvc/Scripts/format-manager.js rename to web/documentserver-example/csharp-mvc/Scripts/formats.js index fafac66b..e423eeb2 --- a/web/documentserver-example/csharp-mvc/Scripts/format-manager.js +++ b/web/documentserver-example/csharp-mvc/Scripts/formats.js @@ -1,44 +1,66 @@ -/** - * - * (c) Copyright Ascensio System SIA 2024 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -class FormatManager { - formats = []; - - constructor(formats) { - if(Array.isArray(formats)) this.formats = formats; - } - - findByExtension(extension) { - return this.formats.find(format => format.name == extension); - } - - isAutoConvertible(extension) { - let format = this.findByExtension(extension); - return format !== undefined && format.isAutoConvertible(); - } - - isEditable(extension) { - let format = this.findByExtension(extension); - return format !== undefined && format.isEditable(); - } - - isFillable(extension) { - let format = this.findByExtension(extension); - return format !== undefined && format.isFillable(); - } +/** + * + * (c) Copyright Ascensio System SIA 2024 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +class Format { + constructor(name, type, actions, convert, mime) { + this.name = name; + this.type = type; + this.actions = actions; + this.convert = convert; + this.mime = mime; + } + + isAutoConvertible() { + return this.actions.includes('auto-convert'); + } + + isEditable() { + return this.actions.includes('edit') || this.actions.includes('lossy-edit'); + } + + isFillable() { + return this.actions.includes('fill'); + } +} + +class FormatManager { + formats = []; + + constructor(formats) { + if(Array.isArray(formats)) this.formats = formats; + } + + findByExtension(extension) { + return this.formats.find(format => format.name == extension); + } + + isAutoConvertible(extension) { + let format = this.findByExtension(extension); + return format !== undefined && format.isAutoConvertible(); + } + + isEditable(extension) { + let format = this.findByExtension(extension); + return format !== undefined && format.isEditable(); + } + + isFillable(extension) { + let format = this.findByExtension(extension); + return format !== undefined && format.isFillable(); + } } \ No newline at end of file diff --git a/web/documentserver-example/csharp/Default.aspx b/web/documentserver-example/csharp/Default.aspx index 3a11f5c5..42dabe8a 100644 --- a/web/documentserver-example/csharp/Default.aspx +++ b/web/documentserver-example/csharp/Default.aspx @@ -364,8 +364,7 @@ - - + diff --git a/web/documentserver-example/csharp/script/format.js b/web/documentserver-example/csharp/script/format.js deleted file mode 100755 index 9ee103a3..00000000 --- a/web/documentserver-example/csharp/script/format.js +++ /dev/null @@ -1,39 +0,0 @@ -/** - * - * (c) Copyright Ascensio System SIA 2024 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -class Format { - constructor(name, type, actions, convert, mime) { - this.name = name; - this.type = type; - this.actions = actions; - this.convert = convert; - this.mime = mime; - } - - isAutoConvertible() { - return this.actions.includes('auto-convert'); - } - - isEditable() { - return this.actions.includes('edit') || this.actions.includes('lossy-edit'); - } - - isFillable() { - return this.actions.includes('fill'); - } -} diff --git a/web/documentserver-example/java-spring/src/main/resources/static/scripts/format-manager.js b/web/documentserver-example/csharp/script/formats.js similarity index 72% rename from web/documentserver-example/java-spring/src/main/resources/static/scripts/format-manager.js rename to web/documentserver-example/csharp/script/formats.js index 5b167856..e423eeb2 100644 --- a/web/documentserver-example/java-spring/src/main/resources/static/scripts/format-manager.js +++ b/web/documentserver-example/csharp/script/formats.js @@ -16,6 +16,28 @@ * */ +class Format { + constructor(name, type, actions, convert, mime) { + this.name = name; + this.type = type; + this.actions = actions; + this.convert = convert; + this.mime = mime; + } + + isAutoConvertible() { + return this.actions.includes('auto-convert'); + } + + isEditable() { + return this.actions.includes('edit') || this.actions.includes('lossy-edit'); + } + + isFillable() { + return this.actions.includes('fill'); + } +} + class FormatManager { formats = []; diff --git a/web/documentserver-example/java-spring/src/main/resources/static/scripts/format.js b/web/documentserver-example/java-spring/src/main/resources/static/scripts/format.js deleted file mode 100644 index 21cd09a1..00000000 --- a/web/documentserver-example/java-spring/src/main/resources/static/scripts/format.js +++ /dev/null @@ -1,39 +0,0 @@ -/** - * - * (c) Copyright Ascensio System SIA 2024 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -class Format { - constructor(name, type, actions, convert, mime) { - this.name = name; - this.type = type; - this.actions = actions; - this.convert = convert; - this.mime = mime; - } - - isAutoConvertible() { - return this.actions.includes('auto-convert'); - } - - isEditable() { - return this.actions.includes('edit') || this.actions.includes('lossy-edit'); - } - - isFillable() { - return this.actions.includes('fill'); - } -} \ No newline at end of file diff --git a/web/documentserver-example/csharp/script/format-manager.js b/web/documentserver-example/java-spring/src/main/resources/static/scripts/formats.js old mode 100755 new mode 100644 similarity index 72% rename from web/documentserver-example/csharp/script/format-manager.js rename to web/documentserver-example/java-spring/src/main/resources/static/scripts/formats.js index fafac66b..e423eeb2 --- a/web/documentserver-example/csharp/script/format-manager.js +++ b/web/documentserver-example/java-spring/src/main/resources/static/scripts/formats.js @@ -1,44 +1,66 @@ -/** - * - * (c) Copyright Ascensio System SIA 2024 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -class FormatManager { - formats = []; - - constructor(formats) { - if(Array.isArray(formats)) this.formats = formats; - } - - findByExtension(extension) { - return this.formats.find(format => format.name == extension); - } - - isAutoConvertible(extension) { - let format = this.findByExtension(extension); - return format !== undefined && format.isAutoConvertible(); - } - - isEditable(extension) { - let format = this.findByExtension(extension); - return format !== undefined && format.isEditable(); - } - - isFillable(extension) { - let format = this.findByExtension(extension); - return format !== undefined && format.isFillable(); - } +/** + * + * (c) Copyright Ascensio System SIA 2024 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +class Format { + constructor(name, type, actions, convert, mime) { + this.name = name; + this.type = type; + this.actions = actions; + this.convert = convert; + this.mime = mime; + } + + isAutoConvertible() { + return this.actions.includes('auto-convert'); + } + + isEditable() { + return this.actions.includes('edit') || this.actions.includes('lossy-edit'); + } + + isFillable() { + return this.actions.includes('fill'); + } +} + +class FormatManager { + formats = []; + + constructor(formats) { + if(Array.isArray(formats)) this.formats = formats; + } + + findByExtension(extension) { + return this.formats.find(format => format.name == extension); + } + + isAutoConvertible(extension) { + let format = this.findByExtension(extension); + return format !== undefined && format.isAutoConvertible(); + } + + isEditable(extension) { + let format = this.findByExtension(extension); + return format !== undefined && format.isEditable(); + } + + isFillable(extension) { + let format = this.findByExtension(extension); + return format !== undefined && format.isFillable(); + } } \ No newline at end of file diff --git a/web/documentserver-example/java-spring/src/main/resources/templates/index.html b/web/documentserver-example/java-spring/src/main/resources/templates/index.html index df6241d8..3eaff80c 100755 --- a/web/documentserver-example/java-spring/src/main/resources/templates/index.html +++ b/web/documentserver-example/java-spring/src/main/resources/templates/index.html @@ -341,8 +341,7 @@ - - + - - + - - + - - + \ No newline at end of file diff --git a/web/documentserver-example/python/static/js/format-manager.js b/web/documentserver-example/python/static/js/format-manager.js deleted file mode 100644 index 5b167856..00000000 --- a/web/documentserver-example/python/static/js/format-manager.js +++ /dev/null @@ -1,44 +0,0 @@ -/** - * - * (c) Copyright Ascensio System SIA 2024 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -class FormatManager { - formats = []; - - constructor(formats) { - if(Array.isArray(formats)) this.formats = formats; - } - - findByExtension(extension) { - return this.formats.find(format => format.name == extension); - } - - isAutoConvertible(extension) { - let format = this.findByExtension(extension); - return format !== undefined && format.isAutoConvertible(); - } - - isEditable(extension) { - let format = this.findByExtension(extension); - return format !== undefined && format.isEditable(); - } - - isFillable(extension) { - let format = this.findByExtension(extension); - return format !== undefined && format.isFillable(); - } -} \ No newline at end of file diff --git a/web/documentserver-example/python/static/js/format.js b/web/documentserver-example/python/static/js/format.js deleted file mode 100644 index 21cd09a1..00000000 --- a/web/documentserver-example/python/static/js/format.js +++ /dev/null @@ -1,39 +0,0 @@ -/** - * - * (c) Copyright Ascensio System SIA 2024 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -class Format { - constructor(name, type, actions, convert, mime) { - this.name = name; - this.type = type; - this.actions = actions; - this.convert = convert; - this.mime = mime; - } - - isAutoConvertible() { - return this.actions.includes('auto-convert'); - } - - isEditable() { - return this.actions.includes('edit') || this.actions.includes('lossy-edit'); - } - - isFillable() { - return this.actions.includes('fill'); - } -} \ No newline at end of file diff --git a/web/documentserver-example/python/static/js/formats.js b/web/documentserver-example/python/static/js/formats.js new file mode 100644 index 00000000..e423eeb2 --- /dev/null +++ b/web/documentserver-example/python/static/js/formats.js @@ -0,0 +1,66 @@ +/** + * + * (c) Copyright Ascensio System SIA 2024 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +class Format { + constructor(name, type, actions, convert, mime) { + this.name = name; + this.type = type; + this.actions = actions; + this.convert = convert; + this.mime = mime; + } + + isAutoConvertible() { + return this.actions.includes('auto-convert'); + } + + isEditable() { + return this.actions.includes('edit') || this.actions.includes('lossy-edit'); + } + + isFillable() { + return this.actions.includes('fill'); + } +} + +class FormatManager { + formats = []; + + constructor(formats) { + if(Array.isArray(formats)) this.formats = formats; + } + + findByExtension(extension) { + return this.formats.find(format => format.name == extension); + } + + isAutoConvertible(extension) { + let format = this.findByExtension(extension); + return format !== undefined && format.isAutoConvertible(); + } + + isEditable(extension) { + let format = this.findByExtension(extension); + return format !== undefined && format.isEditable(); + } + + isFillable(extension) { + let format = this.findByExtension(extension); + return format !== undefined && format.isFillable(); + } +} \ No newline at end of file diff --git a/web/documentserver-example/python/templates/index.html b/web/documentserver-example/python/templates/index.html index bfa9fe95..31d0a83c 100644 --- a/web/documentserver-example/python/templates/index.html +++ b/web/documentserver-example/python/templates/index.html @@ -338,8 +338,7 @@ - - + +