Commit cc64f2a814802abe9ae3bb8297079b643c8774df
1 parent
0a160399
Exists in
master
and in
4 other branches
Common filtering for dashboard and group. Share partial search result partial
Showing
11 changed files
with
214 additions
and
207 deletions
Show diff stats
... | ... | @@ -0,0 +1,31 @@ |
1 | +class FilterContext | |
2 | + attr_accessor :items, :params | |
3 | + | |
4 | + def initialize(items, params) | |
5 | + @items = items | |
6 | + @params = params | |
7 | + end | |
8 | + | |
9 | + def execute | |
10 | + apply_filter(items) | |
11 | + end | |
12 | + | |
13 | + def apply_filter items | |
14 | + if params[:project_id] | |
15 | + items = items.where(project_id: params[:project_id]) | |
16 | + end | |
17 | + | |
18 | + if params[:search].present? | |
19 | + items = items.search(params[:search]) | |
20 | + end | |
21 | + | |
22 | + case params[:status] | |
23 | + when 'closed' | |
24 | + items.closed | |
25 | + when 'all' | |
26 | + items | |
27 | + else | |
28 | + items.opened | |
29 | + end | |
30 | + end | |
31 | +end | ... | ... |
app/controllers/dashboard_controller.rb
... | ... | @@ -36,14 +36,14 @@ class DashboardController < ApplicationController |
36 | 36 | # Get authored or assigned open merge requests |
37 | 37 | def merge_requests |
38 | 38 | @merge_requests = current_user.cared_merge_requests |
39 | - @merge_requests = dashboard_filter(@merge_requests) | |
39 | + @merge_requests = FilterContext.new(@merge_requests, params).execute | |
40 | 40 | @merge_requests = @merge_requests.recent.page(params[:page]).per(20) |
41 | 41 | end |
42 | 42 | |
43 | 43 | # Get only assigned issues |
44 | 44 | def issues |
45 | 45 | @issues = current_user.assigned_issues |
46 | - @issues = dashboard_filter(@issues) | |
46 | + @issues = FilterContext.new(@issues, params).execute | |
47 | 47 | @issues = @issues.recent.page(params[:page]).per(20) |
48 | 48 | @issues = @issues.includes(:author, :project) |
49 | 49 | |
... | ... | @@ -62,23 +62,4 @@ class DashboardController < ApplicationController |
62 | 62 | def event_filter |
63 | 63 | @event_filter ||= EventFilter.new(params[:event_filter]) |
64 | 64 | end |
65 | - | |
66 | - def dashboard_filter items | |
67 | - if params[:project_id] | |
68 | - items = items.where(project_id: params[:project_id]) | |
69 | - end | |
70 | - | |
71 | - if params[:search].present? | |
72 | - items = items.search(params[:search]) | |
73 | - end | |
74 | - | |
75 | - case params[:status] | |
76 | - when 'closed' | |
77 | - items.closed | |
78 | - when 'all' | |
79 | - items | |
80 | - else | |
81 | - items.opened | |
82 | - end | |
83 | - end | |
84 | 65 | end | ... | ... |
app/controllers/groups_controller.rb
... | ... | @@ -21,15 +21,16 @@ class GroupsController < ApplicationController |
21 | 21 | |
22 | 22 | # Get authored or assigned open merge requests |
23 | 23 | def merge_requests |
24 | - @merge_requests = current_user.cared_merge_requests.opened | |
25 | - @merge_requests = @merge_requests.of_group(@group).recent.page(params[:page]).per(20) | |
24 | + @merge_requests = current_user.cared_merge_requests.of_group(@group) | |
25 | + @merge_requests = FilterContext.new(@merge_requests, params).execute | |
26 | + @merge_requests = @merge_requests.recent.page(params[:page]).per(20) | |
26 | 27 | end |
27 | 28 | |
28 | 29 | # Get only assigned issues |
29 | 30 | def issues |
30 | - @user = current_user | |
31 | - @issues = current_user.assigned_issues.opened | |
32 | - @issues = @issues.of_group(@group).recent.page(params[:page]).per(20) | |
31 | + @issues = current_user.assigned_issues.of_group(@group) | |
32 | + @issues = FilterContext.new(@issues, params).execute | |
33 | + @issues = @issues.recent.page(params[:page]).per(20) | |
33 | 34 | @issues = @issues.includes(:author, :project) |
34 | 35 | |
35 | 36 | respond_to do |format| |
... | ... | @@ -44,6 +45,7 @@ class GroupsController < ApplicationController |
44 | 45 | @projects = result[:projects] |
45 | 46 | @merge_requests = result[:merge_requests] |
46 | 47 | @issues = result[:issues] |
48 | + @wiki_pages = result[:wiki_pages] | |
47 | 49 | end |
48 | 50 | |
49 | 51 | def people | ... | ... |
... | ... | @@ -0,0 +1,17 @@ |
1 | +module GroupsHelper | |
2 | + def group_filter_path(entity, options={}) | |
3 | + exist_opts = { | |
4 | + status: params[:status], | |
5 | + project_id: params[:project_id], | |
6 | + } | |
7 | + | |
8 | + options = exist_opts.merge(options) | |
9 | + | |
10 | + case entity | |
11 | + when 'issue' then | |
12 | + issues_group_path(@group, options) | |
13 | + when 'merge_request' | |
14 | + merge_requests_group_path(@group, options) | |
15 | + end | |
16 | + end | |
17 | +end | ... | ... |
... | ... | @@ -0,0 +1,33 @@ |
1 | += form_tag group_filter_path(entity), method: 'get' do | |
2 | + %fieldset.dashboard-search-filter | |
3 | + = search_field_tag "search", params[:search], { placeholder: 'Search', class: 'search-text-input' } | |
4 | + = button_tag type: 'submit', class: 'btn' do | |
5 | + %i.icon-search | |
6 | + | |
7 | + %fieldset | |
8 | + %legend Status: | |
9 | + %ul.nav.nav-pills.nav-stacked | |
10 | + %li{class: ("active" if !params[:status])} | |
11 | + = link_to group_filter_path(entity, status: nil) do | |
12 | + Open | |
13 | + %li{class: ("active" if params[:status] == 'closed')} | |
14 | + = link_to group_filter_path(entity, status: 'closed') do | |
15 | + Closed | |
16 | + %li{class: ("active" if params[:status] == 'all')} | |
17 | + = link_to group_filter_path(entity, status: 'all') do | |
18 | + All | |
19 | + | |
20 | + %fieldset | |
21 | + %legend Projects: | |
22 | + %ul.nav.nav-pills.nav-stacked | |
23 | + - @projects.each do |project| | |
24 | + - unless entities_per_project(project, entity).zero? | |
25 | + %li{class: ("active" if params[:project_id] == project.id.to_s)} | |
26 | + = link_to group_filter_path(entity, project_id: project.id) do | |
27 | + = project.name_with_namespace | |
28 | + %small.right= entities_per_project(project, entity) | |
29 | + | |
30 | + %fieldset | |
31 | + %hr | |
32 | + = link_to "Reset", group_filter_path(entity), class: 'btn right' | |
33 | + | ... | ... |
app/views/groups/issues.html.haml
... | ... | @@ -3,18 +3,21 @@ |
3 | 3 | %small (assigned to you) |
4 | 4 | %small.right #{@issues.total_count} issues |
5 | 5 | |
6 | -%br | |
7 | -.clearfix | |
8 | -- if @issues.any? | |
9 | - - @issues.group_by(&:project).each do |group| | |
10 | - %div.ui-box | |
11 | - - @project = group[0] | |
12 | - %h5.title | |
13 | - = @project.name | |
14 | - %ul.well-list.issues_table | |
15 | - - group[1].each do |issue| | |
16 | - = render(partial: 'issues/show', locals: {issue: issue}) | |
17 | - %hr | |
18 | - = paginate @issues, theme: "gitlab" | |
19 | -- else | |
20 | - %h3.nothing_here_message Nothing to show here | |
6 | +%hr | |
7 | +.row | |
8 | + .span3 | |
9 | + = render 'filter', entity: 'issue' | |
10 | + .span9 | |
11 | + - if @issues.any? | |
12 | + - @issues.group_by(&:project).each do |group| | |
13 | + %div.ui-box | |
14 | + - @project = group[0] | |
15 | + %h5.title | |
16 | + = link_to_project @project | |
17 | + %ul.well-list.issues_table | |
18 | + - group[1].each do |issue| | |
19 | + = render(partial: 'issues/show', locals: {issue: issue}) | |
20 | + %hr | |
21 | + = paginate @issues, theme: "gitlab" | |
22 | + - else | |
23 | + %p.nothing_here_message Nothing to show here | ... | ... |
app/views/groups/merge_requests.html.haml
... | ... | @@ -3,17 +3,22 @@ |
3 | 3 | %small (authored by or assigned to you) |
4 | 4 | %small.right #{@merge_requests.total_count} merge requests |
5 | 5 | |
6 | -%br | |
7 | -- if @merge_requests.any? | |
8 | - - @merge_requests.group_by(&:project).each do |group| | |
9 | - %ul.well-list.ui-box | |
10 | - - @project = group[0] | |
11 | - %h5.title | |
12 | - = @project.name | |
13 | - - group[1].each do |merge_request| | |
14 | - = render(partial: 'merge_requests/merge_request', locals: {merge_request: merge_request}) | |
15 | - %hr | |
16 | - = paginate @merge_requests, theme: "gitlab" | |
6 | +%hr | |
7 | +.row | |
8 | + .span3 | |
9 | + = render 'filter', entity: 'merge_request' | |
10 | + .span9 | |
11 | + - if @merge_requests.any? | |
12 | + - @merge_requests.group_by(&:project).each do |group| | |
13 | + .ui-box | |
14 | + - @project = group[0] | |
15 | + %h5.title | |
16 | + = link_to_project @project | |
17 | + %ul.well-list | |
18 | + - group[1].each do |merge_request| | |
19 | + = render(partial: 'merge_requests/merge_request', locals: {merge_request: merge_request}) | |
20 | + %hr | |
21 | + = paginate @merge_requests, theme: "gitlab" | |
17 | 22 | |
18 | -- else | |
19 | - %h3.nothing_here_message Nothing to show here | |
23 | + - else | |
24 | + %h3.nothing_here_message Nothing to show here | ... | ... |
app/views/groups/search.html.haml
... | ... | @@ -6,70 +6,4 @@ |
6 | 6 | = search_field_tag :search, params[:search], placeholder: "issue 143", class: "input-xxlarge search-text-input", id: "dashboard_search" |
7 | 7 | = submit_tag 'Search', class: "btn primary wide" |
8 | 8 | - if params[:search].present? |
9 | - %br | |
10 | - %h3 | |
11 | - Search results | |
12 | - %small (#{@projects.count + @merge_requests.count + @issues.count}) | |
13 | - %hr | |
14 | - .search_results | |
15 | - .row | |
16 | - .span6 | |
17 | - %table | |
18 | - %thead | |
19 | - %tr | |
20 | - %th Projects | |
21 | - %tbody | |
22 | - - @projects.each do |project| | |
23 | - %tr | |
24 | - %td | |
25 | - = link_to project do | |
26 | - %strong.term= project.name | |
27 | - %small.cgray | |
28 | - last activity at | |
29 | - = project.last_activity_date.stamp("Aug 25, 2011") | |
30 | - - if @projects.blank? | |
31 | - %tr | |
32 | - %td | |
33 | - %h4.nothing_here_message No Projects | |
34 | - %br | |
35 | - %table | |
36 | - %thead | |
37 | - %tr | |
38 | - %th Merge Requests | |
39 | - %tbody | |
40 | - - @merge_requests.each do |merge_request| | |
41 | - %tr | |
42 | - %td | |
43 | - = link_to [merge_request.project, merge_request] do | |
44 | - %span.badge.badge-info ##{merge_request.id} | |
45 | - – | |
46 | - %strong.term= truncate merge_request.title, length: 50 | |
47 | - %strong.right | |
48 | - %span.label= merge_request.project.name | |
49 | - - if @merge_requests.blank? | |
50 | - %tr | |
51 | - %td | |
52 | - %h4.nothing_here_message No Merge Requests | |
53 | - .span6 | |
54 | - %table | |
55 | - %thead | |
56 | - %tr | |
57 | - %th Issues | |
58 | - %tbody | |
59 | - - @issues.each do |issue| | |
60 | - %tr | |
61 | - %td | |
62 | - = link_to [issue.project, issue] do | |
63 | - %span.badge.badge-info ##{issue.id} | |
64 | - – | |
65 | - %strong.term= truncate issue.title, length: 40 | |
66 | - %strong.right | |
67 | - %span.label= issue.project.name | |
68 | - - if @issues.blank? | |
69 | - %tr | |
70 | - %td | |
71 | - %h4.nothing_here_message No Issues | |
72 | - :javascript | |
73 | - $(function() { | |
74 | - $(".search_results .term").highlight("#{params[:search]}"); | |
75 | - }) | |
9 | + = render 'search/result' | ... | ... |
app/views/groups/show.html.haml
... | ... | @@ -7,7 +7,7 @@ |
7 | 7 | %span.cgray Events and projects are filtered in scope of group |
8 | 8 | %hr |
9 | 9 | - if @events.any? |
10 | - .content_list= render @events | |
10 | + .content_list | |
11 | 11 | - else |
12 | 12 | %p.nothing_here_message Projects activity will be displayed here |
13 | 13 | .loading.hide |
... | ... | @@ -26,4 +26,4 @@ |
26 | 26 | = link_to "@gitlabhq", "https://twitter.com/gitlabhq" |
27 | 27 | |
28 | 28 | :javascript |
29 | - $(function(){ Pager.init(20); }); | |
29 | + $(function(){ Pager.init(20, true); }); | ... | ... |
app/views/search/_result.html.haml
1 | +%br | |
2 | +%h3.page_title | |
3 | + Search results | |
4 | + %span.cgray (#{@projects.count + @merge_requests.count + @issues.count + @wiki_pages.count}) | |
5 | +%hr | |
6 | +.search_results | |
7 | + .row | |
8 | + .span6 | |
9 | + %table | |
10 | + %thead | |
11 | + %tr | |
12 | + %th Projects | |
13 | + %tbody | |
14 | + - @projects.each do |project| | |
15 | + %tr | |
16 | + %td | |
17 | + = link_to project do | |
18 | + %strong.term= project.name_with_namespace | |
19 | + %small.cgray | |
20 | + last activity at | |
21 | + = project.last_activity_date.stamp("Aug 25, 2011") | |
22 | + - if @projects.blank? | |
23 | + %tr | |
24 | + %td | |
25 | + %h4.nothing_here_message No Projects | |
26 | + %br | |
27 | + %table | |
28 | + %thead | |
29 | + %tr | |
30 | + %th Merge Requests | |
31 | + %tbody | |
32 | + - @merge_requests.each do |merge_request| | |
33 | + %tr | |
34 | + %td | |
35 | + = link_to [merge_request.project, merge_request] do | |
36 | + %span.badge.badge-info ##{merge_request.id} | |
37 | + – | |
38 | + %strong.term= truncate merge_request.title, length: 50 | |
39 | + %strong.right | |
40 | + %span.label= merge_request.project.name | |
41 | + - if @merge_requests.blank? | |
42 | + %tr | |
43 | + %td | |
44 | + %h4.nothing_here_message No Merge Requests | |
45 | + .span6 | |
46 | + %table | |
47 | + %thead | |
48 | + %tr | |
49 | + %th Issues | |
50 | + %tbody | |
51 | + - @issues.each do |issue| | |
52 | + %tr | |
53 | + %td | |
54 | + = link_to [issue.project, issue] do | |
55 | + %span.badge.badge-info ##{issue.id} | |
56 | + – | |
57 | + %strong.term= truncate issue.title, length: 40 | |
58 | + %strong.right | |
59 | + %span.label= issue.project.name | |
60 | + - if @issues.blank? | |
61 | + %tr | |
62 | + %td | |
63 | + %h4.nothing_here_message No Issues | |
64 | + .span6 | |
65 | + %table | |
66 | + %thead | |
67 | + %tr | |
68 | + %th Wiki | |
69 | + %tbody | |
70 | + - @wiki_pages.each do |wiki_page| | |
71 | + %tr | |
72 | + %td | |
73 | + = link_to project_wiki_path(wiki_page.project, wiki_page) do | |
74 | + %strong.term= truncate wiki_page.title, length: 40 | |
75 | + %strong.right | |
76 | + %span.label= wiki_page.project.name | |
77 | + - if @wiki_pages.blank? | |
78 | + %tr | |
79 | + %td | |
80 | + %h4.nothing_here_message No wiki pages | |
81 | +:javascript | |
82 | + $(function() { | |
83 | + $(".search_results .term").highlight("#{escape_javascript(params[:search])}"); | |
84 | + }) | |
1 | 85 | ... | ... |
app/views/search/show.html.haml
... | ... | @@ -6,87 +6,4 @@ |
6 | 6 | = search_field_tag :search, params[:search], placeholder: "issue 143", class: "input-xxlarge search-text-input", id: "dashboard_search" |
7 | 7 | = submit_tag 'Search', class: "btn primary wide" |
8 | 8 | - if params[:search].present? |
9 | - %br | |
10 | - %h3 | |
11 | - Search results | |
12 | - %small (#{@projects.count + @merge_requests.count + @issues.count + @wiki_pages.count}) | |
13 | - %hr | |
14 | - .search_results | |
15 | - .row | |
16 | - .span6 | |
17 | - %table | |
18 | - %thead | |
19 | - %tr | |
20 | - %th Projects | |
21 | - %tbody | |
22 | - - @projects.each do |project| | |
23 | - %tr | |
24 | - %td | |
25 | - = link_to project do | |
26 | - %strong.term= project.name_with_namespace | |
27 | - %small.cgray | |
28 | - last activity at | |
29 | - = project.last_activity_date.stamp("Aug 25, 2011") | |
30 | - - if @projects.blank? | |
31 | - %tr | |
32 | - %td | |
33 | - %h4.nothing_here_message No Projects | |
34 | - %br | |
35 | - %table | |
36 | - %thead | |
37 | - %tr | |
38 | - %th Merge Requests | |
39 | - %tbody | |
40 | - - @merge_requests.each do |merge_request| | |
41 | - %tr | |
42 | - %td | |
43 | - = link_to [merge_request.project, merge_request] do | |
44 | - %span.badge.badge-info ##{merge_request.id} | |
45 | - – | |
46 | - %strong.term= truncate merge_request.title, length: 50 | |
47 | - %strong.right | |
48 | - %span.label= merge_request.project.name | |
49 | - - if @merge_requests.blank? | |
50 | - %tr | |
51 | - %td | |
52 | - %h4.nothing_here_message No Merge Requests | |
53 | - .span6 | |
54 | - %table | |
55 | - %thead | |
56 | - %tr | |
57 | - %th Issues | |
58 | - %tbody | |
59 | - - @issues.each do |issue| | |
60 | - %tr | |
61 | - %td | |
62 | - = link_to [issue.project, issue] do | |
63 | - %span.badge.badge-info ##{issue.id} | |
64 | - – | |
65 | - %strong.term= truncate issue.title, length: 40 | |
66 | - %strong.right | |
67 | - %span.label= issue.project.name | |
68 | - - if @issues.blank? | |
69 | - %tr | |
70 | - %td | |
71 | - %h4.nothing_here_message No Issues | |
72 | - .span6 | |
73 | - %table | |
74 | - %thead | |
75 | - %tr | |
76 | - %th Wiki | |
77 | - %tbody | |
78 | - - @wiki_pages.each do |wiki_page| | |
79 | - %tr | |
80 | - %td | |
81 | - = link_to project_wiki_path(wiki_page.project, wiki_page) do | |
82 | - %strong.term= truncate wiki_page.title, length: 40 | |
83 | - %strong.right | |
84 | - %span.label= wiki_page.project.name | |
85 | - - if @wiki_pages.blank? | |
86 | - %tr | |
87 | - %td | |
88 | - %h4.nothing_here_message No wiki pages | |
89 | - :javascript | |
90 | - $(function() { | |
91 | - $(".search_results .term").highlight("#{escape_javascript(params[:search])}"); | |
92 | - }) | |
9 | + = render 'search/result' | ... | ... |