mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-23 10:58:26 +00:00
Indicate saving custom field values
This commit is contained in:
@ -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" ]
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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" ]
|
||||
|
Reference in New Issue
Block a user