mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-09 04:59:31 -06:00
gfse: make it workw ith "gf -server" cloud services
This commit is contained in:
@@ -123,8 +123,10 @@ function download_json() {
|
||||
get_list(download_files);
|
||||
}
|
||||
|
||||
function link_directories(olddir,newdir,cont) {
|
||||
ajax_http_get("upload.cgi?rmdir="+olddir+"&newdir="+newdir,cont)
|
||||
function link_directories(newdir,cont) {
|
||||
with_dir(function(olddir) {
|
||||
ajax_http_get("upload.cgi?rmdir="+olddir+"&newdir="+newdir,cont)
|
||||
})
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
@@ -10,14 +10,19 @@ function with_dir(cont) {
|
||||
}
|
||||
|
||||
function remove_cloud_grammar(g) {
|
||||
alert("remove_cloud_grammar(g) not implemented yet!!!")
|
||||
var dir=local.get("dir")
|
||||
if(dir && g.unique_name) {
|
||||
var path=g.unique_name+".json"
|
||||
gfcloud("rm",{file:path},debug);
|
||||
}
|
||||
}
|
||||
|
||||
// Upload the grammar to the server and check it for errors
|
||||
function upload(g) {
|
||||
function upload2(dir) {
|
||||
var form=node("form",{method:"post",action:"/upload"},
|
||||
[hidden("dir",dir),hidden(g.basename,show_abstract(g))])
|
||||
var form=node("form",{method:"post",action:"/cloud"},
|
||||
[hidden("dir",dir),hidden("command","upload"),
|
||||
hidden(g.basename,show_abstract(g))])
|
||||
var files = [g.basename+".gf"]
|
||||
for(var i in g.concretes) {
|
||||
var cname=g.basename+g.concretes[i].langcode;
|
||||
@@ -39,19 +44,105 @@ function upload(g) {
|
||||
|
||||
// Upload the grammar to store it in the cloud
|
||||
function upload_json(cont) {
|
||||
alert("upload_json() not implemented yet!!!")
|
||||
function upload3(resptext,status) {
|
||||
local.put("json_uploaded",Date.now());
|
||||
//debug("Upload complete")
|
||||
if(cont) cont();
|
||||
else {
|
||||
var sharing=element("sharing");
|
||||
if(sharing) sharing.innerHTML=resptext;
|
||||
}
|
||||
}
|
||||
function upload2(dir) {
|
||||
var prefix=dir.substr(10)+"-" // skip "/tmp/gfse."
|
||||
//debug("New form data");
|
||||
//var form=new FormData(); // !!! Doesn't work on Android 2.2!
|
||||
var form={dir:dir};
|
||||
//debug("Preparing form data");
|
||||
for(var i=0;i<local.count;i++) {
|
||||
var g=local.get(i,null);
|
||||
if(g) {
|
||||
if(!g.unique_name) {
|
||||
g.unique_name=prefix+i;
|
||||
save_grammar(g)
|
||||
}
|
||||
//form.append(g.unique_name+".json",JSON.stringify(g));
|
||||
form[encodeURIComponent(g.unique_name+".json")]=JSON.stringify(g)
|
||||
}
|
||||
}
|
||||
//debug("Upload to "+prefix);
|
||||
ajax_http_post("/cloud","command=upload"+encodeArgs(form),upload3,cont)
|
||||
}
|
||||
|
||||
with_dir(upload2);
|
||||
}
|
||||
|
||||
function download_json() {
|
||||
alert("download_json() not implemented yet!!!")
|
||||
var dir=local.get("dir");
|
||||
var index=grammar_index();
|
||||
var downloading=0;
|
||||
|
||||
function get_list(ok,err) { gfcloud("ls",{},ok,err) }
|
||||
|
||||
function get_file(file,ok,err) {
|
||||
downloading++;
|
||||
gfcloud("download",{file:encodeURIComponent(file)},ok,err);
|
||||
}
|
||||
|
||||
function file_failed(errormsg,status) {
|
||||
debug(errormsg)
|
||||
downloading--;
|
||||
}
|
||||
function file_downloaded(grammar) {
|
||||
downloading--;
|
||||
var newg=JSON.parse(grammar);
|
||||
debug("Downloaded "+newg.unique_name)
|
||||
var i=index[newg.unique_name];
|
||||
if(i!=undefined) merge_grammar(i,newg)
|
||||
else {
|
||||
debug("New")
|
||||
newg.index=null;
|
||||
save_grammar(newg);
|
||||
}
|
||||
if(downloading==0) done()
|
||||
}
|
||||
|
||||
function done() {
|
||||
setTimeout(function(){location.href="."},2000);
|
||||
}
|
||||
|
||||
function download_files(ls) {
|
||||
local.put("current",0);
|
||||
if(ls) {
|
||||
//debug("Downloading "+ls);
|
||||
var files=ls.split(" ");
|
||||
cleanup_deleted(files);
|
||||
for(var i in files) get_file(files[i],file_downloaded,file_failed);
|
||||
}
|
||||
else {
|
||||
debug("No grammars in the cloud")
|
||||
done()
|
||||
}
|
||||
}
|
||||
|
||||
get_list(download_files);
|
||||
}
|
||||
|
||||
function link_directories(olddir,newdir,cont) {
|
||||
alert("link_directories(...) not implemented yet!!!")
|
||||
function link_directories(newdir,cont) {
|
||||
gfcloud("link_directories",{newdir:newdir},cont)
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
// Request GF cloud service
|
||||
function gfcloud(cmd,args,cont,err) {
|
||||
with_dir(function(dir) {
|
||||
var enc=encodeURIComponent;
|
||||
var url="/cloud?dir="+enc(dir)+"&command="+enc(cmd)+encodeArgs(args)
|
||||
ajax_http_get(url,cont,err)
|
||||
})
|
||||
}
|
||||
|
||||
// Send a command to the GF shell
|
||||
function gfshell(cmd,cont) {
|
||||
with_dir(function(dir) {
|
||||
|
||||
@@ -1070,7 +1070,7 @@ function download_from_cloud() {
|
||||
|
||||
function download2(olddir) {
|
||||
//debug("Starting grammar sharing in the cloud")
|
||||
if(newdir!=olddir) link_directories(olddir,newdir,download3)
|
||||
if(newdir!=olddir) link_directories(newdir,download3)
|
||||
else download4()
|
||||
}
|
||||
function download3() {
|
||||
|
||||
@@ -32,8 +32,7 @@ function exb_state(g,ci) {
|
||||
|
||||
function exb_call(g,ci,command,args,cont) {
|
||||
var url=window.exb_url || "exb/exb.fcgi";
|
||||
var q=""
|
||||
for(var arg in args) q+="&"+arg+"="+encodeURIComponent(args[arg]);
|
||||
var q=encodeArgs(args);
|
||||
var cmd="?command="+command+"&state="+encodeURIComponent(exb_state(g,ci))+q;
|
||||
http_get_json(url+cmd,cont)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user