forked from janek/compareware
Add values to tasks
This commit is contained in:
parent
5f92b8d71d
commit
f87cf81d24
|
@ -0,0 +1 @@
|
||||||
|
ALTER TABLE tags ADD COLUMN value TEXT NOT NULL;
|
|
@ -6,7 +6,8 @@ CREATE TABLE tasks (
|
||||||
CREATE TABLE tags (
|
CREATE TABLE tags (
|
||||||
id UUID DEFAULT uuid_generate_v4() PRIMARY KEY NOT NULL,
|
id UUID DEFAULT uuid_generate_v4() PRIMARY KEY NOT NULL,
|
||||||
name TEXT NOT NULL,
|
name TEXT NOT NULL,
|
||||||
task_id UUID NOT NULL
|
task_id UUID NOT NULL,
|
||||||
|
value TEXT NOT NULL
|
||||||
);
|
);
|
||||||
CREATE INDEX tags_task_id_index ON tags (task_id);
|
CREATE INDEX tags_task_id_index ON tags (task_id);
|
||||||
ALTER TABLE tags ADD CONSTRAINT tags_ref_task_id FOREIGN KEY (task_id) REFERENCES tasks (id) ON DELETE NO ACTION;
|
ALTER TABLE tags ADD CONSTRAINT tags_ref_task_id FOREIGN KEY (task_id) REFERENCES tasks (id) ON DELETE NO ACTION;
|
||||||
|
|
|
@ -32,15 +32,15 @@ instance Controller TasksController where
|
||||||
|
|
||||||
let tagIds :: [Id Tag] = paramList "tags_id"
|
let tagIds :: [Id Tag] = paramList "tags_id"
|
||||||
let tagNames :: [Text] = paramList "tags_name"
|
let tagNames :: [Text] = paramList "tags_name"
|
||||||
|
let tagValues :: [Text] = paramList "tags_value"
|
||||||
originalTags <- fetch tagIds
|
originalTags <- fetch tagIds
|
||||||
let tags = zip tagIds tagNames
|
let tags = zip3 tagIds tagNames tagValues
|
||||||
|> map (\(id, name) -> originalTags
|
|> map (\(id, name, value) -> originalTags
|
||||||
|> find (\tag -> tag.id == id)
|
|> find (\tag -> tag.id == id)
|
||||||
|> fromMaybe (newRecord |> set #taskId task.id)
|
|> fromMaybe (newRecord |> set #taskId task.id)
|
||||||
|> \tag -> buildTag tag name
|
|> \tag -> buildTag tag name value
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
task
|
task
|
||||||
|> buildTask
|
|> buildTask
|
||||||
|> updateField @"tags" tags
|
|> updateField @"tags" tags
|
||||||
|
@ -62,7 +62,8 @@ instance Controller TasksController where
|
||||||
action CreateTaskAction = do
|
action CreateTaskAction = do
|
||||||
let task = newRecord @Task
|
let task = newRecord @Task
|
||||||
let names :: [Text] = paramList "tags_name"
|
let names :: [Text] = paramList "tags_name"
|
||||||
let tags = names |> map (buildTag newRecord)
|
let values :: [Text] = paramList "tags_value"
|
||||||
|
let tags = zip names values |> map (\(name, value) -> buildTag newRecord name value)
|
||||||
|
|
||||||
task
|
task
|
||||||
|> buildTask
|
|> buildTask
|
||||||
|
@ -92,9 +93,10 @@ buildTask task = task
|
||||||
|> fill @'["description"]
|
|> fill @'["description"]
|
||||||
|> validateField #description nonEmpty
|
|> validateField #description nonEmpty
|
||||||
|
|
||||||
buildTag :: Tag -> Text -> Tag
|
buildTag :: Tag -> Text -> Text -> Tag
|
||||||
buildTag tag name = tag
|
buildTag tag name value = tag
|
||||||
|> set #name name
|
|> set #name name
|
||||||
|
|> set #value value
|
||||||
|> validateField #name nonEmpty
|
|> validateField #name nonEmpty
|
||||||
|
|
||||||
-- | Adds a validation error to the record when any of the child records is invalid
|
-- | Adds a validation error to the record when any of the child records is invalid
|
||||||
|
@ -120,4 +122,4 @@ updateOrCreateRecord record | isNew record = createRecord record
|
||||||
updateOrCreateRecord record = updateRecord record
|
updateOrCreateRecord record = updateRecord record
|
||||||
|
|
||||||
clearTags :: Include "tags" Task -> Task
|
clearTags :: Include "tags" Task -> Task
|
||||||
clearTags task = updateField @"tags" (newRecord @Task).tags task
|
clearTags task = updateField @"tags" (newRecord @Task).tags task
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
module Web.View.Tasks.New where
|
module Web.View.Tasks.New where
|
||||||
|
|
||||||
import Web.View.Prelude
|
import Web.View.Prelude
|
||||||
import Text.Blaze.Html.Renderer.Text
|
import Text.Blaze.Html.Renderer.Text
|
||||||
|
|
||||||
|
@ -16,6 +17,7 @@ instance View NewView where
|
||||||
[ breadcrumbLink "Tasks" TasksAction
|
[ breadcrumbLink "Tasks" TasksAction
|
||||||
, breadcrumbText "New Task"
|
, breadcrumbText "New Task"
|
||||||
]
|
]
|
||||||
|
|
||||||
renderForm :: Include "tags" Task -> Html
|
renderForm :: Include "tags" Task -> Html
|
||||||
renderForm task = formFor task [hsx|
|
renderForm task = formFor task [hsx|
|
||||||
{textField #description}
|
{textField #description}
|
||||||
|
@ -42,4 +44,5 @@ prototypeFor field record =
|
||||||
renderTagForm :: (?formContext :: FormContext Tag) => Html
|
renderTagForm :: (?formContext :: FormContext Tag) => Html
|
||||||
renderTagForm = [hsx|
|
renderTagForm = [hsx|
|
||||||
{(textField #name) { disableLabel = True, placeholder = "Tag name" } }
|
{(textField #name) { disableLabel = True, placeholder = "Tag name" } }
|
||||||
|
{(textField #value) { disableLabel = True, placeholder = "Tag value" } }
|
||||||
|]
|
|]
|
||||||
|
|
Loading…
Reference in New Issue