Skip to content

Commit

Permalink
Allow to show results alphabetically
Browse files Browse the repository at this point in the history
  • Loading branch information
garbas committed Jul 10, 2020
1 parent 71eba22 commit 5dfd71e
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 21 deletions.
9 changes: 5 additions & 4 deletions src/Main.elm
Expand Up @@ -127,6 +127,7 @@ submitQuery old ( new, cmd ) =
(Maybe.withDefault "" newModel.query)
newModel.from
newModel.size
newModel.sort
|> Cmd.map msg
]
)
Expand Down Expand Up @@ -183,7 +184,7 @@ changeRouteTo model url =
-- on the home page
( newModel, Browser.Navigation.pushUrl newModel.navKey "/packages" )

Just (Route.Packages channel query show from size) ->
Just (Route.Packages channel query show from size sort) ->
let
modelPage =
case newModel.page of
Expand All @@ -193,11 +194,11 @@ changeRouteTo model url =
_ ->
Nothing
in
Page.Packages.init channel query show from size modelPage
Page.Packages.init channel query show from size sort modelPage
|> updateWith Packages PackagesMsg newModel
|> submitQuery newModel

Just (Route.Options channel query show from size) ->
Just (Route.Options channel query show from size sort) ->
let
modelPage =
case newModel.page of
Expand All @@ -207,7 +208,7 @@ changeRouteTo model url =
_ ->
Nothing
in
Page.Options.init channel query show from size modelPage
Page.Options.init channel query show from size sort modelPage
|> updateWith Options OptionsMsg newModel
|> submitQuery newModel

Expand Down
10 changes: 6 additions & 4 deletions src/Page/Options.elm
Expand Up @@ -73,12 +73,13 @@ init :
-> Maybe String
-> Maybe Int
-> Maybe Int
-> Maybe String
-> Maybe Model
-> ( Model, Cmd Msg )
init channel query show from size model =
init channel query show from size sort model =
let
( newModel, newCmd ) =
Search.init channel query show from size model
Search.init channel query show from size sort model
in
( newModel
, Cmd.map SearchMsg newCmd
Expand Down Expand Up @@ -285,8 +286,9 @@ makeRequest :
-> String
-> Int
-> Int
-> Search.Sort
-> Cmd Msg
makeRequest options channel queryRaw from size =
makeRequest options channel queryRaw from size sort =
let
query =
queryRaw
Expand Down Expand Up @@ -402,7 +404,7 @@ makeRequest options channel queryRaw from size =
|> List.append (should_match 10)
in
Search.makeRequest
(Search.makeRequestBody query from size "option" "option_name_query" should_queries)
(Search.makeRequestBody query from size sort "option" "option_name" "option_name_query" should_queries)
("latest-" ++ String.fromInt options.mappingSchemaVersion ++ "-" ++ channel)
decodeResultItemSource
options
Expand Down
10 changes: 6 additions & 4 deletions src/Page/Packages.elm
Expand Up @@ -108,12 +108,13 @@ init :
-> Maybe String
-> Maybe Int
-> Maybe Int
-> Maybe String
-> Maybe Model
-> ( Model, Cmd Msg )
init channel query show from size model =
init channel query show from size sort model =
let
( newModel, newCmd ) =
Search.init channel query show from size model
Search.init channel query show from size sort model
in
( newModel
, Cmd.map SearchMsg newCmd
Expand Down Expand Up @@ -381,8 +382,9 @@ makeRequest :
-> String
-> Int
-> Int
-> Search.Sort
-> Cmd Msg
makeRequest options channel queryRaw from size =
makeRequest options channel queryRaw from size sort =
let
query =
queryRaw
Expand Down Expand Up @@ -504,7 +506,7 @@ makeRequest options channel queryRaw from size =
|> List.append (should_match 10)
in
Search.makeRequest
(Search.makeRequestBody query from size "package" "package_attr_name_query" should_queries)
(Search.makeRequestBody query from size sort "package" "package_attr_name" "package_attr_name_query" should_queries)
("latest-" ++ String.fromInt options.mappingSchemaVersion ++ "-" ++ channel)
decodeResultItemSource
options
Expand Down
12 changes: 8 additions & 4 deletions src/Route.elm
Expand Up @@ -15,8 +15,8 @@ import Url.Parser.Query
type Route
= NotFound
| Home
| Packages (Maybe String) (Maybe String) (Maybe String) (Maybe Int) (Maybe Int)
| Options (Maybe String) (Maybe String) (Maybe String) (Maybe Int) (Maybe Int)
| Packages (Maybe String) (Maybe String) (Maybe String) (Maybe Int) (Maybe Int) (Maybe String)
| Options (Maybe String) (Maybe String) (Maybe String) (Maybe Int) (Maybe Int) (Maybe String)


parser : Url.Parser.Parser (Route -> msg) msg
Expand All @@ -36,6 +36,7 @@ parser =
<?> Url.Parser.Query.string "show"
<?> Url.Parser.Query.int "from"
<?> Url.Parser.Query.int "size"
<?> Url.Parser.Query.string "sort"
)
, Url.Parser.map
Options
Expand All @@ -45,6 +46,7 @@ parser =
<?> Url.Parser.Query.string "show"
<?> Url.Parser.Query.int "from"
<?> Url.Parser.Query.int "size"
<?> Url.Parser.Query.string "sort"
)
]

Expand Down Expand Up @@ -94,22 +96,24 @@ routeToPieces page =
NotFound ->
( [ "not-found" ], [] )

Packages channel query show from size ->
Packages channel query show from size sort ->
( [ "packages" ]
, [ channel
, query
, show
, Maybe.map String.fromInt from
, Maybe.map String.fromInt size
, sort
]
)

Options channel query show from size ->
Options channel query show from size sort ->
( [ "options" ]
, [ channel
, query
, show
, Maybe.map String.fromInt from
, Maybe.map String.fromInt size
, sort
]
)

0 comments on commit 5dfd71e

Please sign in to comment.