Define how many tags to see in ui settings

This commit is contained in:
Eike Kettner 2020-08-08 11:16:45 +02:00
parent 4c57d16501
commit f0a5f84c8b
6 changed files with 405 additions and 190 deletions

View File

@ -10,6 +10,7 @@ import Api.Model.FolderItem exposing (FolderItem)
import Html exposing (..) import Html exposing (..)
import Html.Attributes exposing (..) import Html.Attributes exposing (..)
import Html.Events exposing (onClick) import Html.Events exposing (onClick)
import Util.ExpandCollapse
import Util.List import Util.List
@ -103,44 +104,18 @@ renderItems constr model =
expandToggle : Int -> Model -> List (Html Msg) expandToggle : Int -> Model -> List (Html Msg)
expandToggle max model = expandToggle max model =
if max > List.length model.all then Util.ExpandCollapse.expandToggle
[] max
(List.length model.all)
else ToggleExpand
[ a
[ class "item"
, onClick ToggleExpand
, href "#"
]
[ i [ class "angle down icon" ] []
, div [ class "content" ]
[ div [ class "description" ]
[ em [] [ text "Show More " ]
]
]
]
]
collapseToggle : Int -> Model -> List (Html Msg) collapseToggle : Int -> Model -> List (Html Msg)
collapseToggle max model = collapseToggle max model =
if max > List.length model.all then Util.ExpandCollapse.collapseToggle
[] max
(List.length model.all)
else ToggleExpand
[ a
[ class "item"
, onClick ToggleExpand
, href "#"
]
[ i [ class "angle up icon" ] []
, div [ class "content" ]
[ div [ class "description" ]
[ em [] [ text "Show Less " ]
]
]
]
]
viewItem : Model -> FolderItem -> Html Msg viewItem : Model -> FolderItem -> Html Msg

View File

@ -555,32 +555,18 @@ view : Flags -> UiSettings -> Model -> Html Msg
view flags settings model = view flags settings model =
let let
formHeader icon headline = formHeader icon headline =
div [ class "ui small dividing header" ] div [ class "ui tiny header" ]
[ icon [ icon
, div [ class "content" ] , div [ class "content" ]
[ text headline [ text headline
] ]
] ]
formHeaderHelp icon headline tagger = segmentClass =
div [ class "ui small dividing header" ] "ui vertical segment"
[ a
[ class "right-float"
, href "#"
, onClick tagger
]
[ i [ class "small grey help link icon" ] []
]
, icon
, div [ class "content" ]
[ text headline
]
]
nameIcon =
i [ class "left align icon" ] []
in in
div [ class "ui form" ] div [ class "ui form" ]
[ div [ class segmentClass ]
[ div [ class "inline field" ] [ div [ class "inline field" ]
[ div [ class "ui checkbox" ] [ div [ class "ui checkbox" ]
[ input [ input
@ -594,42 +580,15 @@ view flags settings model =
] ]
] ]
] ]
, Html.map TagSelectMsg (Comp.TagSelect.view settings model.tagSelectModel) ]
, div [ class segmentClass ]
[ Html.map TagSelectMsg (Comp.TagSelect.viewTags settings model.tagSelectModel)
, Html.map TagSelectMsg (Comp.TagSelect.viewCats settings model.tagSelectModel)
, Html.map FolderSelectMsg , Html.map FolderSelectMsg
(Comp.FolderSelect.view settings.searchMenuFolderCount model.folderList) (Comp.FolderSelect.view settings.searchMenuFolderCount model.folderList)
, formHeaderHelp nameIcon "Names" ToggleNameHelp
, span
[ classList
[ ( "small-info", True )
, ( "invisible hidden", not model.showNameHelp )
] ]
] , div [ class segmentClass ]
[ text "Use wildcards " [ formHeader (Icons.correspondentIcon "")
, code [] [ text "*" ]
, text " at beginning or end. Added automatically if not "
, text "present and not quoted. Press "
, em [] [ text "Enter" ]
, text " to start searching."
]
, div [ class "field" ]
[ input
[ type_ "text"
, onInput SetAllName
, Util.Html.onKeyUpCode KeyUpMsg
, model.allNameModel |> Maybe.withDefault "" |> value
, placeholder "Search in various names"
]
[]
, span
[ classList
[ ( "small-info", True )
, ( "invisible hidden", not model.showNameHelp )
]
]
[ text "Looks in correspondents, concerned entities, item name and notes."
]
]
, formHeader (Icons.correspondentIcon "")
(case getDirection model of (case getDirection model of
Just Data.Direction.Incoming -> Just Data.Direction.Incoming ->
"Sender" "Sender"
@ -657,14 +616,17 @@ view flags settings model =
[ label [] [ text "Equipment" ] [ label [] [ text "Equipment" ]
, Html.map ConcEquipmentMsg (Comp.Dropdown.view settings model.concEquipmentModel) , Html.map ConcEquipmentMsg (Comp.Dropdown.view settings model.concEquipmentModel)
] ]
, formHeader (Icons.searchIcon "") "Content" ]
, div [ class segmentClass ]
[ formHeader (Icons.searchIcon "") "Text Search"
, div , div
[ classList [ classList
[ ( "field", True ) [ ( "field", True )
, ( "invisible hidden", not flags.config.fullTextSearchEnabled ) , ( "invisible hidden", not flags.config.fullTextSearchEnabled )
] ]
] ]
[ input [ label [] [ text "Fulltext Search" ]
, input
[ type_ "text" [ type_ "text"
, onInput SetFulltext , onInput SetFulltext
, Util.Html.onKeyUpCode KeyUpMsg , Util.Html.onKeyUpCode KeyUpMsg
@ -676,7 +638,49 @@ view flags settings model =
[ text "Fulltext search in document contents and notes." [ text "Fulltext search in document contents and notes."
] ]
] ]
, formHeader (Icons.dateIcon "") "Date" , div [ class "field" ]
[ label []
[ text "Names"
, a
[ class "right-float"
, href "#"
, onClick ToggleNameHelp
]
[ i [ class "small grey help link icon" ] []
]
]
, input
[ type_ "text"
, onInput SetAllName
, Util.Html.onKeyUpCode KeyUpMsg
, model.allNameModel |> Maybe.withDefault "" |> value
, placeholder "Search in various names"
]
[]
, span
[ classList
[ ( "small-info", True )
]
]
[ text "Looks in correspondents, concerned entities, item name and notes."
]
, p
[ classList
[ ( "small-info", True )
, ( "invisible hidden", not model.showNameHelp )
]
]
[ text "Use wildcards "
, code [] [ text "*" ]
, text " at beginning or end. They are added automatically on both sides "
, text "if not present in the search term and the term is not quoted. Press "
, em [] [ text "Enter" ]
, text " to start searching."
]
]
]
, div [ class segmentClass ]
[ formHeader (Icons.dateIcon "") "Date"
, div [ class "fields" ] , div [ class "fields" ]
[ div [ class "field" ] [ div [ class "field" ]
[ label [] [ label []
@ -722,8 +726,11 @@ view flags settings model =
) )
] ]
] ]
, formHeader (Icons.directionIcon "") "Direction" ]
, div [ class segmentClass ]
[ formHeader (Icons.directionIcon "") "Direction"
, div [ class "field" ] , div [ class "field" ]
[ Html.map DirectionMsg (Comp.Dropdown.view settings model.directionModel) [ Html.map DirectionMsg (Comp.Dropdown.view settings model.directionModel)
] ]
] ]
]

View File

@ -6,7 +6,10 @@ module Comp.TagSelect exposing
, emptySelection , emptySelection
, init , init
, update , update
, view , view1
, view2
, viewCats
, viewTags
) )
import Api.Model.TagCount exposing (TagCount) import Api.Model.TagCount exposing (TagCount)
@ -16,6 +19,7 @@ import Dict exposing (Dict)
import Html exposing (..) import Html exposing (..)
import Html.Attributes exposing (..) import Html.Attributes exposing (..)
import Html.Events exposing (onClick) import Html.Events exposing (onClick)
import Util.ExpandCollapse
type alias Model = type alias Model =
@ -206,8 +210,8 @@ catState model name =
Deselect Deselect
view : UiSettings -> Model -> Html Msg viewTags : UiSettings -> Model -> Html Msg
view settings model = viewTags settings model =
div [ class "ui list" ] div [ class "ui list" ]
[ div [ class "item" ] [ div [ class "item" ]
[ I.tagIcon "" [ I.tagIcon ""
@ -216,7 +220,39 @@ view settings model =
[ text "Tags" [ text "Tags"
] ]
, div [ class "ui relaxed list" ] , div [ class "ui relaxed list" ]
(List.map (viewTagItem settings model) model.all) (renderTagItems settings model)
]
]
]
viewCats : UiSettings -> Model -> Html Msg
viewCats settings model =
div [ class "ui list" ]
[ div [ class "item" ]
[ I.tagsIcon ""
, div [ class "content" ]
[ div [ class "header" ]
[ text "Categories"
]
, div [ class "ui relaxed list" ]
(renderCatItems settings model)
]
]
]
view1 : UiSettings -> Model -> Html Msg
view1 settings model =
div [ class "ui list" ]
[ div [ class "item" ]
[ I.tagIcon ""
, div [ class "content" ]
[ div [ class "header" ]
[ text "Tags"
]
, div [ class "ui relaxed list" ]
(renderTagItems settings model)
] ]
] ]
, div [ class "item" ] , div [ class "item" ]
@ -226,12 +262,81 @@ view settings model =
[ text "Categories" [ text "Categories"
] ]
, div [ class "ui relaxed list" ] , div [ class "ui relaxed list" ]
(List.map (viewCategoryItem settings model) model.categories) (renderCatItems settings model)
] ]
] ]
] ]
view2 : UiSettings -> Model -> List (Html Msg)
view2 settings model =
[ viewTags settings model
, viewCats settings model
]
renderTagItems : UiSettings -> Model -> List (Html Msg)
renderTagItems settings model =
let
tags =
model.all
max =
settings.searchMenuTagCount
exp =
Util.ExpandCollapse.expandToggle
max
(List.length tags)
ToggleExpandTags
cps =
Util.ExpandCollapse.collapseToggle
max
(List.length tags)
ToggleExpandTags
in
if max <= 0 then
List.map (viewTagItem settings model) model.all
else if model.expandedTags then
List.map (viewTagItem settings model) model.all ++ cps
else
List.map (viewTagItem settings model) (List.take max model.all) ++ exp
renderCatItems : UiSettings -> Model -> List (Html Msg)
renderCatItems settings model =
let
cats =
model.categories
max =
settings.searchMenuTagCatCount
exp =
Util.ExpandCollapse.expandToggle
max
(List.length cats)
ToggleExpandCats
cps =
Util.ExpandCollapse.collapseToggle
max
(List.length cats)
ToggleExpandCats
in
if max <= 0 then
List.map (viewCategoryItem settings model) model.categories
else if model.expandedCats then
List.map (viewCategoryItem settings model) model.categories ++ cps
else
List.map (viewCategoryItem settings model) (List.take max model.categories) ++ exp
viewCategoryItem : UiSettings -> Model -> Category -> Html Msg viewCategoryItem : UiSettings -> Model -> Category -> Html Msg
viewCategoryItem settings model cat = viewCategoryItem settings model cat =
let let

View File

@ -32,6 +32,10 @@ type alias Model =
, itemDetailNotesPosition : Pos , itemDetailNotesPosition : Pos
, searchMenuFolderCount : Maybe Int , searchMenuFolderCount : Maybe Int
, searchMenuFolderCountModel : Comp.IntField.Model , searchMenuFolderCountModel : Comp.IntField.Model
, searchMenuTagCount : Maybe Int
, searchMenuTagCountModel : Comp.IntField.Model
, searchMenuTagCatCount : Maybe Int
, searchMenuTagCatCountModel : Comp.IntField.Model
} }
@ -65,6 +69,20 @@ init flags settings =
(Just 2000) (Just 2000)
False False
"Number of folders in search menu" "Number of folders in search menu"
, searchMenuTagCount = Just settings.searchMenuTagCount
, searchMenuTagCountModel =
Comp.IntField.init
(Just 0)
(Just 2000)
False
"Number of tags in search menu"
, searchMenuTagCatCount = Just settings.searchMenuTagCatCount
, searchMenuTagCatCountModel =
Comp.IntField.init
(Just 0)
(Just 2000)
False
"Number of categories in search menu"
} }
, Api.getTags flags "" GetTagsResp , Api.getTags flags "" GetTagsResp
) )
@ -78,6 +96,8 @@ type Msg
| NoteLengthMsg Comp.IntField.Msg | NoteLengthMsg Comp.IntField.Msg
| SetNotesPosition Pos | SetNotesPosition Pos
| SearchMenuFolderMsg Comp.IntField.Msg | SearchMenuFolderMsg Comp.IntField.Msg
| SearchMenuTagMsg Comp.IntField.Msg
| SearchMenuTagCatMsg Comp.IntField.Msg
@ -135,6 +155,38 @@ update sett msg model =
in in
( model_, nextSettings ) ( model_, nextSettings )
SearchMenuTagMsg lm ->
let
( m, n ) =
Comp.IntField.update lm model.searchMenuTagCountModel
nextSettings =
Maybe.map (\len -> { sett | searchMenuTagCount = len }) n
model_ =
{ model
| searchMenuTagCountModel = m
, searchMenuTagCount = n
}
in
( model_, nextSettings )
SearchMenuTagCatMsg lm ->
let
( m, n ) =
Comp.IntField.update lm model.searchMenuTagCatCountModel
nextSettings =
Maybe.map (\len -> { sett | searchMenuTagCatCount = len }) n
model_ =
{ model
| searchMenuTagCatCountModel = m
, searchMenuTagCatCount = n
}
in
( model_, nextSettings )
SetNotesPosition pos -> SetNotesPosition pos ->
let let
model_ = model_ =
@ -232,9 +284,23 @@ view flags _ model =
) )
, div [ class "ui dividing header" ] , div [ class "ui dividing header" ]
[ text "Search Menu" ] [ text "Search Menu" ]
, Html.map SearchMenuTagMsg
(Comp.IntField.viewWithInfo
"How many tags to display in search menu at once. Others can be expanded. Use 0 to always show all."
model.searchMenuTagCount
"field"
model.searchMenuTagCountModel
)
, Html.map SearchMenuTagCatMsg
(Comp.IntField.viewWithInfo
"How many categories to display in search menu at once. Others can be expanded. Use 0 to always show all."
model.searchMenuTagCatCount
"field"
model.searchMenuTagCatCountModel
)
, Html.map SearchMenuFolderMsg , Html.map SearchMenuFolderMsg
(Comp.IntField.viewWithInfo (Comp.IntField.viewWithInfo
"How many folders to display in search menu at once. Other folders can be expanded." "How many folders to display in search menu at once. Other folders can be expanded. Use 0 to always show all."
model.searchMenuFolderCount model.searchMenuFolderCount
"field" "field"
model.searchMenuFolderCountModel model.searchMenuFolderCountModel

View File

@ -34,6 +34,8 @@ type alias StoredUiSettings =
, itemSearchNoteLength : Maybe Int , itemSearchNoteLength : Maybe Int
, itemDetailNotesPosition : Maybe String , itemDetailNotesPosition : Maybe String
, searchMenuFolderCount : Maybe Int , searchMenuFolderCount : Maybe Int
, searchMenuTagCount : Maybe Int
, searchMenuTagCatCount : Maybe Int
} }
@ -51,6 +53,8 @@ type alias UiSettings =
, itemSearchNoteLength : Int , itemSearchNoteLength : Int
, itemDetailNotesPosition : Pos , itemDetailNotesPosition : Pos
, searchMenuFolderCount : Int , searchMenuFolderCount : Int
, searchMenuTagCount : Int
, searchMenuTagCatCount : Int
} }
@ -89,7 +93,9 @@ defaults =
, nativePdfPreview = False , nativePdfPreview = False
, itemSearchNoteLength = 0 , itemSearchNoteLength = 0
, itemDetailNotesPosition = Top , itemDetailNotesPosition = Top
, searchMenuFolderCount = 4 , searchMenuFolderCount = 3
, searchMenuTagCount = 6
, searchMenuTagCatCount = 3
} }
@ -114,6 +120,10 @@ merge given fallback =
, searchMenuFolderCount = , searchMenuFolderCount =
choose given.searchMenuFolderCount choose given.searchMenuFolderCount
fallback.searchMenuFolderCount fallback.searchMenuFolderCount
, searchMenuTagCount =
choose given.searchMenuTagCount fallback.searchMenuTagCount
, searchMenuTagCatCount =
choose given.searchMenuTagCatCount fallback.searchMenuTagCatCount
} }
@ -132,6 +142,8 @@ toStoredUiSettings settings =
, itemSearchNoteLength = Just settings.itemSearchNoteLength , itemSearchNoteLength = Just settings.itemSearchNoteLength
, itemDetailNotesPosition = Just (posToString settings.itemDetailNotesPosition) , itemDetailNotesPosition = Just (posToString settings.itemDetailNotesPosition)
, searchMenuFolderCount = Just settings.searchMenuFolderCount , searchMenuFolderCount = Just settings.searchMenuFolderCount
, searchMenuTagCount = Just settings.searchMenuTagCount
, searchMenuTagCatCount = Just settings.searchMenuTagCatCount
} }

View File

@ -0,0 +1,50 @@
module Util.ExpandCollapse exposing
( collapseToggle
, expandToggle
)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (onClick)
expandToggle : Int -> Int -> msg -> List (Html msg)
expandToggle max all m =
if max >= all then
[]
else
[ a
[ class "item"
, onClick m
, href "#"
]
[ i [ class "angle down icon" ] []
, div [ class "content" ]
[ div [ class "description" ]
[ em [] [ text "Show More " ]
]
]
]
]
collapseToggle : Int -> Int -> msg -> List (Html msg)
collapseToggle max all m =
if max >= all then
[]
else
[ a
[ class "item"
, onClick m
, href "#"
]
[ i [ class "angle up icon" ] []
, div [ class "content" ]
[ div [ class "description" ]
[ em [] [ text "Show Less " ]
]
]
]
]