mirror of
https://github.com/antos-rde/antosdk-apps.git
synced 2024-11-08 06:28:29 +01:00
add only office document example
This commit is contained in:
parent
efb58ea93d
commit
e6e374f70b
@ -3,5 +3,8 @@
|
||||
This application is the front-end connector of the OnlyOffice suite.
|
||||
It needs to connect to a working OnlyOffice document server.
|
||||
|
||||
The application allows to open/edit document, presentation, and spreedsheet
|
||||
The application allows to open/edit commons document, presentation, and spreedsheet.
|
||||
Integrate OnlyOffice to an virtual window environment like AntOs allows an inconvenient
|
||||
way to work with multiple document at the same time
|
||||
|
||||
|
||||
|
@ -3,5 +3,8 @@
|
||||
This application is the front-end connector of the OnlyOffice suite.
|
||||
It needs to connect to a working OnlyOffice document server.
|
||||
|
||||
The application allows to open/edit document, presentation, and spreedsheet
|
||||
The application allows to open/edit commons document, presentation, and spreedsheet.
|
||||
Integrate OnlyOffice to an virtual window environment like AntOs allows an inconvenient
|
||||
way to work with multiple document at the same time
|
||||
|
||||
|
||||
|
@ -1,250 +1 @@
|
||||
(function() {
|
||||
var OnlyOffice;
|
||||
|
||||
OnlyOffice = class OnlyOffice extends this.OS.application.BaseApplication {
|
||||
constructor(args) {
|
||||
super("OnlyOffice", args);
|
||||
this.eid = `id${Math.random().toString(36).replace(".", "")}`;
|
||||
}
|
||||
|
||||
main() {
|
||||
this.currfile = void 0;
|
||||
if (this.args && this.args.length > 0) {
|
||||
this.currfile = this.args[0].path.asFileHandle();
|
||||
}
|
||||
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;
|
||||
}
|
||||
return this.exec("token", {
|
||||
file: this.currfile.path
|
||||
}).then((d) => {
|
||||
if (d.error) {
|
||||
return this.error(d.error);
|
||||
}
|
||||
this.access_token = d.result;
|
||||
return this.currfile.onready().then((meta) => {
|
||||
this.scheme.apptitle = this.currfile.path;
|
||||
$(this.placeholder).empty();
|
||||
if (this.editor) {
|
||||
this.editor.destroyEditor();
|
||||
}
|
||||
return this.editor = new DocsAPI.DocEditor(this.eid, {
|
||||
events: {
|
||||
onRequestCreateNew: () => {
|
||||
return this.newDocument();
|
||||
},
|
||||
onRequestSaveAs: (e) => {
|
||||
return this.saveAs(e);
|
||||
}
|
||||
},
|
||||
document: {
|
||||
fileType: this.currfile.ext,
|
||||
key: meta.mtime.hash().toString(),
|
||||
title: this.currfile.filename,
|
||||
url: this.currfile.getlink() + "?" + this.access_token
|
||||
},
|
||||
documentType: this.getDocType(this.currfile.ext),
|
||||
editorConfig: {
|
||||
user: {
|
||||
id: this.systemsetting.user.id.toString(),
|
||||
name: this.systemsetting.user.username
|
||||
},
|
||||
customization: {
|
||||
compactHeader: false
|
||||
},
|
||||
//autosave: false,
|
||||
//forcesave: true
|
||||
callbackUrl: this.uapi("save")
|
||||
}
|
||||
});
|
||||
});
|
||||
}).catch((e) => {
|
||||
return this.error(e.toString(), e);
|
||||
});
|
||||
}
|
||||
|
||||
getDocType(ext) {
|
||||
if ("doc,docx,epub,odt".split(",").includes(ext)) {
|
||||
return "word";
|
||||
}
|
||||
if ("csv,ods,xls,xlsx".split(",").includes(ext)) {
|
||||
return "cell";
|
||||
}
|
||||
if ("odp,ppt,pptx".split(",").includes(ext)) {
|
||||
return "slide";
|
||||
}
|
||||
return "none";
|
||||
}
|
||||
|
||||
saveAs(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() {
|
||||
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) {
|
||||
return `${this._api.REST}/system/apigateway?ws=0&path=${this.path()}/api.lua&action=${action}&file=${this.currfile.path}&${this.access_token}`;
|
||||
}
|
||||
|
||||
exec(action, args) {
|
||||
var cmd;
|
||||
cmd = {
|
||||
path: `${this.path()}/api.lua`,
|
||||
parameters: {
|
||||
action: action,
|
||||
args: args
|
||||
}
|
||||
};
|
||||
return this.call(cmd);
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
if (this.editor) {
|
||||
this.editor.destroyEditor();
|
||||
}
|
||||
return this.editor = void 0;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
OnlyOffice.dependencies = ["https://office.iohub.dev/web-apps/apps/api/documents/api.js"];
|
||||
|
||||
this.OS.register("OnlyOffice", OnlyOffice);
|
||||
|
||||
this.extensionParams = {
|
||||
url: "https://office.iohub.dev/web-apps/"
|
||||
};
|
||||
|
||||
}).call(this);
|
||||
(function(){var e;(e=class extends this.OS.application.BaseApplication{constructor(e){super("OnlyOffice",e),this.eid="id"+Math.random().toString(36).replace(".","")}main(){if(this.currfile=void 0,this.args&&this.args.length>0&&(this.currfile=this.args[0].path.asFileHandle()),this.placeholder=this.find("editor-area"),this.placeholder.id=this.eid,this.find("btn-open-file").onbtclick=e=>this.openFile(),this.find("btn-new-doc").onbtclick=e=>this.create("word"),this.find("btn-new-cell").onbtclick=e=>this.create("sheet"),this.find("btn-new-slide").onbtclick=e=>this.create("slide"),this.currfile)return this.open()}create(e){var t;return t=void 0,"word"===e&&(t="docx"),"sheet"===e&&(t="xlsx"),"slide"===e&&(t="pptx"),t?this.openDialog("FileDialog",{title:__("Save file as"),type:"dir",file:("home://Untitled."+t).asFileHandle()}).then(e=>{var i,s;return i=`${e.file.path}/${e.name}`.asFileHandle(),(s=`${this.path()}/templates/model.${t}`.asFileHandle()).read("binary").then(e=>{var t;return t=new Blob([e],{type:s.info.mime}),i.cache=t,i.write(s.info.mime).then(e=>(i.cache=void 0,this.currfile=i,this.open())).catch(e=>this.error(e.toString(),e))}).catch(e=>this.error(e.toString(),e))}):this.error(__("Unkown file type"))}openFile(){return this.openDialog("FileDialog",{title:__("Open file"),type:"file",mimes:this.meta().mimes}).then((e,t)=>(this.currfile=e.file.path.asFileHandle(),this.open()))}editorReady(){return console.log($('iframe[name="frameEditor"]',this.scheme).contents())}open(){if(this.currfile)return this.exec("token",{file:this.currfile.path}).then(e=>e.error?this.error(e.error):(this.access_token=e.result,this.currfile.onready().then(e=>{var t;return t=(t=`${this.systemsetting.user.username}:${this.currfile.path}:${e.mtime}`).hash().toString(),this.scheme.apptitle=this.currfile.path,$(this.placeholder).empty(),this.editor&&this.editor.destroyEditor(),this.editor=new DocsAPI.DocEditor(this.eid,{events:{onAppReady:e=>this.editorReady(e),onRequestCreateNew:()=>this.newDocument(),onRequestSaveAs:e=>this.saveAs(e)},document:{fileType:this.currfile.ext,key:t,title:this.currfile.filename,url:this.currfile.getlink()+"?"+this.access_token},documentType:this.getDocType(this.currfile.ext),editorConfig:{user:{id:this.systemsetting.user.id.toString(),name:this.systemsetting.user.username},customization:{compactHeader:!1},callbackUrl:this.uapi("save")}})}))).catch(e=>this.error(e.toString(),e))}getDocType(e){return"doc,docx,epub,odt".split(",").includes(e)?"word":"csv,ods,xls,xlsx".split(",").includes(e)?"cell":"odp,ppt,pptx".split(",").includes(e)?"slide":"none"}saveAs(e){if(e.data.url)return e.data.url.asFileHandle(),this.openDialog("FileDialog",{title:__("Save file as"),type:"dir",file:("home://"+e.data.title).asFileHandle()}).then(t=>{var i;return i=`${t.file.path}/${t.name}`,this.exec("duplicate",{remote:e.data.url,as:i}).then(e=>e.error?this.error(e.error):(this.currfile=i.asFileHandle(),this.open())).catch(e=>this.error(e.toString(),e))})}newDocument(){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(e=>{switch(e.type){case"open":return this.openFile();default:return this.create(e.type)}})}uapi(e){return`${this._api.REST}/system/apigateway?ws=0&path=${this.path()}/api.lua&action=${e}&file=${this.currfile.path}&${this.access_token}`}exec(e,t){var i;return i={path:this.path()+"/api.lua",parameters:{action:e,args:t}},this.call(i)}cleanup(){return this.editor&&this.editor.destroyEditor(),this.editor=void 0}}).dependencies=["https://office.iohub.dev/web-apps/apps/api/documents/api.js"],this.OS.register("OnlyOffice",e),this.extensionParams={url:"https://office.iohub.dev/web-apps/"}}).call(this);
|
@ -4,10 +4,10 @@
|
||||
"name":"Office Suite",
|
||||
"description":"Online Office suite based on OnlyOffice",
|
||||
"info":{
|
||||
"author": "",
|
||||
"email": ""
|
||||
"author": "Xuan Sang LE",
|
||||
"email": "mrsang@iohub.dev"
|
||||
},
|
||||
"version":"0.0.1-a",
|
||||
"version":"0.1.0-a",
|
||||
"category":"Other",
|
||||
"icon":"icon.png",
|
||||
"mimes":[
|
||||
|
Binary file not shown.
@ -68,6 +68,9 @@ class OnlyOffice extends this.OS.application.BaseApplication
|
||||
@currfile = f.file.path.asFileHandle()
|
||||
@open()
|
||||
|
||||
editorReady: () ->
|
||||
console.log $('iframe[name="frameEditor"]', @scheme).contents()
|
||||
|
||||
open: () ->
|
||||
return unless @currfile
|
||||
@exec("token", {file: @currfile.path})
|
||||
@ -76,17 +79,20 @@ class OnlyOffice extends this.OS.application.BaseApplication
|
||||
@access_token = d.result
|
||||
@currfile.onready()
|
||||
.then (meta) =>
|
||||
key = "#{@systemsetting.user.username}:#{@currfile.path}:#{meta.mtime}"
|
||||
key = key.hash().toString()
|
||||
@scheme.apptitle = @currfile.path
|
||||
$(@placeholder).empty()
|
||||
@editor.destroyEditor() if @editor
|
||||
@editor = new DocsAPI.DocEditor(@eid, {
|
||||
events: {
|
||||
onAppReady: (e) => @editorReady(e),
|
||||
onRequestCreateNew: () => @newDocument(),
|
||||
onRequestSaveAs: (e) => @saveAs(e)
|
||||
},
|
||||
document: {
|
||||
fileType: @currfile.ext,
|
||||
key: meta.mtime.hash().toString(),
|
||||
key: key,
|
||||
title: @currfile.filename,
|
||||
url: @currfile.getlink() + "?" + @access_token
|
||||
},
|
||||
|
@ -4,10 +4,10 @@
|
||||
"name":"Office Suite",
|
||||
"description":"Online Office suite based on OnlyOffice",
|
||||
"info":{
|
||||
"author": "",
|
||||
"email": ""
|
||||
"author": "Xuan Sang LE",
|
||||
"email": "mrsang@iohub.dev"
|
||||
},
|
||||
"version":"0.0.1-a",
|
||||
"version":"0.1.0-a",
|
||||
"category":"Other",
|
||||
"icon":"icon.png",
|
||||
"mimes":[
|
||||
|
BIN
OnlyOffice/screenshot.png
Normal file
BIN
OnlyOffice/screenshot.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 187 KiB |
@ -149,6 +149,16 @@
|
||||
"dependencies": ["SimpleMDE@1.11.2-r"],"mimes":["text/.*"],
|
||||
"download": "https://raw.githubusercontent.com/lxsang/antosdk-apps/master/MarkOn/build/release/MarkOn.zip"
|
||||
},
|
||||
{
|
||||
"pkgname": "OnlyOffice",
|
||||
"name": "Office Suite",
|
||||
"description": "https://raw.githubusercontent.com/lxsang/antosdk-apps/master/OnlyOffice/README.md",
|
||||
"category": "Other",
|
||||
"author": "Xuan Sang LE",
|
||||
"version": "0.1.0-a",
|
||||
"dependencies": [],
|
||||
"download": "https://raw.githubusercontent.com/lxsang/antosdk-apps/master/OnlyOffice/build/release/OnlyOffice.zip"
|
||||
},
|
||||
{
|
||||
"pkgname": "OpenPage",
|
||||
"name": "OpenPage",
|
||||
|
Loading…
Reference in New Issue
Block a user