summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhallgren <hallgren@chalmers.se>2012-11-17 14:22:30 +0000
committerhallgren <hallgren@chalmers.se>2012-11-17 14:22:30 +0000
commitca5b066588332f66b2e70bdb983e3a00b0d31ac9 (patch)
treea2d30113a99729d0554938b8b2bbdf77af692b91
parent73c78c884042c78f075f29a88d04fc011dd7076d (diff)
PGF service: command=browse&format=json returns info on all cats and funs
The browse command used to have a required parameter id=... and it returned info on the given identifier only. Now, if format=json, the id=... parameter can be omitted to get info on all identifiers at the same time. The returned JSON structure in this case is {cats:{...},funs:{...}} where the inner objects contain one field per category and function, respectively, in the same format as when you request info on one category or function.
-rw-r--r--src/server/PGFService.hs30
1 files changed, 22 insertions, 8 deletions
diff --git a/src/server/PGFService.hs b/src/server/PGFService.hs
index bc283bf24..ebb32f4b9 100644
--- a/src/server/PGFService.hs
+++ b/src/server/PGFService.hs
@@ -71,7 +71,7 @@ pgfMain pgf command =
Just l <- getFrom
outputGraphviz (parseTree pgf l t)
"abstrjson" -> outputJSONP . jsonExpr =<< getTree
- "browse" -> id =<< doBrowse pgf `fmap` getId `ap` getCSSClass `ap` getHRef `ap` getFormat "html"
+ "browse" -> id =<< doBrowse pgf `fmap` getOptId `ap` getCSSClass `ap` getHRef `ap` getFormat "html"
"external" -> do cmd <- getInput "external"
input <- getText
doExternal cmd input
@@ -109,10 +109,13 @@ pgfMain pgf command =
getTo = getLang "to"
getId :: CGI PGF.CId
- getId = do mb_id <- fmap (>>= PGF.readCId) (getInput "id")
- case mb_id of
- Just id -> return id
- Nothing -> throwCGIError 400 "Bad identifier" []
+ getId = maybe errorMissingId return =<< getOptId
+
+ getOptId :: CGI (Maybe PGF.CId)
+ getOptId = maybe (return Nothing) rd =<< getInput "id"
+ where
+ rd = maybe err (return . Just) . PGF.readCId
+ err = throwCGIError 400 "Bad identifier" []
getCSSClass :: CGI (Maybe String)
getCSSClass = getInput "css-class"
@@ -137,6 +140,9 @@ pgfMain pgf command =
Just lang | lang `elem` PGF.languages pgf -> return $ Just lang
| otherwise -> throwCGIError 400 "Unknown language" ["Unknown language: " ++ l]
+
+errorMissingId = throwCGIError 400 "Missing identifier" []
+
getFormat def = maybe def id `fmap` getInput "format"
-- Hook for simple extensions of the PGF service
@@ -367,12 +373,20 @@ pipeIt2graphviz format code = do
ExitSuccess -> return output
ExitFailure r -> fail ("pipeIt2graphviz: (exit " ++ show r ++ ")")
-doBrowse pgf id _ _ "json" =
- outputJSONP . makeObj . maybe [] obj $ PGF.browse pgf id
+browse1json pgf id = makeObj . maybe [] obj $ PGF.browse pgf id
where
obj (def,ps,cs) = ["def".=def,"producers".=ps,"consumers".=cs]
-doBrowse pgf id cssClass href _ = -- default to "html" format
+doBrowse pgf (Just id) _ _ "json" = outputJSONP $ browse1json pgf id
+doBrowse pgf Nothing _ _ "json" =
+ outputJSONP $ makeObj ["cats".=all (PGF.categories pgf),
+ "funs".=all (PGF.functions pgf)]
+ where
+ all = makeObj . map one
+ one id = PGF.showCId id.=browse1json pgf id
+
+doBrowse pgf Nothing cssClass href _ = errorMissingId
+doBrowse pgf (Just id) cssClass href _ = -- default to "html" format
outputHTML $
case PGF.browse pgf id of
Just (def,ps,cs) -> "<PRE>"++annotate def++"</PRE>\n"++