From 9b9104e8f9138d863b9f81250ee2d89894f2df29 Mon Sep 17 00:00:00 2001 From: Erudition Date: Mon, 4 Dec 2023 11:40:23 -0600 Subject: [PATCH] Allow creation and naming of new assignables --- elm/Integrations/Marvin/MarvinItem.elm | 2 +- elm/Pages/TaskList.elm | 31 ++++++++++++++++++++------ elm/Task/Assignable.elm | 6 ++--- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/elm/Integrations/Marvin/MarvinItem.elm b/elm/Integrations/Marvin/MarvinItem.elm index e35136b1..369ccf01 100644 --- a/elm/Integrations/Marvin/MarvinItem.elm +++ b/elm/Integrations/Marvin/MarvinItem.elm @@ -587,7 +587,7 @@ toDocketTask profile marvinItem = projectChanger : Changer Project projectChanger newProject = -- TODO need Change.reuseContext ? - [ Task.Assignable.createWithinProject [ newAssignableChanger ] newProject ] + [ Task.Assignable.createWithinProject "TODO - Marvin assignable title?" [ newAssignableChanger ] newProject ] newAssignableChanger : Changer Task.Assignable.Assignable newAssignableChanger newAssignable = diff --git a/elm/Pages/TaskList.elm b/elm/Pages/TaskList.elm index 41905a37..03dd3ae3 100644 --- a/elm/Pages/TaskList.elm +++ b/elm/Pages/TaskList.elm @@ -207,8 +207,25 @@ update shared msg model = AddAssignable project -> let - frameDescription = - "Added a new assignable to project." + handleResult result = + case result of + Ok newName -> + RunEffect <| Effect.saveChanges (frameDescription newName) (finalChanges newName) + + Err _ -> + RunEffect <| Effect.none + + promptOptions = + { title = Just ("New Assignable in project: " ++ Maybe.withDefault "Untitled Project" (Project.title project)) + , message = "Enter a name for the assignable." + , okButtonTitle = Just "Rename" + , cancelButtonTitle = Nothing + , inputPlaceholder = Just "Assignable title here" + , inputText = Nothing + } + + frameDescription newName = + "Added a new assignable to project: " ++ newName assignableChanger : Assignable -> List Change assignableChanger parentAssignable = @@ -218,12 +235,12 @@ update shared msg model = -- actionToAdd = -- Action.newActionSkel (Change.reuseContext "in-action" c) "first action" (\_ -> []) - finalChanges = - [ RepList.insert RepList.Last frameDescription shared.replica.errors - , Assignable.createWithinProject [ assignableChanger ] project + finalChanges newName = + [ RepList.insert RepList.Last (frameDescription newName) shared.replica.errors + , Assignable.createWithinProject newName [ assignableChanger ] project ] in - ( model, Effect.saveChanges frameDescription finalChanges ) + ( model, Effect.dialogPrompt handleResult promptOptions ) AddAssignment assignable -> let @@ -525,7 +542,7 @@ viewProject profile ( time, timeZone ) trackedTaskMaybe project = entryContents = case Project.children project |> RepList.listValues of [] -> - text "No assignables in this project." + node "ion-button" [ attribute "fill" "clear", onClick (AddAssignable project) ] [ node "ion-icon" [ name "add-circle-outline" ] [], text "Add first assignable" ] someChildren -> div [] <| List.map viewProjectChild someChildren diff --git a/elm/Task/Assignable.elm b/elm/Task/Assignable.elm index 0c4f1b53..cd89944f 100644 --- a/elm/Task/Assignable.elm +++ b/elm/Task/Assignable.elm @@ -60,8 +60,8 @@ fromSkel project assignableSkelReg = } -createWithinProject : List (Changer Assignable) -> Project -> Change -createWithinProject changers parentProject = +createWithinProject : String -> List (Changer Assignable) -> Project -> Change +createWithinProject newAssignableTitle changers parentProject = let assignableSkelChangers : List (Changer (Reg AssignableSkel)) assignableSkelChangers = @@ -70,7 +70,7 @@ createWithinProject changers parentProject = assignableSkelCreator : Changer (Reg AssignableSkel) -> Creator NestedOrAssignable assignableSkelCreator skelChanger = \wrappedContext -> - AssignableSkel.create "this assignable title was not set upon creation" + AssignableSkel.create newAssignableTitle skelChanger -- TODO debug then just use Change.mapCreator (Change.reuseContext "NestedOrAssignable" wrappedContext)