Indicate saving custom field values

This commit is contained in:
Eike Kettner 2020-11-23 00:16:50 +01:00
parent bcdb2fc0fe
commit 7026852123
9 changed files with 111 additions and 14 deletions

View File

@ -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 [] []

View File

@ -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" ]

View File

@ -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

View File

@ -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

View File

@ -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" ]

View File

@ -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
)
]

View File

@ -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
}

View File

@ -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

View File

@ -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"