2011-04-11 11:47:57 +01:00
|
|
|
class BuildList::Item < ActiveRecord::Base
|
2014-01-21 04:51:49 +00:00
|
|
|
|
|
|
|
belongs_to :build_list, touch: true
|
2011-04-11 11:47:57 +01:00
|
|
|
|
|
|
|
attr_protected :build_list_id
|
|
|
|
|
2012-01-23 18:11:53 +00:00
|
|
|
GIT_ERROR = 5
|
2014-01-21 04:51:49 +00:00
|
|
|
|
2013-11-05 18:41:46 +00:00
|
|
|
STATUSES = [BuildList::SUCCESS, BuildList::BUILD_ERROR, BuildList::BUILD_STARTED, GIT_ERROR, BuildList::BUILD_CANCELED] # BuildList::DEPENDENCIES_ERROR
|
2011-04-11 11:47:57 +01:00
|
|
|
HUMAN_STATUSES = {
|
2011-04-22 17:13:47 +01:00
|
|
|
nil => :unknown,
|
2012-01-23 18:11:53 +00:00
|
|
|
GIT_ERROR => :git_error,
|
2014-01-21 04:51:49 +00:00
|
|
|
# BuildList:DEPENDENCIES_ERROR: :dependencies_error,
|
|
|
|
BuildList:SUCCESS: :success,
|
|
|
|
BuildList:BUILD_STARTED: :build_started,
|
|
|
|
BuildList:BUILD_ERROR: :build_error,
|
|
|
|
BuildList:BUILD_CANCELED: :build_canceled
|
2011-04-11 11:47:57 +01:00
|
|
|
}
|
|
|
|
|
2013-02-28 15:34:38 +00:00
|
|
|
scope :recent, order("#{table_name}.level ASC, #{table_name}.name ASC")
|
2011-04-11 11:47:57 +01:00
|
|
|
|
|
|
|
def self.group_by_level
|
|
|
|
items = scoped({}).recent
|
|
|
|
|
|
|
|
groups = []
|
|
|
|
current_level = -1
|
|
|
|
items.each do |item|
|
|
|
|
groups << [] if current_level < item.level
|
|
|
|
groups.last << item
|
|
|
|
current_level = item.level
|
|
|
|
end
|
|
|
|
|
|
|
|
groups
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.human_status(status)
|
|
|
|
I18n.t("layout.build_lists.items.statuses.#{HUMAN_STATUSES[status]}")
|
|
|
|
end
|
|
|
|
|
|
|
|
def human_status
|
|
|
|
self.class.human_status(status)
|
|
|
|
end
|
2014-01-21 04:51:49 +00:00
|
|
|
|
2011-04-22 17:13:47 +01:00
|
|
|
end
|