channel drowdown (#21)

This commit is contained in:
Rok Garbas 2020-05-11 22:42:57 +02:00 committed by GitHub
parent c47f1c0ccb
commit ce2121e30e
Failed to generate hash of commit
6 changed files with 74 additions and 21 deletions

View file

@ -24,8 +24,11 @@ import Html
, h1 , h1
, input , input
, li , li
, option
, p , p
, pre , select
, span
, strong
, text , text
, ul , ul
) )
@ -53,7 +56,8 @@ import Url.Builder
type alias Model a = type alias Model a =
{ query : Maybe String { channel : String
, query : Maybe String
, result : RemoteData.WebData (Result a) , result : RemoteData.WebData (Result a)
, showDetailsFor : Maybe String , showDetailsFor : Maybe String
, from : Int , from : Int
@ -90,11 +94,13 @@ type alias ResultItem a =
init : init :
Maybe String Maybe String
-> Maybe String -> Maybe String
-> Maybe String
-> Maybe Int -> Maybe Int
-> Maybe Int -> Maybe Int
-> ( Model a, Cmd msg ) -> ( Model a, Cmd msg )
init query showDetailsFor from size = init channel query showDetailsFor from size =
( { query = query ( { channel = Maybe.withDefault "unstable" channel
, query = query
, result = RemoteData.NotAsked , result = RemoteData.NotAsked
, showDetailsFor = showDetailsFor , showDetailsFor = showDetailsFor
, from = Maybe.withDefault 0 from , from = Maybe.withDefault 0 from
@ -112,6 +118,7 @@ init query showDetailsFor from size =
type Msg a type Msg a
= NoOp = NoOp
| ChannelChange String
| QueryInput String | QueryInput String
| QuerySubmit | QuerySubmit
| QueryResponse (RemoteData.WebData (Result a)) | QueryResponse (RemoteData.WebData (Result a))
@ -131,6 +138,11 @@ update path navKey msg model =
, Cmd.none , Cmd.none
) )
ChannelChange channel ->
( { model | channel = channel }
, Cmd.none
)
QueryInput query -> QueryInput query ->
( { model | query = Just query } ( { model | query = Just query }
, Cmd.none , Cmd.none
@ -138,7 +150,9 @@ update path navKey msg model =
QuerySubmit -> QuerySubmit ->
( model ( model
, createUrl path , createUrl
path
model.channel
model.query model.query
model.showDetailsFor model.showDetailsFor
0 0
@ -153,7 +167,9 @@ update path navKey msg model =
ShowDetails selected -> ShowDetails selected ->
( model ( model
, createUrl path , createUrl
path
model.channel
model.query model.query
(if model.showDetailsFor == Just selected then (if model.showDetailsFor == Just selected then
Nothing Nothing
@ -169,14 +185,16 @@ update path navKey msg model =
createUrl : createUrl :
String String
-> String
-> Maybe String -> Maybe String
-> Maybe String -> Maybe String
-> Int -> Int
-> Int -> Int
-> String -> String
createUrl path query showDetailsFor from size = createUrl path channel query showDetailsFor from size =
[ Url.Builder.int "from" from [ Url.Builder.int "from" from
, Url.Builder.int "size" size , Url.Builder.int "size" size
, Url.Builder.string "channel" channel
] ]
|> List.append |> List.append
(query (query
@ -225,6 +243,24 @@ view path title model viewSuccess outMsg =
[ button [ class "btn" ] [ text "Search" ] [ 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 , case model.result of
@ -290,6 +326,7 @@ viewPager outMsg model result path =
href <| href <|
createUrl createUrl
path path
model.channel
model.query model.query
model.showDetailsFor model.showDetailsFor
0 0
@ -310,6 +347,7 @@ viewPager outMsg model result path =
else else
createUrl createUrl
path path
model.channel
model.query model.query
model.showDetailsFor model.showDetailsFor
(model.from - model.size) (model.from - model.size)
@ -330,6 +368,7 @@ viewPager outMsg model result path =
else else
createUrl createUrl
path path
model.channel
model.query model.query
model.showDetailsFor model.showDetailsFor
(model.from + model.size) (model.from + model.size)
@ -350,6 +389,7 @@ viewPager outMsg model result path =
else else
createUrl createUrl
path path
model.channel
model.query model.query
model.showDetailsFor model.showDetailsFor
((result.hits.total.value // model.size) * model.size) ((result.hits.total.value // model.size) * model.size)

View file

@ -116,6 +116,7 @@ submitQuery old ( new, cmd ) =
[ cmd [ cmd
, makeRequest , makeRequest
new.elasticsearch new.elasticsearch
newModel.channel
(Maybe.withDefault "" newModel.query) (Maybe.withDefault "" newModel.query)
newModel.from newModel.from
newModel.size newModel.size
@ -172,13 +173,13 @@ changeRouteTo model url =
-- on the home page -- on the home page
( newModel, Browser.Navigation.pushUrl newModel.navKey "/packages" ) ( newModel, Browser.Navigation.pushUrl newModel.navKey "/packages" )
Just (Route.Packages query showDetailsFor from size) -> Just (Route.Packages channel query showDetailsFor from size) ->
Page.Packages.init query showDetailsFor from size Page.Packages.init channel query showDetailsFor from size
|> updateWith Packages PackagesMsg newModel |> updateWith Packages PackagesMsg newModel
|> submitQuery newModel |> submitQuery newModel
Just (Route.Options query showDetailsFor from size) -> Just (Route.Options channel query showDetailsFor from size) ->
Page.Options.init query showDetailsFor from size Page.Options.init channel query showDetailsFor from size
|> updateWith Options OptionsMsg newModel |> updateWith Options OptionsMsg newModel
|> submitQuery newModel |> submitQuery newModel

View file

@ -65,6 +65,7 @@ type alias ResultItemSource =
init : init :
Maybe String Maybe String
-> Maybe String -> Maybe String
-> Maybe String
-> Maybe Int -> Maybe Int
-> Maybe Int -> Maybe Int
-> ( Model, Cmd Msg ) -> ( Model, Cmd Msg )
@ -211,13 +212,14 @@ viewResultItemDetails item =
makeRequest : makeRequest :
ElasticSearch.Options ElasticSearch.Options
-> String -> String
-> String
-> Int -> Int
-> Int -> Int
-> Cmd Msg -> Cmd Msg
makeRequest options query from size = makeRequest options channel query from size =
ElasticSearch.makeRequest ElasticSearch.makeRequest
"option_name" "option_name"
"nixos-unstable-options" ("nixos-" ++ channel ++ "-options")
decodeResultItemSource decodeResultItemSource
options options
query query

View file

@ -81,6 +81,7 @@ type alias ResultPackageMaintainer =
init : init :
Maybe String Maybe String
-> Maybe String -> Maybe String
-> Maybe String
-> Maybe Int -> Maybe Int
-> Maybe Int -> Maybe Int
-> ( Model, Cmd Msg ) -> ( Model, Cmd Msg )
@ -279,13 +280,14 @@ viewResultItemDetails item =
makeRequest : makeRequest :
ElasticSearch.Options ElasticSearch.Options
-> String -> String
-> String
-> Int -> Int
-> Int -> Int
-> Cmd Msg -> Cmd Msg
makeRequest options query from size = makeRequest options channel query from size =
ElasticSearch.makeRequest ElasticSearch.makeRequest
"attr_name" "attr_name"
"nixos-unstable-packages" ("nixos-" ++ channel ++ "-packages")
decodeResultItemSource decodeResultItemSource
options options
query query

View file

@ -15,8 +15,8 @@ import Url.Parser.Query
type Route type Route
= NotFound = NotFound
| Home | Home
| Packages (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 Int) (Maybe Int) | Options (Maybe String) (Maybe String) (Maybe String) (Maybe Int) (Maybe Int)
parser : Url.Parser.Parser (Route -> msg) msg parser : Url.Parser.Parser (Route -> msg) msg
@ -31,6 +31,7 @@ parser =
, Url.Parser.map , Url.Parser.map
Packages Packages
(Url.Parser.s "packages" (Url.Parser.s "packages"
<?> Url.Parser.Query.string "channel"
<?> Url.Parser.Query.string "query" <?> Url.Parser.Query.string "query"
<?> Url.Parser.Query.string "showDetailsFor" <?> Url.Parser.Query.string "showDetailsFor"
<?> Url.Parser.Query.int "from" <?> Url.Parser.Query.int "from"
@ -39,6 +40,7 @@ parser =
, Url.Parser.map , Url.Parser.map
Options Options
(Url.Parser.s "options" (Url.Parser.s "options"
<?> Url.Parser.Query.string "channel"
<?> Url.Parser.Query.string "query" <?> Url.Parser.Query.string "query"
<?> Url.Parser.Query.string "showDetailsFor" <?> Url.Parser.Query.string "showDetailsFor"
<?> Url.Parser.Query.int "from" <?> Url.Parser.Query.int "from"
@ -92,18 +94,20 @@ routeToPieces page =
NotFound -> NotFound ->
( [ "not-found" ], [] ) ( [ "not-found" ], [] )
Packages query showDetailsFor from size -> Packages channel query showDetailsFor from size ->
( [ "packages" ] ( [ "packages" ]
, [ query , [ channel
, query
, showDetailsFor , showDetailsFor
, Maybe.map String.fromInt from , Maybe.map String.fromInt from
, Maybe.map String.fromInt size , Maybe.map String.fromInt size
] ]
) )
Options query showDetailsFor from size -> Options channel query showDetailsFor from size ->
( [ "options" ] ( [ "options" ]
, [ query , [ channel
, query
, showDetailsFor , showDetailsFor
, Maybe.map String.fromInt from , Maybe.map String.fromInt from
, Maybe.map String.fromInt size , Maybe.map String.fromInt size

View file

@ -18,11 +18,15 @@ header .navbar {
.input-append input { .input-append input {
font-size: 24px; font-size: 24px;
height: 40px; height: 40px;
width: 10em;
} }
.input-append button { .input-append button {
font-size: 24px; font-size: 24px;
height: 50px; height: 50px;
} }
select {
width: 100px;
}
} }
.search-result { .search-result {
tbody > tr { tbody > tr {