[Fencommits] fenserve: show categories in table view
Benja Fallenstein
benja.fallenstein at gmail.com
Wed May 23 16:49:58 EEST 2007
Wed May 23 16:49:50 EEST 2007 Benja Fallenstein <benja.fallenstein at gmail.com>
* show categories in table view
diff -rN -u old-fenserve/fendata/Main.hs new-fenserve/fendata/Main.hs
--- old-fenserve/fendata/Main.hs 2007-05-23 16:49:58.000000000 +0300
+++ new-fenserve/fendata/Main.hs 2007-05-23 16:49:58.000000000 +0300
@@ -4,6 +4,7 @@
import Control.Monad.State
import Data.Generics (Typeable, Data, everywhere, mkT)
import Data.Binary hiding (get,put)
+import Data.List (intersperse)
import Data.Maybe (fromJust, fromMaybe)
import Data.Map (Map)
import qualified Data.Map as Map
@@ -383,15 +384,27 @@
f ('$':cs) part = reverse part : f cs ""
f (c:cs) part = f cs (c:part)
f "" part = [reverse part]
+
+commaList :: [String] -> String
+commaList [] = ""
+commaList [x] = x
+commaList xs = concat (intersperse ", " $ init xs) ++ ", and " ++ last xs
+
+capitalize (c:cs) = toUpper c : cs
+capitalize "" = ""
showTable :: () -> MyState -> (String, MyState)
showTable () s = (
(new++) . ("<hr>"++) . (++new) .
- concatFor (Map.toList $ stateItems s) $ \(id, Item fields _) ->
+ concatFor (Map.toList $ stateItems s) $ \(id, Item fields cats) ->
(++ "<p><form action='delItem' method=post>\
\<input type=hidden name=item value='"++show id++"'>\
- \<a href='item/"++show id++"?returnTo=table'>[Edit item]</a> "++mdot++"\
- \<button style='cursor: pointer; background: none; border: none; font: inherit; margin: 0; padding: 0'>[Delete item]</button></form><hr>") . ("<p>"++)
+ \<p><i>Categorized as " ++
+ commaList (map (("<b>"++).(++"</b>").capitalize) (Set.toList cats)) ++
+ "</i> " ++ mdot ++ " \
+ \<a href='item/"++show id++"?returnTo=table'>[Edit item]</a> "++mdot++"\
+ \<button style='cursor: pointer; background: none; border: none; font: inherit; margin: 0; padding: 0'>[Delete item]</button></form><hr>")
+ . ("<p>"++)
. concatFor (Map.toList fields) $ \(f:fs,v) ->
"<b>" ++ (toUpper f : fs) ++ ":</b> " ++ v ++ "<br>",
s) where new = ("<p><form action='newItem' method=post>\
More information about the Fencommits
mailing list