Commit e0df75de authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

refactor Issues.js. Remove unused actions. Respect filters while searching for issue

parent 7f368753
function initIssuesSearch() {
var href = $('#issue_search_form').attr('action');
var last_terms = '';
$('#issue_search').keyup(function() {
var terms = $(this).val();
var milestone_id = $('#milestone_id').val();
var status = $('#status').val();
if (terms != last_terms) {
last_terms = terms;
if (terms.length >= 2 || terms.length == 0) {
$.get(href, { 'status': status, 'terms': terms, 'milestone_id': milestone_id }, function(response) {
$('.issues-holder').html(response);
});
}
}
});
}
/**
* Init issues page
*
*/
function issuesPage(){
initIssuesSearch();
$("#update_status").chosen();
$("#update_assignee_id").chosen();
$("#update_milestone_id").chosen();
$("#label_name").chosen();
$("#assignee_id").chosen();
$("#milestone_id").chosen();
$("#milestone_id, #assignee_id, #label_name").on("change", function(){
$(this).closest("form").submit();
});
$('body').on('ajax:success', '.close_issue, .reopen_issue', function(){
var t = $(this),
totalIssues,
reopen = t.hasClass('reopen_issue');
$('.issue_counter').each(function(){
var issue = $(this);
totalIssues = parseInt( $(this).html(), 10 );
if( reopen && issue.closest('.main_menu').length ){
$(this).html( totalIssues+1 );
}else {
$(this).html( totalIssues-1 );
}
});
});
$(".check_all_issues").click(function () {
$('.selected_issue').attr('checked', this.checked);
issuesCheckChanged();
});
$('.selected_issue').bind('change', issuesCheckChanged);
}
function issuesCheckChanged() {
var checked_issues = $('.selected_issue:checked');
if(checked_issues.length > 0) {
var ids = []
$.each(checked_issues, function(index, value) {
ids.push($(value).attr("data-id"));
})
$('#update_issues_ids').val(ids);
$('.issues_filters').hide();
$('.issues_bulk_update').show();
} else {
$('#update_issues_ids').val([]);
$('.issues_bulk_update').hide();
$('.issues_filters').show();
}
}
@Issues =
init: ->
Issues.initSearch()
Issues.initSelects()
$("body").on "ajax:success", ".close_issue, .reopen_issue", ->
t = $(this)
totalIssues = undefined
reopen = t.hasClass("reopen_issue")
$(".issue_counter").each ->
issue = $(this)
totalIssues = parseInt($(this).html(), 10)
if reopen and issue.closest(".main_menu").length
$(this).html totalIssues + 1
else
$(this).html totalIssues - 1
reload: ->
Issues.initSelects()
Issues.initChecks()
$('#filter_issue_search').val($('#issue_search').val())
initSelects: ->
$("#update_status").chosen()
$("#update_assignee_id").chosen()
$("#update_milestone_id").chosen()
$("#label_name").chosen()
$("#assignee_id").chosen()
$("#milestone_id").chosen()
$("#milestone_id, #assignee_id, #label_name").on "change", ->
$(this).closest("form").submit()
initChecks: ->
$(".check_all_issues").click ->
$(".selected_issue").attr "checked", @checked
Issues.checkChanged()
$(".selected_issue").bind "change", Issues.checkChanged
initSearch: ->
form = $("#issue_search_form")
last_terms = ""
$("#issue_search").keyup ->
terms = $(this).val()
unless terms is last_terms
last_terms = terms
if terms.length >= 2 or terms.length is 0
$('#search_status').val($('#status').val())
$('#search_assignee_id').val($('#assignee_id').val())
$('#search_milestone_id').val($('#milestone_id').val())
$('#search_label_name').val($('#label_name').val())
form.submit()
checkChanged: ->
checked_issues = $(".selected_issue:checked")
if checked_issues.length > 0
ids = []
$.each checked_issues, (index, value) ->
ids.push $(value).attr("data-id")
$("#update_issues_ids").val ids
$(".issues_filters").hide()
$(".issues_bulk_update").show()
else
$("#update_issues_ids").val []
$(".issues_bulk_update").hide()
$(".issues_filters").show()
......@@ -14,7 +14,10 @@ class IssuesController < ProjectResourceController
respond_to :js, :html
def index
terms = params['issue_search']
@issues = issues_filtered
@issues = @issues.where("title LIKE ?", "%#{terms}%") if terms.present?
@issues = @issues.page(params[:page]).per(20)
respond_to do |format|
......@@ -76,28 +79,6 @@ class IssuesController < ProjectResourceController
end
end
def sort
return render_404 unless can?(current_user, :admin_issue, @project)
@issues = @project.issues.where(id: params['issue'])
@issues.each do |issue|
issue.position = params['issue'].index(issue.id.to_s) + 1
issue.save
end
render nothing: true
end
def search
terms = params['terms']
@issues = issues_filtered
@issues = @issues.where("title LIKE ?", "%#{terms}%") unless terms.blank?
@issues = @issues.page(params[:page]).per(100)
render partial: 'issues'
end
def bulk_update
result = IssuesBulkUpdateContext.new(project, current_user, params).execute
redirect_to :back, notice: "#{result[:count]} issues updated"
......
......@@ -18,6 +18,7 @@
= select_tag(:assignee_id, options_from_collection_for_select([unassigned_filter] + @project.users.all, "id", "name", params[:assignee_id]), prompt: "Assignee")
= select_tag(:milestone_id, options_from_collection_for_select([unassigned_filter] + issues_active_milestones, "id", "title", params[:milestone_id]), prompt: "Milestone")
= hidden_field_tag :status, params[:status]
= hidden_field_tag :issue_search, params[:status], id: 'filter_issue_search'
%ul.well-list.issues-list
= render @issues
......
......@@ -9,9 +9,11 @@
= 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
%i.icon-plus
New Issue
= form_tag search_project_issues_path(@project), method: :get, remote: true, id: "issue_search_form", class: 'pull-right' do
= hidden_field_tag :project_id, @project.id, { id: 'project_id' }
= hidden_field_tag :status, params[:status]
= form_tag project_issues_path(@project), method: :get, remote: true, id: "issue_search_form", class: 'pull-right' do
= hidden_field_tag :status, params[:status], id: 'search_status'
= hidden_field_tag :assignee_id, params[:assignee_id], id: 'search_assignee_id'
= hidden_field_tag :milestone_id, params[:milestone_id], id: 'search_milestone_id'
= hidden_field_tag :label_name, params[:label_name], id: 'search_label_name'
= search_field_tag :issue_search, nil, { placeholder: 'Search', class: 'issue_search input-xlarge append-right-10 search-text-input' }
.clearfix
......@@ -24,5 +26,5 @@
:javascript
$(function(){
issuesPage();
Issues.init();
})
:plain
$('.issues-holder').html("#{escape_javascript(render('issues'))}");
History.replaceState({path: "#{request.url}"}, document.title, "#{request.url}");
issuesPage();
Issues.reload();
......@@ -266,9 +266,7 @@ Gitlab::Application.routes.draw do
resources :labels, only: [:index]
resources :issues, except: [:destroy] do
collection do
post :sort
post :bulk_update
get :search
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment