mirror of
https://github.com/aelve/guide.git
synced 2024-11-30 11:32:29 +03:00
Change method names
This commit is contained in:
parent
c598160143
commit
34dbe3e640
87
src/Main.hs
87
src/Main.hs
@ -122,8 +122,11 @@ main = runSpock 8080 $ spockT id $ do
|
|||||||
-- them and inject into the page. We don't want to duplicate rendering on
|
-- them and inject into the page. We don't want to duplicate rendering on
|
||||||
-- server side and on client side.
|
-- server side and on client side.
|
||||||
|
|
||||||
-- TODO: rename methods to “category/add” etc
|
-- (category|item)/action
|
||||||
Spock.post "/add/category" $ do
|
-- (category|item)/id/action
|
||||||
|
-- (category|item)/id/thing/action
|
||||||
|
|
||||||
|
Spock.post "/category/add" $ do
|
||||||
title' <- param' "title"
|
title' <- param' "title"
|
||||||
id' <- liftIO (newId stateVar)
|
id' <- liftIO (newId stateVar)
|
||||||
let newCategory = Category {
|
let newCategory = Category {
|
||||||
@ -134,7 +137,7 @@ main = runSpock 8080 $ spockT id $ do
|
|||||||
categories %= (++ [newCategory])
|
categories %= (++ [newCategory])
|
||||||
lucid $ renderCategory newCategory
|
lucid $ renderCategory newCategory
|
||||||
|
|
||||||
Spock.post ("/add/item/library" <//> var) $ \catId' -> do
|
Spock.post ("/category" <//> var <//> "library/add") $ \catId' -> do
|
||||||
name' <- param' "name"
|
name' <- param' "name"
|
||||||
id' <- liftIO (newId stateVar)
|
id' <- liftIO (newId stateVar)
|
||||||
let newItem = Item {
|
let newItem = Item {
|
||||||
@ -150,35 +153,35 @@ main = runSpock 8080 $ spockT id $ do
|
|||||||
categoryById catId' . items %= (++ [newItem])
|
categoryById catId' . items %= (++ [newItem])
|
||||||
lucid $ renderItem newItem
|
lucid $ renderItem newItem
|
||||||
|
|
||||||
Spock.post ("/add/pros" <//> var) $ \itemId' -> do
|
Spock.post ("/item" <//> var <//> "pros/add") $ \itemId' -> do
|
||||||
content <- param' "content"
|
content <- param' "content"
|
||||||
changedItem <- withS $ do
|
changedItem <- withS $ do
|
||||||
itemById itemId' . pros %= (++ [content])
|
itemById itemId' . pros %= (++ [content])
|
||||||
use (itemById itemId')
|
use (itemById itemId')
|
||||||
lucid $ renderItem changedItem
|
lucid $ renderItem changedItem
|
||||||
|
|
||||||
Spock.post ("/add/cons" <//> var) $ \itemId' -> do
|
Spock.post ("/item" <//> var <//> "cons/add") $ \itemId' -> do
|
||||||
content <- param' "content"
|
content <- param' "content"
|
||||||
changedItem <- withS $ do
|
changedItem <- withS $ do
|
||||||
itemById itemId' . cons %= (++ [content])
|
itemById itemId' . cons %= (++ [content])
|
||||||
use (itemById itemId')
|
use (itemById itemId')
|
||||||
lucid $ renderItem changedItem
|
lucid $ renderItem changedItem
|
||||||
|
|
||||||
Spock.post ("/edit/category" <//> var <//> "title") $ \catId' -> do
|
Spock.post ("/category" <//> var <//> "title/set") $ \catId' -> do
|
||||||
title' <- param' "title"
|
title' <- param' "title"
|
||||||
changedCategory <- withS $ do
|
changedCategory <- withS $ do
|
||||||
categoryById catId' . title .= title'
|
categoryById catId' . title .= title'
|
||||||
use (categoryById catId')
|
use (categoryById catId')
|
||||||
lucid $ renderCategoryHeading changedCategory
|
lucid $ renderCategoryHeading changedCategory
|
||||||
|
|
||||||
Spock.get ("/edit/category" <//> var <//> "title/edit") $ \catId' -> do
|
Spock.get ("/category" <//> var <//> "title/render-normal") $ \catId' -> do
|
||||||
category <- withS $ use (categoryById catId')
|
|
||||||
lucid $ renderCategoryHeadingEdit category
|
|
||||||
|
|
||||||
Spock.get ("/edit/category" <//> var <//> "title/cancel") $ \catId' -> do
|
|
||||||
category <- withS $ use (categoryById catId')
|
category <- withS $ use (categoryById catId')
|
||||||
lucid $ renderCategoryHeading category
|
lucid $ renderCategoryHeading category
|
||||||
|
|
||||||
|
Spock.get ("/category" <//> var <//> "title/render-edit") $ \catId' -> do
|
||||||
|
category <- withS $ use (categoryById catId')
|
||||||
|
lucid $ renderCategoryHeadingEdit category
|
||||||
|
|
||||||
renderRoot :: S -> Html ()
|
renderRoot :: S -> Html ()
|
||||||
renderRoot s = do
|
renderRoot s = do
|
||||||
includeJS "https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"
|
includeJS "https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"
|
||||||
@ -292,28 +295,28 @@ allJSFunctions = [
|
|||||||
js_addPros, js_addCons,
|
js_addPros, js_addCons,
|
||||||
js_setItemHtml, js_setCategoryHeadingHtml ]
|
js_setItemHtml, js_setCategoryHeadingHtml ]
|
||||||
|
|
||||||
-- | Add a new library to some category.
|
|
||||||
js_addLibrary :: JSFunction a => a
|
|
||||||
js_addLibrary = makeJSFunction "addLibrary" [text|
|
|
||||||
function addLibrary(catId, s) {
|
|
||||||
$.post("/add/item/library/" + catId, {name: s})
|
|
||||||
.done(function(data) {
|
|
||||||
$("#cat"+catId+" > .items").append(data);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|]
|
|
||||||
|
|
||||||
-- | Create a new category.
|
-- | Create a new category.
|
||||||
js_addCategory :: JSFunction a => a
|
js_addCategory :: JSFunction a => a
|
||||||
js_addCategory = makeJSFunction "addCategory" [text|
|
js_addCategory = makeJSFunction "addCategory" [text|
|
||||||
function addCategory(s) {
|
function addCategory(s) {
|
||||||
$.post("/add/category", {title: s})
|
$.post("/category/add", {title: s})
|
||||||
.done(function(data) {
|
.done(function(data) {
|
||||||
$("#categories").append(data);
|
$("#categories").append(data);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|]
|
|]
|
||||||
|
|
||||||
|
-- | Add a new library to some category.
|
||||||
|
js_addLibrary :: JSFunction a => a
|
||||||
|
js_addLibrary = makeJSFunction "addLibrary" [text|
|
||||||
|
function addLibrary(catId, s) {
|
||||||
|
$.post("/category/"+catId+"/library/add", {name: s})
|
||||||
|
.done(function(data) {
|
||||||
|
$("#cat"+catId+" > .items").append(data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|]
|
||||||
|
|
||||||
{- |
|
{- |
|
||||||
Start category heading editing (this happens when you click on “[edit]”).
|
Start category heading editing (this happens when you click on “[edit]”).
|
||||||
|
|
||||||
@ -322,22 +325,7 @@ This turns the heading into an editbox, and adds a [cancel] link.
|
|||||||
js_startCategoryHeadingEditing :: JSFunction a => a
|
js_startCategoryHeadingEditing :: JSFunction a => a
|
||||||
js_startCategoryHeadingEditing = makeJSFunction "startCategoryHeadingEditing" [text|
|
js_startCategoryHeadingEditing = makeJSFunction "startCategoryHeadingEditing" [text|
|
||||||
function startCategoryHeadingEditing(catId) {
|
function startCategoryHeadingEditing(catId) {
|
||||||
$.get("/edit/category/"+catId+"/title/edit")
|
$.get("/category/"+catId+"/title/render-edit")
|
||||||
.done(function(data) {
|
|
||||||
setCategoryHeadingHtml(catId, data);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|]
|
|
||||||
|
|
||||||
{- |
|
|
||||||
Finish category heading editing (this happens when you submit the field).
|
|
||||||
|
|
||||||
This turns the heading with the editbox back into a simple text heading.
|
|
||||||
-}
|
|
||||||
js_finishCategoryHeadingEditing :: JSFunction a => a
|
|
||||||
js_finishCategoryHeadingEditing = makeJSFunction "finishCategoryHeadingEditing" [text|
|
|
||||||
function finishCategoryHeadingEditing(catId, s) {
|
|
||||||
$.post("/edit/category/"+catId+"/title", {title: s})
|
|
||||||
.done(function(data) {
|
.done(function(data) {
|
||||||
setCategoryHeadingHtml(catId, data);
|
setCategoryHeadingHtml(catId, data);
|
||||||
});
|
});
|
||||||
@ -352,7 +340,22 @@ This turns the heading with the editbox back into a simple text heading.
|
|||||||
js_cancelCategoryHeadingEditing :: JSFunction a => a
|
js_cancelCategoryHeadingEditing :: JSFunction a => a
|
||||||
js_cancelCategoryHeadingEditing = makeJSFunction "cancelCategoryHeadingEditing" [text|
|
js_cancelCategoryHeadingEditing = makeJSFunction "cancelCategoryHeadingEditing" [text|
|
||||||
function cancelCategoryHeadingEditing(catId) {
|
function cancelCategoryHeadingEditing(catId) {
|
||||||
$.get("/edit/category/"+catId+"/title/cancel")
|
$.get("/category/"+catId+"/title/render-normal")
|
||||||
|
.done(function(data) {
|
||||||
|
setCategoryHeadingHtml(catId, data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|]
|
||||||
|
|
||||||
|
{- |
|
||||||
|
Finish category heading editing (this happens when you submit the field).
|
||||||
|
|
||||||
|
This turns the heading with the editbox back into a simple text heading.
|
||||||
|
-}
|
||||||
|
js_finishCategoryHeadingEditing :: JSFunction a => a
|
||||||
|
js_finishCategoryHeadingEditing = makeJSFunction "finishCategoryHeadingEditing" [text|
|
||||||
|
function finishCategoryHeadingEditing(catId, s) {
|
||||||
|
$.post("/category/"+catId+"/title/set", {title: s})
|
||||||
.done(function(data) {
|
.done(function(data) {
|
||||||
setCategoryHeadingHtml(catId, data);
|
setCategoryHeadingHtml(catId, data);
|
||||||
});
|
});
|
||||||
@ -363,7 +366,7 @@ js_cancelCategoryHeadingEditing = makeJSFunction "cancelCategoryHeadingEditing"
|
|||||||
js_addPros :: JSFunction a => a
|
js_addPros :: JSFunction a => a
|
||||||
js_addPros = makeJSFunction "addPros" [text|
|
js_addPros = makeJSFunction "addPros" [text|
|
||||||
function addPros(itemId, s) {
|
function addPros(itemId, s) {
|
||||||
$.post("/add/pros/" + itemId, {content: s})
|
$.post("/item/"+itemId+"/pros/add", {content: s})
|
||||||
.done(function(data) {
|
.done(function(data) {
|
||||||
setItemHtml(itemId, data);
|
setItemHtml(itemId, data);
|
||||||
});
|
});
|
||||||
@ -374,7 +377,7 @@ js_addPros = makeJSFunction "addPros" [text|
|
|||||||
js_addCons :: JSFunction a => a
|
js_addCons :: JSFunction a => a
|
||||||
js_addCons = makeJSFunction "addCons" [text|
|
js_addCons = makeJSFunction "addCons" [text|
|
||||||
function addCons(itemId, s) {
|
function addCons(itemId, s) {
|
||||||
$.post("/add/cons/" + itemId, {content: s})
|
$.post("/item/"+itemId+"/cons/add", {content: s})
|
||||||
.done(function(data) {
|
.done(function(data) {
|
||||||
setItemHtml(itemId, data);
|
setItemHtml(itemId, data);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user