1
1
mirror of https://github.com/aelve/guide.git synced 2024-11-23 12:15:06 +03:00

Merging for item descriptions

This commit is contained in:
Artyom 2016-06-20 14:18:00 +03:00
parent 55258979b8
commit c2dcaa81a8
3 changed files with 32 additions and 8 deletions

View File

@ -508,10 +508,24 @@ submitCategoryNotes =
submitItemDescription :: JSFunction a => a
submitItemDescription =
makeJSFunction "submitItemDescription" ["node", "itemId", "s"]
makeJSFunction "submitItemDescription"
["node", "itemId", "original", "ours"]
[text|
$.post("/haskell/set/item/"+itemId+"/description", {content: s})
.done(replaceWithData(node));
$.post({
url: "/haskell/set/item/"+itemId+"/description",
data: {
original: original,
content: ours },
success: function (data) {
$.magnificPopup.close();
$(node).replaceWith(data); },
statusCode: {
409: function (xhr, st, err) {
modified = xhr.responseJSON["modified"];
merged = xhr.responseJSON["merged"];
showDiffPopup(ours, modified, merged, function (x) {
submitItemDescription(node, itemId, modified, x) }); } }
});
|]
submitItemEcosystem :: JSFunction a => a

View File

@ -461,11 +461,20 @@ setMethods = Spock.subcomponent "set" $ do
lucidIO $ renderItemInfo category item
-- Item description
Spock.post (itemVar <//> "description") $ \itemId -> do
original <- param' "original"
content' <- param' "content"
invalidateCache' (CacheItemDescription itemId)
(edit, item) <- dbUpdate (SetItemDescription itemId content')
addEdit edit
lucidIO $ renderItemDescription item
modified <- view (description.mdText) <$> dbQuery (GetItem itemId)
if modified == original
then do
invalidateCache' (CacheItemDescription itemId)
(edit, item) <- dbUpdate (SetItemDescription itemId content')
addEdit edit
lucidIO $ renderItemDescription item
else do
setStatus HTTP.status409
json $ M.fromList [
("modified" :: Text, modified),
("merged" :: Text, merge original content' modified)]
-- Item ecosystem
Spock.post (itemVar <//> "ecosystem") $ \itemId -> do
original <- param' "original"

View File

@ -930,7 +930,8 @@ renderItemDescription item = cached (CacheItemDescription (item^.uid)) $ do
markdownEditor
[rows_ "10"]
(item^.description)
(\val -> JS.submitItemDescription (this, item^.uid, val))
(\val -> JS.submitItemDescription
(this, item^.uid, item^.description.mdText, val))
(JS.switchSection (this, "normal" :: Text))
renderItemEcosystem :: (MonadIO m, MonadRandom m) => Item -> HtmlT m ()