diff options
| author | Teddy Wing | 2017-07-26 18:21:20 +0200 |
|---|---|---|
| committer | Teddy Wing | 2017-07-26 18:54:05 +0200 |
| commit | a096d387c33aa2499ca1703f5d85da865a5d5490 (patch) | |
| tree | 1751e8f99d2fd122212372e0772bd44735dfd211 /app/controllers/errors_controller.rb | |
| parent | 1a23188b58e9695a0df116c38f1c30d07b1e5501 (diff) | |
| download | chouette-core-a096d387c33aa2499ca1703f5d85da865a5d5490.tar.bz2 | |
RoutingConstraintZones#index: Fix sort in table
Sorting by stop point count and route name wasn't working. Only sorting
by name worked.
This was because these HTML table columns get their data from methods on
the `RoutingConstraintZone` model (`#stop_points_count` and
`#route_name`). Those methods can't be sorted on in the database.
Furthermore, when setting up the order ActiveRecord call, only database
column names on `routing_constraint_zones` were taken into account. When
a `sort` parameter specified an identifier that wasn't a column name,
the `name` column would be used to sort the list.
In this change, we enable sorting by stop point count and by route name.
The SQL work for ordering comes from a couple of new scope methods
defined on the model. Xin explained that he had previously used scope
methods to enable exotic sorting of Referentials on the
Workbenches#show page. I couldn't think of a better way to deal with
these, and it seems like a reasonable thing to do here, so I went with
the same setup.
In `#sort_column`, tack on our custom sorting keys to the list of
accepted keys. This borrows the pattern used in other `#sort_column`
methods in other controllers. Ended up using "route" as the route name
sorting key because that's what gets passed from the frontend.
Eliminated the `if` condition in `#collection` that defaults to `name`
sorting because it was redundant. The `#sort_column` method already
defaults to sorting by name if no `params[:sort]` is passed in. This
makes the method a lot cleaner, nice.
Add a new private method `#sort_collection` that determines what method
to call to sort the query. When using real table column names, it calls
`#order` like before. But now, if the user asked to sort by stop point
count or route name, we delegate instead to our scope methods,
`#order_by_stop_points_count` and `#order_by_route_name`.
Refs #4130
Diffstat (limited to 'app/controllers/errors_controller.rb')
0 files changed, 0 insertions, 0 deletions
