Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • C chouette-core
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 0
    • Issues 0
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 36
    • Merge requests 36
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Packages & Registries
    • Packages & Registries
    • Infrastructure Registry
  • Analytics
    • Analytics
    • CI/CD
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Administrator
  • chouette-core
  • Merge requests
  • !43

Merged
Created Jul 26, 2017 by Administrator@rootMaintainer

RoutingConstraintZones#index: Fix sort in table

  • Overview 0
  • Commits 1
  • Changes 2

Created by: teddywing

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

Assignee
Assign to
Reviewer
Request review from
None
Milestone
None
Assign milestone
Time tracking
Source branch: 4130-routing-constraint-zones-index--table-column-sort-no-longer-works--rb-201707261853