2012-01-30 20:39:34 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
2011-12-19 15:30:14 +00:00
|
|
|
class IssuesController < ApplicationController
|
2012-02-27 16:10:12 +00:00
|
|
|
NON_RESTFUL_ACTION = [:create_label, :update_label, :destroy_label, :search_collaborators]
|
2011-12-19 15:30:14 +00:00
|
|
|
before_filter :authenticate_user!
|
2011-12-28 02:57:42 +00:00
|
|
|
|
2012-03-02 17:38:00 +00:00
|
|
|
load_resource :project
|
2012-03-02 16:52:15 +00:00
|
|
|
load_and_authorize_resource :issue, :through => :project, :find_by => :serial_id, :only => [:show, :edit, :update, :destroy, :new, :create]
|
2012-02-27 16:10:12 +00:00
|
|
|
before_filter :load_and_authorize_label, :only => NON_RESTFUL_ACTION
|
2011-12-19 15:30:14 +00:00
|
|
|
|
2012-02-20 16:54:45 +00:00
|
|
|
layout 'application'
|
2011-12-19 15:30:14 +00:00
|
|
|
|
2012-02-23 14:48:31 +00:00
|
|
|
def index(status = 200)
|
2012-02-20 16:54:45 +00:00
|
|
|
@is_assigned_to_me = params[:filter] == 'to_me'
|
2012-02-23 15:57:51 +00:00
|
|
|
@status = params[:status] == 'closed' ? 'closed' : 'open'
|
2012-02-23 14:48:31 +00:00
|
|
|
@labels = params[:labels] || []
|
2012-02-28 14:28:11 +00:00
|
|
|
@issues = @project.issues
|
2012-02-23 14:48:31 +00:00
|
|
|
@issues = @issues.where(:user_id => current_user.id) if @is_assigned_to_me
|
|
|
|
@issues = @issues.joins(:labels).where(:labels => {:name => @labels}) unless @labels == []
|
2012-02-20 16:54:45 +00:00
|
|
|
|
2012-02-27 16:10:12 +00:00
|
|
|
if params[:search_issue]
|
|
|
|
@issues = @issues.where('issues.title ILIKE ?', "%#{params[:search_issue].mb_chars.downcase}%")
|
2011-12-23 14:34:32 +00:00
|
|
|
end
|
2012-02-28 14:28:11 +00:00
|
|
|
@opened_issues = @issues.opened.count
|
|
|
|
@closed_issues = @issues.closed.count
|
|
|
|
@issues = @issues.where(:status => @status)
|
|
|
|
|
|
|
|
|
2012-02-23 14:48:31 +00:00
|
|
|
@issues = @issues.includes(:creator, :user).order('serial_id desc').uniq.paginate :per_page => 10, :page => params[:page]
|
|
|
|
if status == 200
|
|
|
|
render 'index', :layout => request.format == '*/*' ? 'issues' : 'application' # maybe FIXME '*/*'?
|
|
|
|
else
|
|
|
|
render :status => status, :nothing => true
|
|
|
|
end
|
2011-12-19 15:30:14 +00:00
|
|
|
end
|
|
|
|
|
2011-12-28 02:57:42 +00:00
|
|
|
def new
|
2012-03-02 19:23:45 +00:00
|
|
|
@issue = @project.issues.new
|
2011-12-28 02:57:42 +00:00
|
|
|
end
|
|
|
|
|
2011-12-19 15:30:14 +00:00
|
|
|
def create
|
|
|
|
@user_uname = params[:user_uname]
|
2012-03-02 19:23:45 +00:00
|
|
|
@issue = @project.issues.new(params[:issue])
|
2012-02-27 16:10:12 +00:00
|
|
|
@issue.creator_id = current_user.id
|
2012-01-13 15:07:01 +00:00
|
|
|
|
2011-12-28 02:57:42 +00:00
|
|
|
if @issue.save
|
2012-01-13 15:07:01 +00:00
|
|
|
@issue.subscribe_creator(current_user.id)
|
|
|
|
|
2011-12-19 15:30:14 +00:00
|
|
|
flash[:notice] = I18n.t("flash.issue.saved")
|
|
|
|
redirect_to project_issues_path(@project)
|
|
|
|
else
|
2011-12-28 02:57:42 +00:00
|
|
|
flash[:error] = I18n.t("flash.issue.save_error")
|
2011-12-19 15:30:14 +00:00
|
|
|
render :action => :new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2012-03-06 15:20:29 +00:00
|
|
|
if params[:issue] && status = params[:issue][:status]
|
2012-02-28 14:05:18 +00:00
|
|
|
action = 'issues/_status'
|
|
|
|
@issue.set_close(current_user) if status == 'closed'
|
|
|
|
@issue.set_open if status == 'open'
|
|
|
|
status = 200 if @issue.save
|
2012-02-28 15:41:47 +00:00
|
|
|
render action, :status => (status || 500), :layout => false
|
2012-03-06 15:20:29 +00:00
|
|
|
elsif params[:issue]
|
|
|
|
@issue.labelings.destroy_all if params[:issue][:labelings_attributes] # FIXME
|
2012-03-02 18:21:46 +00:00
|
|
|
status = 200 if @issue.update_attributes(params[:issue])
|
2012-02-28 15:41:47 +00:00
|
|
|
render :nothing => true, :status => (status || 500), :layout => false
|
2012-03-06 15:20:29 +00:00
|
|
|
else
|
2012-03-07 13:36:17 +00:00
|
|
|
render :nothing => true, :status => 200, :layout => false
|
2011-12-19 15:30:14 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@issue.destroy
|
|
|
|
|
|
|
|
flash[:notice] = t("flash.issue.destroyed")
|
|
|
|
redirect_to root_path
|
|
|
|
end
|
|
|
|
|
2012-02-23 14:48:31 +00:00
|
|
|
def create_label
|
|
|
|
status = @project.labels.create(:name => params[:name], :color => params[:color]) ? 200 : 500
|
|
|
|
index(status)
|
|
|
|
end
|
2011-12-19 15:30:14 +00:00
|
|
|
|
2012-02-23 14:48:31 +00:00
|
|
|
def update_label
|
|
|
|
status = @label.update_attributes( :name => params[:name], :color => params[:color]) ? 200 : 500
|
|
|
|
index(status)
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy_label
|
|
|
|
status = (@label && @label_destroy) ? 200 : 500
|
|
|
|
index(status)
|
2011-12-19 15:30:14 +00:00
|
|
|
end
|
|
|
|
|
2012-02-27 16:10:12 +00:00
|
|
|
def search_collaborators
|
|
|
|
search = "%#{params[:search_user]}%"
|
|
|
|
users = User.joins(:groups => :projects).where(:projects => {:id => @project.id}).where("users.uname ILIKE ?", search)
|
|
|
|
users2 = @project.collaborators.where("users.uname ILIKE ?", search)
|
|
|
|
@users = (users + users2).uniq.sort {|x,y| x.uname <=> y.uname}.first(10)
|
|
|
|
render 'issues/_search_collaborators', :layout => false
|
|
|
|
end
|
|
|
|
|
2012-02-23 14:48:31 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def load_and_authorize_label
|
|
|
|
@label = Label.find(params[:label_id]) if params[:label_id]
|
|
|
|
authorize! :write, @project
|
2011-12-19 15:30:14 +00:00
|
|
|
end
|
|
|
|
end
|