From 1a1f5231ca2a4dee28951d5b1d886c45d01c1431 Mon Sep 17 00:00:00 2001 From: Taz17 Date: Wed, 15 Dec 2021 14:01:24 +1100 Subject: [PATCH 1/5] Added `Sort by Date Edited` in policy dropdown menu --- app/views/policies/_policies_chooser.html.haml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/views/policies/_policies_chooser.html.haml b/app/views/policies/_policies_chooser.html.haml index d402ec9e1..5969ad4fc 100644 --- a/app/views/policies/_policies_chooser.html.haml +++ b/app/views/policies/_policies_chooser.html.haml @@ -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 + - if @sort == "date" + Sorted by Date Edited - elsif @sort.nil? Sorted by Subscribers %span.caret @@ -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" \ No newline at end of file From ea1371efb0e10592e1e2e13c339bd85705236654 Mon Sep 17 00:00:00 2001 From: Taz17 Date: Wed, 15 Dec 2021 14:02:08 +1100 Subject: [PATCH 2/5] Updated policies controller to support for sorting on date edited --- app/controllers/policies_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/policies_controller.rb b/app/controllers/policies_controller.rb index d3dcac551..d69f497a9 100644 --- a/app/controllers/policies_controller.rb +++ b/app/controllers/policies_controller.rb @@ -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 From e764362a6d2fedb93dc9a1657327f930b26e0e6d Mon Sep 17 00:00:00 2001 From: Taz17 Date: Wed, 15 Dec 2021 14:07:04 +1100 Subject: [PATCH 3/5] Updated tests for new sorting changes --- spec/fixtures/static_pages/policies.html | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spec/fixtures/static_pages/policies.html b/spec/fixtures/static_pages/policies.html index f7ba8e7b7..49ef74705 100644 --- a/spec/fixtures/static_pages/policies.html +++ b/spec/fixtures/static_pages/policies.html @@ -82,6 +82,9 @@

Policies

+
  • +Date Edited +
  • From bfe5aecb1e21a3b359e0538000b305fc99f31cda Mon Sep 17 00:00:00 2001 From: Taz17 Date: Wed, 15 Dec 2021 14:43:34 +1100 Subject: [PATCH 4/5] changed if to elseif --- app/views/policies/_policies_chooser.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/policies/_policies_chooser.html.haml b/app/views/policies/_policies_chooser.html.haml index 5969ad4fc..3677dfe9c 100644 --- a/app/views/policies/_policies_chooser.html.haml +++ b/app/views/policies/_policies_chooser.html.haml @@ -3,7 +3,7 @@ %button.btn.btn-sm.btn-default.dropdown-toggle{type: "button", id: "dropdownMenu1", data: {toggle: "dropdown"}} - if @sort == "name" Sorted by Name - - if @sort == "date" + - elseif @sort == "date" Sorted by Date Edited - elsif @sort.nil? Sorted by Subscribers From 8e3ed0eec78437af3a76ca808fb5ff1f2c4ed978 Mon Sep 17 00:00:00 2001 From: Taz17 Date: Wed, 15 Dec 2021 14:44:48 +1100 Subject: [PATCH 5/5] fixed typo in elseif to elsif --- app/views/policies/_policies_chooser.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/policies/_policies_chooser.html.haml b/app/views/policies/_policies_chooser.html.haml index 3677dfe9c..a672c174a 100644 --- a/app/views/policies/_policies_chooser.html.haml +++ b/app/views/policies/_policies_chooser.html.haml @@ -3,7 +3,7 @@ %button.btn.btn-sm.btn-default.dropdown-toggle{type: "button", id: "dropdownMenu1", data: {toggle: "dropdown"}} - if @sort == "name" Sorted by Name - - elseif @sort == "date" + - elsif @sort == "date" Sorted by Date Edited - elsif @sort.nil? Sorted by Subscribers