|
|
|
@ -1,7 +1,245 @@
|
|
|
|
|
class IssuesController < ApplicationController
|
|
|
|
|
before_action :require_login
|
|
|
|
|
before_action :set_project
|
|
|
|
|
before_action :check_project_public, only: [:index ,:show]
|
|
|
|
|
before_action :check_issue_permission, except: [:index, :show]
|
|
|
|
|
before_action :set_issue, only: [:edit, :update, :destroy, :show]
|
|
|
|
|
|
|
|
|
|
def index
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def new
|
|
|
|
|
@issue_chosen = issue_left_chosen(@project, nil)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def create
|
|
|
|
|
if params[:subject].blank?
|
|
|
|
|
normal_status(-1, "标题不能为空")
|
|
|
|
|
else
|
|
|
|
|
issue_params = {
|
|
|
|
|
subject: params[:subject],
|
|
|
|
|
description: params[:description],
|
|
|
|
|
is_private: params[:is_private],
|
|
|
|
|
assigned_to_id: params[:assigned_to_id],
|
|
|
|
|
tracker_id: params[:tracker_id],
|
|
|
|
|
status_id: params[:status_id],
|
|
|
|
|
priority_id: params[:priority_id],
|
|
|
|
|
fixed_version_id: params[:fixed_version_id],
|
|
|
|
|
start_date: params[:start_date].to_s.to_date,
|
|
|
|
|
due_date: params[:due_date].to_s.to_date,
|
|
|
|
|
estimated_hours: params[:estimated_hours],
|
|
|
|
|
done_ratio: params[:done_ratio]
|
|
|
|
|
}
|
|
|
|
|
@issue = Issue.new(issue_params.merge(author_id: current_user.id, project_id: @project.id))
|
|
|
|
|
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.save
|
|
|
|
|
end
|
|
|
|
|
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
|
|
|
|
|
normal_status(0, "创建成功")
|
|
|
|
|
else
|
|
|
|
|
normal_status(-1, "创建失败")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def edit
|
|
|
|
|
@issue_chosen = issue_left_chosen(@project, @issue.id)
|
|
|
|
|
@issue_attachments = @issue.attachments
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def update
|
|
|
|
|
issue_params = {
|
|
|
|
|
subject: params[:subject],
|
|
|
|
|
description: params[:description],
|
|
|
|
|
is_private: params[:is_private],
|
|
|
|
|
assigned_to_id: params[:assigned_to_id],
|
|
|
|
|
tracker_id: params[:tracker_id],
|
|
|
|
|
status_id: params[:status_id],
|
|
|
|
|
priority_id: params[:priority_id],
|
|
|
|
|
fixed_version_id: params[:fixed_version_id],
|
|
|
|
|
start_date: params[:start_date].to_s.to_date,
|
|
|
|
|
due_date: params[:due_date].to_s.to_date,
|
|
|
|
|
estimated_hours: params[:estimated_hours],
|
|
|
|
|
done_ratio: params[:done_ratio]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if @issue.update_attributes(issue_params)
|
|
|
|
|
issue_files = params[:attachment_ids]
|
|
|
|
|
change_files = false
|
|
|
|
|
issue_file_ids = []
|
|
|
|
|
if issue_files.present?
|
|
|
|
|
issue_attachments = @issue&.attachments
|
|
|
|
|
issue_file_ids = issue_attachments&.pluck(:id)
|
|
|
|
|
left_file_ids = issue_file_ids - issue_files
|
|
|
|
|
new_file_ids = issue_files - issue_file_ids
|
|
|
|
|
if left_file_ids.size > 0
|
|
|
|
|
change_files = true
|
|
|
|
|
issue_attachments.where(id: left_file_ids).delete_all
|
|
|
|
|
end
|
|
|
|
|
if new_file_ids.size > 0
|
|
|
|
|
change_files = true
|
|
|
|
|
new_file_ids.each do |id|
|
|
|
|
|
attachment = Attachment.select(:id, :container_id, :container_type)&.find_by_id(id)
|
|
|
|
|
unless attachment.blank?
|
|
|
|
|
attachment.container = @issue
|
|
|
|
|
attachment.save
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@issue.create_journal_detail(change_files, issue_files, issue_file_ids)
|
|
|
|
|
normal_status(0, "更新成功")
|
|
|
|
|
else
|
|
|
|
|
normal_status(-1, "更新失败")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def show
|
|
|
|
|
@issue_attachments = @issue.attachments
|
|
|
|
|
@issue_user = @issue.user
|
|
|
|
|
@issue_assign_to = @issue.get_assign_user
|
|
|
|
|
@journals = @issue.journals.journal_includes.order("created_on desc")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
|
if @issue.destroy
|
|
|
|
|
normal_status(0, "删除成功")
|
|
|
|
|
else
|
|
|
|
|
normal_status(-1, "删除失败")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
def set_project
|
|
|
|
|
@project = Project.find_by_id(params[:project_id])
|
|
|
|
|
unless @project.present?
|
|
|
|
|
normal_status(-1, "项目不存在")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def check_project_public
|
|
|
|
|
unless @project.is_public || @project.member?(current_user) || current_user.admin?
|
|
|
|
|
normal_status(-1, "您没有权限")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def set_issue
|
|
|
|
|
@issue = Issue.find_by_id(params[:id])
|
|
|
|
|
unless @issue.present?
|
|
|
|
|
normal_status(-1, "标签不存在")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def check_issue_permission
|
|
|
|
|
unless @project.member?(current_user) || current_user.admin?
|
|
|
|
|
normal_status(-1, "您没有权限")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def issue_left_chosen(project,issue_id)
|
|
|
|
|
issue_info = Array.new(9)
|
|
|
|
|
if issue_id.present?
|
|
|
|
|
select_arrays = [:assigned_to_id, :tracker_id, :status_id, :priority_id, :fixed_version_id, :start_date, :due_date, :estimated_hours, :done_ratio]
|
|
|
|
|
issue_info = Issue.select(select_arrays).where(id: issue_id).pluck(select_arrays)
|
|
|
|
|
issue_info = issue_info[0]
|
|
|
|
|
end
|
|
|
|
|
project_members = project.members_user_infos
|
|
|
|
|
project_members_info = [] #指派给
|
|
|
|
|
project_members.each do |member|
|
|
|
|
|
real_name = member[2] + member[3]
|
|
|
|
|
unless real_name.present?
|
|
|
|
|
real_name = member[1]
|
|
|
|
|
end
|
|
|
|
|
user_id = member[0]
|
|
|
|
|
is_chosen = ((member[0].to_s == issue_info[0].to_s) ? "1" : "0")
|
|
|
|
|
member_info = {id: user_id, name: real_name, is_chosen: is_chosen}
|
|
|
|
|
project_members_info.push(member_info)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
tracker_info = project.trackers&.pluck(:id, :name, :position)
|
|
|
|
|
new_tracker_info = [] #类型
|
|
|
|
|
if tracker_info.size > 0
|
|
|
|
|
tracker_info.each do |t|
|
|
|
|
|
is_chosen = (t[0] == issue_info[1]) ? "1" : "0"
|
|
|
|
|
new_tracker = {id: t[0], name: t[1], position: t[2], is_chosen: is_chosen}
|
|
|
|
|
new_tracker_info.push(new_tracker)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
issue_status = IssueStatus&.pluck(:id,:name,:position)
|
|
|
|
|
new_status_info = [] #缺陷类型
|
|
|
|
|
if issue_status.size > 0
|
|
|
|
|
issue_status.each do |t|
|
|
|
|
|
is_chosen = (t[0] == issue_info[2]) ? "1" : "0"
|
|
|
|
|
new_issue = {id: t[0], name: t[1], position: t[2], is_chosen: is_chosen}
|
|
|
|
|
new_status_info.push(new_issue)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
issue_priority = project.issue_tags&.pluck(:id,:title, :color)
|
|
|
|
|
new_priority_info = [] #issue标签,(优先程度)
|
|
|
|
|
if issue_priority.size > 0
|
|
|
|
|
issue_priority.each do |t|
|
|
|
|
|
is_chosen = (t[0] == issue_info[3]) ? "1" : "0"
|
|
|
|
|
new_issue = {id: t[0], name: t[1], color: t[2], is_chosen: is_chosen}
|
|
|
|
|
new_priority_info.push(new_issue)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
issue_versions = project.versions&.pluck(:id,:name, :status)
|
|
|
|
|
new_version_info = [] #issue里程碑
|
|
|
|
|
if issue_versions.size > 0
|
|
|
|
|
issue_versions.each do |t|
|
|
|
|
|
is_chosen = (t[0] == issue_info[4]) ? "1" : "0"
|
|
|
|
|
new_issue = {id: t[0], name: t[1], status: t[2], is_chosen: is_chosen}
|
|
|
|
|
new_version_info.push(new_issue)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
issue_done_ratio = %w(0 10 20 30 40 50 60 70 80 90 100)
|
|
|
|
|
new_done_info = [] #完成度
|
|
|
|
|
if issue_done_ratio.size > 0
|
|
|
|
|
issue_done_ratio.each do |t|
|
|
|
|
|
is_chosen = (t == issue_info[8].to_s) ? "1" : "0"
|
|
|
|
|
new_issue = {ratio: (t.to_s + "%"), is_chosen: is_chosen}
|
|
|
|
|
new_done_info.push(new_issue)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
"assign_user": project_members_info,
|
|
|
|
|
"tracker": new_tracker_info,
|
|
|
|
|
"issue_status": new_status_info,
|
|
|
|
|
"issue_tag": new_priority_info,
|
|
|
|
|
"issue_version": new_version_info,
|
|
|
|
|
"start_date": issue_info[5],
|
|
|
|
|
"due_date": issue_info[6],
|
|
|
|
|
"estimated_hours": issue_info[7],
|
|
|
|
|
"done_ratio": new_done_info
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
end
|