diff --git a/OnlyOffice/api/api.lua b/OnlyOffice/api/api.lua index 144b491..451fd95 100644 --- a/OnlyOffice/api/api.lua +++ b/OnlyOffice/api/api.lua @@ -26,8 +26,24 @@ handle.token = function() return result("sessionid="..SESSION.sessionid) end +handle.duplicate = function(data) + local file = vfs.ospath(data.as) + local tmpfile = "/tmp/"..std.sha1(file) + local cmd = "curl -o "..tmpfile..' "'..data.remote..'"' + os.execute(cmd) + -- move file to correct position + if ulib.exists(tmpfile) then + cmd = "mv "..tmpfile.." "..file + os.execute(cmd) + print("File "..file.." is duplicated with remote") + else + return error("Unable to duplicate file") + end + return result("File duplicated") +end + handle.save = function() - print(JSON.encode(REQUEST)) + --print(JSON.encode(REQUEST)) if not REQUEST.json then return error("Invalid request") end @@ -40,17 +56,23 @@ handle.save = function() end local file = vfs.ospath(REQUEST.file) if data.status == 2 then - print("download to"..file) - if not web.download(data.url, file) then - print("Unable to download") - return error("Unable to save file") + local tmpfile = "/tmp/"..std.sha1(file) + local cmd = "curl -o "..tmpfile..' "'..data.url..'"' + os.execute(cmd) + -- move file to correct position + if ulib.exists(tmpfile) then + cmd = "mv "..tmpfile.." "..file + os.execute(cmd) + print("File "..file.." sync with remote") + else + return error("Unable to download") end end return result("OK") end -print(JSON.encode(args)) +--print(JSON.encode(args)) if args.action and handle[args.action] then return handle[args.action](args.args) diff --git a/OnlyOffice/assets/icon.png b/OnlyOffice/assets/icon.png new file mode 100644 index 0000000..21d6726 Binary files /dev/null and b/OnlyOffice/assets/icon.png differ diff --git a/OnlyOffice/assets/scheme.html b/OnlyOffice/assets/scheme.html index 1f0b62f..cb1efa8 100644 --- a/OnlyOffice/assets/scheme.html +++ b/OnlyOffice/assets/scheme.html @@ -1,5 +1,18 @@ -
+
+

+ +

+

+ +

+

+ +

+

+ +

+
\ No newline at end of file diff --git a/OnlyOffice/assets/templates/model.docx b/OnlyOffice/assets/templates/model.docx new file mode 100644 index 0000000..d167663 Binary files /dev/null and b/OnlyOffice/assets/templates/model.docx differ diff --git a/OnlyOffice/assets/templates/model.pptx b/OnlyOffice/assets/templates/model.pptx new file mode 100644 index 0000000..a795055 Binary files /dev/null and b/OnlyOffice/assets/templates/model.pptx differ diff --git a/OnlyOffice/assets/templates/model.xlsx b/OnlyOffice/assets/templates/model.xlsx new file mode 100644 index 0000000..6c7b924 Binary files /dev/null and b/OnlyOffice/assets/templates/model.xlsx differ diff --git a/OnlyOffice/build/debug/api.lua b/OnlyOffice/build/debug/api.lua index 144b491..451fd95 100644 --- a/OnlyOffice/build/debug/api.lua +++ b/OnlyOffice/build/debug/api.lua @@ -26,8 +26,24 @@ handle.token = function() return result("sessionid="..SESSION.sessionid) end +handle.duplicate = function(data) + local file = vfs.ospath(data.as) + local tmpfile = "/tmp/"..std.sha1(file) + local cmd = "curl -o "..tmpfile..' "'..data.remote..'"' + os.execute(cmd) + -- move file to correct position + if ulib.exists(tmpfile) then + cmd = "mv "..tmpfile.." "..file + os.execute(cmd) + print("File "..file.." is duplicated with remote") + else + return error("Unable to duplicate file") + end + return result("File duplicated") +end + handle.save = function() - print(JSON.encode(REQUEST)) + --print(JSON.encode(REQUEST)) if not REQUEST.json then return error("Invalid request") end @@ -40,17 +56,23 @@ handle.save = function() end local file = vfs.ospath(REQUEST.file) if data.status == 2 then - print("download to"..file) - if not web.download(data.url, file) then - print("Unable to download") - return error("Unable to save file") + local tmpfile = "/tmp/"..std.sha1(file) + local cmd = "curl -o "..tmpfile..' "'..data.url..'"' + os.execute(cmd) + -- move file to correct position + if ulib.exists(tmpfile) then + cmd = "mv "..tmpfile.." "..file + os.execute(cmd) + print("File "..file.." sync with remote") + else + return error("Unable to download") end end return result("OK") end -print(JSON.encode(args)) +--print(JSON.encode(args)) if args.action and handle[args.action] then return handle[args.action](args.args) diff --git a/OnlyOffice/build/debug/icon.png b/OnlyOffice/build/debug/icon.png new file mode 100644 index 0000000..21d6726 Binary files /dev/null and b/OnlyOffice/build/debug/icon.png differ diff --git a/OnlyOffice/build/debug/main.css b/OnlyOffice/build/debug/main.css new file mode 100644 index 0000000..6deea5e --- /dev/null +++ b/OnlyOffice/build/debug/main.css @@ -0,0 +1,9 @@ + +afx-app-window[data-id="OnlyOffice"] div[data-id="editor-area"] p{ + text-align: center; +} + +afx-app-window[data-id="OnlyOffice"] div[data-id="editor-area"] button { + width: 250px; + +} \ No newline at end of file diff --git a/OnlyOffice/build/debug/main.js b/OnlyOffice/build/debug/main.js index 249ee6f..9c7f42f 100644 --- a/OnlyOffice/build/debug/main.js +++ b/OnlyOffice/build/debug/main.js @@ -8,23 +8,87 @@ } main() { - var placeholder; this.currfile = void 0; if (this.args && this.args.length > 0) { this.currfile = this.args[0].path.asFileHandle(); } - placeholder = this.find("editor-area"); - placeholder.id = this.eid; + this.placeholder = this.find("editor-area"); + this.placeholder.id = this.eid; + this.find("btn-open-file").onbtclick = (e) => { + return this.openFile(); + }; + this.find("btn-new-doc").onbtclick = (e) => { + return this.create("word"); + }; + this.find("btn-new-cell").onbtclick = (e) => { + return this.create("sheet"); + }; + this.find("btn-new-slide").onbtclick = (e) => { + return this.create("slide"); + }; if (this.currfile) { return this.open(); } } + create(type) { + var ext; + ext = void 0; + if (type === "word") { + ext = "docx"; + } + if (type === "sheet") { + ext = "xlsx"; + } + if (type === "slide") { + ext = "pptx"; + } + if (!ext) { + return this.error(__("Unkown file type")); + } + return this.openDialog("FileDialog", { + title: __("Save file as"), + type: "dir", + file: `home://Untitled.${ext}`.asFileHandle() + }).then((d) => { + var file, model; + file = `${d.file.path}/${d.name}`.asFileHandle(); + // copy file to destination + model = `${this.path()}/templates/model.${ext}`.asFileHandle(); + return model.read("binary").then((d) => { + var blob; + blob = new Blob([d], { + type: model.info.mime + }); + file.cache = blob; + return file.write(model.info.mime).then((r) => { + file.cache = void 0; + this.currfile = file; + return this.open(); + }).catch((e) => { + return this.error(e.toString(), e); + }); + }).catch((err) => { + return this.error(err.toString(), err); + }); + }); + } + + openFile() { + return this.openDialog("FileDialog", { + title: __("Open file"), + type: "file", + mimes: this.meta().mimes + }).then((f, name) => { + this.currfile = f.file.path.asFileHandle(); + return this.open(); + }); + } + open() { if (!this.currfile) { return; } - console.log(this.currfile); return this.exec("token", { file: this.currfile.path }).then((d) => { @@ -33,8 +97,9 @@ } this.access_token = d.result; return this.currfile.onready().then((meta) => { + this.scheme.apptitle = this.currfile.path; + $(this.placeholder).empty(); if (this.editor) { - //@scheme.apptitle = @currfile.path this.editor.destroyEditor(); } return this.editor = new DocsAPI.DocEditor(this.eid, { @@ -43,13 +108,13 @@ return this.newDocument(); }, onRequestSaveAs: (e) => { - return console.log(e); + return this.saveAs(e); } }, document: { fileType: this.currfile.ext, key: meta.mtime.hash().toString(), - title: this.currfile.path, + title: this.currfile.filename, url: this.currfile.getlink() + "?" + this.access_token }, documentType: this.getDocType(this.currfile.ext), @@ -86,12 +151,67 @@ } saveAs(e) { - return console.log(e); + var rfile; + if (!e.data.url) { + return; + } + rfile = e.data.url.asFileHandle(); + return this.openDialog("FileDialog", { + title: __("Save file as"), + type: "dir", + file: `home://${e.data.title}`.asFileHandle() + }).then((d) => { + var file; + file = `${d.file.path}/${d.name}`; + // copy file to destination + return this.exec("duplicate", { + remote: e.data.url, + as: file + }).then((r) => { + if (r.error) { + return this.error(r.error); + } + this.currfile = file.asFileHandle(); + return this.open(); + }).catch((e) => { + return this.error(e.toString(), e); + }); + }); } newDocument() { - console.log("create document"); - return this.error(__("Unable to create document")); + return this.openDialog("SelectionDialog", { + title: __("Create new"), + data: [ + { + text: __("Open a file"), + iconclass: "fa fa-folder-open", + type: "open" + }, + { + text: __("Document"), + iconclass: "fa fa-file-word-o", + type: "word" + }, + { + text: __("Spreadsheet"), + iconclass: "fa fa-file-excel-o", + type: "sheet" + }, + { + text: __("Presentation"), + iconclass: "fa fa-file-powerpoint-o", + type: "slide" + } + ] + }).then((d) => { + switch (d.type) { + case "open": + return this.openFile(); + default: + return this.create(d.type); + } + }); } uapi(action) { diff --git a/OnlyOffice/build/debug/package.json b/OnlyOffice/build/debug/package.json index 26e9ddc..cc0de41 100644 --- a/OnlyOffice/build/debug/package.json +++ b/OnlyOffice/build/debug/package.json @@ -9,7 +9,7 @@ }, "version":"0.0.1-a", "category":"Other", - "iconclass":"fa fa-adn", + "icon":"icon.png", "mimes":[ "application/vnd.oasis.opendocument.text", "application/vnd.oasis.opendocument.spreadsheet", diff --git a/OnlyOffice/build/debug/scheme.html b/OnlyOffice/build/debug/scheme.html index 1f0b62f..cb1efa8 100644 --- a/OnlyOffice/build/debug/scheme.html +++ b/OnlyOffice/build/debug/scheme.html @@ -1,5 +1,18 @@ -
+
+

+ +

+

+ +

+

+ +

+

+ +

+
\ No newline at end of file diff --git a/OnlyOffice/build/debug/templates/model.docx b/OnlyOffice/build/debug/templates/model.docx new file mode 100644 index 0000000..d167663 Binary files /dev/null and b/OnlyOffice/build/debug/templates/model.docx differ diff --git a/OnlyOffice/build/debug/templates/model.pptx b/OnlyOffice/build/debug/templates/model.pptx new file mode 100644 index 0000000..a795055 Binary files /dev/null and b/OnlyOffice/build/debug/templates/model.pptx differ diff --git a/OnlyOffice/build/debug/templates/model.xlsx b/OnlyOffice/build/debug/templates/model.xlsx new file mode 100644 index 0000000..6c7b924 Binary files /dev/null and b/OnlyOffice/build/debug/templates/model.xlsx differ diff --git a/OnlyOffice/build/release/OnlyOffice.zip b/OnlyOffice/build/release/OnlyOffice.zip new file mode 100644 index 0000000..357d655 Binary files /dev/null and b/OnlyOffice/build/release/OnlyOffice.zip differ diff --git a/OnlyOffice/coffees/main.coffee b/OnlyOffice/coffees/main.coffee index 3fb105b..ffd0966 100644 --- a/OnlyOffice/coffees/main.coffee +++ b/OnlyOffice/coffees/main.coffee @@ -7,30 +7,87 @@ class OnlyOffice extends this.OS.application.BaseApplication @currfile = undefined if @args and @args.length > 0 @currfile = @args[0].path.asFileHandle() - placeholder = @find "editor-area" - placeholder.id = @eid + @placeholder = @find "editor-area" + @placeholder.id = @eid + + @find("btn-open-file").onbtclick = (e) => + @openFile() + + @find("btn-new-doc").onbtclick = (e) => + @create("word") + + @find("btn-new-cell").onbtclick = (e) => + @create("sheet") + + @find("btn-new-slide").onbtclick = (e) => + @create("slide") + @open() if @currfile + + create: (type) -> + ext = undefined + ext = "docx" if type is "word" + ext = "xlsx" if type is "sheet" + ext = "pptx" if type is "slide" + return @error __("Unkown file type") unless ext + @openDialog "FileDialog", { + title: __("Save file as"), + type: "dir", + file: "home://Untitled.#{ext}".asFileHandle() + } + .then (d) => + file = "#{d.file.path}/#{d.name}".asFileHandle() + # copy file to destination + model = "#{@path()}/templates/model.#{ext}".asFileHandle() + model + .read("binary") + .then (d) => + blob = new Blob([d], { + type: model.info.mime, + }) + file.cache = blob + file + .write(model.info.mime) + .then (r) => + file.cache = undefined + @currfile = file + @open() + .catch (e) => + @error e.toString(), e + .catch (err) => + @error err.toString(), err + + openFile: () -> + @openDialog "FileDialog", { + title: __("Open file"), + type: "file", + mimes: @meta().mimes + } + .then (f, name) => + @currfile = f.file.path.asFileHandle() + @open() + open: () -> return unless @currfile - console.log @currfile @exec("token", {file: @currfile.path}) .then (d) => return @error d.error if d.error @access_token = d.result @currfile.onready() .then (meta) => - #@scheme.apptitle = @currfile.path + @scheme.apptitle = @currfile.path + $(@placeholder).empty() @editor.destroyEditor() if @editor @editor = new DocsAPI.DocEditor(@eid, { events: { onRequestCreateNew: () => @newDocument(), - onRequestSaveAs: (e) => console.log e + onRequestSaveAs: (e) => @saveAs(e) }, document: { fileType: @currfile.ext, key: meta.mtime.hash().toString(), - title: @currfile.path, + title: @currfile.filename, url: @currfile.getlink() + "?" + @access_token }, documentType: @getDocType(@currfile.ext), @@ -57,11 +114,58 @@ class OnlyOffice extends this.OS.application.BaseApplication return "none" saveAs: (e) -> - console.log e + return unless e.data.url + rfile = e.data.url.asFileHandle() + @openDialog "FileDialog", { + title: __("Save file as"), + type: "dir", + file: "home://#{e.data.title}".asFileHandle() + } + .then (d) => + file = "#{d.file.path}/#{d.name}" + # copy file to destination + @exec("duplicate", { + remote: e.data.url, + as: file + }).then (r) => + return @error r.error if r.error + @currfile = file.asFileHandle() + @open() + .catch (e) => + @error e.toString(), e newDocument: () -> - console.log("create document") - @error __("Unable to create document") + @openDialog "SelectionDialog", { + title: __("Create new"), + data:[ + { + text: __("Open a file"), + iconclass: "fa fa-folder-open", + type: "open" + }, + { + text: __("Document"), + iconclass: "fa fa-file-word-o", + type: "word" + }, + { + text: __("Spreadsheet"), + iconclass: "fa fa-file-excel-o", + type: "sheet" + }, + { + text: __("Presentation"), + iconclass: "fa fa-file-powerpoint-o", + type: "slide" + }, + ] + } + .then (d) => + switch d.type + when "open" + @openFile() + else + @create(d.type) uapi: (action) -> return "#{@_api.REST}/system/apigateway?ws=0&path=#{@path()}/api.lua&action=#{action}&file=#{@currfile.path}&#{@access_token}" diff --git a/OnlyOffice/css/main.css b/OnlyOffice/css/main.css new file mode 100644 index 0000000..1231545 --- /dev/null +++ b/OnlyOffice/css/main.css @@ -0,0 +1,8 @@ +afx-app-window[data-id="OnlyOffice"] div[data-id="editor-area"] p{ + text-align: center; +} + +afx-app-window[data-id="OnlyOffice"] div[data-id="editor-area"] button { + width: 250px; + +} \ No newline at end of file diff --git a/OnlyOffice/package.json b/OnlyOffice/package.json index 26e9ddc..cc0de41 100644 --- a/OnlyOffice/package.json +++ b/OnlyOffice/package.json @@ -9,7 +9,7 @@ }, "version":"0.0.1-a", "category":"Other", - "iconclass":"fa fa-adn", + "icon":"icon.png", "mimes":[ "application/vnd.oasis.opendocument.text", "application/vnd.oasis.opendocument.spreadsheet", diff --git a/OnlyOffice/project.json b/OnlyOffice/project.json index 942253d..3f36d4e 100644 --- a/OnlyOffice/project.json +++ b/OnlyOffice/project.json @@ -1,7 +1,7 @@ { "name": "OnlyOffice", - "css": [], + "css": ["css/main.css"], "javascripts": [], "coffees": ["coffees/main.coffee"], - "copies": ["api/api.lua", "assets/scheme.html", "package.json", "README.md"] + "copies": ["assets/templates", "assets/icon.png","api/api.lua", "assets/scheme.html", "package.json", "README.md"] } \ No newline at end of file