2020-11-23 15:35:03 +08:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: versions
|
|
|
|
#
|
|
|
|
# id :integer not null, primary key
|
|
|
|
# project_id :integer default("0"), not null
|
2023-06-13 15:30:16 +08:00
|
|
|
# name :string(255)
|
2020-11-23 15:35:03 +08:00
|
|
|
# description :text(65535)
|
|
|
|
# effective_date :date
|
|
|
|
# created_on :datetime
|
|
|
|
# updated_on :datetime
|
|
|
|
# wiki_page_title :string(255)
|
|
|
|
# status :string(255) default("open")
|
|
|
|
# sharing :string(255) default("none"), not null
|
|
|
|
# user_id :integer
|
|
|
|
# issues_count :integer default("0")
|
|
|
|
# closed_issues_count :integer default("0")
|
|
|
|
# percent :float(24) default("0")
|
|
|
|
#
|
|
|
|
# Indexes
|
|
|
|
#
|
|
|
|
# index_versions_on_sharing (sharing)
|
|
|
|
# versions_project_id (project_id)
|
|
|
|
#
|
|
|
|
|
2020-03-09 00:40:16 +08:00
|
|
|
class Version < ApplicationRecord
|
2021-05-26 17:37:13 +08:00
|
|
|
belongs_to :project, counter_cache: true, touch: true
|
2020-03-09 00:40:16 +08:00
|
|
|
has_many :issues, class_name: "Issue", foreign_key: "fixed_version_id"
|
|
|
|
belongs_to :user, optional: true
|
|
|
|
|
2023-02-23 17:32:55 +08:00
|
|
|
has_many :opened_issues, -> {where(issue_classify: "issue").where.not(status_id: 5)}, class_name: "Issue", foreign_key: :fixed_version_id
|
|
|
|
has_many :closed_issues, -> {where(issue_classify: "issue", status_id: 5)}, class_name: "Issue", foreign_key: :fixed_version_id
|
2023-02-20 11:42:22 +08:00
|
|
|
|
2020-03-09 00:40:16 +08:00
|
|
|
scope :version_includes, ->{includes(:issues, :user)}
|
2021-06-11 14:11:44 +08:00
|
|
|
scope :closed, ->{where(status: 'closed')}
|
2021-06-16 09:49:08 +08:00
|
|
|
scope :opening, ->{where(status: 'open')}
|
2020-03-09 00:40:16 +08:00
|
|
|
|
|
|
|
# def open_issues_count
|
|
|
|
# issues.select(:id,:status_id).where(status_id: [1,2,3,4,6]).size
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
# def close_issues_count
|
|
|
|
# issues.select(:id,:status_id).where(status_id: 5).size
|
|
|
|
# end
|
|
|
|
|
2022-02-15 17:13:06 +08:00
|
|
|
after_create :send_create_message_to_notice_system
|
|
|
|
after_save :send_update_message_to_notice_system
|
|
|
|
|
2023-02-20 11:42:22 +08:00
|
|
|
def issue_percent
|
|
|
|
issues_total_count = opened_issues.size + closed_issues.size
|
|
|
|
issues_total_count.zero? ? 0.0 : closed_issues.size.to_f / issues_total_count
|
|
|
|
end
|
|
|
|
|
2020-03-09 00:40:16 +08:00
|
|
|
def version_user
|
|
|
|
User.select(:login, :lastname,:firstname, :nickname)&.find_by_id(self.user_id)
|
|
|
|
end
|
|
|
|
|
2023-03-29 18:49:20 +08:00
|
|
|
def to_builder
|
|
|
|
Jbuilder.new do |version|
|
|
|
|
version.(self, :id, :name, :description, :effective_date)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-02-15 17:13:06 +08:00
|
|
|
private
|
|
|
|
def send_create_message_to_notice_system
|
|
|
|
SendTemplateMessageJob.perform_later('ProjectMilestone', self.id, self.user_id) if Site.has_notice_menu?
|
|
|
|
end
|
|
|
|
|
|
|
|
def send_update_message_to_notice_system
|
2023-02-20 11:42:22 +08:00
|
|
|
SendTemplateMessageJob.perform_later('ProjectMilestoneCompleted', self.id) if Site.has_notice_menu? && self.issue_percent == 1.0
|
2022-02-15 17:13:06 +08:00
|
|
|
end
|
2020-03-09 00:40:16 +08:00
|
|
|
end
|