Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Sort by Date Edited feature to policies index page #1297

Merged
merged 6 commits into from
Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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