Commit e0df75de3fbe640528e2b327a387e4ebce442055
1 parent
7f368753
Exists in
master
and in
4 other branches
refactor Issues.js. Remove unused actions. Respect filters while searching for issue
Showing
7 changed files
with
80 additions
and
109 deletions
Show diff stats
app/assets/javascripts/issues.js
@@ -1,80 +0,0 @@ | @@ -1,80 +0,0 @@ | ||
1 | -function initIssuesSearch() { | ||
2 | - var href = $('#issue_search_form').attr('action'); | ||
3 | - var last_terms = ''; | ||
4 | - | ||
5 | - $('#issue_search').keyup(function() { | ||
6 | - var terms = $(this).val(); | ||
7 | - var milestone_id = $('#milestone_id').val(); | ||
8 | - var status = $('#status').val(); | ||
9 | - | ||
10 | - if (terms != last_terms) { | ||
11 | - last_terms = terms; | ||
12 | - | ||
13 | - if (terms.length >= 2 || terms.length == 0) { | ||
14 | - $.get(href, { 'status': status, 'terms': terms, 'milestone_id': milestone_id }, function(response) { | ||
15 | - $('.issues-holder').html(response); | ||
16 | - }); | ||
17 | - } | ||
18 | - } | ||
19 | - }); | ||
20 | -} | ||
21 | - | ||
22 | -/** | ||
23 | - * Init issues page | ||
24 | - * | ||
25 | - */ | ||
26 | -function issuesPage(){ | ||
27 | - initIssuesSearch(); | ||
28 | - $("#update_status").chosen(); | ||
29 | - $("#update_assignee_id").chosen(); | ||
30 | - $("#update_milestone_id").chosen(); | ||
31 | - | ||
32 | - $("#label_name").chosen(); | ||
33 | - $("#assignee_id").chosen(); | ||
34 | - $("#milestone_id").chosen(); | ||
35 | - $("#milestone_id, #assignee_id, #label_name").on("change", function(){ | ||
36 | - $(this).closest("form").submit(); | ||
37 | - }); | ||
38 | - | ||
39 | - $('body').on('ajax:success', '.close_issue, .reopen_issue', function(){ | ||
40 | - var t = $(this), | ||
41 | - totalIssues, | ||
42 | - reopen = t.hasClass('reopen_issue'); | ||
43 | - $('.issue_counter').each(function(){ | ||
44 | - var issue = $(this); | ||
45 | - totalIssues = parseInt( $(this).html(), 10 ); | ||
46 | - | ||
47 | - if( reopen && issue.closest('.main_menu').length ){ | ||
48 | - $(this).html( totalIssues+1 ); | ||
49 | - }else { | ||
50 | - $(this).html( totalIssues-1 ); | ||
51 | - } | ||
52 | - }); | ||
53 | - | ||
54 | - }); | ||
55 | - | ||
56 | - $(".check_all_issues").click(function () { | ||
57 | - $('.selected_issue').attr('checked', this.checked); | ||
58 | - issuesCheckChanged(); | ||
59 | - }); | ||
60 | - | ||
61 | - $('.selected_issue').bind('change', issuesCheckChanged); | ||
62 | -} | ||
63 | - | ||
64 | -function issuesCheckChanged() { | ||
65 | - var checked_issues = $('.selected_issue:checked'); | ||
66 | - | ||
67 | - if(checked_issues.length > 0) { | ||
68 | - var ids = [] | ||
69 | - $.each(checked_issues, function(index, value) { | ||
70 | - ids.push($(value).attr("data-id")); | ||
71 | - }) | ||
72 | - $('#update_issues_ids').val(ids); | ||
73 | - $('.issues_filters').hide(); | ||
74 | - $('.issues_bulk_update').show(); | ||
75 | - } else { | ||
76 | - $('#update_issues_ids').val([]); | ||
77 | - $('.issues_bulk_update').hide(); | ||
78 | - $('.issues_filters').show(); | ||
79 | - } | ||
80 | -} |
@@ -0,0 +1,69 @@ | @@ -0,0 +1,69 @@ | ||
1 | +@Issues = | ||
2 | + init: -> | ||
3 | + Issues.initSearch() | ||
4 | + Issues.initSelects() | ||
5 | + | ||
6 | + $("body").on "ajax:success", ".close_issue, .reopen_issue", -> | ||
7 | + t = $(this) | ||
8 | + totalIssues = undefined | ||
9 | + reopen = t.hasClass("reopen_issue") | ||
10 | + $(".issue_counter").each -> | ||
11 | + issue = $(this) | ||
12 | + totalIssues = parseInt($(this).html(), 10) | ||
13 | + if reopen and issue.closest(".main_menu").length | ||
14 | + $(this).html totalIssues + 1 | ||
15 | + else | ||
16 | + $(this).html totalIssues - 1 | ||
17 | + | ||
18 | + | ||
19 | + reload: -> | ||
20 | + Issues.initSelects() | ||
21 | + Issues.initChecks() | ||
22 | + $('#filter_issue_search').val($('#issue_search').val()) | ||
23 | + | ||
24 | + initSelects: -> | ||
25 | + $("#update_status").chosen() | ||
26 | + $("#update_assignee_id").chosen() | ||
27 | + $("#update_milestone_id").chosen() | ||
28 | + $("#label_name").chosen() | ||
29 | + $("#assignee_id").chosen() | ||
30 | + $("#milestone_id").chosen() | ||
31 | + $("#milestone_id, #assignee_id, #label_name").on "change", -> | ||
32 | + $(this).closest("form").submit() | ||
33 | + | ||
34 | + initChecks: -> | ||
35 | + $(".check_all_issues").click -> | ||
36 | + $(".selected_issue").attr "checked", @checked | ||
37 | + Issues.checkChanged() | ||
38 | + | ||
39 | + $(".selected_issue").bind "change", Issues.checkChanged | ||
40 | + | ||
41 | + | ||
42 | + initSearch: -> | ||
43 | + form = $("#issue_search_form") | ||
44 | + last_terms = "" | ||
45 | + $("#issue_search").keyup -> | ||
46 | + terms = $(this).val() | ||
47 | + unless terms is last_terms | ||
48 | + last_terms = terms | ||
49 | + if terms.length >= 2 or terms.length is 0 | ||
50 | + $('#search_status').val($('#status').val()) | ||
51 | + $('#search_assignee_id').val($('#assignee_id').val()) | ||
52 | + $('#search_milestone_id').val($('#milestone_id').val()) | ||
53 | + $('#search_label_name').val($('#label_name').val()) | ||
54 | + form.submit() | ||
55 | + | ||
56 | + checkChanged: -> | ||
57 | + checked_issues = $(".selected_issue:checked") | ||
58 | + if checked_issues.length > 0 | ||
59 | + ids = [] | ||
60 | + $.each checked_issues, (index, value) -> | ||
61 | + ids.push $(value).attr("data-id") | ||
62 | + | ||
63 | + $("#update_issues_ids").val ids | ||
64 | + $(".issues_filters").hide() | ||
65 | + $(".issues_bulk_update").show() | ||
66 | + else | ||
67 | + $("#update_issues_ids").val [] | ||
68 | + $(".issues_bulk_update").hide() | ||
69 | + $(".issues_filters").show() |
app/controllers/issues_controller.rb
@@ -14,7 +14,10 @@ class IssuesController < ProjectResourceController | @@ -14,7 +14,10 @@ class IssuesController < ProjectResourceController | ||
14 | respond_to :js, :html | 14 | respond_to :js, :html |
15 | 15 | ||
16 | def index | 16 | def index |
17 | + terms = params['issue_search'] | ||
18 | + | ||
17 | @issues = issues_filtered | 19 | @issues = issues_filtered |
20 | + @issues = @issues.where("title LIKE ?", "%#{terms}%") if terms.present? | ||
18 | @issues = @issues.page(params[:page]).per(20) | 21 | @issues = @issues.page(params[:page]).per(20) |
19 | 22 | ||
20 | respond_to do |format| | 23 | respond_to do |format| |
@@ -76,28 +79,6 @@ class IssuesController < ProjectResourceController | @@ -76,28 +79,6 @@ class IssuesController < ProjectResourceController | ||
76 | end | 79 | end |
77 | end | 80 | end |
78 | 81 | ||
79 | - def sort | ||
80 | - return render_404 unless can?(current_user, :admin_issue, @project) | ||
81 | - | ||
82 | - @issues = @project.issues.where(id: params['issue']) | ||
83 | - @issues.each do |issue| | ||
84 | - issue.position = params['issue'].index(issue.id.to_s) + 1 | ||
85 | - issue.save | ||
86 | - end | ||
87 | - | ||
88 | - render nothing: true | ||
89 | - end | ||
90 | - | ||
91 | - def search | ||
92 | - terms = params['terms'] | ||
93 | - | ||
94 | - @issues = issues_filtered | ||
95 | - @issues = @issues.where("title LIKE ?", "%#{terms}%") unless terms.blank? | ||
96 | - @issues = @issues.page(params[:page]).per(100) | ||
97 | - | ||
98 | - render partial: 'issues' | ||
99 | - end | ||
100 | - | ||
101 | def bulk_update | 82 | def bulk_update |
102 | result = IssuesBulkUpdateContext.new(project, current_user, params).execute | 83 | result = IssuesBulkUpdateContext.new(project, current_user, params).execute |
103 | redirect_to :back, notice: "#{result[:count]} issues updated" | 84 | redirect_to :back, notice: "#{result[:count]} issues updated" |
app/views/issues/_issues.html.haml
@@ -18,6 +18,7 @@ | @@ -18,6 +18,7 @@ | ||
18 | = select_tag(:assignee_id, options_from_collection_for_select([unassigned_filter] + @project.users.all, "id", "name", params[:assignee_id]), prompt: "Assignee") | 18 | = select_tag(:assignee_id, options_from_collection_for_select([unassigned_filter] + @project.users.all, "id", "name", params[:assignee_id]), prompt: "Assignee") |
19 | = select_tag(:milestone_id, options_from_collection_for_select([unassigned_filter] + issues_active_milestones, "id", "title", params[:milestone_id]), prompt: "Milestone") | 19 | = select_tag(:milestone_id, options_from_collection_for_select([unassigned_filter] + issues_active_milestones, "id", "title", params[:milestone_id]), prompt: "Milestone") |
20 | = hidden_field_tag :status, params[:status] | 20 | = hidden_field_tag :status, params[:status] |
21 | + = hidden_field_tag :issue_search, params[:status], id: 'filter_issue_search' | ||
21 | 22 | ||
22 | %ul.well-list.issues-list | 23 | %ul.well-list.issues-list |
23 | = render @issues | 24 | = render @issues |
app/views/issues/index.html.haml
@@ -9,9 +9,11 @@ | @@ -9,9 +9,11 @@ | ||
9 | = link_to new_project_issue_path(@project, issue: { assignee_id: params[:assignee_id], milestone_id: params[:milestone_id]}), class: "btn btn-primary pull-right", title: "New Issue", id: "new_issue_link" do | 9 | = link_to new_project_issue_path(@project, issue: { assignee_id: params[:assignee_id], milestone_id: params[:milestone_id]}), class: "btn btn-primary pull-right", title: "New Issue", id: "new_issue_link" do |
10 | %i.icon-plus | 10 | %i.icon-plus |
11 | New Issue | 11 | New Issue |
12 | - = form_tag search_project_issues_path(@project), method: :get, remote: true, id: "issue_search_form", class: 'pull-right' do | ||
13 | - = hidden_field_tag :project_id, @project.id, { id: 'project_id' } | ||
14 | - = hidden_field_tag :status, params[:status] | 12 | + = form_tag project_issues_path(@project), method: :get, remote: true, id: "issue_search_form", class: 'pull-right' do |
13 | + = hidden_field_tag :status, params[:status], id: 'search_status' | ||
14 | + = hidden_field_tag :assignee_id, params[:assignee_id], id: 'search_assignee_id' | ||
15 | + = hidden_field_tag :milestone_id, params[:milestone_id], id: 'search_milestone_id' | ||
16 | + = hidden_field_tag :label_name, params[:label_name], id: 'search_label_name' | ||
15 | = search_field_tag :issue_search, nil, { placeholder: 'Search', class: 'issue_search input-xlarge append-right-10 search-text-input' } | 17 | = search_field_tag :issue_search, nil, { placeholder: 'Search', class: 'issue_search input-xlarge append-right-10 search-text-input' } |
16 | 18 | ||
17 | .clearfix | 19 | .clearfix |
@@ -24,5 +26,5 @@ | @@ -24,5 +26,5 @@ | ||
24 | 26 | ||
25 | :javascript | 27 | :javascript |
26 | $(function(){ | 28 | $(function(){ |
27 | - issuesPage(); | 29 | + Issues.init(); |
28 | }) | 30 | }) |
app/views/issues/index.js.haml
1 | :plain | 1 | :plain |
2 | $('.issues-holder').html("#{escape_javascript(render('issues'))}"); | 2 | $('.issues-holder').html("#{escape_javascript(render('issues'))}"); |
3 | History.replaceState({path: "#{request.url}"}, document.title, "#{request.url}"); | 3 | History.replaceState({path: "#{request.url}"}, document.title, "#{request.url}"); |
4 | - issuesPage(); | 4 | + Issues.reload(); |
config/routes.rb
@@ -266,9 +266,7 @@ Gitlab::Application.routes.draw do | @@ -266,9 +266,7 @@ Gitlab::Application.routes.draw do | ||
266 | resources :labels, only: [:index] | 266 | resources :labels, only: [:index] |
267 | resources :issues, except: [:destroy] do | 267 | resources :issues, except: [:destroy] do |
268 | collection do | 268 | collection do |
269 | - post :sort | ||
270 | post :bulk_update | 269 | post :bulk_update |
271 | - get :search | ||
272 | end | 270 | end |
273 | end | 271 | end |
274 | 272 |