mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-04-05 10:59:33 +00:00
Merge pull request #529 from eikek/custom-field-fixes
Custom field fixes
This commit is contained in:
commit
561ac9442a
@ -400,7 +400,8 @@ mainTagsAndFields settings item =
|
|||||||
[]
|
[]
|
||||||
|
|
||||||
else
|
else
|
||||||
List.map showField item.customfields
|
List.sortBy Util.CustomField.nameOrLabel item.customfields
|
||||||
|
|> List.map showField
|
||||||
|
|
||||||
renderTags =
|
renderTags =
|
||||||
if hideTags then
|
if hideTags then
|
||||||
|
90
modules/webapp/src/main/elm/Comp/SearchStatsView.elm
Normal file
90
modules/webapp/src/main/elm/Comp/SearchStatsView.elm
Normal file
@ -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
|
@ -51,6 +51,7 @@ type alias Model =
|
|||||||
, cardTitlePattern : PatternModel
|
, cardTitlePattern : PatternModel
|
||||||
, cardSubtitlePattern : PatternModel
|
, cardSubtitlePattern : PatternModel
|
||||||
, showPatternHelp : Bool
|
, showPatternHelp : Bool
|
||||||
|
, searchStatsVisible : Bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -141,6 +142,7 @@ init flags settings =
|
|||||||
, cardTitlePattern = initPatternModel settings.cardTitleTemplate
|
, cardTitlePattern = initPatternModel settings.cardTitleTemplate
|
||||||
, cardSubtitlePattern = initPatternModel settings.cardSubtitleTemplate
|
, cardSubtitlePattern = initPatternModel settings.cardSubtitleTemplate
|
||||||
, showPatternHelp = False
|
, showPatternHelp = False
|
||||||
|
, searchStatsVisible = settings.searchStatsVisible
|
||||||
}
|
}
|
||||||
, Api.getTags flags "" GetTagsResp
|
, Api.getTags flags "" GetTagsResp
|
||||||
)
|
)
|
||||||
@ -164,6 +166,7 @@ type Msg
|
|||||||
| SetCardTitlePattern String
|
| SetCardTitlePattern String
|
||||||
| SetCardSubtitlePattern String
|
| SetCardSubtitlePattern String
|
||||||
| TogglePatternHelpMsg
|
| TogglePatternHelpMsg
|
||||||
|
| ToggleSearchStatsVisible
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -415,6 +418,15 @@ update sett msg model =
|
|||||||
TogglePatternHelpMsg ->
|
TogglePatternHelpMsg ->
|
||||||
( { model | showPatternHelp = not model.showPatternHelp }, Nothing )
|
( { model | showPatternHelp = not model.showPatternHelp }, Nothing )
|
||||||
|
|
||||||
|
ToggleSearchStatsVisible ->
|
||||||
|
let
|
||||||
|
flag =
|
||||||
|
not model.searchStatsVisible
|
||||||
|
in
|
||||||
|
( { model | searchStatsVisible = flag }
|
||||||
|
, Just { sett | searchStatsVisible = flag }
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--- View
|
--- View
|
||||||
@ -447,6 +459,19 @@ view flags _ model =
|
|||||||
"field"
|
"field"
|
||||||
model.searchPageSizeModel
|
model.searchPageSizeModel
|
||||||
)
|
)
|
||||||
|
, div [ class "field" ]
|
||||||
|
[ div [ class "ui checkbox" ]
|
||||||
|
[ input
|
||||||
|
[ type_ "checkbox"
|
||||||
|
, onCheck (\_ -> ToggleSearchStatsVisible)
|
||||||
|
, checked model.searchStatsVisible
|
||||||
|
]
|
||||||
|
[]
|
||||||
|
, label []
|
||||||
|
[ text "Show basic search statistics by default"
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]
|
||||||
, div [ class "ui dividing header" ]
|
, div [ class "ui dividing header" ]
|
||||||
[ text "Item Cards"
|
[ text "Item Cards"
|
||||||
]
|
]
|
||||||
|
@ -52,6 +52,7 @@ type alias StoredUiSettings =
|
|||||||
, cardPreviewSize : Maybe String
|
, cardPreviewSize : Maybe String
|
||||||
, cardTitleTemplate : Maybe String
|
, cardTitleTemplate : Maybe String
|
||||||
, cardSubtitleTemplate : Maybe String
|
, cardSubtitleTemplate : Maybe String
|
||||||
|
, searchStatsVisible : Bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -78,6 +79,7 @@ type alias UiSettings =
|
|||||||
, cardPreviewSize : BasicSize
|
, cardPreviewSize : BasicSize
|
||||||
, cardTitleTemplate : ItemPattern
|
, cardTitleTemplate : ItemPattern
|
||||||
, cardSubtitleTemplate : ItemPattern
|
, cardSubtitleTemplate : ItemPattern
|
||||||
|
, searchStatsVisible : Bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -144,6 +146,7 @@ defaults =
|
|||||||
{ template = Data.ItemTemplate.dateLong
|
{ template = Data.ItemTemplate.dateLong
|
||||||
, pattern = "{{dateLong}}"
|
, pattern = "{{dateLong}}"
|
||||||
}
|
}
|
||||||
|
, searchStatsVisible = True
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -189,6 +192,7 @@ merge given fallback =
|
|||||||
, cardSubtitleTemplate =
|
, cardSubtitleTemplate =
|
||||||
Maybe.andThen readPattern given.cardSubtitleTemplate
|
Maybe.andThen readPattern given.cardSubtitleTemplate
|
||||||
|> Maybe.withDefault fallback.cardSubtitleTemplate
|
|> Maybe.withDefault fallback.cardSubtitleTemplate
|
||||||
|
, searchStatsVisible = given.searchStatsVisible
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -221,6 +225,7 @@ toStoredUiSettings settings =
|
|||||||
|> Just
|
|> Just
|
||||||
, cardTitleTemplate = settings.cardTitleTemplate.pattern |> Just
|
, cardTitleTemplate = settings.cardTitleTemplate.pattern |> Just
|
||||||
, cardSubtitleTemplate = settings.cardSubtitleTemplate.pattern |> Just
|
, cardSubtitleTemplate = settings.cardSubtitleTemplate.pattern |> Just
|
||||||
|
, searchStatsVisible = settings.searchStatsVisible
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,11 +5,10 @@ import Comp.FixedDropdown
|
|||||||
import Comp.ItemCardList
|
import Comp.ItemCardList
|
||||||
import Comp.ItemDetail.EditMenu
|
import Comp.ItemDetail.EditMenu
|
||||||
import Comp.SearchMenu
|
import Comp.SearchMenu
|
||||||
|
import Comp.SearchStatsView
|
||||||
import Comp.YesNoDimmer
|
import Comp.YesNoDimmer
|
||||||
import Data.Flags exposing (Flags)
|
import Data.Flags exposing (Flags)
|
||||||
import Data.Icons as Icons
|
|
||||||
import Data.ItemSelection
|
import Data.ItemSelection
|
||||||
import Data.Money
|
|
||||||
import Data.UiSettings exposing (UiSettings)
|
import Data.UiSettings exposing (UiSettings)
|
||||||
import Html exposing (..)
|
import Html exposing (..)
|
||||||
import Html.Attributes exposing (..)
|
import Html.Attributes exposing (..)
|
||||||
@ -125,7 +124,7 @@ view flags settings model =
|
|||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
[]
|
[]
|
||||||
, viewStats flags model
|
, viewStats flags settings model
|
||||||
, [ Html.map ItemCardListMsg
|
, [ Html.map ItemCardListMsg
|
||||||
(Comp.ItemCardList.view itemViewCfg settings model.itemListModel)
|
(Comp.ItemCardList.view itemViewCfg settings model.itemListModel)
|
||||||
]
|
]
|
||||||
@ -164,74 +163,13 @@ view flags settings model =
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
viewStats : Flags -> Model -> List (Html Msg)
|
viewStats : Flags -> UiSettings -> Model -> List (Html Msg)
|
||||||
viewStats _ model =
|
viewStats _ settings model =
|
||||||
let
|
if settings.searchStatsVisible then
|
||||||
stats =
|
Comp.SearchStatsView.view model.searchStats
|
||||||
model.searchStats
|
|
||||||
|
|
||||||
isNumField f =
|
else
|
||||||
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 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)
|
|
||||||
]
|
|
||||||
]
|
|
||||||
]
|
|
||||||
]
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
viewLeftMenu : Flags -> UiSettings -> Model -> List (Html Msg)
|
viewLeftMenu : Flags -> UiSettings -> Model -> List (Html Msg)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
module Util.CustomField exposing (renderValue)
|
module Util.CustomField exposing (nameOrLabel, renderValue)
|
||||||
|
|
||||||
import Api.Model.ItemFieldValue exposing (ItemFieldValue)
|
import Api.Model.ItemFieldValue exposing (ItemFieldValue)
|
||||||
import Data.CustomFieldType
|
import Data.CustomFieldType
|
||||||
@ -7,6 +7,11 @@ import Html exposing (..)
|
|||||||
import Html.Attributes exposing (..)
|
import Html.Attributes exposing (..)
|
||||||
|
|
||||||
|
|
||||||
|
nameOrLabel : ItemFieldValue -> String
|
||||||
|
nameOrLabel fv =
|
||||||
|
Maybe.withDefault fv.name fv.label
|
||||||
|
|
||||||
|
|
||||||
renderValue : String -> ItemFieldValue -> Html msg
|
renderValue : String -> ItemFieldValue -> Html msg
|
||||||
renderValue classes cv =
|
renderValue classes cv =
|
||||||
let
|
let
|
||||||
@ -19,7 +24,7 @@ renderValue classes cv =
|
|||||||
in
|
in
|
||||||
div [ class classes ]
|
div [ class classes ]
|
||||||
[ Icons.customFieldTypeIconString "" cv.ftype
|
[ Icons.customFieldTypeIconString "" cv.ftype
|
||||||
, Maybe.withDefault cv.name cv.label |> text
|
, nameOrLabel cv |> text
|
||||||
, div [ class "detail" ]
|
, div [ class "detail" ]
|
||||||
[ if Data.CustomFieldType.fromString cv.ftype == Just Data.CustomFieldType.Boolean then
|
[ if Data.CustomFieldType.fromString cv.ftype == Just Data.CustomFieldType.Boolean then
|
||||||
renderBool
|
renderBool
|
||||||
|
Loading…
x
Reference in New Issue
Block a user