1
1
mirror of https://github.com/aelve/guide.git synced 2024-12-25 22:02:58 +03:00

Group edits by IP

This commit is contained in:
Artyom 2016-04-13 18:38:35 +03:00
parent a029f06ea1
commit a025db8d9b
2 changed files with 27 additions and 15 deletions

View File

@ -25,6 +25,9 @@ module Utils
deleteAt, deleteAt,
insertAt, insertAt,
-- * 'Eq'
equating,
-- * URLs -- * URLs
Url, Url,
sanitiseUrl, sanitiseUrl,
@ -125,6 +128,9 @@ insertAt _ a [] = [a]
insertAt 0 a xs = a:xs insertAt 0 a xs = a:xs
insertAt n a (x:xs) = x : insertAt (n-1) a xs insertAt n a (x:xs) = x : insertAt (n-1) a xs
equating :: Eq b => (a -> b) -> (a -> a -> Bool)
equating f = (==) `on` f
type Url = Text type Url = Text
sanitiseUrl :: Url -> Maybe Url sanitiseUrl :: Url -> Maybe Url

View File

@ -159,17 +159,23 @@ renderAdmin globalState edits = do
includeJS "/js.js" includeJS "/js.js"
includeJS "/jquery-2.2.0.min.js" includeJS "/jquery-2.2.0.min.js"
includeCSS "/markup.css" includeCSS "/markup.css"
title_ "admin Aelve Guide"
meta_ [name_ "viewport", meta_ [name_ "viewport",
content_ "width=device-width, initial-scale=1.0, user-scalable=yes"] content_ "width=device-width, initial-scale=1.0, user-scalable=yes"]
body_ $ do body_ $ do
ul_ $ for_ edits $ \(edit, EditDetails{..}) -> li_ $ do h1_ "Pending edits"
editNode <- thisNode -- Group edits by IP
p_ $ do let editGroups = groupBy (equating (editIP . snd)) edits
case editIP of -- For each group, show the IP and then edits as a list
for_ editGroups $ \editGroup -> do
h2_ $ case editIP (snd (head editGroup)) of
Nothing -> "<unknown IP>" Nothing -> "<unknown IP>"
Just ip -> toHtml (show ip) Just ip -> toHtml (show ip)
", " ul_ $ do
for_ editGroup $ \(edit, EditDetails{..}) -> li_ $ do
editNode <- thisNode
p_ $ do
toHtml =<< liftIO (humanReadableTime editDate) toHtml =<< liftIO (humanReadableTime editDate)
emptySpan "1em" emptySpan "1em"
textButton "accept" $ textButton "accept" $