Browse Source

FIX 修复易修标题过长导致排版问题

tags/v3.0.3^2
jasder 5 years ago
parent
commit
51597335a4
4 changed files with 65 additions and 39 deletions
  1. +37
    -39
      app/controllers/issues_controller.rb
  2. +11
    -0
      app/forms/issues/create_form.rb
  3. +10
    -0
      app/forms/issues/update_form.rb
  4. +7
    -0
      config/locales/forms/create_issuse_form.zh-CN.yml

+ 37
- 39
app/controllers/issues_controller.rb View File

@@ -101,51 +101,46 @@ class IssuesController < ApplicationController
end

def create
if params[:subject].blank?
normal_status(-1, "标题不能为空")
elsif params[:subject].to_s.size > 255
normal_status(-1, "标题不能超过255个字符")
else
issue_params = issue_send_params(params)

@issue = Issue.new(issue_params)
if @issue.save!
if params[:attachment_ids].present?
params[:attachment_ids].each do |id|
attachment = Attachment.select(:id, :container_id, :container_type)&.find_by_id(id)
unless attachment.blank?
attachment.container = @issue
attachment.author_id = current_user.id
attachment.description = ""
attachment.save
end
end
end
if params[:issue_tag_ids].present?
params[:issue_tag_ids].each do |tag|
IssueTagsRelate.create!(issue_id: @issue.id, issue_tag_id: tag)
issue_params = issue_send_params(params)
Issues::CreateForm.new({subject:issue_params[:subject]}).validate!
@issue = Issue.new(issue_params)
if @issue.save!
if params[:attachment_ids].present?
params[:attachment_ids].each do |id|
attachment = Attachment.select(:id, :container_id, :container_type)&.find_by_id(id)
unless attachment.blank?
attachment.container = @issue
attachment.author_id = current_user.id
attachment.description = ""
attachment.save
end
end
if params[:assigned_to_id].present?
Tiding.create!(user_id: params[:assigned_to_id], trigger_user_id: current_user.id,
container_id: @issue.id, container_type: 'Issue',
parent_container_id: @project.id, parent_container_type: "Project",
tiding_type: 'issue', status: 0)
end

#为悬赏任务时, 扣除当前用户的积分
if params[:issue_type].to_s == "2"
post_to_chain("minus", params[:token].to_i, current_user.try(:login))
end
if params[:issue_tag_ids].present?
params[:issue_tag_ids].each do |tag|
IssueTagsRelate.create!(issue_id: @issue.id, issue_tag_id: tag)
end
end
if params[:assigned_to_id].present?
Tiding.create!(user_id: params[:assigned_to_id], trigger_user_id: current_user.id,
container_id: @issue.id, container_type: 'Issue',
parent_container_id: @project.id, parent_container_type: "Project",
tiding_type: 'issue', status: 0)
end

@issue.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: "create")
render json: {status: 0, message: "创建成", id: @issue.id}
else
normal_status(-1, "创建失败")
#为悬赏任务时, 扣除当前用户的积分
if params[:issue_type].to_s == "2"
post_to_chain("minus", params[:token].to_i, current_user.try(:login))
end

@issue.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: "create")
render json: {status: 0, message: "创建成", id: @issue.id}
else
normal_status(-1, "创建失败")
end

rescue Exception => exception
puts exception.message
normal_status(-1, exception.message)
end

def edit
@@ -199,7 +194,7 @@ class IssuesController < ApplicationController
normal_status(-1, "不允许修改为关闭状态")
else
issue_params = issue_send_params(params).except(:issue_classify, :author_id, :project_id)
Issues::UpdateForm.new({subject:issue_params[:subject]}).validate!
if @issue.update_attributes(issue_params)
if params[:status_id].to_i == 5 #任务由非关闭状态到关闭状态时
@issue.issue_times.update_all(end_time: Time.now)
@@ -225,6 +220,9 @@ class IssuesController < ApplicationController
normal_status(-1, "更新失败")
end
end
rescue Exception => exception
puts exception.message
normal_status(-1, exception.message)
end

def show


+ 11
- 0
app/forms/issues/create_form.rb View File

@@ -0,0 +1,11 @@
class Issues::CreateForm
include ActiveModel::Model

attr_accessor :subject

validates :subject, presence: { message: "不能为空" }

validates :subject, length: { maximum: 80, too_long: "不能超过80个字符" }


end

+ 10
- 0
app/forms/issues/update_form.rb View File

@@ -0,0 +1,10 @@
class Issues::UpdateForm
include ActiveModel::Model

attr_accessor :subject

validates :subject, presence: { message: "不能为空" }

validates :subject, length: { maximum: 80, too_long: "不能超过80个字符" }

end

+ 7
- 0
config/locales/forms/create_issuse_form.zh-CN.yml View File

@@ -0,0 +1,7 @@
'zh-CN':
activemodel:
attributes:
issues/create_form:
subject: 标题
issues/update_form:
subject: 标题

Loading…
Cancel
Save