diff --git a/app/assets/javascripts/extra/tracker.js b/app/assets/javascripts/extra/tracker.js index 24aaf3f2f..dc084057e 100644 --- a/app/assets/javascripts/extra/tracker.js +++ b/app/assets/javascripts/extra/tracker.js @@ -50,7 +50,7 @@ $(document).ready(function() { return send_index_tracker_request('GET'); }); - $('#search_issue').live('submit', function() { + $('.ajax_search_form').live('submit', function() { return send_index_tracker_request('GET', $(this).attr("action"), $(this).serialize()); }); diff --git a/app/controllers/projects/issues_controller.rb b/app/controllers/projects/issues_controller.rb index dbf9e5841..594aed8cb 100644 --- a/app/controllers/projects/issues_controller.rb +++ b/app/controllers/projects/issues_controller.rb @@ -11,11 +11,11 @@ class Projects::IssuesController < Projects::BaseController def index(status = 200) @labels = params[:labels] || [] - @issues = @project.issues.includes(:pull_request).includes(:assignee, :user) + @issues = @project.issues.without_pull_requests @issues = @issues.where(:assignee_id => current_user.id) if @is_assigned_to_me = params[:filter] == 'to_me' @issues = @issues.joins(:labels).where(:labels => {:name => @labels}) unless @labels == [] # Using mb_chars for correct transform to lowercase ('Русский Текст'.downcase => "Русский Текст") - @issues = @issues.where('issues.title ILIKE ?', "%#{params[:search_issue].mb_chars.downcase}%") if params[:search_issue] + @issues = @issues.search(params[:search_issue]) @opened_issues, @closed_issues = @issues.not_closed_or_merged.count, @issues.closed_or_merged.count if params[:status] == 'closed' @@ -24,10 +24,10 @@ class Projects::IssuesController < Projects::BaseController @issues, @status = @issues.not_closed_or_merged, 'open' end - @issues = @issues.includes(:assignee, :user).order('issues.serial_id desc').uniq + @issues = @issues.includes(:assignee, :user, :pull_request).def_order.uniq .paginate :per_page => 10, :page => params[:page] if status == 200 - render 'index', :layout => request.xhr? ? 'issues' : 'application' + render 'index', :layout => request.xhr? ? 'with_sidebar' : 'application' else render :status => status, :nothing => true end diff --git a/app/controllers/projects/pull_requests_controller.rb b/app/controllers/projects/pull_requests_controller.rb index 67f13b809..e2015518d 100644 --- a/app/controllers/projects/pull_requests_controller.rb +++ b/app/controllers/projects/pull_requests_controller.rb @@ -89,22 +89,21 @@ class Projects::PullRequestsController < Projects::BaseController end def index(status = 200) - @pull_requests = @project.issues.joins(:pull_request).includes(:pull_request).includes(:assignee, :user) - @pull_requests = @pull_requests.where(:assignee_id => current_user.id) if @is_assigned_to_me = params[:filter] == 'to_me' - # Using mb_chars for correct transform to lowercase ('Русский Текст'.downcase => "Русский Текст") - @pull_requests = @pull_requests.where('issues.title ILIKE ?', "%#{params[:search_issue].mb_chars.downcase}%") if params[:search_issue] + @issues_with_pull_request = @project.issues.joins(:pull_request) + @issues_with_pull_request = @issues_with_pull_request.search(params[:search_pull_request]) - @opened_issues, @closed_issues = @pull_requests.not_closed_or_merged.count, @pull_requests.closed_or_merged.count + @opened_issues, @closed_issues = @issues_with_pull_request.not_closed_or_merged.count, @issues_with_pull_request.closed_or_merged.count if params[:status] == 'closed' - @pull_requests, @status = @pull_requests.closed_or_merged, params[:status] + @issues_with_pull_request, @status = @issues_with_pull_request.closed_or_merged, params[:status] else - @pull_requests, @status = @pull_requests.not_closed_or_merged, 'open' + @issues_with_pull_request, @status = @issues_with_pull_request.not_closed_or_merged, 'open' end - @pull_requests = @pull_requests.includes(:assignee, :user).order('issues.serial_id desc').uniq - .paginate :per_page => 10, :page => params[:page] + @issues_with_pull_request = @issues_with_pull_request. + includes(:assignee, :user, :pull_request).def_order.uniq. + paginate :per_page => 10, :page => params[:page] if status == 200 - render 'index', :layout => request.xhr? ? 'issues' : 'application' + render 'index', :layout => request.xhr? ? 'with_sidebar' : 'application' else render :status => status, :nothing => true end diff --git a/app/models/issue.rb b/app/models/issue.rb index 6a8eb33a3..3f40cc118 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -28,6 +28,12 @@ class Issue < ActiveRecord::Base scope :needed_checking, where(:issues => {:status => ['open', 'blocked', 'ready', 'already']}) scope :not_closed_or_merged, needed_checking scope :closed_or_merged, where(:issues => {:status => ['closed', 'merged']}) + # Using mb_chars for correct transform to lowercase ('Русский Текст'.downcase => "Русский Текст") + scope :search, lambda {|q| where('issues.title ILIKE ?', "%#{q.mb_chars.downcase}%") if q.present?} + scope :def_order, order('issues.serial_id desc') + scope :without_pull_requests, + joins("LEFT OUTER JOIN pull_requests ON issues.id = pull_requests.issue_id"). + where(:pull_requests => { :issue_id => nil } ) def assign_uname assignee.uname if assignee diff --git a/app/views/layouts/issues.html.haml b/app/views/layouts/with_sidebar.html.haml similarity index 92% rename from app/views/layouts/issues.html.haml rename to app/views/layouts/with_sidebar.html.haml index 75987198b..87bd1860c 100644 --- a/app/views/layouts/issues.html.haml +++ b/app/views/layouts/with_sidebar.html.haml @@ -1,4 +1,4 @@ - if content_for?(:sidebar) %aside= yield :sidebar .right= yield -.both \ No newline at end of file +.both diff --git a/app/views/projects/base/_submenu.html.haml b/app/views/projects/base/_submenu.html.haml index 6d465fb3d..c504995ff 100644 --- a/app/views/projects/base/_submenu.html.haml +++ b/app/views/projects/base/_submenu.html.haml @@ -15,6 +15,5 @@ %li= link_to t("project_menu.wiki"), project_wiki_index_path(@project), :class => (contr == :wiki ? 'active' : nil) %li=# link_to t("project_menu.readme"), "#" #pending - if can? :update, @project - %li= link_to t("project_menu.settings"), edit_project_path(@project), :class => (act == :edit && contr == :projects ? 'active' : nil) - / %li=link_to t("project_menu.pull_requests"), project_pull_requests_path(@project), :class => (contr == :pull_requests ? 'active' : nil) + %li= link_to t("project_menu.settings"), edit_project_path(@project), :class => (act == :edit && contr == :projects ? 'active' : nil) diff --git a/app/views/projects/issues/_index_sidebar.html.haml b/app/views/projects/issues/_index_sidebar.html.haml index d1ccfc387..03f8fb427 100644 --- a/app/views/projects/issues/_index_sidebar.html.haml +++ b/app/views/projects/issues/_index_sidebar.html.haml @@ -7,12 +7,12 @@ %tr %td.width18=radio_button_tag :myradio, 'all', !@is_assigned_to_me, {:id => 'myradio1', :class => 'niceRadio', :name => 'filter'} %td.width135=t("layout.issues.all") - %td.width30.right=@project.issues.count + %td.width30.right=@project.issues.without_pull_requests.count %tr %td=radio_button_tag :myradio, 'to_me', @is_assigned_to_me, {:id => 'myradio1', :class => 'niceRadio', :name => 'filter'} %td=t("layout.issues.to_me") - %td.width30.right=@project.issues.where(:assignee_id => current_user.id).count - =form_tag project_issues_path(@project), :id => 'search_issue', :method => :get do + %td.width30.right=@project.issues.without_pull_requests.where(:assignee_id => current_user.id).count + =form_tag project_issues_path(@project), :id => 'search_issue', :class => 'ajax_search_form', :method => :get do .bordered.bpadding20 =tracker_search_field(:search_issue, t('layout.issues.search')) - if can? :new, @project.issues.new diff --git a/app/views/projects/pull_requests/_index_sidebar.html.haml b/app/views/projects/pull_requests/_index_sidebar.html.haml index 6f25ec81c..449f47c85 100644 --- a/app/views/projects/pull_requests/_index_sidebar.html.haml +++ b/app/views/projects/pull_requests/_index_sidebar.html.haml @@ -1,16 +1,5 @@ -content_for :sidebar do - if current_user - =form_tag project_pull_requests_path(@project), :id => 'filter_issues', :method => :get do - .bordered.nopadding - %h3=t("layout.issues.accessory") - %table - %tr - %td.width18=radio_button_tag :myradio, 'all', !@is_assigned_to_me, {:id => 'myradio1', :class => 'niceRadio', :name => 'filter'} - %td.width135=t("layout.issues.all") - %td.width30.right=@project.pull_requests.count - %tr - %td=radio_button_tag :myradio, 'to_me', @is_assigned_to_me, {:id => 'myradio1', :class => 'niceRadio', :name => 'filter'} - %td=t("layout.issues.to_me") - %td.width30.right=@project.issues.joins(:pull_request).where(:assignee_id => current_user.id).count + =form_tag project_pull_requests_path(@project), :id => 'filter_pull_requests', :method => :get, :class => 'ajax_search_form' do .bordered.bpadding20 - =tracker_search_field(:search_issue, t('layout.issues.search')) + =tracker_search_field(:search_pull_request, t('layout.pull_requests.search')) diff --git a/app/views/projects/pull_requests/index.html.haml b/app/views/projects/pull_requests/index.html.haml index 50bac1df6..f0b76f5f3 100644 --- a/app/views/projects/pull_requests/index.html.haml +++ b/app/views/projects/pull_requests/index.html.haml @@ -19,5 +19,5 @@ %th.th1{:colspan => "2"}=t('layout.issues.number') %th{:colspan => "2"}=t('layout.issues.description') %tbody - = render :partial => 'projects/issues/issue', :collection => @pull_requests - = will_paginate @pull_requests + = render :partial => 'projects/issues/issue', :collection => @issues_with_pull_request + = will_paginate @issues_with_pull_request diff --git a/config/locales/models/pull_request.en.yml b/config/locales/models/pull_request.en.yml index 0b1141ad7..f72fe2790 100644 --- a/config/locales/models/pull_request.en.yml +++ b/config/locales/models/pull_request.en.yml @@ -47,4 +47,8 @@ en: head_ref: Head refs: 'branch · tag' base_project: Base project - head_project: Head project \ No newline at end of file + head_project: Head project + + layout: + pull_requests: + search: Find pull request... diff --git a/config/locales/models/pull_request.ru.yml b/config/locales/models/pull_request.ru.yml index e29e20d33..5fd188622 100644 --- a/config/locales/models/pull_request.ru.yml +++ b/config/locales/models/pull_request.ru.yml @@ -49,4 +49,8 @@ ru: head_ref: Источник refs: 'ветка · тег' base_project: Базовый проект - head_project: Проект-источник \ No newline at end of file + head_project: Проект-источник + + layout: + pull_requests: + search: Найти пул реквест...