Store tag category colors in ui settings

This commit is contained in:
Eike Kettner 2020-06-07 22:16:40 +02:00
parent f4e37b512f
commit 1cd65b7b7c
6 changed files with 53 additions and 20 deletions

View File

@ -139,6 +139,7 @@ view data opts model =
[ i [ class "add icon" ] []
]
]
, renderFormData opts data
, span
[ classList
[ ( "small-info", True )
@ -148,7 +149,6 @@ view data opts model =
[ Maybe.withDefault "" opts.description
|> text
]
, renderFormData opts data
]

View File

@ -25,7 +25,6 @@ type alias Model =
, input : StoredUiSettings
, searchPageSizeModel : Comp.IntField.Model
, tagColorModel : Comp.MappingForm.Model
, tagColors : Dict String String
}
@ -38,12 +37,11 @@ init flags defaults =
(Just 10)
(Just 500)
False
"Item search page"
"Page size"
, tagColorModel =
Comp.MappingForm.init
[]
Data.Color.allString
, tagColors = Dict.empty
}
, Api.getTags flags "" GetTagsResp
)
@ -92,12 +90,23 @@ update msg model =
let
( m_, d_ ) =
Comp.MappingForm.update lm model.tagColorModel
newData =
case d_ of
Just data ->
Dict.toList data
Nothing ->
model.input.tagCategoryColors
model_ =
{ model
| tagColorModel = m_
, input = changeInput (\s -> { s | tagCategoryColors = newData }) model
}
in
( { model
| tagColorModel = m_
, tagColors = Maybe.withDefault model.tagColors d_
}
, Nothing
( model_
, Maybe.map (\_ -> getSettings model_) d_
)
GetTagsResp (Ok tl) ->
@ -111,7 +120,6 @@ update msg model =
Comp.MappingForm.init
categories
Data.Color.allString
, tagColors = Dict.empty
}
, Nothing
)
@ -138,16 +146,22 @@ tagColorViewOpts =
view : Model -> Html Msg
view model =
div [ class "ui form" ]
[ Html.map SearchPageSizeMsg
[ div [ class "ui dividing header" ]
[ text "Item Search"
]
, Html.map SearchPageSizeMsg
(Comp.IntField.viewWithInfo
"Maximum results in one page when searching items."
model.input.itemSearchPageSize
"field"
model.searchPageSizeModel
)
, div [ class "ui dividing header" ]
[ text "Tag Category Colors"
]
, Html.map TagColorMsg
(Comp.MappingForm.view
model.tagColors
(Dict.fromList model.input.tagCategoryColors)
tagColorViewOpts
model.tagColorModel
)

View File

@ -58,7 +58,12 @@ update flags msg model =
( { model
| formModel = m_
, settings = sett
, message = Nothing
, message =
if sett /= Nothing then
Nothing
else
model.message
}
, Cmd.none
, Sub.none

View File

@ -7,6 +7,9 @@ module Data.UiSettings exposing
, toStoredUiSettings
)
import Dict exposing (Dict)
{-| Settings for the web ui. All fields should be optional, since it
is loaded from local storage.
@ -15,10 +18,9 @@ versions. Also if a user is logged out, an empty object is send to
force default settings.
-}
type alias StoredUiSettings =
{ itemSearchPageSize : Maybe Int
, tagCategoryColors : List ( String, String )
}
@ -31,12 +33,14 @@ default value, converting the StoredUiSettings into a UiSettings.
-}
type alias UiSettings =
{ itemSearchPageSize : Int
, tagCategoryColors : Dict String String
}
defaults : UiSettings
defaults =
{ itemSearchPageSize = 60
, tagCategoryColors = Dict.empty
}
@ -44,6 +48,9 @@ merge : StoredUiSettings -> UiSettings -> UiSettings
merge given fallback =
{ itemSearchPageSize =
choose given.itemSearchPageSize fallback.itemSearchPageSize
, tagCategoryColors =
Dict.union (Dict.fromList given.tagCategoryColors)
fallback.tagCategoryColors
}
@ -55,6 +62,7 @@ mergeDefaults given =
toStoredUiSettings : UiSettings -> StoredUiSettings
toStoredUiSettings settings =
{ itemSearchPageSize = Just settings.itemSearchPageSize
, tagCategoryColors = Dict.toList settings.tagCategoryColors
}

View File

@ -32,13 +32,13 @@ port setAllProgress : ( String, Int ) -> Cmd msg
port scrollToElem : String -> Cmd msg
port saveUiSettings : ( AuthResult, UiSettings ) -> Cmd msg
port saveUiSettings : ( AuthResult, StoredUiSettings ) -> Cmd msg
port receiveUiSettings : (StoredUiSettings -> msg) -> Sub msg
port requestUiSettings : ( AuthResult, UiSettings ) -> Cmd msg
port requestUiSettings : ( AuthResult, StoredUiSettings ) -> Cmd msg
port uiSettingsSaved : (() -> msg) -> Sub msg
@ -53,7 +53,10 @@ storeUiSettings : Flags -> UiSettings -> Cmd msg
storeUiSettings flags settings =
case flags.account of
Just ar ->
saveUiSettings ( ar, settings )
saveUiSettings
( ar
, Data.UiSettings.toStoredUiSettings settings
)
Nothing ->
Cmd.none
@ -68,7 +71,10 @@ getUiSettings : Flags -> Cmd msg
getUiSettings flags =
case flags.account of
Just ar ->
requestUiSettings ( ar, Data.UiSettings.defaults )
requestUiSettings
( ar
, Data.UiSettings.toStoredUiSettings Data.UiSettings.defaults
)
Nothing ->
Cmd.none

View File

@ -153,7 +153,7 @@ label span.muted {
margin-left: 0.5em;
}
.ui.search.dropdown.open {
.ui.search.dropdown.open, .ui.selection.dropdown.open {
z-index: 20;
}