forgeplus/app/models/issue_priority.rb

59 lines
1.1 KiB
Ruby

# == Schema Information
#
# Table name: issue_priorities
#
# id :integer not null, primary key
# name :string(255)
# position :integer
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_issue_priorities_on_name (name)
#
class IssuePriority < ApplicationRecord
has_many :issues
def self.init_data
map = {
"1" => "",
"2" => "正常",
"3" => "",
"4" => "紧急"
}
IssuePriority.order(id: :asc).each do |prty|
if map["#{prty.id}"] == prty.name
IssuePriority.find_or_create_by(id: prty.id, name: prty.name)
else
Issue.where(priority_id: prty.id).each{|i| i.update_column(:priority_id, 2)}
prty.destroy!
end
end
end
def to_builder
Jbuilder.new do |priority|
priority.(self, :id, :name)
end
end
def pm_color
case name
when '低'
'#008043'
when '正常'
'#0D5EF8'
when '高'
'#DA965D'
when '紧急'
'#C90713'
# when '立刻'
# '#f5222d'
else
'#C90713'
end
end
end