From 730175d07ed97cc50d9be9de26efac3c6c8a6231 Mon Sep 17 00:00:00 2001 From: Steven Vandevelde Date: Fri, 25 Aug 2017 23:43:07 +0200 Subject: [PATCH] Add ability to select a different background image --- src/App/Settings/Ports.elm | 9 +++ src/App/Settings/State.elm | 30 +++++++++ src/App/Settings/Types.elm | 16 +++++ src/App/Settings/View.elm | 58 ++++++++++++++---- src/App/State.elm | 6 ++ src/App/Types.elm | 6 +- src/App/View.elm | 19 ++++++ src/Css/Styles.elm | 6 +- src/Js/elm-loader.js | 5 ++ src/Static/Html/Proxy.html | 2 - src/Static/Images/ep_naturalblack_pattern.jpg | Bin 0 -> 48330 bytes src/Static/Images/ep_naturalblack_pattern.png | Bin 0 -> 111057 bytes 12 files changed, 140 insertions(+), 17 deletions(-) create mode 100644 src/App/Settings/Ports.elm create mode 100644 src/App/Settings/State.elm create mode 100644 src/App/Settings/Types.elm create mode 100644 src/Static/Images/ep_naturalblack_pattern.jpg create mode 100644 src/Static/Images/ep_naturalblack_pattern.png diff --git a/src/App/Settings/Ports.elm b/src/App/Settings/Ports.elm new file mode 100644 index 00000000..e0dcca46 --- /dev/null +++ b/src/App/Settings/Ports.elm @@ -0,0 +1,9 @@ +port module Settings.Ports exposing (..) + +import Settings.Types exposing (..) + + +-- 💡 + + +port storeApplicationSettings : Model -> Cmd msg diff --git a/src/App/Settings/State.elm b/src/App/Settings/State.elm new file mode 100644 index 00000000..6c8a5f0c --- /dev/null +++ b/src/App/Settings/State.elm @@ -0,0 +1,30 @@ +module Settings.State exposing (..) + +import Settings.Ports as Ports +import Settings.Types exposing (..) +import Types as TopLevel exposing (ProgramFlags) + + +-- 💧 + + +initialModel : ProgramFlags -> Model +initialModel flags = + flags.settings.application + + + +-- 🔥 + + +update : Msg -> Model -> ( Model, Cmd TopLevel.Msg ) +update msg model = + case msg of + SetBackgroundImage filename -> + let + newModel = + { model | backgroundImage = filename } + in + (!) + newModel + [ Ports.storeApplicationSettings newModel ] diff --git a/src/App/Settings/Types.elm b/src/App/Settings/Types.elm new file mode 100644 index 00000000..36074050 --- /dev/null +++ b/src/App/Settings/Types.elm @@ -0,0 +1,16 @@ +module Settings.Types exposing (..) + +-- Messages + + +type Msg + = SetBackgroundImage String + + + +-- Model + + +type alias Model = + { backgroundImage : String + } diff --git a/src/App/Settings/View.elm b/src/App/Settings/View.elm index 83a1da08..393a0fcf 100644 --- a/src/App/Settings/View.elm +++ b/src/App/Settings/View.elm @@ -1,10 +1,14 @@ module Settings.View exposing (..) +import Color import Html exposing (..) import Html.Attributes exposing (..) +import Html.Events exposing (onInput) import Material.Icons.Action as Icons +import Material.Icons.Navigation as Icons import Material.Icons.Image as Icons import Navigation.View as Navigation +import Settings.Types import Types exposing (Model, Msg(..)) import Utils exposing (cssClass) import Variables exposing (colorDerivatives) @@ -12,6 +16,7 @@ import Variables exposing (colorDerivatives) -- Styles +import Form.Styles as FormStyles import Styles exposing (Classes(..)) @@ -40,16 +45,47 @@ entry model = ------------------------------------ , div [ cssClass ContentBox ] - [ h1 - [] - [ text "Settings" ] - , div - [ cssClass EmptyState ] - [ Icons.panorama_wide_angle colorDerivatives.text 16 - , div - [] - [ text "Coming soon" - ] - ] + [ h1 [] [ text "Settings" ] + , Html.map SettingsMsg (theForm model) + ] + ] + + +theForm : Model -> Html Settings.Types.Msg +theForm model = + Html.form + [ style + [ ( "max-width", "350px" ) ] + ] + [ label + [] + [ text "Background image" ] + , div + [ cssClass FormStyles.SelectBox ] + [ select + [ onInput Settings.Types.SetBackgroundImage ] + (List.map + (\( val, lbl ) -> + option + [ selected (val == model.settings.backgroundImage) + , value val + ] + [ text lbl ] + ) + backgroundImages + ) + , Icons.expand_more (Color.greyscale 0.325) 20 ] ] + + +backgroundImages : List ( String, String ) +backgroundImages = + [ ( "1.jpg", "Option 1" ) + , ( "2.jpg", "Option 2" ) + , ( "3.jpg", "Option 3" ) + , ( "4.jpg", "Option 4 (default)" ) + , ( "5.jpg", "Option 5" ) + , ( "6.jpg", "Option 6" ) + , ( "7.jpg", "Option 7" ) + ] diff --git a/src/App/State.elm b/src/App/State.elm index be7bbfa3..bddd4f83 100644 --- a/src/App/State.elm +++ b/src/App/State.elm @@ -20,6 +20,7 @@ import Console.State as Console import Equalizer.State as Equalizer import Queue.State as Queue import Routing.State as Routing +import Settings.State as Settings import Sources.State as Sources import Tracks.State as Tracks @@ -59,6 +60,7 @@ initialModel flags location = , equalizer = Equalizer.initialModel flags , queue = Queue.initialModel flags , routing = Routing.initialModel location + , settings = Settings.initialModel flags , sources = Sources.initialModel flags , tracks = Tracks.initialModel flags } @@ -156,6 +158,10 @@ update msg model = |> mapModel (\x -> { model | routing = x }) |> handleRouteTransitions sub model + SettingsMsg sub -> + Settings.update sub model.settings + |> mapModel (\x -> { model | settings = x }) + SourcesMsg sub -> Sources.update sub model.sources |> mapModel (\x -> { model | sources = x }) diff --git a/src/App/Types.elm b/src/App/Types.elm index da2e90b2..91592a98 100644 --- a/src/App/Types.elm +++ b/src/App/Types.elm @@ -14,6 +14,7 @@ import Console.Types as Console import Equalizer.Types as Equalizer import Queue.Types as Queue import Routing.Types as Routing +import Settings.Types as Settings import Sources.Types as Sources import Tracks.Types as Tracks @@ -34,6 +35,7 @@ type Msg | EqualizerMsg Equalizer.Msg | QueueMsg Queue.Msg | RoutingMsg Routing.Msg + | SettingsMsg Settings.Msg | SourcesMsg Sources.Msg | TracksMsg Tracks.Msg -- Children, Pt. 2 @@ -76,6 +78,7 @@ type alias Model = , equalizer : Equalizer.Model , queue : Queue.Model , routing : Routing.Model + , settings : Settings.Model , sources : Sources.Model , tracks : Tracks.Model } @@ -101,7 +104,8 @@ type alias ProgramFlags = type alias Settings = - { equalizer : Equalizer.Settings + { application : Settings.Model + , equalizer : Equalizer.Settings , queue : Queue.Settings , tracks : Tracks.Settings } diff --git a/src/App/View.elm b/src/App/View.elm index 3812ec0c..4cedfdfa 100644 --- a/src/App/View.elm +++ b/src/App/View.elm @@ -141,6 +141,25 @@ entry model = style [] ] [] + + -- + -- Background image + -- + , div + [ cssClass BackgroundImage + , style + [ ( "background-image" + , "url(images/Background/" ++ model.settings.backgroundImage ++ ")" + ) + , case model.settings.backgroundImage of + "1.jpg" -> + ( "background-position", "center 30%" ) + + _ -> + ( "background-position", "center bottom" ) + ] + ] + [] ] diff --git a/src/Css/Styles.elm b/src/Css/Styles.elm index 1d0f2bf5..0cad31fa 100644 --- a/src/Css/Styles.elm +++ b/src/Css/Styles.elm @@ -83,7 +83,8 @@ stylesLocal = -- ------------------------------------------------------ , body - [ backgroundColor (hex "#000") + [ backgroundColor (hex "#02070E") + , backgroundImage (url "/images/ep_naturalblack_pattern.jpg") , color (cssColor colorDerivatives.text) , defaultFont , fontSize (Css.rem 1) @@ -103,8 +104,7 @@ stylesLocal = -- > Not on the for a reason. ------------------------------------------------------ , class BackgroundImage - [ backgroundImage (url "images/Background/4.jpg") - , backgroundPosition bottom + [ backgroundPosition bottom , backgroundSize cover -- For: 1.jpg diff --git a/src/Js/elm-loader.js b/src/Js/elm-loader.js index 2915ce80..2668319b 100644 --- a/src/Js/elm-loader.js +++ b/src/Js/elm-loader.js @@ -39,6 +39,10 @@ function initialize(params) { function initializeFlags(params) { return { settings: { + application: Object.assign( + { backgroundImage: "4.jpg" }, + loadSettings("application") + ), equalizer: Object.assign( { low: 0, mid: 0, high: 0, volume: 1 }, loadSettings("equalizer") @@ -181,6 +185,7 @@ function initializePorts(app, flags) { app.ports.storeTracks.subscribe(v => storeData("tracks", v)); app.ports.storeFavourites.subscribe(v => storeData("favourites", v)); + app.ports.storeApplicationSettings.subscribe(s => saveSettings("application", s)); app.ports.storeEqualizerSettings.subscribe(s => saveSettings("equalizer", s)); app.ports.storeQueueSettings.subscribe(s => saveSettings("queue", s)); app.ports.storeTracksSettings.subscribe(s => saveSettings("tracks", s)); diff --git a/src/Static/Html/Proxy.html b/src/Static/Html/Proxy.html index c77c0dd5..72f38027 100644 --- a/src/Static/Html/Proxy.html +++ b/src/Static/Html/Proxy.html @@ -33,8 +33,6 @@ -
-