1
1
mirror of https://github.com/aelve/guide.git synced 2024-12-23 04:42:24 +03:00

Simplify/fix #29 handling

This commit is contained in:
Artyom 2017-06-01 20:29:12 +03:00
parent f40299acf4
commit 9be1db3b50
No known key found for this signature in database
GPG Key ID: B8E35A33FF522710
5 changed files with 13 additions and 13 deletions

View File

@ -244,14 +244,14 @@ setMethods = Spock.subcomponent "set" $ do
("modified" :: Text, modified),
("merged" :: Text, merge original content' modified)]
-- Trait
Spock.post (itemVar <//> categoryVar <//> traitVar) $ \itemId catId traitId -> do
Spock.post (itemVar <//> traitVar) $ \itemId traitId -> do
original <- param' "original"
content' <- param' "content"
modified <- view (content.mdText) <$> dbQuery (GetTrait itemId traitId)
if modified == original
then do
trait <- uncache (CacheItemTraits itemId) $ do
(edit, trait) <- dbUpdate (SetTraitContent itemId catId traitId content')
(edit, trait) <- dbUpdate (SetTraitContent itemId traitId content')
addEdit edit
return trait
lucidIO $ renderTrait itemId trait

View File

@ -231,11 +231,11 @@ undoEdit (Edit'SetItemEcosystem itemId old new) = do
if now /= new
then return (Left "ecosystem has been changed further")
else Right () <$ dbUpdate (SetItemEcosystem itemId old)
undoEdit (Edit'SetTraitContent itemId catId traitId old new) = do
undoEdit (Edit'SetTraitContent itemId traitId old new) = do
now <- view (content.mdText) <$> dbQuery (GetTrait itemId traitId)
if now /= new
then return (Left "trait has been changed further")
else Right () <$ dbUpdate (SetTraitContent itemId catId traitId old)
else Right () <$ dbUpdate (SetTraitContent itemId traitId old)
undoEdit (Edit'DeleteCategory catId pos) = do
dbUpdate (RestoreCategory catId pos)
undoEdit (Edit'DeleteItem itemId pos) = do
@ -291,7 +291,7 @@ invalidateCacheForEdit ed = do
[CacheItemNotes itemId]
Edit'SetItemEcosystem itemId _ _ ->
[CacheItemEcosystem itemId]
Edit'SetTraitContent itemId _ _ _ _ ->
Edit'SetTraitContent itemId _ _ _ ->
[CacheItemTraits itemId]
Edit'DeleteCategory catId _ ->
[CacheCategory catId]

View File

@ -456,11 +456,11 @@ setItemEcosystem itemId ecosystem' = do
(oldEcosystem ^. mdText) ecosystem'
(edit,) <$> use (itemById itemId)
setTraitContent :: Uid Item -> Uid Category -> Uid Trait -> Text -> Acid.Update GlobalState (Edit, Trait)
setTraitContent itemId catId traitId content' = do
setTraitContent :: Uid Item -> Uid Trait -> Text -> Acid.Update GlobalState (Edit, Trait)
setTraitContent itemId traitId content' = do
oldContent <- itemById itemId . traitById traitId . content <<.=
toMarkdownInline content'
let edit = Edit'SetTraitContent itemId catId traitId
let edit = Edit'SetTraitContent itemId traitId
(oldContent ^. mdText) content'
(edit,) <$> use (itemById itemId . traitById traitId)

View File

@ -106,7 +106,6 @@ data Edit
-- Change trait properties
| Edit'SetTraitContent {
editItemUid :: Uid Item,
editCategoryUid :: Uid Category,
editTraitUid :: Uid Trait,
editTraitContent :: Text,
editTraitNewContent :: Text }

View File

@ -390,9 +390,9 @@ renderEdit globalState edit = do
-- Add
Edit'AddCategory _catId title' -> p_ $ do
"added category " >> quote (toHtml title')
Edit'AddItem catId _itemId _ -> p_ $ do
Edit'AddItem catId _itemId name' -> p_ $ do
"added item " >> printItem _itemId
" (initially called " >> quote (toHtml name') >> ")"
" to category " >> printCategory catId
Edit'AddPro itemId _traitId content' -> do
p_ $ "added pro to item " >> printItem itemId
@ -473,9 +473,10 @@ renderEdit globalState edit = do
td_ $ blockquote_ $ toHtml (toMarkdownBlock newEcosystem)
-- Change trait properties
Edit'SetTraitContent itemId catId _traitId oldContent newContent -> do
Edit'SetTraitContent itemId _traitId oldContent newContent -> do
p_ $ (if T.null oldContent then "added" else "changed") >>
" trait of item " >> printItem itemId >> " from category " >> printCategory catId
" trait of item " >> printItem itemId >>
" from category " >> printCategory (findItem itemId ^. _1.uid)
table_ $ tr_ $ do
unless (T.null oldContent) $
td_ $ blockquote_ $ p_ (toHtml (toMarkdownInline oldContent))