From ab03bb549038f82f35c59f1ad4ef7d9a0ee076ac Mon Sep 17 00:00:00 2001 From: metoou Date: Tue, 8 Jun 2021 13:31:40 +0300 Subject: [PATCH] nodejs: added the ability to Create New from templates for user "John Smith" --- web/documentserver-example/nodejs/app.js | 22 ++++++++++++++++--- .../nodejs/helpers/docManager.js | 14 ++++++++++++ .../nodejs/helpers/users.js | 17 +++++++++----- .../nodejs/views/config.ejs | 3 ++- 4 files changed, 46 insertions(+), 10 deletions(-) diff --git a/web/documentserver-example/nodejs/app.js b/web/documentserver-example/nodejs/app.js index 51b73d8b..66b2943f 100644 --- a/web/documentserver-example/nodejs/app.js +++ b/web/documentserver-example/nodejs/app.js @@ -628,6 +628,7 @@ app.get("/editor", function (req, res) { // define a handler for editing docume docManager.init(storageFolder, req, res); + var fileName = fileUtility.getFileName(req.query.fileName); var fileExt = req.query.fileExt; var history = []; var historyData = []; @@ -638,6 +639,21 @@ app.get("/editor", function (req, res) { // define a handler for editing docume var name = user.name; var actionData = req.query.action ? req.query.action : "null"; + var templatesImageUrl = docManager.getTemplateImageUrl(fileUtility.getFileType(fileName)); + var createUrl = docManager.getCreateUrl(fileUtility.getFileType(fileName), userid, type, lang); + var templates = [ + { + "image": templatesImageUrl, + "title": "Blank", + "url": createUrl + }, + { + "image": templatesImageUrl, + "title": "With sample content", + "url": createUrl + "&sample=true" + } + ]; + var userGroup = user.group; var reviewGroups = user.reviewGroups; @@ -651,7 +667,6 @@ app.get("/editor", function (req, res) { // define a handler for editing docume } var userAddress = docManager.curUserHostAddress(); - var fileName = fileUtility.getFileName(req.query.fileName); if (!docManager.existsSync(docManager.storagePath(fileName, userAddress))) { // if the file with a given name doesn't exist throw { "message": "File not found: " + fileName // display error message @@ -741,7 +756,8 @@ app.get("/editor", function (req, res) { // define a handler for editing docume key: key, token: "", callbackUrl: docManager.getCallback(fileName), - createUrl: docManager.getCreateUrl(fileUtility.getFileType(fileName), userid, type, lang), + createUrl: userid != "uid-0" ? createUrl : null, + templates: user.templates ? templates : null, isEdit: canEdit && (mode == "edit" || mode == "view" || mode == "filter" || mode == "blockcontent"), review: canEdit && (mode == "edit" || mode == "review"), comment: mode != "view" && mode != "fillForms" && mode != "embedded" && mode != "blockcontent", @@ -779,7 +795,7 @@ app.get("/editor", function (req, res) { // define a handler for editing docume fileType: "csv", url: docManager.getServerUrl(true) + "/csv" }, - usersForMentions: user.id != "uid-0" ? users.getUsersForMentions(user.id) : null + usersForMentions: user.id != "uid-0" ? users.getUsersForMentions(user.id) : null, }; if (cfgSignatureEnable) { diff --git a/web/documentserver-example/nodejs/helpers/docManager.js b/web/documentserver-example/nodejs/helpers/docManager.js index 33387500..f1888f1a 100644 --- a/web/documentserver-example/nodejs/helpers/docManager.js +++ b/web/documentserver-example/nodejs/helpers/docManager.js @@ -331,6 +331,20 @@ docManager.getInternalExtension = function (fileType) { return ".docx"; // the default value is .docx }; +docManager.getTemplateImageUrl = function (fileType) { + let path = docManager.getServerUrl(true); + if (fileType == fileUtility.fileType.word) // for word type + return path + "/images/file_docx.svg"; + + if (fileType == fileUtility.fileType.cell) // for cell type + return path + "/images/file_xlsx.svg"; + + if (fileType == fileUtility.fileType.slide) // for slide type + return path + "/images/file_pptx.svg"; + + return path + "/images/file_docx.svg"; // the default value +} + // get document key docManager.getKey = function (fileName) { const userAddress = docManager.curUserHostAddress(); diff --git a/web/documentserver-example/nodejs/helpers/users.js b/web/documentserver-example/nodejs/helpers/users.js index 2acf3680..42546613 100644 --- a/web/documentserver-example/nodejs/helpers/users.js +++ b/web/documentserver-example/nodejs/helpers/users.js @@ -47,13 +47,13 @@ var descr_user_0 = [ ]; var users = [ - new User("uid-1", "John Smith", "smith@mail.ru", null, null, null, [], descr_user_1), - new User("uid-2", "Mark Pottato", "pottato@mail.ru", "group-2", ["group-2", ""], true, [], descr_user_2), // own and without group - new User("uid-3", "Hamish Mitchell", "mitchell@mail.ru", "group-3", ["group-2"], false, ["copy", "download", "print"], descr_user_3), // other group only - new User("uid-0", null, null, null, null, null, [], descr_user_0), + new User("uid-1", "John Smith", "smith@mail.ru", null, null, null, [], descr_user_1, true), + new User("uid-2", "Mark Pottato", "pottato@mail.ru", "group-2", ["group-2", ""], true, [], descr_user_2, false), // own and without group + new User("uid-3", "Hamish Mitchell", "mitchell@mail.ru", "group-3", ["group-2"], false, ["copy", "download", "print"], descr_user_3, false), // other group only + new User("uid-0", null, null, null, null, null, [], descr_user_0, false), ]; -function User(id, name, email, group, reviewGroups, favorite, deniedPermissions, descriptions) { +function User(id, name, email, group, reviewGroups, favorite, deniedPermissions, descriptions, templates) { this.id = id; this.name = name; this.email = email; @@ -62,6 +62,11 @@ function User(id, name, email, group, reviewGroups, favorite, deniedPermissions, this.favorite = favorite; this.deniedPermissions = deniedPermissions; this.descriptions = descriptions; + this.templates = templates; +}; + +users.getAllUsers = function () { + return users; }; users.getUser = function (id) { @@ -82,6 +87,6 @@ users.getUsersForMentions = function (id) { } }); return result; -} +}; module.exports = users; \ No newline at end of file diff --git a/web/documentserver-example/nodejs/views/config.ejs b/web/documentserver-example/nodejs/views/config.ejs index b176fa90..c15858cc 100644 --- a/web/documentserver-example/nodejs/views/config.ejs +++ b/web/documentserver-example/nodejs/views/config.ejs @@ -31,7 +31,8 @@ "mode": "<%- editor.mode %>", "lang": "<%- editor.lang %>", "callbackUrl": "<%- editor.callbackUrl %>", - "createUrl": "<%- editor.createUrl%>", + "createUrl": <%- JSON.stringify(editor.createUrl) %>, + "templates": <%- JSON.stringify(editor.templates) %>, "user": { "group": "<%- editor.userGroup %>", "id": "<%- editor.userid %>",