Skip to content

Commit 1cb2b90

Browse files
committed
preserving sorting on problems index errbit#1067
Commit is a squash merge to master from mfrederickson:fix-1052-sorting since. The source branch became stale and required a conflict resolution. Thanks to @mfrederickson for the contribution.
1 parent fa6bd6c commit 1cb2b90

File tree

6 files changed

+10
-6
lines changed

6 files changed

+10
-6
lines changed

app/helpers/sort_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ def link_for_sort(name, field = nil)
55
current = (params_sort == field)
66
order = (current && (params_order == "asc")) ? "desc" : "asc"
77
url = request.path + "?sort=#{field}&order=#{order}"
8+
url += "&all_errs=true" if all_errs
89
options = {}
910
options.merge!(class: "current #{order}") if current
1011
link_to(name, url, options)

app/views/apps/show.html.haml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
- if current_user.admin?
1414
= link_to t('.edit'), edit_app_path(app), :class => 'button'
1515
- if all_errs
16-
= link_to t('.unresolved_errs'), app_path(app), :class => 'button'
16+
= link_to t('.unresolved_errs'), app_path(app, sort: params_sort, order: params_order), :class => 'button'
1717
- else
18-
= link_to t('.all_errs'), app_path(app, :all_errs => true), :class => 'button'
18+
= link_to t('.all_errs'), app_path(app, all_errs: true, sort: params_sort, order: params_order), :class => 'button'
1919

2020
- if app.watched_by?(current_user)
2121
= link_to t('.unwatch'), app_watcher_path(app_id: app, id: current_user.id), method: :delete, class: 'button'

app/views/problems/_search.html.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
= form_tag search_problems_path(:all_errs => all_errs, :app_id => app_id), :method => :get, :remote => true do
1+
= form_tag search_problems_path(:all_errs => all_errs, :app_id => app_id, :sort => params_sort, :order => params_order), :method => :get, :remote => true do
22
= text_field_tag :search, params[:search], :placeholder => t('.search_placeholder')

app/views/problems/index.html.haml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
- content_for :action_bar do
66
- if all_errs
7-
= link_to t('.hide_resolved'), problems_path, :class => 'button'
7+
= link_to t('.hide_resolved'), problems_path(sort: params_sort, order: params_order), :class => 'button'
88
- else
9-
= link_to t('.show_resolved'), problems_path(:all_errs => true), :class => 'button'
9+
= link_to t('.show_resolved'), problems_path(all_errs: true, sort: params_sort, order: params_order), :class => 'button'
1010

1111
%section
1212
= render 'problems/search', :all_errs => all_errs, :app_id => nil

spec/views/apps/show.html.haml_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
before do
1010
allow(view).to receive(:app).and_return(app)
1111
allow(view).to receive(:all_errs).and_return(false)
12+
allow(view).to receive(:params_order).and_return('asc')
13+
allow(view).to receive(:params_sort).and_return('latest_notice_at')
1214
allow(controller).to receive(:current_user).and_return(user)
1315
end
1416

spec/views/problems/index.html.haml_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
allow(view).to receive(:problems).and_return(
99
Kaminari.paginate_array([problem_1, problem_2]).page(1).per(10)
1010
)
11-
allow(view).to receive(:params_sort).and_return('asc')
11+
allow(view).to receive(:params_sort).and_return('last_notice_at')
12+
allow(view).to receive(:params_order).and_return('asc')
1213
allow(controller).to receive(:current_user).and_return(Fabricate(:user))
1314
end
1415

0 commit comments

Comments
 (0)