From 7026852123b4454642d38e8c20d7fad5fc7685b3 Mon Sep 17 00:00:00 2001 From: Eike Kettner Date: Mon, 23 Nov 2020 00:16:50 +0100 Subject: [PATCH] Indicate saving custom field values --- .../main/elm/Comp/CustomFieldMultiInput.elm | 12 +++-- .../src/main/elm/Comp/ItemDetail/EditMenu.elm | 18 +++++++- .../src/main/elm/Comp/ItemDetail/Model.elm | 3 ++ .../src/main/elm/Comp/ItemDetail/Update.elm | 46 ++++++++++++++++--- .../src/main/elm/Comp/ItemDetail/View.elm | 5 +- .../webapp/src/main/elm/Comp/SearchMenu.elm | 2 +- .../webapp/src/main/elm/Page/Home/Data.elm | 2 + .../webapp/src/main/elm/Page/Home/Update.elm | 26 +++++++++++ .../webapp/src/main/elm/Page/Home/View.elm | 11 ++++- 9 files changed, 111 insertions(+), 14 deletions(-) diff --git a/modules/webapp/src/main/elm/Comp/CustomFieldMultiInput.elm b/modules/webapp/src/main/elm/Comp/CustomFieldMultiInput.elm index e443b472..21ee078f 100644 --- a/modules/webapp/src/main/elm/Comp/CustomFieldMultiInput.elm +++ b/modules/webapp/src/main/elm/Comp/CustomFieldMultiInput.elm @@ -309,6 +309,7 @@ update msg model = type alias ViewSettings = { showAddButton : Bool , classes : String + , fieldIcon : CustomField -> Maybe String } @@ -316,7 +317,7 @@ view : ViewSettings -> Model -> Html Msg view viewSettings model = div [ class viewSettings.classes ] (viewMenuBar viewSettings model - :: List.map (viewCustomField model) (visibleFields model) + :: List.map (viewCustomField viewSettings model) (visibleFields model) ) @@ -344,8 +345,8 @@ viewMenuBar viewSettings model = ) -viewCustomField : Model -> CustomField -> Html Msg -viewCustomField model field = +viewCustomField : ViewSettings -> Model -> CustomField -> Html Msg +viewCustomField viewSettings model field = let visibleField = Dict.get field.name model.visibleFields @@ -353,7 +354,10 @@ viewCustomField model field = case visibleField of Just vf -> Html.map (CustomFieldInputMsg field) - (Comp.CustomFieldInput.view "field" Nothing vf.inputModel) + (Comp.CustomFieldInput.view "field" + (viewSettings.fieldIcon vf.field) + vf.inputModel + ) Nothing -> span [] [] diff --git a/modules/webapp/src/main/elm/Comp/ItemDetail/EditMenu.elm b/modules/webapp/src/main/elm/Comp/ItemDetail/EditMenu.elm index 37d1316f..40f0c13a 100644 --- a/modules/webapp/src/main/elm/Comp/ItemDetail/EditMenu.elm +++ b/modules/webapp/src/main/elm/Comp/ItemDetail/EditMenu.elm @@ -598,6 +598,7 @@ nameThrottleSub model = type alias ViewConfig = { menuClass : String , nameState : SaveNameState + , customFieldState : String -> SaveNameState } @@ -605,6 +606,7 @@ defaultViewConfig : ViewConfig defaultViewConfig = { menuClass = "ui vertical segment" , nameState = SaveSuccess + , customFieldState = \_ -> SaveSuccess } @@ -651,8 +653,22 @@ renderEditForm cfg settings model = ReplaceTags -> "Tags chosen here *replace* those on selected items." + customFieldIcon field = + case cfg.customFieldState field.id of + SaveSuccess -> + Nothing + + SaveFailed -> + Just "red exclamation triangle icon" + + Saving -> + Just "refresh loading icon" + customFieldSettings = - Comp.CustomFieldMultiInput.ViewSettings False "field" + Comp.CustomFieldMultiInput.ViewSettings + False + "field" + customFieldIcon in div [ class cfg.menuClass ] [ div [ class "ui form warning" ] diff --git a/modules/webapp/src/main/elm/Comp/ItemDetail/Model.elm b/modules/webapp/src/main/elm/Comp/ItemDetail/Model.elm index c6d79e5a..8f5bbf67 100644 --- a/modules/webapp/src/main/elm/Comp/ItemDetail/Model.elm +++ b/modules/webapp/src/main/elm/Comp/ItemDetail/Model.elm @@ -95,6 +95,7 @@ type alias Model = , attachRename : Maybe AttachmentRename , keyInputModel : Comp.KeyInput.Model , customFieldsModel : Comp.CustomFieldMultiInput.Model + , customFieldSavingIcon : Dict String String } @@ -197,6 +198,7 @@ emptyModel = , attachRename = Nothing , keyInputModel = Comp.KeyInput.init , customFieldsModel = Comp.CustomFieldMultiInput.initWith [] + , customFieldSavingIcon = Dict.empty } @@ -283,6 +285,7 @@ type Msg | UiSettingsUpdated | SetLinkTarget LinkTarget | CustomFieldMsg Comp.CustomFieldMultiInput.Msg + | CustomFieldSaveResp String (Result Http.Error BasicResult) type SaveNameState diff --git a/modules/webapp/src/main/elm/Comp/ItemDetail/Update.elm b/modules/webapp/src/main/elm/Comp/ItemDetail/Update.elm index f610f1ce..2dd84c8d 100644 --- a/modules/webapp/src/main/elm/Comp/ItemDetail/Update.elm +++ b/modules/webapp/src/main/elm/Comp/ItemDetail/Update.elm @@ -1300,19 +1300,32 @@ update key flags inav settings msg model = cmd_ = Cmd.map CustomFieldMsg result.cmd - action = + loadingIcon = + "refresh loading icon" + + ( action, icons ) = case result.result of NoFieldChange -> - Cmd.none + ( Cmd.none, model.customFieldSavingIcon ) FieldValueRemove field -> - Api.deleteCustomValue flags model.item.id field.id SaveResp + ( Api.deleteCustomValue flags + model.item.id + field.id + (CustomFieldSaveResp field.id) + , Dict.insert field.id loadingIcon model.customFieldSavingIcon + ) FieldValueChange field value -> - Api.putCustomValue flags model.item.id (CustomFieldValue field.id value) SaveResp + ( Api.putCustomValue flags + model.item.id + (CustomFieldValue field.id value) + (CustomFieldSaveResp field.id) + , Dict.insert field.id loadingIcon model.customFieldSavingIcon + ) FieldCreateNew -> - Cmd.none + ( Cmd.none, model.customFieldSavingIcon ) sub_ = Sub.map CustomFieldMsg result.subs @@ -1325,7 +1338,11 @@ update key flags inav settings msg model = Nothing model_ = - { model | customFieldsModel = result.model, modalEdit = modalEdit } + { model + | customFieldsModel = result.model + , modalEdit = modalEdit + , customFieldSavingIcon = icons + } in { model = model_ , cmd = Cmd.batch [ cmd_, action ] @@ -1333,6 +1350,23 @@ update key flags inav settings msg model = , linkTarget = Comp.LinkTarget.LinkNone } + CustomFieldSaveResp fieldId (Ok res) -> + let + model_ = + { model | customFieldSavingIcon = Dict.remove fieldId model.customFieldSavingIcon } + in + if res.success then + resultModelCmd + ( model_ + , Api.itemDetail flags model.item.id GetItemResp + ) + + else + resultModel model_ + + CustomFieldSaveResp fieldId (Err _) -> + resultModel { model | customFieldSavingIcon = Dict.remove fieldId model.customFieldSavingIcon } + --- Helper diff --git a/modules/webapp/src/main/elm/Comp/ItemDetail/View.elm b/modules/webapp/src/main/elm/Comp/ItemDetail/View.elm index d5dadbf1..b5fbd555 100644 --- a/modules/webapp/src/main/elm/Comp/ItemDetail/View.elm +++ b/modules/webapp/src/main/elm/Comp/ItemDetail/View.elm @@ -773,7 +773,10 @@ renderEditForm settings model = && Comp.CustomFieldMultiInput.nonEmpty model.customFieldsModel customFieldSettings = - Comp.CustomFieldMultiInput.ViewSettings True "field" + Comp.CustomFieldMultiInput.ViewSettings + True + "field" + (\f -> Dict.get f.id model.customFieldSavingIcon) in div [ class "ui attached segment" ] [ div [ class "ui form warning" ] diff --git a/modules/webapp/src/main/elm/Comp/SearchMenu.elm b/modules/webapp/src/main/elm/Comp/SearchMenu.elm index ff385da8..406cbf9a 100644 --- a/modules/webapp/src/main/elm/Comp/SearchMenu.elm +++ b/modules/webapp/src/main/elm/Comp/SearchMenu.elm @@ -854,7 +854,7 @@ viewDrop ddd flags settings model = [ formHeader (Icons.customFieldIcon "") "Custom Fields" , Html.map CustomFieldMsg (Comp.CustomFieldMultiInput.view - (Comp.CustomFieldMultiInput.ViewSettings False "field") + (Comp.CustomFieldMultiInput.ViewSettings False "field" (\_ -> Nothing)) model.customFieldModel ) ] diff --git a/modules/webapp/src/main/elm/Page/Home/Data.elm b/modules/webapp/src/main/elm/Page/Home/Data.elm index dcd14300..333d1442 100644 --- a/modules/webapp/src/main/elm/Page/Home/Data.elm +++ b/modules/webapp/src/main/elm/Page/Home/Data.elm @@ -63,6 +63,7 @@ type alias SelectViewModel = , deleteAllConfirm : Comp.YesNoDimmer.Model , editModel : Comp.ItemDetail.EditMenu.Model , saveNameState : SaveNameState + , saveCustomFieldState : Set String } @@ -73,6 +74,7 @@ initSelectViewModel = , deleteAllConfirm = Comp.YesNoDimmer.initActive , editModel = Comp.ItemDetail.EditMenu.init , saveNameState = SaveSuccess + , saveCustomFieldState = Set.empty } diff --git a/modules/webapp/src/main/elm/Page/Home/Update.elm b/modules/webapp/src/main/elm/Page/Home/Update.elm index a57fd172..454c7790 100644 --- a/modules/webapp/src/main/elm/Page/Home/Update.elm +++ b/modules/webapp/src/main/elm/Page/Home/Update.elm @@ -459,6 +459,16 @@ update mId key flags settings msg model = _ -> svm.saveNameState + , saveCustomFieldState = + case res.change of + CustomValueChange field _ -> + Set.insert field.id svm.saveCustomFieldState + + RemoveCustomValue field -> + Set.insert field.id svm.saveCustomFieldState + + _ -> + svm.saveCustomFieldState } cmd_ = @@ -542,6 +552,16 @@ update mId key flags settings msg model = updateSelectViewNameState : Bool -> Model -> FormChange -> Model updateSelectViewNameState success model change = + let + removeCustomField field svm = + { model + | viewMode = + SelectView + { svm + | saveCustomFieldState = Set.remove field.id svm.saveCustomFieldState + } + } + in case model.viewMode of SelectView svm -> case change of @@ -559,6 +579,12 @@ updateSelectViewNameState success model change = in { model | viewMode = SelectView svm_ } + RemoveCustomValue field -> + removeCustomField field svm + + CustomValueChange field _ -> + removeCustomField field svm + _ -> model diff --git a/modules/webapp/src/main/elm/Page/Home/View.elm b/modules/webapp/src/main/elm/Page/Home/View.elm index dd2d3ef1..fada780f 100644 --- a/modules/webapp/src/main/elm/Page/Home/View.elm +++ b/modules/webapp/src/main/elm/Page/Home/View.elm @@ -178,7 +178,16 @@ viewLeftMenu flags settings model = Comp.ItemDetail.EditMenu.defaultViewConfig cfg = - { cfg_ | nameState = svm.saveNameState } + { cfg_ + | nameState = svm.saveNameState + , customFieldState = + \fId -> + if Set.member fId svm.saveCustomFieldState then + Comp.ItemDetail.EditMenu.Saving + + else + Comp.ItemDetail.EditMenu.SaveSuccess + } in [ div [ class "ui dividing header" ] [ text "Multi-Edit"