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 = type alias ViewSettings =
{ showAddButton : Bool { showAddButton : Bool
, classes : String , classes : String
, fieldIcon : CustomField -> Maybe String
} }
@ -316,7 +317,7 @@ view : ViewSettings -> Model -> Html Msg
view viewSettings model = view viewSettings model =
div [ class viewSettings.classes ] div [ class viewSettings.classes ]
(viewMenuBar viewSettings model (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 : ViewSettings -> Model -> CustomField -> Html Msg
viewCustomField model field = viewCustomField viewSettings model field =
let let
visibleField = visibleField =
Dict.get field.name model.visibleFields Dict.get field.name model.visibleFields
@ -353,7 +354,10 @@ viewCustomField model field =
case visibleField of case visibleField of
Just vf -> Just vf ->
Html.map (CustomFieldInputMsg field) Html.map (CustomFieldInputMsg field)
(Comp.CustomFieldInput.view "field" Nothing vf.inputModel) (Comp.CustomFieldInput.view "field"
(viewSettings.fieldIcon vf.field)
vf.inputModel
)
Nothing -> Nothing ->
span [] [] span [] []

View File

@ -598,6 +598,7 @@ nameThrottleSub model =
type alias ViewConfig = type alias ViewConfig =
{ menuClass : String { menuClass : String
, nameState : SaveNameState , nameState : SaveNameState
, customFieldState : String -> SaveNameState
} }
@ -605,6 +606,7 @@ defaultViewConfig : ViewConfig
defaultViewConfig = defaultViewConfig =
{ menuClass = "ui vertical segment" { menuClass = "ui vertical segment"
, nameState = SaveSuccess , nameState = SaveSuccess
, customFieldState = \_ -> SaveSuccess
} }
@ -651,8 +653,22 @@ renderEditForm cfg settings model =
ReplaceTags -> ReplaceTags ->
"Tags chosen here *replace* those on selected items." "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 = customFieldSettings =
Comp.CustomFieldMultiInput.ViewSettings False "field" Comp.CustomFieldMultiInput.ViewSettings
False
"field"
customFieldIcon
in in
div [ class cfg.menuClass ] div [ class cfg.menuClass ]
[ div [ class "ui form warning" ] [ div [ class "ui form warning" ]

View File

@ -95,6 +95,7 @@ type alias Model =
, attachRename : Maybe AttachmentRename , attachRename : Maybe AttachmentRename
, keyInputModel : Comp.KeyInput.Model , keyInputModel : Comp.KeyInput.Model
, customFieldsModel : Comp.CustomFieldMultiInput.Model , customFieldsModel : Comp.CustomFieldMultiInput.Model
, customFieldSavingIcon : Dict String String
} }
@ -197,6 +198,7 @@ emptyModel =
, attachRename = Nothing , attachRename = Nothing
, keyInputModel = Comp.KeyInput.init , keyInputModel = Comp.KeyInput.init
, customFieldsModel = Comp.CustomFieldMultiInput.initWith [] , customFieldsModel = Comp.CustomFieldMultiInput.initWith []
, customFieldSavingIcon = Dict.empty
} }
@ -283,6 +285,7 @@ type Msg
| UiSettingsUpdated | UiSettingsUpdated
| SetLinkTarget LinkTarget | SetLinkTarget LinkTarget
| CustomFieldMsg Comp.CustomFieldMultiInput.Msg | CustomFieldMsg Comp.CustomFieldMultiInput.Msg
| CustomFieldSaveResp String (Result Http.Error BasicResult)
type SaveNameState type SaveNameState

View File

@ -1300,19 +1300,32 @@ update key flags inav settings msg model =
cmd_ = cmd_ =
Cmd.map CustomFieldMsg result.cmd Cmd.map CustomFieldMsg result.cmd
action = loadingIcon =
"refresh loading icon"
( action, icons ) =
case result.result of case result.result of
NoFieldChange -> NoFieldChange ->
Cmd.none ( Cmd.none, model.customFieldSavingIcon )
FieldValueRemove field -> 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 -> 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 -> FieldCreateNew ->
Cmd.none ( Cmd.none, model.customFieldSavingIcon )
sub_ = sub_ =
Sub.map CustomFieldMsg result.subs Sub.map CustomFieldMsg result.subs
@ -1325,7 +1338,11 @@ update key flags inav settings msg model =
Nothing Nothing
model_ = model_ =
{ model | customFieldsModel = result.model, modalEdit = modalEdit } { model
| customFieldsModel = result.model
, modalEdit = modalEdit
, customFieldSavingIcon = icons
}
in in
{ model = model_ { model = model_
, cmd = Cmd.batch [ cmd_, action ] , cmd = Cmd.batch [ cmd_, action ]
@ -1333,6 +1350,23 @@ update key flags inav settings msg model =
, linkTarget = Comp.LinkTarget.LinkNone , 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 --- Helper

View File

@ -773,7 +773,10 @@ renderEditForm settings model =
&& Comp.CustomFieldMultiInput.nonEmpty model.customFieldsModel && Comp.CustomFieldMultiInput.nonEmpty model.customFieldsModel
customFieldSettings = customFieldSettings =
Comp.CustomFieldMultiInput.ViewSettings True "field" Comp.CustomFieldMultiInput.ViewSettings
True
"field"
(\f -> Dict.get f.id model.customFieldSavingIcon)
in in
div [ class "ui attached segment" ] div [ class "ui attached segment" ]
[ div [ class "ui form warning" ] [ div [ class "ui form warning" ]

View File

@ -854,7 +854,7 @@ viewDrop ddd flags settings model =
[ formHeader (Icons.customFieldIcon "") "Custom Fields" [ formHeader (Icons.customFieldIcon "") "Custom Fields"
, Html.map CustomFieldMsg , Html.map CustomFieldMsg
(Comp.CustomFieldMultiInput.view (Comp.CustomFieldMultiInput.view
(Comp.CustomFieldMultiInput.ViewSettings False "field") (Comp.CustomFieldMultiInput.ViewSettings False "field" (\_ -> Nothing))
model.customFieldModel model.customFieldModel
) )
] ]

View File

@ -63,6 +63,7 @@ type alias SelectViewModel =
, deleteAllConfirm : Comp.YesNoDimmer.Model , deleteAllConfirm : Comp.YesNoDimmer.Model
, editModel : Comp.ItemDetail.EditMenu.Model , editModel : Comp.ItemDetail.EditMenu.Model
, saveNameState : SaveNameState , saveNameState : SaveNameState
, saveCustomFieldState : Set String
} }
@ -73,6 +74,7 @@ initSelectViewModel =
, deleteAllConfirm = Comp.YesNoDimmer.initActive , deleteAllConfirm = Comp.YesNoDimmer.initActive
, editModel = Comp.ItemDetail.EditMenu.init , editModel = Comp.ItemDetail.EditMenu.init
, saveNameState = SaveSuccess , saveNameState = SaveSuccess
, saveCustomFieldState = Set.empty
} }

View File

@ -459,6 +459,16 @@ update mId key flags settings msg model =
_ -> _ ->
svm.saveNameState 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_ = cmd_ =
@ -542,6 +552,16 @@ update mId key flags settings msg model =
updateSelectViewNameState : Bool -> Model -> FormChange -> Model updateSelectViewNameState : Bool -> Model -> FormChange -> Model
updateSelectViewNameState success model change = updateSelectViewNameState success model change =
let
removeCustomField field svm =
{ model
| viewMode =
SelectView
{ svm
| saveCustomFieldState = Set.remove field.id svm.saveCustomFieldState
}
}
in
case model.viewMode of case model.viewMode of
SelectView svm -> SelectView svm ->
case change of case change of
@ -559,6 +579,12 @@ updateSelectViewNameState success model change =
in in
{ model | viewMode = SelectView svm_ } { model | viewMode = SelectView svm_ }
RemoveCustomValue field ->
removeCustomField field svm
CustomValueChange field _ ->
removeCustomField field svm
_ -> _ ->
model model

View File

@ -178,7 +178,16 @@ viewLeftMenu flags settings model =
Comp.ItemDetail.EditMenu.defaultViewConfig Comp.ItemDetail.EditMenu.defaultViewConfig
cfg = 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 in
[ div [ class "ui dividing header" ] [ div [ class "ui dividing header" ]
[ text "Multi-Edit" [ text "Multi-Edit"