Put number of folders to display in ui settings

This commit is contained in:
Eike Kettner 2020-08-08 00:06:23 +02:00
parent 873d9fafc3
commit c8ad9bf11f
3 changed files with 46 additions and 5 deletions

View File

@ -30,6 +30,8 @@ type alias Model =
, itemSearchNoteLength : Maybe Int
, searchNoteLengthModel : Comp.IntField.Model
, itemDetailNotesPosition : Pos
, searchMenuFolders : Maybe Int
, searchMenuFoldersModel : Comp.IntField.Model
}
@ -56,6 +58,13 @@ init flags settings =
False
"Max. Note Length"
, itemDetailNotesPosition = settings.itemDetailNotesPosition
, searchMenuFolders = Just settings.searchMenuFolders
, searchMenuFoldersModel =
Comp.IntField.init
(Just 0)
(Just 2000)
False
"Number of folders in search menu"
}
, Api.getTags flags "" GetTagsResp
)
@ -68,6 +77,7 @@ type Msg
| TogglePdfPreview
| NoteLengthMsg Comp.IntField.Msg
| SetNotesPosition Pos
| SearchMenuFolderMsg Comp.IntField.Msg
@ -109,6 +119,22 @@ update sett msg model =
in
( model_, nextSettings )
SearchMenuFolderMsg lm ->
let
( m, n ) =
Comp.IntField.update lm model.searchMenuFoldersModel
nextSettings =
Maybe.map (\len -> { sett | searchMenuFolders = len }) n
model_ =
{ model
| searchMenuFoldersModel = m
, searchMenuFolders = n
}
in
( model_, nextSettings )
SetNotesPosition pos ->
let
model_ =
@ -204,6 +230,15 @@ view flags _ model =
"field"
model.searchNoteLengthModel
)
, div [ class "ui dividing header" ]
[ text "Search Menu" ]
, Html.map SearchMenuFolderMsg
(Comp.IntField.viewWithInfo
"How many folders to display in search menu at once. Other folders can be expanded."
model.searchMenuFolders
"field"
model.searchMenuFoldersModel
)
, div [ class "ui dividing header" ]
[ text "Item Detail"
]

View File

@ -31,6 +31,7 @@ type alias StoredUiSettings =
, nativePdfPreview : Bool
, itemSearchNoteLength : Maybe Int
, itemDetailNotesPosition : Maybe String
, searchMenuFolders : Maybe Int
}
@ -47,6 +48,7 @@ type alias UiSettings =
, nativePdfPreview : Bool
, itemSearchNoteLength : Int
, itemDetailNotesPosition : Pos
, searchMenuFolders : Int
}
@ -85,6 +87,7 @@ defaults =
, nativePdfPreview = False
, itemSearchNoteLength = 0
, itemDetailNotesPosition = Top
, searchMenuFolders = 5
}
@ -106,6 +109,9 @@ merge given fallback =
, itemDetailNotesPosition =
choose (Maybe.andThen posFromString given.itemDetailNotesPosition)
fallback.itemDetailNotesPosition
, searchMenuFolders =
choose given.searchMenuFolders
fallback.searchMenuFolders
}
@ -123,6 +129,7 @@ toStoredUiSettings settings =
, nativePdfPreview = settings.nativePdfPreview
, itemSearchNoteLength = Just settings.itemSearchNoteLength
, itemDetailNotesPosition = Just (posToString settings.itemDetailNotesPosition)
, searchMenuFolders = Just settings.searchMenuFolders
}

View File

@ -57,13 +57,12 @@ fromString str =
filter : (a -> Bool) -> Maybe a -> Maybe a
filter predicate ma =
case ma of
Just v ->
let
check v =
if predicate v then
Just v
else
Nothing
Nothing ->
Nothing
in
Maybe.andThen check ma