1
1
mirror of https://github.com/aelve/guide.git synced 2024-12-24 21:35:06 +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,
insertAt,
-- * 'Eq'
equating,
-- * URLs
Url,
sanitiseUrl,
@ -125,6 +128,9 @@ insertAt _ a [] = [a]
insertAt 0 a xs = 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
sanitiseUrl :: Url -> Maybe Url

View File

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