parent
212cbc6c78
commit
eaa5919cc0
@ -0,0 +1,73 @@
|
||||
class JournalsController < ApplicationController
|
||||
before_action :require_login
|
||||
before_action :set_issue
|
||||
before_action :check_issue_permission
|
||||
|
||||
def index
|
||||
@page = params[:page] || 1
|
||||
@limit = params[:limit] || 10
|
||||
journals = @issue.journals.journal_includes.order("created_on desc")
|
||||
@journals_size = journals.size
|
||||
@journals = journals.parent_journals.page(@page).per(@limit)
|
||||
end
|
||||
|
||||
def create
|
||||
notes = params[:content]
|
||||
if notes.blank?
|
||||
normal_status(-1, "评论内容不能为空")
|
||||
else
|
||||
journal_params = {
|
||||
journalized_id: @issue.id ,
|
||||
journalized_type: "Issue",
|
||||
user_id: current_user.id ,
|
||||
notes: notes.to_s.strip,
|
||||
parent_id: params[:parent_id]
|
||||
}
|
||||
journal = Journal.new journal_params
|
||||
if journal.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 = journal
|
||||
attachment.save
|
||||
end
|
||||
end
|
||||
end
|
||||
normal_status(0, "评论成功")
|
||||
else
|
||||
normal_status(-1, "评论失败")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
journal = Journal.find(params[:id])
|
||||
if journal.present?
|
||||
if journal.destroy #如果有子评论,子评论删除吗?
|
||||
normal_status(0, "评论删除成功")
|
||||
else
|
||||
normal_status(-1, "评论删除失败")
|
||||
end
|
||||
else
|
||||
normal_status(-1, "评论不存在")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def set_issue
|
||||
@issue = Issue.find_by_id(params[:issue_id])
|
||||
unless @issue.present?
|
||||
normal_status(-1, "标签不存在")
|
||||
end
|
||||
end
|
||||
|
||||
def check_issue_permission
|
||||
@project = @issue.project
|
||||
unless @project.member?(current_user) || current_user.admin?
|
||||
normal_status(-1, "您没有权限")
|
||||
end
|
||||
end
|
||||
end
|
@ -1,45 +1,52 @@
|
||||
class Issue < ApplicationRecord
|
||||
belongs_to :project
|
||||
belongs_to :tracker
|
||||
belongs_to :issue_tag, foreign_key: :priority_id
|
||||
belongs_to :issue_tag, foreign_key: :priority_id,optional: true
|
||||
belongs_to :version, foreign_key: :fixed_version_id,optional: true
|
||||
belongs_to :user,optional: true, foreign_key: :author_id
|
||||
belongs_to :issue_status, foreign_key: :status_id,optional: true
|
||||
has_many :commit_issues
|
||||
has_many :attachments, as: :container, dependent: :destroy
|
||||
has_many :memos
|
||||
has_many :journals
|
||||
has_many :journals, :as => :journalized, :dependent => :destroy
|
||||
has_many :journal_details, through: :journals
|
||||
|
||||
scope :issue_includes, ->{includes(:user)}
|
||||
|
||||
# scope :issues_count, lambda{|tracker_id| where(tracker_id: tracker_id).size}
|
||||
|
||||
|
||||
def get_assign_user
|
||||
User.select(:login, :lastname,:firstname, :nickname)&.find_by_id(self.assigned_to_id)
|
||||
end
|
||||
|
||||
def create_journal_detail(change_files, issue_files, issue_file_ids)
|
||||
journal = Journal.where(journalized_id: self.id, journalized_type: "Issue", user_id: self.author_id, notes: [nil,""])
|
||||
if journal.present?
|
||||
journal.update_all(created_on: Time.now)
|
||||
journal = journal.last
|
||||
else
|
||||
journal_params = {
|
||||
journalized_id: self.id, journalized_type: "Issue", user_id: self.author_id
|
||||
}
|
||||
journal = Journal.new journal_params
|
||||
journal.save
|
||||
end
|
||||
if change_files
|
||||
journal.journal_details.create(property: "attachment", prop_key: "#{issue_files.size}", old_value: issue_file_ids, value: issue_files)
|
||||
end
|
||||
journal_params = {
|
||||
journalized_id: self.id, journalized_type: "Issue", user_id: self.author_id
|
||||
}
|
||||
journal = Journal.new journal_params
|
||||
|
||||
change_values = %w(subject description is_private assigned_to_id tracker_id status_id priority_id fixed_version_id start_date due_date estimated_hours done_ratio)
|
||||
change_values.each do |at|
|
||||
if self.send("saved_change_to_#{at}?")
|
||||
journal.journal_details.create(property: "attr", prop_key: "#{at}", old_value: self.send("#{at}_before_last_save"), value: self.send(at))
|
||||
if journal.save
|
||||
if change_files
|
||||
old_attachment_names = self.attachments.select(:filename,:id).where(id: issue_file_ids).pluck(:filename).join(",")
|
||||
new_attachment_name = self.attachments.select(:filename,:id).where(id: issue_files).pluck(:filename).join(",")
|
||||
journal.journal_details.create(property: "attachment", prop_key: "#{issue_files.size}", old_value: old_attachment_names, value: new_attachment_name)
|
||||
end
|
||||
change_values = %w(subject description is_private assigned_to_id tracker_id status_id priority_id fixed_version_id start_date due_date estimated_hours done_ratio)
|
||||
change_values.each do |at|
|
||||
if self.send("saved_change_to_#{at}?")
|
||||
journal.journal_details.create(property: "attr", prop_key: "#{at}", old_value: self.send("#{at}_before_last_save"), value: self.send(at))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def get_journals_size
|
||||
journals.size
|
||||
end
|
||||
|
||||
def self.issues_count(tracker_id)
|
||||
includes(:trakcer).where(tracker_id: tracker_id).size
|
||||
end
|
||||
|
||||
end
|
@ -1,7 +1,75 @@
|
||||
class Journal < ApplicationRecord
|
||||
belongs_to :user
|
||||
belongs_to :issue, foreign_key: :journalized_id
|
||||
belongs_to :issue, foreign_key: :journalized_id, :touch => true
|
||||
has_many :journal_details, :dependent => :delete_all
|
||||
has_many :attachments, as: :container, dependent: :destroy
|
||||
|
||||
scope :journal_includes, ->{includes(:user, :journal_details, :attachments)}
|
||||
scope :parent_journals, ->{where(parent_id: nil)}
|
||||
scope :children_journals, lambda{|journal_id| where(parent_id: journal_id)}
|
||||
|
||||
|
||||
def is_journal_detail?
|
||||
self.notes.blank? && self.journal_details.present?
|
||||
end
|
||||
|
||||
def journal_content
|
||||
send_details = []
|
||||
if self.is_journal_detail?
|
||||
details = self.journal_details.select(:property, :prop_key, :old_value, :value).pluck(:property, :prop_key, :old_value, :value)
|
||||
if details.size > 0
|
||||
details.each do |de|
|
||||
if de[0] == "attr"
|
||||
content = ""
|
||||
else
|
||||
content = "附件"
|
||||
end
|
||||
old_value = de[2]
|
||||
value = de[3]
|
||||
if de[1].to_i > 0
|
||||
prop_name = ""
|
||||
else
|
||||
prop_name = I18n.t("journal_detail.#{de[1]}")
|
||||
case de[1]
|
||||
when "is_private"
|
||||
old_value = I18n.t("journal_detail.#{de[2]}")
|
||||
value = I18n.t("journal_detail.#{de[3]}")
|
||||
when "assigned_to_id"
|
||||
u = User.select(:id, :login, :lastname, :firstname)
|
||||
old_value = u.find(de[2]).try(:show_real_name)
|
||||
value = u.find(de[3]).try(:show_real_name)
|
||||
when "tracker_id"
|
||||
t = Tracker.select(:id, :name)
|
||||
old_value = t.find(de[2]).try(:name)
|
||||
value = t.find(de[3]).try(:name)
|
||||
when "status_id"
|
||||
t = IssueStatus.select(:id, :name)
|
||||
old_value = t.find(de[2]).try(:name)
|
||||
value = t.find(de[3]).try(:name)
|
||||
when "priority_id"
|
||||
t = IssueTag.select(:id, :title)
|
||||
old_value = t.find(de[2]).try(:title)
|
||||
value = t.find(de[3]).try(:title)
|
||||
when "fixed_version_id"
|
||||
t = Version.select(:id, :title)
|
||||
old_value = t.find(de[2]).try(:title)
|
||||
value = t.find(de[3]).try(:title)
|
||||
else
|
||||
old_value = de[2]
|
||||
value = de[3]
|
||||
end
|
||||
end
|
||||
prop_hash = {
|
||||
detail: (content + prop_name),
|
||||
old_value: old_value,
|
||||
value: value
|
||||
}
|
||||
send_details.push(prop_hash)
|
||||
end
|
||||
end
|
||||
end
|
||||
send_details
|
||||
end
|
||||
|
||||
|
||||
scope :journal_includes, ->{includes(:user, :journal_details)}
|
||||
end
|
@ -1,3 +0,0 @@
|
||||
json.issue_id journal.journalized_id
|
||||
json.notes journal.try(:notes)
|
||||
json.created_at time_from_now(journal.created_on)
|
@ -0,0 +1,4 @@
|
||||
json.all_count @all_issues_size
|
||||
json.open_count @open_issues_size
|
||||
json.close_count @close_issues_size
|
||||
json.commit_issues @commit_issues
|
@ -0,0 +1,8 @@
|
||||
if @status > 0
|
||||
json.status 0
|
||||
json.message "复制成功"
|
||||
json.issue_id @new_issue.id
|
||||
else
|
||||
json.status -1
|
||||
json.message "复制失败"
|
||||
end
|
@ -1,10 +1,11 @@
|
||||
json.partial! "commons/success"
|
||||
json.extract! @issue, :id,:subject,:description,:is_private,:assigned_to_id,:tracker_id,:status_id,:priority_id,:fixed_version_id,
|
||||
:start_date,:due_date,:estimated_hours,:done_ratio
|
||||
:start_date,:due_date,:estimated_hours
|
||||
json.done_ratio @issue.done_ratio.to_s + "%"
|
||||
json.issue_chosen @issue_chosen
|
||||
|
||||
json.attachments do
|
||||
json.array! @issue_attachments do |attachment|
|
||||
json.partial! "attachments/attachment", attachment: attachment
|
||||
json.partial! "attachments/attachment_simple", locals: {attachment: attachment}
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,27 @@
|
||||
json.partial! "commons/success"
|
||||
json.all_count @all_issues_size
|
||||
json.open_count @open_issues_size
|
||||
json.close_count @close_issues_size
|
||||
json.assign_me_count @assign_to_me_size
|
||||
json.my_published_count @my_published_size
|
||||
json.search_count @issues_size
|
||||
json.limit @limit
|
||||
|
||||
json.issues do
|
||||
json.array! @issues.to_a do |issue|
|
||||
json.id issue.id
|
||||
json.name issue.subject
|
||||
json.created_at format_time(issue.created_on)
|
||||
json.updated_at format_time(issue.updated_on)
|
||||
json.assign_user_name issue.get_assign_user.try(:show_real_name)
|
||||
json.assign_user_login issue.get_assign_user.try(:login)
|
||||
json.author_name issue.user.try(:show_real_name)
|
||||
json.author_login issue.user.try(:login)
|
||||
json.tracker issue.tracker.try(:name)
|
||||
json.issue_status issue.issue_status.try(:name)
|
||||
json.priority issue.issue_tag.try(:title)
|
||||
json.version issue.version.try(:title)
|
||||
json.done_ratio issue.done_ratio.to_s + "%"
|
||||
json.journals_count issue.get_journals_size
|
||||
end
|
||||
end
|
@ -0,0 +1,13 @@
|
||||
wb = xlsx_package.workbook
|
||||
wb.styles do |s|
|
||||
sz_all = s.add_style :border => { :style => :thin, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center, :vertical => :center}
|
||||
blue_cell = s.add_style :bg_color => "FAEBDC", :sz => 10,:height => 20,:b => true, :border => { :style => :thin, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center}
|
||||
|
||||
wb.add_worksheet(:name => "issues列表") do |sheet|
|
||||
sheet.add_row table_columns, :style => blue_cell, height: 30
|
||||
sheet.column_info.first.width = 12
|
||||
issues.each do |user|
|
||||
sheet.add_row user, :style => sz_all #用户id
|
||||
end #each_widh_index
|
||||
end #add_worksheet
|
||||
end
|
@ -0,0 +1,2 @@
|
||||
json.partial! "commons/success"
|
||||
json.issue_chosen @issue_chosen
|
@ -0,0 +1,15 @@
|
||||
json.id journal.id
|
||||
json.user_name journal.user.try(:show_real_name)
|
||||
json.user_login journal.user.try(:login)
|
||||
json.user_picture url_to_avatar(journal.user)
|
||||
json.is_journal_detail journal.is_journal_detail? #判断是否修改了参数而添加的回复内容
|
||||
json.content journal.try(:notes)
|
||||
json.children_journals children_content(journal.id)
|
||||
json.journal_details journal.journal_content
|
||||
json.created_at time_from_now(journal.created_on)
|
||||
|
||||
json.attachments do
|
||||
json.array! journal.attachments do |attachment|
|
||||
json.partial! "attachments/attachment_simple", locals: {attachment: attachment}
|
||||
end
|
||||
end
|
@ -0,0 +1,8 @@
|
||||
json.partial! "commons/success"
|
||||
json.limit @limit
|
||||
json.journals_count @journals_size
|
||||
json.issue_journals do
|
||||
json.array! @journals do |journal|
|
||||
json.partial! "journals/journal_item", journal: journal
|
||||
end
|
||||
end
|
Loading…
Reference in new issue