From 31ef32a815f129002380a58d9a50e827d71800fc Mon Sep 17 00:00:00 2001 From: Thomas Hallgren Date: Thu, 29 Mar 2018 14:54:42 +0200 Subject: gfse: sort list of public grammars by age, by default There is also a menu so you can choose to sort the list by name or by age --- src/www/gfse/editor.js | 83 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 58 insertions(+), 25 deletions(-) (limited to 'src/www') diff --git a/src/www/gfse/editor.js b/src/www/gfse/editor.js index a579a5eea..4e3630af0 100644 --- a/src/www/gfse/editor.js +++ b/src/www/gfse/editor.js @@ -126,35 +126,68 @@ function draw_grammar_list() { function rmpublic(file) { return function() { remove_public(file,draw_grammar_list) } } - publiclist.appendChild(wrap("h3",text("Public grammars"))) - if(files.length>0) { - var unique_id=local.get("unique_id","-") - var t=empty_class("table","grammar_list") - for(var i in files) { - var file=files[i].path - var parts=file.split(/[-.]/) - var basename=parts[0] - var unique_name=parts[1]+"-"+parts[2] - var mine = my_grammar(unique_name)!=null - var del = mine - ? delete_button(rmpublic(file),"Don't publish this grammar") - : [] - var tip = mine - ? "This is a copy of your grammar" - : "Click to download a copy of this grammar" - var modt=new Date(files[i].time) - var fmtmodt=modt.toDateString()+", "+modt.toTimeString().split(" ")[0] - var when=wrap_class("small","modtime",text(" "+fmtmodt)) - t.appendChild(edtr([td(del), - td(title(tip, - a(jsurl('open_public("'+file+'")'), - [text(basename)]))), - td(when)])) + var h=wrap("h3",text("Public grammars")) + var ordermenu=wrap("select",[option("Newest first","byAge"), + option("Alphabetical","byName")]) + ordermenu.value=local.get("publicOrder","byAge") + ordermenu.onchange=function(){ + local.put("publicOrder",ordermenu.value) + if(n>1) show_grammars() + } + var n=files.length + var count=n==1 ? " (One grammar)" : " ("+n + " grammars)" + var t=table(tr([td(h),td(text(count)),td(ordermenu)])) + publiclist.appendChild(t) + for(var i in files) { + var file=files[i] + file.t=new Date(file.time) + file.s=file.t.getTime() + } + function sort_grammars() { + switch(ordermenu.value) { + case "byAge": + files.sort((f1,f2)=>f2.s-f1.s) + break; + case "byName": + files.sort((f1,f2)=>(f1.path>f2.path)-(f1.path0) { + sort_grammars() + //var unique_id=local.get("unique_id","-") + for(var i in files) { + var file=files[i].path + var parts=file.split(/[-.]/) + var basename=parts[0] + var unique_name=parts[1]+"-"+parts[2] + var mine = my_grammar(unique_name)!=null + var del = mine + ? delete_button(rmpublic(file),"Don't publish this grammar") + : [] + var tip = mine + ? "This is a copy of your grammar" + : "Click to download a copy of this grammar" + var modt=new Date(files[i].time) + var fmtmodt=modt.toDateString()+", "+modt.toTimeString().split(" ")[0] + var when=wrap_class("small","modtime",text(" "+fmtmodt)) + gt.appendChild(edtr([td(del), + td(title(tip, + a(jsurl('open_public("'+file+'")'), + [text(basename)]))), + td(when)])) + } + } else publiclist.appendChild(p(text("No public grammars are available."))) + // This is outside the table so it won't be cleared, + // but show_grammars is only called once then there is less + // than 2 grammars, so it's OK. + } + show_grammars() } if(navigator.onLine) gfcloud_public_json("ls-l",{},show_public,no_public) -- cgit v1.2.3 From 78cf1849574b8ba2709d1712202ebe34327c63f9 Mon Sep 17 00:00:00 2001 From: Thomas Hallgren Date: Thu, 29 Mar 2018 16:17:25 +0200 Subject: gfse: fix for some browser: hovering over an empty grammar comment to edit it This was a problem in Safari (an other similar browsers I presume), but not in Firefox: hovering over the grammar comment (shown below the grammar name when you edit a grammar) didn't reveal the button to edit it, thus preventing you from adding a comment. It was till possible by selecting the "Enable editing on touch devices." at the bottom of the screen, but most people probably didn't notice that it is possible to add a comment. --- src/www/gfse/editor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/www') diff --git a/src/www/gfse/editor.js b/src/www/gfse/editor.js index 4e3630af0..42638090c 100644 --- a/src/www/gfse/editor.js +++ b/src/www/gfse/editor.js @@ -832,7 +832,7 @@ function draw_abstract(g) { } function draw_comment(g) { - return div_class("comment",editable("span",text(g.comment || ""),g,edit_comment,"Edit grammar description")); + return div_class("comment",editable("span",text(g.comment || "…"),g,edit_comment,"Edit grammar description")); } function module_name(g,ix) { -- cgit v1.2.3 From 750a1349ffad116d57b46ea5f816e678018a1d7f Mon Sep 17 00:00:00 2001 From: Thomas Hallgren Date: Thu, 29 Mar 2018 17:02:22 +0200 Subject: gfse: allow public grammars to be deleted in more cases The editor doesn't show delete buttons on grammars published by other users, but it was too picky when deciding which grammars you own. Now it should be possible to delete grammars from the device/browser you published it from, even if you don't have a private copy of it any more. On a related note, there seems to be problem with the way unique grammars names are created and maintained, causing published grammars to be duplicated in some cases. This needs to be overhauled. --- src/www/gfse/editor.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/www') diff --git a/src/www/gfse/editor.js b/src/www/gfse/editor.js index 42638090c..cb93c305a 100644 --- a/src/www/gfse/editor.js +++ b/src/www/gfse/editor.js @@ -158,15 +158,16 @@ function draw_grammar_list() { clear(gt) if(files.length>0) { sort_grammars() - //var unique_id=local.get("unique_id","-") + var unique_id=local.get("unique_id","-") for(var i in files) { var file=files[i].path var parts=file.split(/[-.]/) var basename=parts[0] var unique_name=parts[1]+"-"+parts[2] var mine = my_grammar(unique_name)!=null - var del = mine - ? delete_button(rmpublic(file),"Don't publish this grammar") + var from_me = parts[1] == unique_id + var del = from_me || mine + ? delete_button(rmpublic(file),"Remove this public grammar") : [] var tip = mine ? "This is a copy of your grammar" -- cgit v1.2.3 From 3d6a5e88646e7147972d474e304dc99615f4b905 Mon Sep 17 00:00:00 2001 From: Thomas Hallgren Date: Thu, 29 Mar 2018 18:23:32 +0200 Subject: gfse: show grammar comments in the list of public grammars gf -server now includes the comment field from the grammar in the response to /cloud requests with command=ls-t and ext=.json --- src/compiler/GF/Server.hs | 17 +++++++++++++---- src/www/gfse/editor.js | 1 + 2 files changed, 14 insertions(+), 4 deletions(-) (limited to 'src/www') diff --git a/src/compiler/GF/Server.hs b/src/compiler/GF/Server.hs index de0ec6abc..1ca6f399d 100644 --- a/src/compiler/GF/Server.hs +++ b/src/compiler/GF/Server.hs @@ -33,7 +33,7 @@ import Network.Shed.Httpd(initServer,Request(..),Response(..),noCache) --import qualified Network.FastCGI as FCGI -- from hackage direct-fastcgi import Network.CGI(handleErrors,liftIO) import CGIUtils(handleCGIErrors)--,outputJSONP,stderrToFile -import Text.JSON(encode,showJSON,makeObj) +import Text.JSON(JSValue(..),Result(..),valFromObj,encode,decode,showJSON,makeObj) --import System.IO.Silently(hCapture) import System.Process(readProcessWithExitCode) import System.Exit(ExitCode(..)) @@ -283,13 +283,17 @@ handle logLn documentroot state0 cache execute1 stateVar skip_empty = filter (not.null.snd) jsonList = jsonList' return - jsonListLong = jsonList' (mapM addTime) + jsonListLong ext = jsonList' (mapM (addTime ext)) ext jsonList' details ext = fmap (json200) (details =<< ls_ext "." ext) - addTime path = + addTime ext path = do t <- getModificationTime path - return $ makeObj ["path".=path,"time".=format t] + if ext==".json" + then addComment (time t) <$> liftIO (try $ getComment path) + else return . makeObj $ time t where + addComment t = makeObj . either (const t) (\c->t++["comment".=c]) + time t = ["path".=path,"time".=format t] format = formatTime defaultTimeLocale rfc822DateFormat rm path | takeExtension path `elem` ok_to_delete = @@ -331,6 +335,11 @@ handle logLn documentroot state0 cache execute1 stateVar do paths <- getDirectoryContents dir return [path | path<-paths, takeExtension path==ext] + getComment path = + do Ok (JSObject obj) <- decode <$> readFile path + Ok cmnt <- return (valFromObj "comment" obj) + return (cmnt::String) + -- * Dynamic content jsonresult cwd dir cmd (ecode,stdout,stderr) files = diff --git a/src/www/gfse/editor.js b/src/www/gfse/editor.js index cb93c305a..ddd8e0058 100644 --- a/src/www/gfse/editor.js +++ b/src/www/gfse/editor.js @@ -179,6 +179,7 @@ function draw_grammar_list() { td(title(tip, a(jsurl('open_public("'+file+'")'), [text(basename)]))), + td(text(files[i].comment||"")), td(when)])) } } -- cgit v1.2.3