diff --git a/Application/Schema.sql b/Application/Schema.sql index f8fcad3..3f8a7d8 100644 --- a/Application/Schema.sql +++ b/Application/Schema.sql @@ -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; diff --git a/Web/Controller/Tasks.hs b/Web/Controller/Tasks.hs index e2858d4..e4e20af 100644 --- a/Web/Controller/Tasks.hs +++ b/Web/Controller/Tasks.hs @@ -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 ) @@ -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 @@ -78,7 +80,7 @@ instance Controller TasksController where |> createMany pure (task, tags) - + setSuccessMessage "Task and Tags created" redirectTo TasksAction @@ -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. diff --git a/Web/View/Tasks/New.hs b/Web/View/Tasks/New.hs index 12b48e4..cd8d640 100644 --- a/Web/View/Tasks/New.hs +++ b/Web/View/Tasks/New.hs @@ -41,5 +41,8 @@ prototypeFor field record = renderTagForm :: (?formContext :: FormContext Tag) => Html renderTagForm = [hsx| - {(textField #name) { disableLabel = True, placeholder = "Tag name" } } +
|] \ No newline at end of file diff --git a/default.nix b/default.nix index f529d4b..d44f6c4 100644 --- a/default.nix +++ b/default.nix @@ -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" {