[Fencommits] fenserve: add 'lastlog' view showing only the last 15 lines
Benja Fallenstein
benja.fallenstein at gmail.com
Fri Apr 27 21:35:17 EEST 2007
Fri Apr 27 21:35:11 EEST 2007 Benja Fallenstein <benja.fallenstein at gmail.com>
* add 'lastlog' view showing only the last 15 lines
diff -rN -u old-fenserve/notetaker/Main.hs new-fenserve/notetaker/Main.hs
--- old-fenserve/notetaker/Main.hs 2007-04-27 21:35:17.000000000 +0300
+++ new-fenserve/notetaker/Main.hs 2007-04-27 21:35:17.000000000 +0300
@@ -30,12 +30,16 @@
\ document.forms[0].elements[1].focus();\
\</script>"
+views n nick = "Views: "++concat (intersperse " | " [view i|i<-[0..2]])++"<p>"
+ where links = [("main", "/"), ("log", "/log"), ("lastlog", "/lastlog")]
+ view i | i == n = printf "<b>%s</b>" name
+ | otherwise = printf "<a href=%s?nick=%s>%s</a>" uri nick name
+ where (name,uri) = links !! i
+
page nick = do
(lines :: [Line]) <- get
let Note _ notes = foldl (flip execute) (Note "HOME" []) lines
- respond $ form nick
- ++ "Views: <b>main</b> | <a href='/log?nick="++nick++"'>log</a><p>"
- ++ renderNotes notes
+ respond $ form nick ++ views 0 nick ++ renderNotes notes
renderNotes notes = "<ol>" ++ concatMap renderNote notes ++ "</ol>" where
renderNote (Note title children) = "<li>" ++ title ++ renderNotes children
@@ -73,11 +77,11 @@
instance FromMessage (String,String) where
fromMessageM m = do l <- lookM m "line"; return (getNick m, l)
-renderLog nick = do
- lines <- get
- respond $ form nick
- ++ "Views: <a href='/?nick="++nick++"'>main</a> | <b>log</b><p>"
- ++ flip concatMap lines (\(Line time nick body) ->
+renderLog nick lastlog = do
+ lines <- if not lastlog then get
+ else get >>= return . reverse . take 15 . reverse
+ respond $ form nick ++ views (if lastlog then 2 else 1) nick ++
+ flip concatMap lines (\(Line time nick body) ->
renderTime time ++ " " ++ renderBody nick body ++ "<br>")
renderBody :: String -> Body -> String
@@ -96,12 +100,13 @@
where t = toUTCTime (TOD (fromIntegral t0) 0)
main = stdHTTP [ debugFilter
- , h ["log"] GET $ ok $ \() nick -> renderLog nick
+ , h ["log"] GET $ ok $ \() nick -> renderLog nick False
+ , h ["lastlog"] GET $ ok $ \() nick -> renderLog nick True
, h [""] GET $ ok $ \() nick -> page nick
, h () POST $ ok $ \() (nick,line) -> do
time <- getTime; let body = readBody line
modify (++[Line time nick body])
- case body of Body _ -> renderLog nick; _ -> page nick
+ case body of Body _ -> renderLog nick True; _ -> page nick
, h () POST $ ok $ \() () -> respond "Huh."
]
More information about the Fencommits
mailing list