2012-01-30 20:39:34 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
2011-04-11 11:47:57 +01:00
|
|
|
class BuildList::Item < ActiveRecord::Base
|
2012-01-23 18:11:53 +00:00
|
|
|
|
2012-04-12 13:12:06 +01: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
|
|
|
|
|
2013-01-24 11:32:00 +00:00
|
|
|
STATUSES = [BuildList::SUCCESS, BuildList::DEPENDENCIES_ERROR, BuildList::BUILD_ERROR, BuildList::BUILD_STARTED, GIT_ERROR, BuildList::BUILD_CANCELED]
|
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,
|
2013-01-24 11:32:00 +00:00
|
|
|
BuildList::DEPENDENCIES_ERROR => :dependencies_error,
|
|
|
|
BuildList::SUCCESS => :success,
|
|
|
|
BuildList::BUILD_STARTED => :build_started,
|
|
|
|
BuildList::BUILD_ERROR => :build_error,
|
2012-12-06 16:28:44 +00:00
|
|
|
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
|
|
|
|
|
2011-04-22 17:13:47 +01:00
|
|
|
end
|