Merge pull request #660 from warpc/90-separate-issues-and-pull-requests

#90: separate issues and pull requests
This commit is contained in:
Alexander Machehin 2012-09-26 09:53:19 -07:00
commit 496cb7d354
14 changed files with 78 additions and 34 deletions

View File

@ -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());
});

View File

@ -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

View File

@ -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])

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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
= render 'issues_table', :issues => @issues

View File

@ -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'))

View File

@ -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

View File

@ -48,3 +48,7 @@ en:
refs: 'branch · tag'
base_project: Base project
head_project: Head project
layout:
pull_requests:
search: Find pull request...

View File

@ -50,3 +50,7 @@ ru:
refs: 'ветка · тег'
base_project: Базовый проект
head_project: Проект-источник
layout:
pull_requests:
search: Найти пул реквест...

View File

@ -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