Skip to content

Commit

Permalink
Merge pull request #1297 from Taz17/sort-by-date
Browse files Browse the repository at this point in the history
Added Sort by Date Edited feature to policies index page
  • Loading branch information
mlandauer authored Dec 15, 2021
2 parents 8d9918c + 8e3ed0e commit 0a54716
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/controllers/policies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ def index
case @sort
when "name"
@policies = @policies.order(:name)
when "date"
@policies = @policies.order("updated_at DESC")
else
@policies = @policies.left_joins(:watches).group(:id).order("COUNT(watches.id) DESC")
@sort = nil
Expand Down
4 changes: 4 additions & 0 deletions app/views/policies/_policies_chooser.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
%button.btn.btn-sm.btn-default.dropdown-toggle{type: "button", id: "dropdownMenu1", data: {toggle: "dropdown"}}
- if @sort == "name"
Sorted by Name
- elsif @sort == "date"
Sorted by Date Edited
- elsif @sort.nil?
Sorted by Subscribers
%span.caret
Expand All @@ -12,3 +14,5 @@
= link_to "Name", {sort: "name"}, title: "Sort by name", role: "menuitem", tabindex: "-1"
%li{role: "presentation", class: "#{'disabled' if @sort.nil?}"}
= link_to "Subscribers", {sort: nil}, title: "Sort by subscribers", role: "menuitem", tabindex: "-1"
%li{role: "presentation", class: "#{'disabled' if @sort == 'date'}"}
= link_to "Date Edited", {sort: "date"}, title: "Sort by date edited", role: "menuitem", tabindex: "-1"
3 changes: 3 additions & 0 deletions spec/fixtures/static_pages/policies.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ <h1>Policies</h1>
<li class='disabled' role='presentation'>
<a title="Sort by subscribers" role="menuitem" tabindex="-1" href="/policies">Subscribers</a>
</li>
<li class='' role='presentation'>
<a title="Sort by date edited" role="menuitem" tabindex="-1" href="/policies?sort=date">Date Edited</a>
</li>
</ul>
</div>
</div>
Expand Down

0 comments on commit 0a54716

Please sign in to comment.