mirror of
https://github.com/antos-rde/antosdk-apps.git
synced 2024-11-08 06:28:29 +01:00
first complete version
This commit is contained in:
parent
46d271ad90
commit
efb58ea93d
@ -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)
|
||||
|
BIN
OnlyOffice/assets/icon.png
Normal file
BIN
OnlyOffice/assets/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.8 KiB |
@ -1,5 +1,18 @@
|
||||
<afx-app-window apptitle="Office Suite" width="700" height="500" data-id="OnlyOffice">
|
||||
<afx-hbox >
|
||||
<div data-id="editor-area" id='placeholder'></div>
|
||||
<div data-id="editor-area" id='placeholder'>
|
||||
<p>
|
||||
<afx-button data-id="btn-open-file" text="__(Open file)" iconclass="fa fa-folder-open" ></afx-button>
|
||||
</p>
|
||||
<p>
|
||||
<afx-button data-id="btn-new-doc" text="__(Create Document)" iconclass="fa fa-file-word-o"></afx-button>
|
||||
</p>
|
||||
<p>
|
||||
<afx-button data-id="btn-new-cell" text="__(Create Spreadsheet)" iconclass="fa fa-file-excel-o"></afx-button>
|
||||
</p>
|
||||
<p>
|
||||
<afx-button data-id="btn-new-slide" text="__(Create Presentation)" iconclass="fa fa-file-powerpoint-o"></afx-button>
|
||||
</p>
|
||||
</div>
|
||||
</afx-hbox>
|
||||
</afx-app-window>
|
BIN
OnlyOffice/assets/templates/model.docx
Normal file
BIN
OnlyOffice/assets/templates/model.docx
Normal file
Binary file not shown.
BIN
OnlyOffice/assets/templates/model.pptx
Normal file
BIN
OnlyOffice/assets/templates/model.pptx
Normal file
Binary file not shown.
BIN
OnlyOffice/assets/templates/model.xlsx
Normal file
BIN
OnlyOffice/assets/templates/model.xlsx
Normal file
Binary file not shown.
@ -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)
|
||||
|
BIN
OnlyOffice/build/debug/icon.png
Normal file
BIN
OnlyOffice/build/debug/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.8 KiB |
9
OnlyOffice/build/debug/main.css
Normal file
9
OnlyOffice/build/debug/main.css
Normal file
@ -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;
|
||||
|
||||
}
|
@ -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) {
|
||||
|
@ -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",
|
||||
|
@ -1,5 +1,18 @@
|
||||
<afx-app-window apptitle="Office Suite" width="700" height="500" data-id="OnlyOffice">
|
||||
<afx-hbox >
|
||||
<div data-id="editor-area" id='placeholder'></div>
|
||||
<div data-id="editor-area" id='placeholder'>
|
||||
<p>
|
||||
<afx-button data-id="btn-open-file" text="__(Open file)" iconclass="fa fa-folder-open" ></afx-button>
|
||||
</p>
|
||||
<p>
|
||||
<afx-button data-id="btn-new-doc" text="__(Create Document)" iconclass="fa fa-file-word-o"></afx-button>
|
||||
</p>
|
||||
<p>
|
||||
<afx-button data-id="btn-new-cell" text="__(Create Spreadsheet)" iconclass="fa fa-file-excel-o"></afx-button>
|
||||
</p>
|
||||
<p>
|
||||
<afx-button data-id="btn-new-slide" text="__(Create Presentation)" iconclass="fa fa-file-powerpoint-o"></afx-button>
|
||||
</p>
|
||||
</div>
|
||||
</afx-hbox>
|
||||
</afx-app-window>
|
BIN
OnlyOffice/build/debug/templates/model.docx
Normal file
BIN
OnlyOffice/build/debug/templates/model.docx
Normal file
Binary file not shown.
BIN
OnlyOffice/build/debug/templates/model.pptx
Normal file
BIN
OnlyOffice/build/debug/templates/model.pptx
Normal file
Binary file not shown.
BIN
OnlyOffice/build/debug/templates/model.xlsx
Normal file
BIN
OnlyOffice/build/debug/templates/model.xlsx
Normal file
Binary file not shown.
BIN
OnlyOffice/build/release/OnlyOffice.zip
Normal file
BIN
OnlyOffice/build/release/OnlyOffice.zip
Normal file
Binary file not shown.
@ -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}"
|
||||
|
8
OnlyOffice/css/main.css
Normal file
8
OnlyOffice/css/main.css
Normal file
@ -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;
|
||||
|
||||
}
|
@ -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",
|
||||
|
@ -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"]
|
||||
}
|
Loading…
Reference in New Issue
Block a user