channel drowdown (#21)
This commit is contained in:
parent
c47f1c0ccb
commit
ce2121e30e
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue