diff --git a/modules/webapp/src/main/elm/Comp/ItemCard.elm b/modules/webapp/src/main/elm/Comp/ItemCard.elm index e5eb1295..ac6da75f 100644 --- a/modules/webapp/src/main/elm/Comp/ItemCard.elm +++ b/modules/webapp/src/main/elm/Comp/ItemCard.elm @@ -400,7 +400,8 @@ mainTagsAndFields settings item = [] else - List.map showField item.customfields + List.sortBy Util.CustomField.nameOrLabel item.customfields + |> List.map showField renderTags = if hideTags then diff --git a/modules/webapp/src/main/elm/Comp/SearchStatsView.elm b/modules/webapp/src/main/elm/Comp/SearchStatsView.elm new file mode 100644 index 00000000..3d337fa0 --- /dev/null +++ b/modules/webapp/src/main/elm/Comp/SearchStatsView.elm @@ -0,0 +1,90 @@ +module Comp.SearchStatsView exposing + ( nameOrLabel + , sortFields + , view + ) + +import Api.Model.FieldStats exposing (FieldStats) +import Api.Model.SearchStats exposing (SearchStats) +import Data.Icons as Icons +import Data.Money +import Html exposing (..) +import Html.Attributes exposing (..) + + +nameOrLabel : FieldStats -> String +nameOrLabel f = + Maybe.withDefault f.name f.label + + +view : SearchStats -> List (Html msg) +view stats = + let + 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 (nameOrLabel f) + ] + ] + , 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 + |> sortFields + in + [ div [ class "ui container" ] + [ div [ class "ui middle aligned stackable grid" ] + [ div [ class "three wide center aligned column" ] + [ div [ class "ui small statistic" ] + [ div [ class "value" ] + [ String.fromInt stats.count |> text + ] + , div [ class "label" ] + [ text "Items" + ] + ] + ] + , div [ class "thirteen wide column" ] + [ 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) + ] + ] + ] + ] + ] + + +sortFields : List FieldStats -> List FieldStats +sortFields fields = + List.sortBy nameOrLabel fields diff --git a/modules/webapp/src/main/elm/Page/Home/View.elm b/modules/webapp/src/main/elm/Page/Home/View.elm index 05c7d90a..7ac48fa2 100644 --- a/modules/webapp/src/main/elm/Page/Home/View.elm +++ b/modules/webapp/src/main/elm/Page/Home/View.elm @@ -5,11 +5,10 @@ import Comp.FixedDropdown import Comp.ItemCardList import Comp.ItemDetail.EditMenu import Comp.SearchMenu +import Comp.SearchStatsView 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 (..) @@ -166,72 +165,7 @@ 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 - [ div [ class "ui container" ] - [ div [ class "ui middle aligned stackable grid" ] - [ div [ class "three wide center aligned column" ] - [ div [ class "ui small statistic" ] - [ div [ class "value" ] - [ String.fromInt stats.count |> text - ] - , div [ class "label" ] - [ text "Results" - ] - ] - ] - , div [ class "thirteen wide column" ] - [ 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) - ] - ] - ] - ] - ] + Comp.SearchStatsView.view model.searchStats viewLeftMenu : Flags -> UiSettings -> Model -> List (Html Msg) diff --git a/modules/webapp/src/main/elm/Util/CustomField.elm b/modules/webapp/src/main/elm/Util/CustomField.elm index 3006ae7e..800864cf 100644 --- a/modules/webapp/src/main/elm/Util/CustomField.elm +++ b/modules/webapp/src/main/elm/Util/CustomField.elm @@ -1,4 +1,4 @@ -module Util.CustomField exposing (renderValue) +module Util.CustomField exposing (nameOrLabel, renderValue) import Api.Model.ItemFieldValue exposing (ItemFieldValue) import Data.CustomFieldType @@ -7,6 +7,11 @@ import Html exposing (..) import Html.Attributes exposing (..) +nameOrLabel : ItemFieldValue -> String +nameOrLabel fv = + Maybe.withDefault fv.name fv.label + + renderValue : String -> ItemFieldValue -> Html msg renderValue classes cv = let @@ -19,7 +24,7 @@ renderValue classes cv = in div [ class classes ] [ Icons.customFieldTypeIconString "" cv.ftype - , Maybe.withDefault cv.name cv.label |> text + , nameOrLabel cv |> text , div [ class "detail" ] [ if Data.CustomFieldType.fromString cv.ftype == Just Data.CustomFieldType.Boolean then renderBool