1
1
mirror of https://github.com/aelve/guide.git synced 2024-12-24 13:26:08 +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,25 +159,31 @@ 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
Nothing -> "<unknown IP>"
Just ip -> toHtml (show ip)
", "
toHtml =<< liftIO (humanReadableTime editDate)
emptySpan "1em"
textButton "accept" $
JS.acceptEdit (editId, editNode)
emptySpan "0.5em"
textButton "try to undo" $
JS.undoEdit (editId, editNode)
renderEdit globalState edit
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" $
JS.acceptEdit (editId, editNode)
emptySpan "0.5em"
textButton "try to undo" $
JS.undoEdit (editId, editNode)
renderEdit globalState edit
-- TODO: when showing Edit'DeleteCategory, show the amount of items in that
-- category and titles of items themselves