[Fencommits] fenserve: make /table category-specific
Benja Fallenstein
benja.fallenstein at gmail.com
Wed May 30 19:09:16 EEST 2007
Wed May 30 19:09:05 EEST 2007 Benja Fallenstein <benja.fallenstein at gmail.com>
* make /table category-specific
diff -rN -u old-fenserve/fendata/Main.hs new-fenserve/fendata/Main.hs
--- old-fenserve/fendata/Main.hs 2007-05-30 19:09:16.000000000 +0300
+++ new-fenserve/fendata/Main.hs 2007-05-30 19:09:16.000000000 +0300
@@ -211,11 +211,12 @@
s' = s { stateSidebarPages = stateSidebarPages s ++ [page] }
Just page@(fn,args) = fmap read $ lookM msg "page"
-showTable :: (?root :: String) => () -> MyState -> (HTML, MyState)
-showTable () s = (
- makePage s "List of items in the database" "" $
+showTable :: (?root :: String) => Request -> MyState -> (HTML, MyState)
+showTable req s = (
+ makePage s ("List of "++plural cat++" in the database") "" $
(new+++) . (hr+++) . (+++new) .
catFor (Map.toList $ stateItems s) $ \(id, Item fields cats) ->
+ if cat `Set.member` cats then
(+++ para (formP (?root++"delItem") (hidden "item" (show id)
+++ mdotted
[ link (?root++"item/"++show id++"?returnTo=table")
@@ -226,13 +227,14 @@
+++ hr)
. para
. catFor (Map.toList fields) $ \(f,v) ->
- bold (capitalize f) +++ ": " +++ v +++ br,
+ bold (capitalize f) +++ ": " +++ v +++ br else toHTML "",
s) where new = para . formP (?root++"newItem")
. (+++ hidden "returnTo" "table")
. (+++ " " +++ mdot +++ " "
+++ bold (link (?root++"addCategory") "[Add category]"))
. mdotted . for (Map.keys $ stateSchema s) $ \cat ->
button' "cat" cat $ bold ("[New "+++cat+++"]")
+ cat = fromMaybe (head $ Map.keys $ stateSchema s) (lookM req "cat")
showItem :: (?root :: String) =>
String -> Request -> MyState -> (HTML, MyState)
diff -rN -u old-fenserve/fendata/Potions.hs new-fenserve/fendata/Potions.hs
--- old-fenserve/fendata/Potions.hs 2007-05-30 19:09:16.000000000 +0300
+++ new-fenserve/fendata/Potions.hs 2007-05-30 19:09:16.000000000 +0300
@@ -21,7 +21,7 @@
import System.Time
catType cat = Type cat
-pluralType cat = Type (cat ++ "s")
+pluralType cat = Type (plural cat)
string = Type "text"
readFun :: MyState -> String -> Fun
diff -rN -u old-fenserve/fendata/UI.hs new-fenserve/fendata/UI.hs
--- old-fenserve/fendata/UI.hs 2007-05-30 19:09:16.000000000 +0300
+++ new-fenserve/fendata/UI.hs 2007-05-30 19:09:16.000000000 +0300
@@ -7,6 +7,8 @@
import PotionTypes
import Utils
+import qualified Data.Map as Map
+
header = HTML "<head><style>a.editLink { text-decoration: none; color: inherit} \
\button {\
\ cursor: pointer; background: none; border: none; \
@@ -47,7 +49,9 @@
in para $ bold $ link uri $ renderExp exp id string) +++
hr +++
para (link (?root++"potion?exp="++(escape' $ show $ Block [])) "New page") +++
- para (link (?root++"table") "List of items in the database")) +++
+ catFor (Map.keys $ stateSchema state) (\cat ->
+ para (link (?root++"table?cat="++escape' cat)
+ ("List of "++plural cat++" in the database")))) +++
tag "div" [("class", "content")] body) +++
tag "div" [("class", "footer")]
("Fenlight (c) 2007 by Benja Fallenstein and Tuukka Hastrup. " +++
diff -rN -u old-fenserve/fendata/Utils.hs new-fenserve/fendata/Utils.hs
--- old-fenserve/fendata/Utils.hs 2007-05-30 19:09:16.000000000 +0300
+++ new-fenserve/fendata/Utils.hs 2007-05-30 19:09:16.000000000 +0300
@@ -30,6 +30,9 @@
uncapitalize (c:cs) = toLower c : cs
uncapitalize "" = ""
+
+plural s | last s == 'y' = init s ++ "ies"
+ | otherwise = s ++ "s"
mdot = style "margin-left: 0.5em; margin-right: 0.5em; font-weight: bold" $
HTML "·"
More information about the Fencommits
mailing list