Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Application/Schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ CREATE TABLE tasks (
CREATE TABLE tags (
id UUID DEFAULT uuid_generate_v4() PRIMARY KEY NOT NULL,
name TEXT NOT NULL,
task_id UUID NOT NULL
task_id UUID NOT NULL,
Number INT NOT NULL
);
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;
19 changes: 12 additions & 7 deletions Web/Controller/Tasks.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ instance Controller TasksController where

let tagIds :: [Id Tag] = paramList "tags_id"
let tagNames :: [Text] = paramList "tags_name"
let tagNumbers :: [Int] = paramList "tags_number"
originalTags <- fetch tagIds
let tags = zip tagIds tagNames
|> map (\(id, name) -> originalTags
let tags = zip3 tagIds tagNames tagNumbers
|> map (\(id, name, number) -> originalTags
|> find (\tag -> tag.id == id)
|> fromMaybe (newRecord |> set #taskId task.id)
|> \tag -> buildTag tag name
|> \tag -> buildTag tag name number
)


Expand All @@ -62,7 +63,8 @@ instance Controller TasksController where
action CreateTaskAction = do
let task = newRecord @Task
let names :: [Text] = paramList "tags_name"
let tags = names |> map (buildTag newRecord)
let numbers :: [Int] = paramList "tags_number"
let tags = zip names numbers |> map (\(name, number) -> buildTag newRecord name number)

task
|> buildTask
Expand All @@ -78,7 +80,7 @@ instance Controller TasksController where
|> createMany

pure (task, tags)

setSuccessMessage "Task and Tags created"
redirectTo TasksAction

Expand All @@ -92,10 +94,13 @@ buildTask task = task
|> fill @'["description"]
|> validateField #description nonEmpty

buildTag :: Tag -> Text -> Tag
buildTag tag name = tag
buildTag :: Tag -> Text -> Int -> Tag
buildTag tag name number = tag
|> set #name name
|> set #number number
|> validateField #name nonEmpty
-- Validate number is above 10
|> validateField #number (isGreaterThan 10)

-- | Adds a validation error to the record when any of the child records is invalid
bubbleValidationResult :: forall fieldName record childRecord.
Expand Down
5 changes: 4 additions & 1 deletion Web/View/Tasks/New.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,8 @@ prototypeFor field record =

renderTagForm :: (?formContext :: FormContext Tag) => Html
renderTagForm = [hsx|
{(textField #name) { disableLabel = True, placeholder = "Tag name" } }
<fieldset class="border p-2 my-4">
{(textField #name) { disableLabel = True, placeholder = "Tag name" } }
{(numberField #number) { disableLabel = True, placeholder = "Tag number" } }
</fieldset>
|]
1 change: 1 addition & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
let
ihp = builtins.fetchGit {
url = "https://github.com/digitallyinduced/ihp.git";
ref = "refs/heads/nestedFormFor";
rev = "c049d0e3f0f1c7fcc80f275b8307446ece00bcf0";
};
haskellEnv = import "${ihp}/NixSupport/default.nix" {
Expand Down