diff --git a/app/assets/javascripts/extra/tracker.js b/app/assets/javascripts/extra/tracker.js index f9232c3a4..6ffbf2bad 100644 --- a/app/assets/javascripts/extra/tracker.js +++ b/app/assets/javascripts/extra/tracker.js @@ -37,7 +37,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 01de8980a..3762c1fbb 100644 --- a/app/controllers/projects/pull_requests_controller.rb +++ b/app/controllers/projects/pull_requests_controller.rb @@ -4,8 +4,8 @@ class Projects::PullRequestsController < Projects::BaseController skip_before_filter :authenticate_user!, :only => [:index, :show] if APP_CONFIG['anonymous_access'] load_resource :project - load_and_authorize_resource :issue, :through => :project, :find_by => :serial_id, :parent => false, :except => :autocomplete_base_project - load_resource :instance_name => :pull, :through => :issue, :singleton => true + load_and_authorize_resource :issue, :through => :project, :find_by => :serial_id, :parent => false, :except => [:autocomplete_base_project, :index] + load_resource :instance_name => :pull, :through => :issue, :singleton => true, :except => [:index] def new base_project = (Project.find(params[:base_project_id]) if params[:base_project_id]) || @project.root @@ -88,6 +88,27 @@ class Projects::PullRequestsController < Projects::BaseController load_diff_commits_data end + def index(status = 200) + @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 = @issues_with_pull_request.not_closed_or_merged.count, @issues_with_pull_request.closed_or_merged.count + if params[:status] == 'closed' + @issues_with_pull_request, @status = @issues_with_pull_request.closed_or_merged, params[:status] + else + @issues_with_pull_request, @status = @issues_with_pull_request.not_closed_or_merged, 'open' + end + + @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? ? 'with_sidebar' : 'application' + else + render :status => status, :nothing => true + end + end + def autocomplete_base_project #Maybe slow? ILIKE? items = Project.accessible_by(current_ability, :membered).search(params[:term]) diff --git a/app/models/issue.rb b/app/models/issue.rb index 6a8eb33a3..3e9e929be 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -28,6 +28,10 @@ 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, where('NOT EXISTS (select null from pull_requests as pr where pr.issue_id = issues.id)') 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/issues/_issues_table.html.haml b/app/views/projects/issues/_issues_table.html.haml new file mode 100644 index 000000000..4b62218c7 --- /dev/null +++ b/app/views/projects/issues/_issues_table.html.haml @@ -0,0 +1,18 @@ +#closed-switcher.blue-switcher + =hidden_field_tag :issues_status, @status, :id => 'issues_status' + .open + ="#{t('layout.issues.statuses.open')} (#{@opened_issues})" + #closed-tasks.closed + ="#{t('layout.issues.statuses.closed')} (#{@closed_issues})" + #blue-switch-select.selected{:style => "margin-left: #{@status == 'open' ? '0' : '130'}px;"} + .both +.both +#table1 + %table#myTable.tablesorter.tracker{:cellpadding => "0", :cellspacing => "0"} + %thead + %tr + %th.th1{:colspan => "2"}=t('layout.issues.number') + %th{:colspan => "2"}=t('layout.issues.description') + %tbody + = render :partial => 'projects/issues/issue', :collection => issues + = will_paginate issues diff --git a/app/views/projects/issues/index.html.haml b/app/views/projects/issues/index.html.haml index 02c05d53f..7b116f361 100644 --- a/app/views/projects/issues/index.html.haml +++ b/app/views/projects/issues/index.html.haml @@ -2,21 +2,4 @@ -render 'submenu' -render 'index_sidebar' -#closed-switcher.blue-switcher - =hidden_field_tag :issues_status, @status, :id => 'issues_status' - .open - ="#{t('layout.issues.statuses.open')} (#{@opened_issues})" - #closed-tasks.closed - ="#{t('layout.issues.statuses.closed')} (#{@closed_issues})" - #blue-switch-select.selected{:style => "margin-left: #{@status == 'open' ? '0' : '130'}px;"} - .both -.both -#table1 - %table#myTable.tablesorter.tracker{:cellpadding => "0", :cellspacing => "0"} - %thead - %tr - %th.th1{:colspan => "2"}=t('layout.issues.number') - %th{:colspan => "2"}=t('layout.issues.description') - %tbody - = render :partial => 'issue', :collection => @issues - = will_paginate @issues \ No newline at end of file += render 'issues_table', :issues => @issues diff --git a/app/views/projects/pull_requests/_index_sidebar.html.haml b/app/views/projects/pull_requests/_index_sidebar.html.haml new file mode 100644 index 000000000..449f47c85 --- /dev/null +++ b/app/views/projects/pull_requests/_index_sidebar.html.haml @@ -0,0 +1,5 @@ +-content_for :sidebar do + - if current_user + =form_tag project_pull_requests_path(@project), :id => 'filter_pull_requests', :method => :get, :class => 'ajax_search_form' do + .bordered.bpadding20 + =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 new file mode 100644 index 000000000..5aa20c682 --- /dev/null +++ b/app/views/projects/pull_requests/index.html.haml @@ -0,0 +1,6 @@ +-ar = 'activerecord.attributes.pull_requests' +-set_meta_tags :title => [title_object(@project), t('.title')] +-render 'submenu' +-render 'index_sidebar' + += render 'projects/issues/issues_table', :issues => @issues_with_pull_request diff --git a/config/locales/models/pull_request.en.yml b/config/locales/models/pull_request.en.yml index 5cc7fdb1f..d2829bb11 100644 --- a/config/locales/models/pull_request.en.yml +++ b/config/locales/models/pull_request.en.yml @@ -49,3 +49,7 @@ en: refs: 'branch · tag' base_project: Base project 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 36c7076e9..988abf9fc 100644 --- a/config/locales/models/pull_request.ru.yml +++ b/config/locales/models/pull_request.ru.yml @@ -51,3 +51,7 @@ ru: refs: 'ветка · тег' base_project: Базовый проект head_project: Проект-источник + + layout: + pull_requests: + search: Найти пул реквест... diff --git a/config/routes.rb b/config/routes.rb index 49cb74f1f..161bc86c7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -186,7 +186,7 @@ Rosa::Application.routes.draw do resources :collaborators do get :find, :on => :collection end - resources :pull_requests, :except => [:destroy, :index] do + resources :pull_requests, :except => :destroy do get :autocomplete_base_project, :on => :collection put :merge, :on => :member end