Merge items in webui

This commit is contained in:
eikek 2021-08-16 12:55:25 +02:00
parent 85085ec173
commit 8099b78b0e
5 changed files with 42 additions and 8 deletions

View File

@ -80,6 +80,7 @@ module Api exposing
, login , login
, loginSession , loginSession
, logout , logout
, mergeItems
, moveAttachmentBefore , moveAttachmentBefore
, newInvite , newInvite
, postCustomField , postCustomField
@ -1470,6 +1471,20 @@ getJobQueueStateTask flags =
--- Item (Mulit Edit) --- Item (Mulit Edit)
mergeItems :
Flags
-> List String
-> (Result Http.Error BasicResult -> msg)
-> Cmd msg
mergeItems flags items receive =
Http2.authPost
{ url = flags.config.baseUrl ++ "/api/v1/sec/items/merge"
, account = getAccount flags
, body = Http.jsonBody (Api.Model.IdList.encode (IdList items))
, expect = Http.expectJson receive Api.Model.BasicResult.decoder
}
reprocessMultiple : reprocessMultiple :
Flags Flags
-> Set String -> Set String

View File

@ -18,6 +18,7 @@ import Api
import Api.Model.BasicResult exposing (BasicResult) import Api.Model.BasicResult exposing (BasicResult)
import Api.Model.ItemLight exposing (ItemLight) import Api.Model.ItemLight exposing (ItemLight)
import Api.Model.ItemLightList exposing (ItemLightList) import Api.Model.ItemLightList exposing (ItemLightList)
import Comp.Basic
import Comp.MenuBar as MB import Comp.MenuBar as MB
import Data.Direction import Data.Direction
import Data.Fields import Data.Fields
@ -89,6 +90,7 @@ type FormState
| FormStateHttp Http.Error | FormStateHttp Http.Error
| FormStateMergeSuccessful | FormStateMergeSuccessful
| FormStateError String | FormStateError String
| FormStateMergeInProcess
@ -119,8 +121,8 @@ type Msg
| MergeResp (Result Http.Error BasicResult) | MergeResp (Result Http.Error BasicResult)
update : Msg -> Model -> UpdateResult update : Flags -> Msg -> Model -> UpdateResult
update msg model = update flags msg model =
case msg of case msg of
ItemResp (Ok list) -> ItemResp (Ok list) ->
notDoneResult ( init (flatten list), Cmd.none ) notDoneResult ( init (flatten list), Cmd.none )
@ -176,7 +178,14 @@ update msg model =
notDoneResult ( model_, Cmd.none ) notDoneResult ( model_, Cmd.none )
SubmitMerge -> SubmitMerge ->
notDoneResult ( model, Cmd.none ) let
ids =
List.map .id model.items
in
notDoneResult
( { model | formState = FormStateMergeInProcess }
, Api.mergeItems flags ids MergeResp
)
CancelMerge -> CancelMerge ->
{ model = model { model = model
@ -429,7 +438,7 @@ renderFormState texts model =
FormStateError msg -> FormStateError msg ->
div div
[ class S.errorMessage [ class S.errorMessage
, class "py-2" , class "my-2"
] ]
[ text msg [ text msg
] ]
@ -437,7 +446,7 @@ renderFormState texts model =
FormStateHttp err -> FormStateHttp err ->
div div
[ class S.errorMessage [ class S.errorMessage
, class "py-2" , class "my-2"
] ]
[ text (texts.httpError err) [ text (texts.httpError err)
] ]
@ -445,11 +454,17 @@ renderFormState texts model =
FormStateMergeSuccessful -> FormStateMergeSuccessful ->
div div
[ class S.successMessage [ class S.successMessage
, class "py-2" , class "my-2"
] ]
[ text texts.mergeSuccessful [ text texts.mergeSuccessful
] ]
FormStateMergeInProcess ->
Comp.Basic.loadingDimmer
{ active = True
, label = texts.mergeInProcess
}
templateCtx : Texts -> IT.TemplateContext templateCtx : Texts -> IT.TemplateContext
templateCtx texts = templateCtx texts =

View File

@ -31,6 +31,7 @@ type alias Texts =
, submitMergeTitle : String , submitMergeTitle : String
, cancelMergeTitle : String , cancelMergeTitle : String
, mergeSuccessful : String , mergeSuccessful : String
, mergeInProcess : String
} }
@ -48,6 +49,7 @@ gb =
, cancelMerge = "Cancel" , cancelMerge = "Cancel"
, cancelMergeTitle = "Back to select view" , cancelMergeTitle = "Back to select view"
, mergeSuccessful = "Items merged successfully" , mergeSuccessful = "Items merged successfully"
, mergeInProcess = "Items are merged "
} }
@ -65,4 +67,5 @@ de =
, cancelMerge = "Abbrechen" , cancelMerge = "Abbrechen"
, cancelMergeTitle = "Zurück zur Auswahl" , cancelMergeTitle = "Zurück zur Auswahl"
, mergeSuccessful = "Die Dokumente wurden erfolgreich zusammengeführt." , mergeSuccessful = "Die Dokumente wurden erfolgreich zusammengeführt."
, mergeInProcess = "Dokumente werden zusammengeführt"
} }

View File

@ -583,7 +583,7 @@ update mId key flags settings msg model =
SelectView svm -> SelectView svm ->
let let
result = result =
Comp.ItemMerge.update lmsg svm.mergeModel Comp.ItemMerge.update flags lmsg svm.mergeModel
nextView = nextView =
if result.done then if result.done then

View File

@ -51,7 +51,7 @@ viewContent texts flags settings model =
] ]
(searchStats texts flags settings model (searchStats texts flags settings model
++ itemsBar texts flags settings model ++ itemsBar texts flags settings model
++ [ div [ class "relative" ] ++ [ div [ class "sm:relative" ]
(itemMergeView texts settings model (itemMergeView texts settings model
++ itemCardList texts flags settings model ++ itemCardList texts flags settings model
) )
@ -72,6 +72,7 @@ itemMergeView texts settings model =
MergeSelected -> MergeSelected ->
[ div [ div
[ class S.dimmerMerge [ class S.dimmerMerge
, class "mt-10 sm:mt-0"
] ]
[ Html.map MergeItemsMsg [ Html.map MergeItemsMsg
(Comp.ItemMerge.view texts.itemMerge settings svm.mergeModel) (Comp.ItemMerge.view texts.itemMerge settings svm.mergeModel)