forgeplus/app/models/issue_status.rb

54 lines
1.3 KiB
Ruby

# == Schema Information
#
# Table name: issue_statuses
#
# id :integer not null, primary key
# name :string(30) default(""), not null
# is_closed :boolean default("0"), not null
# is_default :boolean default("0"), not null
# position :integer default("1")
# default_done_ratio :integer
#
# Indexes
#
# index_issue_statuses_on_is_closed (is_closed)
# index_issue_statuses_on_is_default (is_default)
# index_issue_statuses_on_position (position)
#
class IssueStatus < ApplicationRecord
ADD = 1
SOLVING = 2
SOLVED = 3
# FEEDBACK = 4
CLOSED = 5
REJECTED = 6
has_many :issues
belongs_to :project, optional: true
def self.init_data
map = {
"1" => "新增",
"2" => "正在解决",
"3" => "已解决",
"5" => "关闭",
"6" => "拒绝"
}
IssueStatus.order(id: :asc).each do |stat|
if map["#{stat.id}"] == stat.name
IssueStatus.find_or_create_by(id: stat.id, name: stat.name)
else
Issue.where(status_id: stat.id).each{|i| i.update_column(:status_id, 1)}
stat.destroy!
end
end
end
def to_builder
Jbuilder.new do |status|
status.(self, :id, :name)
end
end
end