Merge pull request #623 from warpc/616-issues_and_comments

[refs #616] Refactoring and fixed bugs with issue:
* could not remove all labels from issue;
* after update issue body now no need reload page to view changes;
* refactoring issues controller.
This commit is contained in:
Vladimir Sharshov 2012-08-27 03:46:27 -07:00
commit 6bcff5ad6f
3 changed files with 17 additions and 28 deletions

View File

@ -232,7 +232,7 @@ $(document).ready(function() {
form.fadeOut('slow');
$('#edit_issue_content').fadeIn('slow');
$('h3.issue_title').html(form.find('#issue_title').attr('value'));
$('.fulltext.view.issue_body').html(form.find('#issue_body').attr('value'));
$('.fulltext.view.issue_body').html(data);
},
error: function(data){
alert('error'); // TODO remove

View File

@ -7,7 +7,7 @@ class Projects::IssuesController < Projects::BaseController
load_and_authorize_resource :issue, :through => :project, :find_by => :serial_id, :only => [:show, :edit, :update, :destroy, :new, :create, :index]
before_filter :load_and_authorize_label, :only => NON_RESTFUL_ACTION
layout 'application'
layout false, :only => [:update, :search_collaborators]
def index(status = 200)
@is_assigned_to_me = params[:filter] == 'to_me'
@ -16,18 +16,14 @@ class Projects::IssuesController < Projects::BaseController
@issues = @project.issues
@issues = @issues.where(:assignee_id => current_user.id) if @is_assigned_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]
if params[:search_issue]
@issues = @issues.where('issues.title ILIKE ?', "%#{params[:search_issue].mb_chars.downcase}%")
end
@opened_issues = @issues.opened.count
@closed_issues = @issues.closed.count
@opened_issues, @closed_issues = @issues.opened.count, @issues.closed.count
@issues = @issues.where(:status => @status)
@issues = @issues.includes(:assignee, :user).order('serial_id desc').uniq.paginate :per_page => 10, :page => params[:page]
.includes(:assignee, :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 '*/*'?
render 'index', :layout => request.xhr? ? 'issues' : 'application'
else
render :status => status, :nothing => true
end
@ -38,12 +34,10 @@ class Projects::IssuesController < Projects::BaseController
def create
@assignee_uname = params[:assignee_uname]
@issue = @project.issues.new(params[:issue])
@issue.user_id = current_user.id
if @issue.save
@issue.subscribe_creator(current_user.id)
flash[:notice] = I18n.t("flash.issue.saved")
redirect_to project_issues_path(@project)
else
@ -53,41 +47,35 @@ class Projects::IssuesController < Projects::BaseController
end
def update
@issue.labelings.destroy_all if params[:update_labels]
if params[:issue] && status = params[:issue][:status]
action = 'status'
@issue.set_close(current_user) if status == 'closed'
@issue.set_open if status == 'open'
status = 200 if @issue.save
render :partial => action, :status => (status || 500), :layout => false
render :partial => 'status', :status => (@issue.save ? 200 : 500)
elsif params[:issue]
@issue.labelings.destroy_all if params[:issue][:labelings_attributes] # FIXME
status = 200 if @issue.update_attributes(params[:issue])
render :nothing => true, :status => (status || 500), :layout => false
status = @issue.update_attributes(params[:issue]) ? 200 : 500
render :inline => ActionController::Base.helpers.simple_format(params[:issue][:body]), :status => status
else
render :nothing => true, :status => 200, :layout => false
render :nothing => true, :status => 200
end
end
def destroy
@issue.destroy
flash[:notice] = t("flash.issue.destroyed")
redirect_to root_path
end
def create_label
status = @project.labels.create!(:name => params[:name], :color => params[:color]) ? 200 : 500
index(status)
index(@project.labels.create!(:name => params[:name], :color => params[:color]) ? 200 : 500)
end
def update_label
status = @label.update_attributes(:name => params[:name], :color => params[:color]) ? 200 : 500
index(status)
index(@label.update_attributes(:name => params[:name], :color => params[:color]) ? 200 : 500)
end
def destroy_label
status = (@label && @label_destroy) ? 200 : 500
index(status)
index((@label && @label_destroy) ? 200 : 500)
end
def search_collaborators
@ -95,7 +83,7 @@ class Projects::IssuesController < Projects::BaseController
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 :partial => 'search_collaborators', :layout => false
render :partial => 'search_collaborators'
end
private

View File

@ -47,6 +47,7 @@
.both=hidden_field_tag "flag#{label.id}", label.id, :name => "issue[labelings_attributes][#{label.id}][label_id]"
=form_for :issue, :url => [@project, @issue], :method => :put, :html => { :class => 'edit_labels issue'} do |f|
.manage_labels
=hidden_field_tag "update_labels", true
- @issue.labels.each do |label|
=hidden_field_tag "flag#{label.id}", label.id, :name => "issue[labelings_attributes][#{label.id}][label_id]"
- else