[refs #194] fix issues count

This commit is contained in:
Alexander Machehin 2012-02-28 20:28:11 +06:00
parent bc4a157703
commit 0abea8ff55
3 changed files with 11 additions and 4 deletions

View File

@ -15,14 +15,18 @@ class IssuesController < ApplicationController
@is_assigned_to_me = params[:filter] == 'to_me' @is_assigned_to_me = params[:filter] == 'to_me'
@status = params[:status] == 'closed' ? 'closed' : 'open' @status = params[:status] == 'closed' ? 'closed' : 'open'
@labels = params[:labels] || [] @labels = params[:labels] || []
@issues = @project.issues
@issues = @project.issues.where(:status => @status)
@issues = @issues.where(:user_id => current_user.id) if @is_assigned_to_me @issues = @issues.where(:user_id => current_user.id) if @is_assigned_to_me
@issues = @issues.joins(:labels).where(:labels => {:name => @labels}) unless @labels == [] @issues = @issues.joins(:labels).where(:labels => {:name => @labels}) unless @labels == []
if params[:search_issue] if params[:search_issue]
@issues = @issues.where('issues.title ILIKE ?', "%#{params[:search_issue].mb_chars.downcase}%") @issues = @issues.where('issues.title ILIKE ?', "%#{params[:search_issue].mb_chars.downcase}%")
end end
@opened_issues = @issues.opened.count
@closed_issues = @issues.closed.count
@issues = @issues.where(:status => @status)
@issues = @issues.includes(:creator, :user).order('serial_id desc').uniq.paginate :per_page => 10, :page => params[:page] @issues = @issues.includes(:creator, :user).order('serial_id desc').uniq.paginate :per_page => 10, :page => params[:page]
if status == 200 if status == 200
render 'index', :layout => request.format == '*/*' ? 'issues' : 'application' # maybe FIXME '*/*'? render 'index', :layout => request.format == '*/*' ? 'issues' : 'application' # maybe FIXME '*/*'?

View File

@ -26,6 +26,9 @@ class Issue < ActiveRecord::Base
attr_accessible :labelings_attributes, :title, :body, :project, :project_id, :closed_at, :closed_by attr_accessible :labelings_attributes, :title, :body, :project, :project_id, :closed_at, :closed_by
accepts_nested_attributes_for :labelings, :allow_destroy => true accepts_nested_attributes_for :labelings, :allow_destroy => true
scope :opened, where(:status => 'open', :closed_by => nil, :closed_at => nil)
scope :closed, where(:status => 'closed').where("closed_by is not null and closed_at is not null")
def assign_uname def assign_uname
user.uname if user user.uname if user
end end

View File

@ -4,9 +4,9 @@
#closed-switcher.blue-switcher #closed-switcher.blue-switcher
=hidden_field_tag :issues_status, @status, :id => 'issues_status' =hidden_field_tag :issues_status, @status, :id => 'issues_status'
.open .open
="#{t('layout.issues.statuses.open')} (#{@project.issues.where(:status => 'open').count})" ="#{t('layout.issues.statuses.open')} (#{@opened_issues})"
#closed-tasks.closed #closed-tasks.closed
="#{t('layout.issues.statuses.closed')} (#{@project.issues.where(:status => 'closed').count})" ="#{t('layout.issues.statuses.closed')} (#{@closed_issues})"
#blue-switch-select.selected{:style => "margin-left: #{@status == 'open' ? '0' : '130'}px;"} #blue-switch-select.selected{:style => "margin-left: #{@status == 'open' ? '0' : '130'}px;"}
.both .both
.both .both