Show custom field summary above results

This commit is contained in:
Eike Kettner 2020-12-16 21:34:53 +01:00
parent b66738b4c3
commit 8d7b3c7d74
4 changed files with 91 additions and 19 deletions

View File

@ -45,7 +45,7 @@ concat l0 l1 =
suff =
List.drop 1 l1.groups
in
ItemLightList (prev ++ [ ng ] ++ suff)
ItemLightList (prev ++ (ng :: suff))
else
ItemLightList (l0.groups ++ l1.groups)

View File

@ -53,6 +53,7 @@ type alias Model =
, lastSearchType : SearchType
, dragDropData : DD.DragDropData
, scrollToCard : Maybe String
, searchStats : SearchStats
}
@ -117,6 +118,7 @@ init flags viewMode =
DD.DragDropData DD.init Nothing
, scrollToCard = Nothing
, viewMode = viewMode
, searchStats = Api.Model.SearchStats.empty
}

View File

@ -554,8 +554,11 @@ update mId key flags settings msg model =
let
lm =
SearchMenuMsg (Comp.SearchMenu.GetStatsResp result)
stats =
Result.withDefault model.searchStats result
in
update mId key flags settings lm model
update mId key flags settings lm { model | searchStats = stats }

View File

@ -7,7 +7,9 @@ import Comp.ItemDetail.EditMenu
import Comp.SearchMenu
import Comp.YesNoDimmer
import Data.Flags exposing (Flags)
import Data.Icons as Icons
import Data.ItemSelection
import Data.Money
import Data.UiSettings exposing (UiSettings)
import Html exposing (..)
import Html.Attributes exposing (..)
@ -110,20 +112,25 @@ view flags settings model =
, ( "item-card-list", True )
]
]
[ viewBar flags model
, case model.viewMode of
SelectView svm ->
Html.map DeleteSelectedConfirmMsg
(Comp.YesNoDimmer.view2 (selectAction == DeleteSelected)
deleteAllDimmer
svm.deleteAllConfirm
)
(List.concat
[ viewBar flags model
, case model.viewMode of
SelectView svm ->
[ Html.map DeleteSelectedConfirmMsg
(Comp.YesNoDimmer.view2 (selectAction == DeleteSelected)
deleteAllDimmer
svm.deleteAllConfirm
)
]
_ ->
span [ class "invisible" ] []
, Html.map ItemCardListMsg
(Comp.ItemCardList.view itemViewCfg settings model.itemListModel)
]
_ ->
[]
, viewStats flags model
, [ Html.map ItemCardListMsg
(Comp.ItemCardList.view itemViewCfg settings model.itemListModel)
]
]
)
, div
[ classList
[ ( "sixteen wide column", True )
@ -157,6 +164,66 @@ view flags settings model =
]
viewStats : Flags -> Model -> List (Html Msg)
viewStats _ model =
let
stats =
model.searchStats
isNumField f =
f.sum > 0
statValues f =
tr [ class "center aligned" ]
[ td [ class "left aligned" ]
[ div [ class "ui basic label" ]
[ Icons.customFieldTypeIconString "" f.ftype
, text (Maybe.withDefault f.name f.label)
]
]
, td []
[ f.count |> String.fromInt |> text
]
, td []
[ f.sum |> Data.Money.format |> text
]
, td []
[ f.avg |> Data.Money.format |> text
]
, td []
[ f.min |> Data.Money.format |> text
]
, td []
[ f.max |> Data.Money.format |> text
]
]
fields =
List.filter isNumField stats.fieldStats
in
if List.isEmpty fields then
[]
else
[ div [ class "ui container" ]
[ table [ class "ui very basic tiny six column table" ]
[ thead []
[ tr [ class "center aligned" ]
[ th [] []
, th [] [ text "Count" ]
, th [] [ text "Sum" ]
, th [] [ text "Avg" ]
, th [] [ text "Min" ]
, th [] [ text "Max" ]
]
]
, tbody []
(List.map statValues fields)
]
]
]
viewLeftMenu : Flags -> UiSettings -> Model -> List (Html Msg)
viewLeftMenu flags settings model =
let
@ -206,17 +273,17 @@ viewLeftMenu flags settings model =
searchMenu
viewBar : Flags -> Model -> Html Msg
viewBar : Flags -> Model -> List (Html Msg)
viewBar flags model =
case model.viewMode of
SimpleView ->
viewSearchBar flags model
[ viewSearchBar flags model ]
SearchView ->
div [ class "hidden invisible" ] []
[]
SelectView svm ->
viewActionBar flags svm model
[ viewActionBar flags svm model ]
viewActionBar : Flags -> SelectViewModel -> Model -> Html Msg