From ce2121e30e251692750a3fea31dbbd7f69493f13 Mon Sep 17 00:00:00 2001 From: Rok Garbas Date: Mon, 11 May 2020 22:42:57 +0200 Subject: [PATCH] channel drowdown (#21) --- src/ElasticSearch.elm | 54 +++++++++++++++++++++++++++++++++++++------ src/Main.elm | 9 ++++---- src/Page/Options.elm | 6 +++-- src/Page/Packages.elm | 6 +++-- src/Route.elm | 16 ++++++++----- src/index.scss | 4 ++++ 6 files changed, 74 insertions(+), 21 deletions(-) diff --git a/src/ElasticSearch.elm b/src/ElasticSearch.elm index 5c3d195..56cbb74 100644 --- a/src/ElasticSearch.elm +++ b/src/ElasticSearch.elm @@ -24,8 +24,11 @@ import Html , h1 , input , li + , option , p - , pre + , select + , span + , strong , text , ul ) @@ -53,7 +56,8 @@ import Url.Builder type alias Model a = - { query : Maybe String + { channel : String + , query : Maybe String , result : RemoteData.WebData (Result a) , showDetailsFor : Maybe String , from : Int @@ -90,11 +94,13 @@ type alias ResultItem a = init : Maybe String -> Maybe String + -> Maybe String -> Maybe Int -> Maybe Int -> ( Model a, Cmd msg ) -init query showDetailsFor from size = - ( { query = query +init channel query showDetailsFor from size = + ( { channel = Maybe.withDefault "unstable" channel + , query = query , result = RemoteData.NotAsked , showDetailsFor = showDetailsFor , from = Maybe.withDefault 0 from @@ -112,6 +118,7 @@ init query showDetailsFor from size = type Msg a = NoOp + | ChannelChange String | QueryInput String | QuerySubmit | QueryResponse (RemoteData.WebData (Result a)) @@ -131,6 +138,11 @@ update path navKey msg model = , Cmd.none ) + ChannelChange channel -> + ( { model | channel = channel } + , Cmd.none + ) + QueryInput query -> ( { model | query = Just query } , Cmd.none @@ -138,7 +150,9 @@ update path navKey msg model = QuerySubmit -> ( model - , createUrl path + , createUrl + path + model.channel model.query model.showDetailsFor 0 @@ -153,7 +167,9 @@ update path navKey msg model = ShowDetails selected -> ( model - , createUrl path + , createUrl + path + model.channel model.query (if model.showDetailsFor == Just selected then Nothing @@ -169,14 +185,16 @@ update path navKey msg model = createUrl : String + -> String -> Maybe String -> Maybe String -> Int -> Int -> String -createUrl path query showDetailsFor from size = +createUrl path channel query showDetailsFor from size = [ Url.Builder.int "from" from , Url.Builder.int "size" size + , Url.Builder.string "channel" channel ] |> List.append (query @@ -225,6 +243,24 @@ view path title model viewSuccess outMsg = [ button [ class "btn" ] [ text "Search" ] ] ] + , span [] + [ strong [] + [ text " in " ] + , select + [ onInput (\x -> outMsg (ChannelChange x)) ] + [ option + [ value "unstable" ] + [ text "unstable" ] + , option + [ value "20.03" ] + [ text "20.03" ] + , option + [ value "19.09" ] + [ text "19.09" ] + ] + , strong [] + [ text " channel." ] + ] ] ] , case model.result of @@ -290,6 +326,7 @@ viewPager outMsg model result path = href <| createUrl path + model.channel model.query model.showDetailsFor 0 @@ -310,6 +347,7 @@ viewPager outMsg model result path = else createUrl path + model.channel model.query model.showDetailsFor (model.from - model.size) @@ -330,6 +368,7 @@ viewPager outMsg model result path = else createUrl path + model.channel model.query model.showDetailsFor (model.from + model.size) @@ -350,6 +389,7 @@ viewPager outMsg model result path = else createUrl path + model.channel model.query model.showDetailsFor ((result.hits.total.value // model.size) * model.size) diff --git a/src/Main.elm b/src/Main.elm index 33b019a..a924a3a 100644 --- a/src/Main.elm +++ b/src/Main.elm @@ -116,6 +116,7 @@ submitQuery old ( new, cmd ) = [ cmd , makeRequest new.elasticsearch + newModel.channel (Maybe.withDefault "" newModel.query) newModel.from newModel.size @@ -172,13 +173,13 @@ changeRouteTo model url = -- on the home page ( newModel, Browser.Navigation.pushUrl newModel.navKey "/packages" ) - Just (Route.Packages query showDetailsFor from size) -> - Page.Packages.init query showDetailsFor from size + Just (Route.Packages channel query showDetailsFor from size) -> + Page.Packages.init channel query showDetailsFor from size |> updateWith Packages PackagesMsg newModel |> submitQuery newModel - Just (Route.Options query showDetailsFor from size) -> - Page.Options.init query showDetailsFor from size + Just (Route.Options channel query showDetailsFor from size) -> + Page.Options.init channel query showDetailsFor from size |> updateWith Options OptionsMsg newModel |> submitQuery newModel diff --git a/src/Page/Options.elm b/src/Page/Options.elm index 05d758f..b842f77 100644 --- a/src/Page/Options.elm +++ b/src/Page/Options.elm @@ -65,6 +65,7 @@ type alias ResultItemSource = init : Maybe String -> Maybe String + -> Maybe String -> Maybe Int -> Maybe Int -> ( Model, Cmd Msg ) @@ -211,13 +212,14 @@ viewResultItemDetails item = makeRequest : ElasticSearch.Options -> String + -> String -> Int -> Int -> Cmd Msg -makeRequest options query from size = +makeRequest options channel query from size = ElasticSearch.makeRequest "option_name" - "nixos-unstable-options" + ("nixos-" ++ channel ++ "-options") decodeResultItemSource options query diff --git a/src/Page/Packages.elm b/src/Page/Packages.elm index e9ec289..9016b3b 100644 --- a/src/Page/Packages.elm +++ b/src/Page/Packages.elm @@ -81,6 +81,7 @@ type alias ResultPackageMaintainer = init : Maybe String -> Maybe String + -> Maybe String -> Maybe Int -> Maybe Int -> ( Model, Cmd Msg ) @@ -279,13 +280,14 @@ viewResultItemDetails item = makeRequest : ElasticSearch.Options -> String + -> String -> Int -> Int -> Cmd Msg -makeRequest options query from size = +makeRequest options channel query from size = ElasticSearch.makeRequest "attr_name" - "nixos-unstable-packages" + ("nixos-" ++ channel ++ "-packages") decodeResultItemSource options query diff --git a/src/Route.elm b/src/Route.elm index 7d49714..2fd44e8 100644 --- a/src/Route.elm +++ b/src/Route.elm @@ -15,8 +15,8 @@ import Url.Parser.Query type Route = NotFound | Home - | Packages (Maybe String) (Maybe String) (Maybe Int) (Maybe Int) - | Options (Maybe String) (Maybe String) (Maybe Int) (Maybe Int) + | Packages (Maybe String) (Maybe String) (Maybe String) (Maybe Int) (Maybe Int) + | Options (Maybe String) (Maybe String) (Maybe String) (Maybe Int) (Maybe Int) parser : Url.Parser.Parser (Route -> msg) msg @@ -31,6 +31,7 @@ parser = , Url.Parser.map Packages (Url.Parser.s "packages" + Url.Parser.Query.string "channel" Url.Parser.Query.string "query" Url.Parser.Query.string "showDetailsFor" Url.Parser.Query.int "from" @@ -39,6 +40,7 @@ parser = , Url.Parser.map Options (Url.Parser.s "options" + Url.Parser.Query.string "channel" Url.Parser.Query.string "query" Url.Parser.Query.string "showDetailsFor" Url.Parser.Query.int "from" @@ -92,18 +94,20 @@ routeToPieces page = NotFound -> ( [ "not-found" ], [] ) - Packages query showDetailsFor from size -> + Packages channel query showDetailsFor from size -> ( [ "packages" ] - , [ query + , [ channel + , query , showDetailsFor , Maybe.map String.fromInt from , Maybe.map String.fromInt size ] ) - Options query showDetailsFor from size -> + Options channel query showDetailsFor from size -> ( [ "options" ] - , [ query + , [ channel + , query , showDetailsFor , Maybe.map String.fromInt from , Maybe.map String.fromInt size diff --git a/src/index.scss b/src/index.scss index 9d18229..4a5fba6 100644 --- a/src/index.scss +++ b/src/index.scss @@ -18,11 +18,15 @@ header .navbar { .input-append input { font-size: 24px; height: 40px; + width: 10em; } .input-append button { font-size: 24px; height: 50px; } + select { + width: 100px; + } } .search-result { tbody > tr {