Display item notes in card view if configured

The user can set a maximum length of the item notes to display in each
card. If set to 0, it is hidden.
This commit is contained in:
Eike Kettner 2020-08-04 23:34:08 +02:00
parent 09d74b7e80
commit 08f953dd52
9 changed files with 99 additions and 17 deletions

View File

@ -15,7 +15,9 @@ case class Flags(
signupMode: SignupConfig.Mode, signupMode: SignupConfig.Mode,
docspellAssetPath: String, docspellAssetPath: String,
integrationEnabled: Boolean, integrationEnabled: Boolean,
fullTextSearchEnabled: Boolean fullTextSearchEnabled: Boolean,
maxPageSize: Int,
maxNoteLength: Int
) )
object Flags { object Flags {
@ -26,7 +28,9 @@ object Flags {
cfg.backend.signup.mode, cfg.backend.signup.mode,
s"/app/assets/docspell-webapp/${BuildInfo.version}", s"/app/assets/docspell-webapp/${BuildInfo.version}",
cfg.integrationEndpoint.enabled, cfg.integrationEndpoint.enabled,
cfg.fullTextSearch.enabled cfg.fullTextSearch.enabled,
cfg.maxItemPageSize,
cfg.maxNoteLength
) )
implicit val jsonEncoder: Encoder[Flags] = implicit val jsonEncoder: Encoder[Flags] =

View File

@ -146,7 +146,7 @@ viewQueue model =
viewUserSettings : Model -> Html Msg viewUserSettings : Model -> Html Msg
viewUserSettings model = viewUserSettings model =
Html.map UserSettingsMsg (Page.UserSettings.View.view model.uiSettings model.userSettingsModel) Html.map UserSettingsMsg (Page.UserSettings.View.view model.flags model.uiSettings model.userSettingsModel)
viewCollectiveSettings : Model -> Html Msg viewCollectiveSettings : Model -> Html Msg

View File

@ -197,6 +197,22 @@ viewItem settings item =
) )
] ]
] ]
, div
[ classList
[ ( "content", True )
, ( "invisible hidden"
, settings.itemSearchNoteLength
<= 0
|| Util.String.isNothingOrBlank item.notes
)
]
]
[ span [ class "small-info" ]
[ Maybe.withDefault "" item.notes
|> Util.String.ellipsis settings.itemSearchNoteLength
|> text
]
]
, div [ class "content" ] , div [ class "content" ]
[ div [ class "ui horizontal list" ] [ div [ class "ui horizontal list" ]
[ div [ div

View File

@ -12,7 +12,7 @@ import Comp.ColorTagger
import Comp.IntField import Comp.IntField
import Data.Color exposing (Color) import Data.Color exposing (Color)
import Data.Flags exposing (Flags) import Data.Flags exposing (Flags)
import Data.UiSettings exposing (StoredUiSettings, UiSettings) import Data.UiSettings exposing (UiSettings)
import Dict exposing (Dict) import Dict exposing (Dict)
import Html exposing (..) import Html exposing (..)
import Html.Attributes exposing (..) import Html.Attributes exposing (..)
@ -27,6 +27,8 @@ type alias Model =
, tagColors : Dict String Color , tagColors : Dict String Color
, tagColorModel : Comp.ColorTagger.Model , tagColorModel : Comp.ColorTagger.Model
, nativePdfPreview : Bool , nativePdfPreview : Bool
, itemSearchNoteLength : Maybe Int
, searchNoteLengthModel : Comp.IntField.Model
} }
@ -36,7 +38,7 @@ init flags settings =
, searchPageSizeModel = , searchPageSizeModel =
Comp.IntField.init Comp.IntField.init
(Just 10) (Just 10)
(Just 500) (Just flags.config.maxPageSize)
False False
"Page size" "Page size"
, tagColors = settings.tagCategoryColors , tagColors = settings.tagCategoryColors
@ -45,6 +47,13 @@ init flags settings =
[] []
Data.Color.all Data.Color.all
, nativePdfPreview = settings.nativePdfPreview , nativePdfPreview = settings.nativePdfPreview
, itemSearchNoteLength = Just settings.itemSearchNoteLength
, searchNoteLengthModel =
Comp.IntField.init
(Just 0)
(Just flags.config.maxNoteLength)
False
"Max. Note Length"
} }
, Api.getTags flags "" GetTagsResp , Api.getTags flags "" GetTagsResp
) )
@ -55,6 +64,7 @@ type Msg
| TagColorMsg Comp.ColorTagger.Msg | TagColorMsg Comp.ColorTagger.Msg
| GetTagsResp (Result Http.Error TagList) | GetTagsResp (Result Http.Error TagList)
| TogglePdfPreview | TogglePdfPreview
| NoteLengthMsg Comp.IntField.Msg
@ -80,6 +90,22 @@ update sett msg model =
in in
( model_, nextSettings ) ( model_, nextSettings )
NoteLengthMsg lm ->
let
( m, n ) =
Comp.IntField.update lm model.searchNoteLengthModel
nextSettings =
Maybe.map (\len -> { sett | itemSearchNoteLength = len }) n
model_ =
{ model
| searchNoteLengthModel = m
, itemSearchNoteLength = n
}
in
( model_, nextSettings )
TagColorMsg lm -> TagColorMsg lm ->
let let
( m_, d_ ) = ( m_, d_ ) =
@ -139,19 +165,32 @@ tagColorViewOpts =
} }
view : UiSettings -> Model -> Html Msg view : Flags -> UiSettings -> Model -> Html Msg
view _ model = view flags _ model =
div [ class "ui form" ] div [ class "ui form" ]
[ div [ class "ui dividing header" ] [ div [ class "ui dividing header" ]
[ text "Item Search" [ text "Item Search"
] ]
, Html.map SearchPageSizeMsg , Html.map SearchPageSizeMsg
(Comp.IntField.viewWithInfo (Comp.IntField.viewWithInfo
"Maximum results in one page when searching items." ("Maximum results in one page when searching items. At most "
++ String.fromInt flags.config.maxPageSize
++ "."
)
model.itemSearchPageSize model.itemSearchPageSize
"field" "field"
model.searchPageSizeModel model.searchPageSizeModel
) )
, Html.map NoteLengthMsg
(Comp.IntField.viewWithInfo
("Maximum size of the item notes to display in card view. Between 0 - "
++ String.fromInt flags.config.maxNoteLength
++ "."
)
model.itemSearchNoteLength
"field"
model.searchNoteLengthModel
)
, div [ class "ui dividing header" ] , div [ class "ui dividing header" ]
[ text "Item Detail" [ text "Item Detail"
] ]

View File

@ -115,10 +115,10 @@ isSuccess model =
Maybe.map .success model.message == Just True Maybe.map .success model.message == Just True
view : UiSettings -> String -> Model -> Html Msg view : Flags -> UiSettings -> String -> Model -> Html Msg
view settings classes model = view flags settings classes model =
div [ class classes ] div [ class classes ]
[ Html.map UiSettingsFormMsg (Comp.UiSettingsForm.view settings model.formModel) [ Html.map UiSettingsFormMsg (Comp.UiSettingsForm.view flags settings model.formModel)
, div [ class "ui divider" ] [] , div [ class "ui divider" ] []
, button , button
[ class "ui primary button" [ class "ui primary button"

View File

@ -16,6 +16,8 @@ type alias Config =
, docspellAssetPath : String , docspellAssetPath : String
, integrationEnabled : Bool , integrationEnabled : Bool
, fullTextSearchEnabled : Bool , fullTextSearchEnabled : Bool
, maxPageSize : Int
, maxNoteLength : Int
} }

View File

@ -26,6 +26,7 @@ type alias StoredUiSettings =
{ itemSearchPageSize : Maybe Int { itemSearchPageSize : Maybe Int
, tagCategoryColors : List ( String, String ) , tagCategoryColors : List ( String, String )
, nativePdfPreview : Bool , nativePdfPreview : Bool
, itemSearchNoteLength : Maybe Int
} }
@ -40,6 +41,7 @@ type alias UiSettings =
{ itemSearchPageSize : Int { itemSearchPageSize : Int
, tagCategoryColors : Dict String Color , tagCategoryColors : Dict String Color
, nativePdfPreview : Bool , nativePdfPreview : Bool
, itemSearchNoteLength : Int
} }
@ -48,6 +50,7 @@ defaults =
{ itemSearchPageSize = 60 { itemSearchPageSize = 60
, tagCategoryColors = Dict.empty , tagCategoryColors = Dict.empty
, nativePdfPreview = False , nativePdfPreview = False
, itemSearchNoteLength = 0
} }
@ -64,6 +67,8 @@ merge given fallback =
) )
fallback.tagCategoryColors fallback.tagCategoryColors
, nativePdfPreview = given.nativePdfPreview , nativePdfPreview = given.nativePdfPreview
, itemSearchNoteLength =
choose given.itemSearchNoteLength fallback.itemSearchNoteLength
} }
@ -79,6 +84,7 @@ toStoredUiSettings settings =
Dict.map (\_ -> Data.Color.toString) settings.tagCategoryColors Dict.map (\_ -> Data.Color.toString) settings.tagCategoryColors
|> Dict.toList |> Dict.toList
, nativePdfPreview = settings.nativePdfPreview , nativePdfPreview = settings.nativePdfPreview
, itemSearchNoteLength = Just settings.itemSearchNoteLength
} }

View File

@ -6,6 +6,7 @@ import Comp.ImapSettingsManage
import Comp.NotificationManage import Comp.NotificationManage
import Comp.ScanMailboxManage import Comp.ScanMailboxManage
import Comp.UiSettingsManage import Comp.UiSettingsManage
import Data.Flags exposing (Flags)
import Data.UiSettings exposing (UiSettings) import Data.UiSettings exposing (UiSettings)
import Html exposing (..) import Html exposing (..)
import Html.Attributes exposing (..) import Html.Attributes exposing (..)
@ -14,8 +15,8 @@ import Page.UserSettings.Data exposing (..)
import Util.Html exposing (classActive) import Util.Html exposing (classActive)
view : UiSettings -> Model -> Html Msg view : Flags -> UiSettings -> Model -> Html Msg
view settings model = view flags settings model =
div [ class "usersetting-page ui padded grid" ] div [ class "usersetting-page ui padded grid" ]
[ div [ class "sixteen wide mobile four wide tablet four wide computer column" ] [ div [ class "sixteen wide mobile four wide tablet four wide computer column" ]
[ h4 [ class "ui top attached ablue-comp header" ] [ h4 [ class "ui top attached ablue-comp header" ]
@ -51,7 +52,7 @@ view settings model =
viewScanMailboxManage settings model viewScanMailboxManage settings model
Just UiSettingsTab -> Just UiSettingsTab ->
viewUiSettings settings model viewUiSettings flags settings model
Nothing -> Nothing ->
[] []
@ -72,8 +73,8 @@ makeTab model tab header icon =
] ]
viewUiSettings : UiSettings -> Model -> List (Html Msg) viewUiSettings : Flags -> UiSettings -> Model -> List (Html Msg)
viewUiSettings settings model = viewUiSettings flags settings model =
[ h2 [ class "ui header" ] [ h2 [ class "ui header" ]
[ i [ class "cog icon" ] [] [ i [ class "cog icon" ] []
, text "UI Settings" , text "UI Settings"
@ -84,6 +85,7 @@ viewUiSettings settings model =
] ]
, Html.map UiSettingsMsg , Html.map UiSettingsMsg
(Comp.UiSettingsManage.view (Comp.UiSettingsManage.view
flags
settings settings
"ui segment" "ui segment"
model.uiSettingsModel model.uiSettingsModel

View File

@ -1,6 +1,8 @@
module Util.String exposing module Util.String exposing
( crazyEncode ( crazyEncode
, ellipsis , ellipsis
, isBlank
, isNothingOrBlank
, underscoreToSpace , underscoreToSpace
, withDefault , withDefault
) )
@ -31,7 +33,7 @@ ellipsis len str =
str str
else else
String.left (len - 3) str ++ "..." String.left (len - 1) str ++ ""
withDefault : String -> String -> String withDefault : String -> String -> String
@ -46,3 +48,14 @@ withDefault default str =
underscoreToSpace : String -> String underscoreToSpace : String -> String
underscoreToSpace str = underscoreToSpace str =
String.replace "_" " " str String.replace "_" " " str
isBlank : String -> Bool
isBlank s =
s == "" || (String.trim s == "")
isNothingOrBlank : Maybe String -> Bool
isNothingOrBlank ms =
Maybe.map isBlank ms
|> Maybe.withDefault True