Navigation Menu

Skip to content

Commit

Permalink
channel drowdown
Browse files Browse the repository at this point in the history
  • Loading branch information
garbas committed May 11, 2020
1 parent c47f1c0 commit 5e0d9cb
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 21 deletions.
54 changes: 47 additions & 7 deletions src/ElasticSearch.elm
Expand Up @@ -24,8 +24,11 @@ import Html
, h1
, input
, li
, option
, p
, pre
, select
, span
, strong
, text
, ul
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -112,6 +118,7 @@ init query showDetailsFor from size =

type Msg a
= NoOp
| ChannelChange String
| QueryInput String
| QuerySubmit
| QueryResponse (RemoteData.WebData (Result a))
Expand All @@ -131,14 +138,21 @@ update path navKey msg model =
, Cmd.none
)

ChannelChange channel ->
( { model | channel = channel }
, Cmd.none
)

QueryInput query ->
( { model | query = Just query }
, Cmd.none
)

QuerySubmit ->
( model
, createUrl path
, createUrl
path
model.channel
model.query
model.showDetailsFor
0
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -290,6 +326,7 @@ viewPager outMsg model result path =
href <|
createUrl
path
model.channel
model.query
model.showDetailsFor
0
Expand All @@ -310,6 +347,7 @@ viewPager outMsg model result path =
else
createUrl
path
model.channel
model.query
model.showDetailsFor
(model.from - model.size)
Expand All @@ -330,6 +368,7 @@ viewPager outMsg model result path =
else
createUrl
path
model.channel
model.query
model.showDetailsFor
(model.from + model.size)
Expand All @@ -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)
Expand Down
9 changes: 5 additions & 4 deletions src/Main.elm
Expand Up @@ -116,6 +116,7 @@ submitQuery old ( new, cmd ) =
[ cmd
, makeRequest
new.elasticsearch
newModel.channel
(Maybe.withDefault "" newModel.query)
newModel.from
newModel.size
Expand Down Expand Up @@ -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

Expand Down
6 changes: 4 additions & 2 deletions src/Page/Options.elm
Expand Up @@ -65,6 +65,7 @@ type alias ResultItemSource =
init :
Maybe String
-> Maybe String
-> Maybe String
-> Maybe Int
-> Maybe Int
-> ( Model, Cmd Msg )
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/Page/Packages.elm
Expand Up @@ -81,6 +81,7 @@ type alias ResultPackageMaintainer =
init :
Maybe String
-> Maybe String
-> Maybe String
-> Maybe Int
-> Maybe Int
-> ( Model, Cmd Msg )
Expand Down Expand Up @@ -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
Expand Down
16 changes: 10 additions & 6 deletions src/Route.elm
Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/index.scss
Expand Up @@ -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 {
Expand Down

0 comments on commit 5e0d9cb

Please sign in to comment.