Refactor: Remove leftover comment functionality
This commit is contained in:
parent
a5481e70e4
commit
41bee335c8
5 changed files with 2 additions and 102 deletions
|
@ -72,10 +72,6 @@ article a, .entry a {
|
||||||
padding-bottom: 20px;
|
padding-bottom: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.innerBoxComments {
|
|
||||||
padding-top: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.cCaptcha {
|
.cCaptcha {
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
border: 1px solid #555;
|
border: 1px solid #555;
|
||||||
|
@ -109,10 +105,6 @@ article a, .entry a {
|
||||||
padding-right: 20px;
|
padding-right: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.commentname {
|
|
||||||
text-align: right;
|
|
||||||
}
|
|
||||||
|
|
||||||
.notFoundFace {
|
.notFoundFace {
|
||||||
height: 100px;
|
height: 100px;
|
||||||
padding-top: 50px;
|
padding-top: 50px;
|
||||||
|
|
23
src/Blog.hs
23
src/Blog.hs
|
@ -285,32 +285,9 @@ editPage (Entry{..}) = adminTemplate "Index" $ [shamlet|
|
||||||
<textarea name="mtext" cols="100" rows="15">#{mtext}
|
<textarea name="mtext" cols="100" rows="15">#{mtext}
|
||||||
<input type="hidden" name="eid" value=#{unEntryId entryId}>
|
<input type="hidden" name="eid" value=#{unEntryId entryId}>
|
||||||
<input type="submit" style="margin-left:20px;" value="Absenden">
|
<input type="submit" style="margin-left:20px;" value="Absenden">
|
||||||
<div class="editComments">#{editComments comments entryId}
|
|
||||||
<p>^{adminFooter}
|
<p>^{adminFooter}
|
||||||
|]
|
|]
|
||||||
|
|
||||||
editComments :: [Comment] -> EntryId -> Html
|
|
||||||
editComments comments eId = [shamlet|
|
|
||||||
<table>
|
|
||||||
$forall c <- comments
|
|
||||||
<tr>
|
|
||||||
<td>#{cauthor c}
|
|
||||||
<td>#{cPostTime $ cdate c}
|
|
||||||
<tr>
|
|
||||||
<td><a href=#{cDeleteLink $ cdate c}>Löschen
|
|
||||||
|]
|
|
||||||
where
|
|
||||||
cPostTime = formatTime defaultTimeLocale "%c"
|
|
||||||
cDeleteLink cd = concat ["/admin/cdelete/", show eId, formatTime defaultTimeLocale "/%s%Q" cd]
|
|
||||||
|
|
||||||
commentDeleted :: EntryId -> Html
|
|
||||||
commentDeleted eId = adminTemplate "Kommentar gelöscht" $ [shamlet|
|
|
||||||
<div>Der Kommentar wurde gelöscht.
|
|
||||||
<br>
|
|
||||||
<a href=#{append "/de/" $ show' eId}>Eintrag ansehen | #
|
|
||||||
<a href=#{append "/admin/edit/" $ show' eId}>Eintrag bearbeiten
|
|
||||||
|]
|
|
||||||
|
|
||||||
showError :: BlogError -> BlogLang -> Html
|
showError :: BlogError -> BlogLang -> Html
|
||||||
showError NotFound l = blogTemplate l (T.append ": " $ notFoundTitle l) $ [shamlet|
|
showError NotFound l = blogTemplate l (T.append ": " $ notFoundTitle l) $ [shamlet|
|
||||||
<div .row .text-center>
|
<div .row .text-center>
|
||||||
|
|
|
@ -6,7 +6,6 @@ import Data.Acid
|
||||||
import Data.Acid.Advanced
|
import Data.Acid.Advanced
|
||||||
import Data.Acid.Local
|
import Data.Acid.Local
|
||||||
import Data.ByteString (ByteString)
|
import Data.ByteString (ByteString)
|
||||||
import Data.Char (toLower)
|
|
||||||
import Data.Data (Data, Typeable)
|
import Data.Data (Data, Typeable)
|
||||||
import Data.IxSet (Indexable (..), IxSet (..), Proxy (..),
|
import Data.IxSet (Indexable (..), IxSet (..), Proxy (..),
|
||||||
getOne, ixFun, ixSet, (@=))
|
getOne, ixFun, ixSet, (@=))
|
||||||
|
@ -41,14 +40,6 @@ instance Show BlogLang where
|
||||||
|
|
||||||
$(deriveSafeCopy 0 'base ''BlogLang)
|
$(deriveSafeCopy 0 'base ''BlogLang)
|
||||||
|
|
||||||
data Comment = Comment {
|
|
||||||
cdate :: UTCTime,
|
|
||||||
cauthor :: Text,
|
|
||||||
ctext :: Text
|
|
||||||
} deriving (Eq, Ord, Show, Data, Typeable)
|
|
||||||
|
|
||||||
$(deriveSafeCopy 0 'base ''Comment)
|
|
||||||
|
|
||||||
data Entry = Entry {
|
data Entry = Entry {
|
||||||
entryId :: EntryId,
|
entryId :: EntryId,
|
||||||
lang :: BlogLang,
|
lang :: BlogLang,
|
||||||
|
@ -57,8 +48,7 @@ data Entry = Entry {
|
||||||
btext :: Text,
|
btext :: Text,
|
||||||
mtext :: Text,
|
mtext :: Text,
|
||||||
edate :: UTCTime,
|
edate :: UTCTime,
|
||||||
tags :: [Text],
|
tags :: [Text]
|
||||||
comments :: [Comment]
|
|
||||||
} deriving (Eq, Ord, Show, Data, Typeable)
|
} deriving (Eq, Ord, Show, Data, Typeable)
|
||||||
|
|
||||||
$(deriveSafeCopy 0 'base ''Entry)
|
$(deriveSafeCopy 0 'base ''Entry)
|
||||||
|
@ -93,7 +83,6 @@ instance Indexable Entry where
|
||||||
, ixFun $ \e -> [ MText $ mtext e]
|
, ixFun $ \e -> [ MText $ mtext e]
|
||||||
, ixFun $ \e -> [ EDate $ edate e]
|
, ixFun $ \e -> [ EDate $ edate e]
|
||||||
, ixFun $ \e -> map Tag (tags e)
|
, ixFun $ \e -> map Tag (tags e)
|
||||||
, ixFun comments
|
|
||||||
]
|
]
|
||||||
|
|
||||||
data User = User {
|
data User = User {
|
||||||
|
@ -144,22 +133,6 @@ insertEntry e =
|
||||||
put $ b { blogEntries = IxSet.insert e blogEntries }
|
put $ b { blogEntries = IxSet.insert e blogEntries }
|
||||||
return e
|
return e
|
||||||
|
|
||||||
addComment :: EntryId -> Comment -> Update Blog Entry
|
|
||||||
addComment eId c =
|
|
||||||
do b@Blog{..} <- get
|
|
||||||
let (Just e) = getOne $ blogEntries @= eId
|
|
||||||
let newEntry = e { comments = insert c $ comments e }
|
|
||||||
put $ b { blogEntries = IxSet.updateIx eId newEntry blogEntries }
|
|
||||||
return newEntry
|
|
||||||
|
|
||||||
deleteComment :: EntryId -> UTCTime -> Update Blog Entry
|
|
||||||
deleteComment eId cDate =
|
|
||||||
do b@Blog{..} <- get
|
|
||||||
let (Just e) = getOne $ blogEntries @= eId
|
|
||||||
let newEntry = e {comments = filter (\c -> cdate c /= cDate) (comments e)}
|
|
||||||
put $ b { blogEntries = IxSet.updateIx eId newEntry blogEntries }
|
|
||||||
return newEntry
|
|
||||||
|
|
||||||
updateEntry :: Entry -> Update Blog Entry
|
updateEntry :: Entry -> Update Blog Entry
|
||||||
updateEntry e =
|
updateEntry e =
|
||||||
do b@Blog{..} <- get
|
do b@Blog{..} <- get
|
||||||
|
@ -219,8 +192,6 @@ hashString = B64.encode . SHA.hash . B.pack
|
||||||
|
|
||||||
$(makeAcidic ''Blog
|
$(makeAcidic ''Blog
|
||||||
[ 'insertEntry
|
[ 'insertEntry
|
||||||
, 'addComment
|
|
||||||
, 'deleteComment
|
|
||||||
, 'updateEntry
|
, 'updateEntry
|
||||||
, 'getEntry
|
, 'getEntry
|
||||||
, 'latestEntries
|
, 'latestEntries
|
||||||
|
|
|
@ -99,35 +99,6 @@ noticeText :: BlogLang -> Text
|
||||||
noticeText EN = "site notice"
|
noticeText EN = "site notice"
|
||||||
noticeText DE = "Impressum"
|
noticeText DE = "Impressum"
|
||||||
|
|
||||||
-- comments
|
|
||||||
noComments :: BlogLang -> Text
|
|
||||||
noComments DE = " Keine Kommentare"
|
|
||||||
noComments EN = " No comments yet"
|
|
||||||
|
|
||||||
cHead :: BlogLang -> Text
|
|
||||||
cHead DE = "Kommentare"
|
|
||||||
cHead EN = "Comments"
|
|
||||||
|
|
||||||
cwHead :: BlogLang -> Text
|
|
||||||
cwHead DE = "Kommentieren:"
|
|
||||||
cwHead EN = "Comment:"
|
|
||||||
|
|
||||||
cSingle :: BlogLang -> Text
|
|
||||||
cSingle DE = "Kommentar:" --input label
|
|
||||||
cSingle EN = "Comment:"
|
|
||||||
|
|
||||||
cTimeFormat :: BlogLang -> String --formatTime expects a String
|
|
||||||
cTimeFormat DE = "[Am %Y-%m-%d um %H:%M Uhr]"
|
|
||||||
cTimeFormat EN = "[On %Y-%m-%d at %H:%M]"
|
|
||||||
|
|
||||||
cSend :: BlogLang -> Text
|
|
||||||
cSend DE = "Absenden"
|
|
||||||
cSend EN = "Submit"
|
|
||||||
|
|
||||||
cTextPlaceholder :: BlogLang -> Text
|
|
||||||
cTextPlaceholder DE = "Kommentartext hier eingeben :]"
|
|
||||||
cTextPlaceholder EN = "Enter your comment here :]"
|
|
||||||
|
|
||||||
-- RSS Strings
|
-- RSS Strings
|
||||||
rssTitle :: BlogLang -> String
|
rssTitle :: BlogLang -> String
|
||||||
rssTitle DE = "Tazjins Blog"
|
rssTitle DE = "Tazjins Blog"
|
||||||
|
|
|
@ -32,7 +32,7 @@ instance FromReqURI BlogLang where
|
||||||
_ -> Nothing
|
_ -> Nothing
|
||||||
|
|
||||||
tmpPolicy :: BodyPolicy
|
tmpPolicy :: BodyPolicy
|
||||||
tmpPolicy = defaultBodyPolicy "./tmp/" 0 200000 1000
|
tmpPolicy = defaultBodyPolicy "/tmp" 0 200000 1000
|
||||||
|
|
||||||
runBlog :: AcidState Blog -> Int -> String -> IO ()
|
runBlog :: AcidState Blog -> Int -> String -> IO ()
|
||||||
runBlog acid port respath =
|
runBlog acid port respath =
|
||||||
|
@ -62,9 +62,6 @@ tazBlog acid resDir = do
|
||||||
dirs "admin/edit" $ path $ \(eId :: Integer) -> editEntry acid eId
|
dirs "admin/edit" $ path $ \(eId :: Integer) -> editEntry acid eId
|
||||||
, do guardSession acid
|
, do guardSession acid
|
||||||
dirs "admin/updateentry" $ nullDir >> updateEntry acid
|
dirs "admin/updateentry" $ nullDir >> updateEntry acid
|
||||||
, do guardSession acid
|
|
||||||
dirs "admin/cdelete" $ path $ \(eId :: Integer) -> path $ \(cId :: String) ->
|
|
||||||
deleteComment acid (EntryId eId) cId
|
|
||||||
, do dir "admin" nullDir
|
, do dir "admin" nullDir
|
||||||
guardSession acid
|
guardSession acid
|
||||||
ok $ toResponse $ adminIndex ("tazjin" :: Text)
|
ok $ toResponse $ adminIndex ("tazjin" :: Text)
|
||||||
|
@ -144,7 +141,6 @@ postEntry acid = do
|
||||||
<*> pure nMtext
|
<*> pure nMtext
|
||||||
<*> pure now
|
<*> pure now
|
||||||
<*> pure [] -- NYI
|
<*> pure [] -- NYI
|
||||||
<*> pure []
|
|
||||||
update' acid (InsertEntry nEntry)
|
update' acid (InsertEntry nEntry)
|
||||||
seeOther ("/" ++ lang ++ "/" ++ show eId) (toResponse())
|
seeOther ("/" ++ lang ++ "/" ++ show eId) (toResponse())
|
||||||
where
|
where
|
||||||
|
@ -181,13 +177,6 @@ updateEntry acid = do
|
||||||
seeOther (concat $ intersperse' "/" [show $ lang entry, show eId])
|
seeOther (concat $ intersperse' "/" [show $ lang entry, show eId])
|
||||||
(toResponse ())
|
(toResponse ())
|
||||||
|
|
||||||
deleteComment :: AcidState Blog -> EntryId -> String -> ServerPart Response
|
|
||||||
deleteComment acid eId cId = do
|
|
||||||
nEntry <- update' acid (DeleteComment eId cDate)
|
|
||||||
ok $ toResponse $ commentDeleted eId
|
|
||||||
where
|
|
||||||
(cDate :: UTCTime) = fromJust $ parseTime defaultTimeLocale "%s%Q" cId
|
|
||||||
|
|
||||||
guardSession :: AcidState Blog -> ServerPartT IO ()
|
guardSession :: AcidState Blog -> ServerPartT IO ()
|
||||||
guardSession acid = do
|
guardSession acid = do
|
||||||
(sId :: Text) <- readCookieValue "session"
|
(sId :: Text) <- readCookieValue "session"
|
||||||
|
|
Loading…
Add table
Reference in a new issue