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

This commit is contained in:
jasder 2021-05-08 14:13:16 +08:00
commit 51597335a4
4 changed files with 66 additions and 40 deletions

View File

@ -101,51 +101,46 @@ class IssuesController < ApplicationController
end end
def create def create
if params[:subject].blank? issue_params = issue_send_params(params)
normal_status(-1, "标题不能为空") Issues::CreateForm.new({subject:issue_params[:subject]}).validate!
elsif params[:subject].to_s.size > 255 @issue = Issue.new(issue_params)
normal_status(-1, "标题不能超过255个字符") if @issue.save!
else if params[:attachment_ids].present?
issue_params = issue_send_params(params) params[:attachment_ids].each do |id|
attachment = Attachment.select(:id, :container_id, :container_type)&.find_by_id(id)
@issue = Issue.new(issue_params) unless attachment.blank?
if @issue.save! attachment.container = @issue
if params[:attachment_ids].present? attachment.author_id = current_user.id
params[:attachment_ids].each do |id| attachment.description = ""
attachment = Attachment.select(:id, :container_id, :container_type)&.find_by_id(id) attachment.save
unless attachment.blank?
attachment.container = @issue
attachment.author_id = current_user.id
attachment.description = ""
attachment.save
end
end end
end end
if params[:issue_tag_ids].present? end
params[:issue_tag_ids].each do |tag| if params[:issue_tag_ids].present?
IssueTagsRelate.create!(issue_id: @issue.id, issue_tag_id: tag) params[:issue_tag_ids].each do |tag|
end IssueTagsRelate.create!(issue_id: @issue.id, issue_tag_id: tag)
end end
if params[:assigned_to_id].present? end
Tiding.create!(user_id: params[:assigned_to_id], trigger_user_id: current_user.id, if params[:assigned_to_id].present?
container_id: @issue.id, container_type: 'Issue', Tiding.create!(user_id: params[:assigned_to_id], trigger_user_id: current_user.id,
parent_container_id: @project.id, parent_container_type: "Project", container_id: @issue.id, container_type: 'Issue',
tiding_type: 'issue', status: 0) parent_container_id: @project.id, parent_container_type: "Project",
end tiding_type: 'issue', status: 0)
#为悬赏任务时, 扣除当前用户的积分
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 end
end #为悬赏任务时, 扣除当前用户的积分
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 end
def edit def edit
@ -199,7 +194,7 @@ class IssuesController < ApplicationController
normal_status(-1, "不允许修改为关闭状态") normal_status(-1, "不允许修改为关闭状态")
else else
issue_params = issue_send_params(params).except(:issue_classify, :author_id, :project_id) 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 @issue.update_attributes(issue_params)
if params[:status_id].to_i == 5 #任务由非关闭状态到关闭状态时 if params[:status_id].to_i == 5 #任务由非关闭状态到关闭状态时
@issue.issue_times.update_all(end_time: Time.now) @issue.issue_times.update_all(end_time: Time.now)
@ -225,6 +220,9 @@ class IssuesController < ApplicationController
normal_status(-1, "更新失败") normal_status(-1, "更新失败")
end end
end end
rescue Exception => exception
puts exception.message
normal_status(-1, exception.message)
end end
def show def show

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

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

View File

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