Indicate number of running jobs in tob nav

Issue: #1069
This commit is contained in:
eikek
2021-11-12 21:56:48 +01:00
parent 9acdb8ef96
commit 7a8527f821
16 changed files with 201 additions and 50 deletions

View File

@ -66,6 +66,7 @@ type alias Model =
, anonymousUiLang : UiLanguage
, langMenuOpen : Bool
, showNewItemsArrived : Bool
, jobsWaiting : Int
}
@ -129,6 +130,7 @@ init key url flags_ settings =
, anonymousUiLang = Messages.UiLanguage.English
, langMenuOpen = False
, showNewItemsArrived = False
, jobsWaiting = 0
}
, Cmd.batch
[ Cmd.map UserSettingsMsg uc

View File

@ -311,20 +311,28 @@ updateWithSub msg model =
ReceiveWsMessage data ->
case data of
Ok ItemProcessed ->
Ok (JobDone task) ->
let
newModel =
{ model | showNewItemsArrived = True }
in
case model.page of
HomePage ->
updateHome texts Page.Home.Data.RefreshView newModel
isProcessItem =
task == "process-item"
_ ->
( newModel, Cmd.none, Sub.none )
newModel =
{ model
| showNewItemsArrived = isProcessItem
, jobsWaiting = max 0 (model.jobsWaiting - 1)
}
in
if model.page == HomePage && isProcessItem then
updateHome texts Page.Home.Data.RefreshView newModel
else
( newModel, Cmd.none, Sub.none )
Ok (JobSubmitted _) ->
( { model | jobsWaiting = model.jobsWaiting + 1 }, Cmd.none, Sub.none )
Ok (JobsWaiting n) ->
( model, Cmd.none, Sub.none )
( { model | jobsWaiting = max 0 n }, Cmd.none, Sub.none )
Err err ->
( model, Cmd.none, Sub.none )

View File

@ -259,10 +259,21 @@ dataMenu texts _ model =
div [ class "relative" ]
[ a
[ class dropdownLink
, class "inline-block relative"
, onClick ToggleNavMenu
, href "#"
]
[ i [ class "fa fa-cogs" ] []
, div
[ class "h-5 w-5 rounded-full text-xs px-1 py-1 absolute top-1 left-1 font-bold"
, class "dark:bg-lightblue-500 dark:border-gray-50 dark:text-gray-800"
, class "bg-blue-500 text-gray-50"
, classList [ ( "hidden", model.jobsWaiting <= 0 ) ]
]
[ div [ class "-mt-0.5 ml-0.5" ]
[ text (String.fromInt model.jobsWaiting)
]
]
]
, div
[ class dropdownMenu
@ -301,7 +312,14 @@ dataMenu texts _ model =
, dataPageLink model
QueuePage
[]
[ i [ class "fa fa-tachometer-alt w-6" ] []
[ i
[ if model.jobsWaiting <= 0 then
class "fa fa-tachometer-alt w-6"
else
class "fa fa-circle dark:text-lightblue-500 text-blue-500"
]
[]
, span [ class "ml-1" ]
[ text texts.processingQueue
]

View File

@ -11,7 +11,8 @@ import Json.Decode as D
type ServerEvent
= ItemProcessed
= JobSubmitted String
| JobDone String
| JobsWaiting Int
@ -30,8 +31,13 @@ decode json =
decodeTag : String -> D.Decoder ServerEvent
decodeTag tag =
case tag of
"item-processed" ->
D.succeed ItemProcessed
"job-done" ->
D.field "content" D.string
|> D.map JobDone
"job-submitted" ->
D.field "content" D.string
|> D.map JobSubmitted
"jobs-waiting" ->
D.field "content" D.int