#231: added PlatformArchSetting model, migration, updated views
This commit is contained in:
parent
a1bce13193
commit
d0e748cce0
|
@ -2062,3 +2062,13 @@ a.button.reject_publish, a.button.create_container {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
.rightlist > div.rightlist {
|
||||
width: 150px;
|
||||
input[type="text"] {
|
||||
width: 150px;
|
||||
}
|
||||
}
|
||||
.rightlist > .leftlist {
|
||||
width: 200px;
|
||||
}
|
|
@ -42,11 +42,11 @@ class Platforms::PlatformsController < Platforms::BaseController
|
|||
@admin_id = params[:admin_id]
|
||||
@admin_uname = params[:admin_uname]
|
||||
|
||||
if @platform.update_attributes(
|
||||
:owner => @admin_id.blank? ? get_owner : User.find(@admin_id),
|
||||
:description => params[:platform][:description],
|
||||
:released => (params[:platform][:released] || @platform.released)
|
||||
)
|
||||
platform_params = params[:platform] || {}
|
||||
platform_params = platform_params.slice(:description, :platform_arch_settings_attributes, :released)
|
||||
platform_params[:owner] = User.find(@admin_id) if @admin_id.present?
|
||||
|
||||
if @platform.update_attributes(platform_params)
|
||||
flash[:notice] = I18n.t("flash.platform.saved")
|
||||
redirect_to @platform
|
||||
else
|
||||
|
|
|
@ -10,4 +10,15 @@ module PlatformsHelper
|
|||
platform.released? ? "#{platform.name} #{I18n.t("layout.platforms.released_suffix")}" : platform.name
|
||||
end
|
||||
|
||||
def platform_arch_settings(platform)
|
||||
settings = platform.platform_arch_settings
|
||||
settings |= Arch.where('id not in (?)', settings.pluck(:arch_id)).map do |arch|
|
||||
platform.platform_arch_settings.build(
|
||||
:arch_id => arch.id,
|
||||
:time_living => PlatformArchSetting::DEFAULT_TIME_LIVING
|
||||
)
|
||||
end
|
||||
settings.sort_by{ |s| s.arch.name }
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -413,7 +413,8 @@ class BuildList < ActiveRecord::Base
|
|||
{
|
||||
:id => id,
|
||||
:arch => arch.name,
|
||||
:time_living => 43200, # 12 hours
|
||||
# :time_living => 43200, # 12 hours
|
||||
:time_living => (build_for_platform.platform_arch_settings.by_arch(arch).time_living.first || PlatformArchSetting::DEFAULT_TIME_LIVING),
|
||||
:distrib_type => build_for_platform.distrib_type,
|
||||
:git_project_address => git_project_address,
|
||||
:commit_hash => commit_hash,
|
||||
|
|
|
@ -8,7 +8,8 @@ class Platform < ActiveRecord::Base
|
|||
|
||||
has_many :repositories, :dependent => :destroy
|
||||
has_many :products, :dependent => :destroy
|
||||
has_many :tokens, :as => :subject, :dependent => :destroy
|
||||
has_many :tokens, :as => :subject, :dependent => :destroy
|
||||
has_many :platform_arch_settings, :dependent => :destroy
|
||||
|
||||
has_many :relations, :as => :target, :dependent => :destroy
|
||||
has_many :actors, :as => :target, :class_name => 'Relation', :dependent => :destroy
|
||||
|
@ -53,7 +54,8 @@ class Platform < ActiveRecord::Base
|
|||
scope :main, by_type('main')
|
||||
scope :personal, by_type('personal')
|
||||
|
||||
attr_accessible :name, :distrib_type, :parent_platform_id, :platform_type, :owner, :visibility, :description, :released
|
||||
accepts_nested_attributes_for :platform_arch_settings, :allow_destroy => true
|
||||
attr_accessible :name, :distrib_type, :parent_platform_id, :platform_type, :owner, :visibility, :description, :released, :platform_arch_settings_attributes
|
||||
attr_readonly :name, :distrib_type, :parent_platform_id, :platform_type
|
||||
|
||||
include Modules::Models::Owner
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
class PlatformArchSetting < ActiveRecord::Base
|
||||
DEFAULT_TIME_LIVING = 43200 # seconds, 12 hours
|
||||
MIN_TIME_LIVING = 600 # seconds, 10 minutes
|
||||
MAX_TIME_LIVING = 172800 # seconds, 48 hours
|
||||
include Modules::Models::TimeLiving
|
||||
|
||||
belongs_to :arch
|
||||
belongs_to :platform
|
||||
|
||||
validates :arch_id, :platform_id, :presence => true
|
||||
validates :platform_id, :uniqueness => {:scope => :arch_id}
|
||||
|
||||
scope :by_arch, lambda {|arch| where(:arch_id => arch) if arch.present?}
|
||||
|
||||
attr_accessible :arch_id, :platform_id, :default
|
||||
|
||||
end
|
|
@ -26,6 +26,24 @@
|
|||
= hidden_field_tag 'admin_id', @admin_id, :id => 'admin_id_field'
|
||||
.both
|
||||
|
||||
%h3= t('layout.platform_arch_settings.extra_settings')
|
||||
|
||||
- platform_arch_settings(@platform).each do |setting|
|
||||
.leftlist
|
||||
%h4= setting.arch.name
|
||||
.rightlist
|
||||
= f.fields_for :platform_arch_settings, setting do |s_form|
|
||||
= s_form.hidden_field :arch_id
|
||||
.leftlist= s_form.label :default, :class => :label
|
||||
.rightlist= s_form.check_box :default, :class => 'check_box'
|
||||
.both
|
||||
.leftlist= s_form.label :time_living, :class => :label
|
||||
.rightlist= s_form.text_field :time_living, :value => setting.time_living / 60, :class => 'text_field'
|
||||
.both
|
||||
.both
|
||||
|
||||
|
||||
|
||||
.button_block
|
||||
= submit_tag t("layout.save")
|
||||
-#%input.button{:type => "submit", :class => "button"}
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
en:
|
||||
layout:
|
||||
platform_arch_settings:
|
||||
extra_settings: Extra settings
|
||||
|
||||
flash:
|
||||
platform_arch_settings:
|
||||
|
||||
activerecord:
|
||||
attributes:
|
||||
platform_arch_setting:
|
||||
default: Use by default
|
||||
time_living: Max time build (in minutes)
|
|
@ -0,0 +1,15 @@
|
|||
ru:
|
||||
layout:
|
||||
platform_arch_settings:
|
||||
extra_settings: Дополнительные настройки
|
||||
|
||||
flash:
|
||||
platform_arch_settings:
|
||||
|
||||
activerecord:
|
||||
models:
|
||||
platform_arch_setting: Arch
|
||||
attributes:
|
||||
platform_arch_setting:
|
||||
default: Использовать по умолчанию
|
||||
time_living: Максимальное время сборки (в минутах)
|
|
@ -1,4 +1,4 @@
|
|||
en:
|
||||
flash:
|
||||
time_living:
|
||||
numericality_error: must be 2 to 720 minutes
|
||||
numericality_error: must be %{min} to %{max} minutes
|
|
@ -1,4 +1,4 @@
|
|||
ru:
|
||||
flash:
|
||||
time_living:
|
||||
numericality_error: должно быть от 2 до 720 минут
|
||||
numericality_error: должно быть от %{min} до %{max} минут
|
|
@ -0,0 +1,30 @@
|
|||
class CreatePlatformArchSettings < ActiveRecord::Migration
|
||||
|
||||
def up
|
||||
create_table :platform_arch_settings do |t|
|
||||
t.integer :platform_id, :null => false
|
||||
t.integer :arch_id, :null => false
|
||||
t.integer :time_living, :null => false
|
||||
t.boolean :default
|
||||
t.timestamps
|
||||
end
|
||||
add_index :platform_arch_settings, [:platform_id, :arch_id], :unique => true
|
||||
|
||||
arch_ids = Arch.where(:name => %w(i586 x86_64)).pluck(:id)
|
||||
Platform.main.each do |platform|
|
||||
arch_ids.each do |arch_id|
|
||||
platform.platform_arch_settings.create(
|
||||
:arch_id => arch_id,
|
||||
:default => true,
|
||||
:time_living => PlatformArchSetting::DEFAULT_TIME_LIVING / 60
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def down
|
||||
remove_index :platform_arch_settings, :column => [:platform_id, :arch_id]
|
||||
drop_table :platform_arch_settings
|
||||
end
|
||||
end
|
13
db/schema.rb
13
db/schema.rb
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20130717112337) do
|
||||
ActiveRecord::Schema.define(:version => 20130724105821) do
|
||||
|
||||
create_table "activity_feeds", :force => true do |t|
|
||||
t.integer "user_id", :null => false
|
||||
|
@ -294,6 +294,17 @@ ActiveRecord::Schema.define(:version => 20130717112337) do
|
|||
t.text "extra_build_lists"
|
||||
end
|
||||
|
||||
create_table "platform_arch_settings", :force => true do |t|
|
||||
t.integer "platform_id", :null => false
|
||||
t.integer "arch_id", :null => false
|
||||
t.integer "time_living", :null => false
|
||||
t.boolean "default"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
add_index "platform_arch_settings", ["platform_id", "arch_id"], :name => "index_platform_arch_settings_on_platform_id_and_arch_id", :unique => true
|
||||
|
||||
create_table "platforms", :force => true do |t|
|
||||
t.string "description"
|
||||
t.string "name", :null => false
|
||||
|
|
|
@ -11,9 +11,16 @@ module Modules
|
|||
}, :presence => true
|
||||
|
||||
validate lambda {
|
||||
# MIN_TIME_LIVING <= time_living <= MAX_TIME_LIVING or
|
||||
# 2 min <= time_living <= 12 hours
|
||||
if 120 > time_living.to_i || time_living.to_i > 43200
|
||||
errors.add(:time_living, I18n.t('flash.time_living.numericality_error'))
|
||||
# time_living in seconds
|
||||
min = self.class.const_defined?(:MIN_TIME_LIVING) ? self.class::MIN_TIME_LIVING : 120
|
||||
max = self.class.const_defined?(:MAX_TIME_LIVING) ? self.class::MAX_TIME_LIVING : 43200
|
||||
if min > time_living.to_i || time_living.to_i > max
|
||||
errors.add :time_living, I18n.t('flash.time_living.numericality_error',
|
||||
:min => (min / 60),
|
||||
:max => (max / 60)
|
||||
)
|
||||
end
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue