diff --git a/app/assets/stylesheets/design/custom.scss b/app/assets/stylesheets/design/custom.scss index 7d5e43824..13a978cea 100644 --- a/app/assets/stylesheets/design/custom.scss +++ b/app/assets/stylesheets/design/custom.scss @@ -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; +} \ No newline at end of file diff --git a/app/controllers/platforms/platforms_controller.rb b/app/controllers/platforms/platforms_controller.rb index 57ea23f7c..5cca06898 100644 --- a/app/controllers/platforms/platforms_controller.rb +++ b/app/controllers/platforms/platforms_controller.rb @@ -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 diff --git a/app/helpers/platforms_helper.rb b/app/helpers/platforms_helper.rb index 4ad7df6ac..46778d4c6 100644 --- a/app/helpers/platforms_helper.rb +++ b/app/helpers/platforms_helper.rb @@ -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 diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 4244a96d8..be204b05c 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -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, diff --git a/app/models/platform.rb b/app/models/platform.rb index e83cb931b..d365287ad 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -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 diff --git a/app/models/platform_arch_setting.rb b/app/models/platform_arch_setting.rb new file mode 100644 index 000000000..c14bde843 --- /dev/null +++ b/app/models/platform_arch_setting.rb @@ -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 diff --git a/app/views/platforms/platforms/_form.html.haml b/app/views/platforms/platforms/_form.html.haml index 4508e03b6..bd8afceb0 100644 --- a/app/views/platforms/platforms/_form.html.haml +++ b/app/views/platforms/platforms/_form.html.haml @@ -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"} diff --git a/config/locales/models/platform_arch_settings.en.yml b/config/locales/models/platform_arch_settings.en.yml new file mode 100644 index 000000000..9dab1d1ec --- /dev/null +++ b/config/locales/models/platform_arch_settings.en.yml @@ -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) diff --git a/config/locales/models/platform_arch_settings.ru.yml b/config/locales/models/platform_arch_settings.ru.yml new file mode 100644 index 000000000..c7ef8455a --- /dev/null +++ b/config/locales/models/platform_arch_settings.ru.yml @@ -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: Максимальное время сборки (в минутах) diff --git a/config/locales/models/time_living.en.yml b/config/locales/models/time_living.en.yml index c7c4cd11f..0659b4b91 100644 --- a/config/locales/models/time_living.en.yml +++ b/config/locales/models/time_living.en.yml @@ -1,4 +1,4 @@ en: flash: time_living: - numericality_error: must be 2 to 720 minutes \ No newline at end of file + numericality_error: must be %{min} to %{max} minutes \ No newline at end of file diff --git a/config/locales/models/time_living.ru.yml b/config/locales/models/time_living.ru.yml index ea0ef50b2..e8600ca10 100644 --- a/config/locales/models/time_living.ru.yml +++ b/config/locales/models/time_living.ru.yml @@ -1,4 +1,4 @@ ru: flash: time_living: - numericality_error: должно быть от 2 до 720 минут \ No newline at end of file + numericality_error: должно быть от %{min} до %{max} минут \ No newline at end of file diff --git a/db/migrate/20130724105821_create_platform_arch_settings.rb b/db/migrate/20130724105821_create_platform_arch_settings.rb new file mode 100644 index 000000000..12b749e24 --- /dev/null +++ b/db/migrate/20130724105821_create_platform_arch_settings.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index f67c81e51..b1cd1d2d7 100644 --- a/db/schema.rb +++ b/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 diff --git a/lib/modules/models/time_living.rb b/lib/modules/models/time_living.rb index 81ec89dd3..81969561e 100644 --- a/lib/modules/models/time_living.rb +++ b/lib/modules/models/time_living.rb @@ -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 }