#31: add 'autostart' field to Product model

This commit is contained in:
Vokhmin Alexey V 2013-03-22 18:06:13 +04:00
parent 96698b4195
commit 6a9e270a5c
7 changed files with 107 additions and 63 deletions

View File

@ -6,9 +6,21 @@ class Product < ActiveRecord::Base
belongs_to :project
has_many :product_build_lists, :dependent => :destroy
ONCE_A_12_HOURS = 0
ONCE_A_DAY = 1
ONCE_A_WEEK = 2
AUTOSTART_STATUSES = [ONCE_A_12_HOURS, ONCE_A_DAY, ONCE_A_WEEK]
HUMAN_AUTOSTART_STATUSES = {
ONCE_A_12_HOURS => :once_a_12_hours,
ONCE_A_DAY => :once_a_day,
ONCE_A_WEEK => :once_a_week
}
validates :name, :presence => true, :uniqueness => {:scope => :platform_id}
validates :project_id, :presence => true
validates :main_script, :params, :length => { :maximum => 255 }
validates :autostart, :numericality => true, :inclusion => {:in => AUTOSTART_STATUSES}, :allow_blank => true
scope :recent, order("#{table_name}.name ASC")
@ -17,7 +29,8 @@ class Product < ActiveRecord::Base
:project_id,
:main_script,
:params,
:platform_id
:platform_id,
:autostart
attr_readonly :platform_id
def full_clone(attrs = {})
@ -30,4 +43,12 @@ class Product < ActiveRecord::Base
end
end
def human_status
self.class.human_status(status)
end
def self.human_status(status)
I18n.t("layout.products.autostart_statuses.#{HUMAN_AUTOSTART_STATUSES[status]}")
end
end

View File

@ -53,7 +53,8 @@ class ProductBuildList < ActiveRecord::Base
:project_version,
:commit_hash,
:arch_id,
:product_id
:product_id,
:not_delete
attr_readonly :product_id
serialize :results, Array

View File

@ -1,17 +1,21 @@
.leftlist= f.label :name, t("activerecord.attributes.product.name"), :class => :label
.leftlist= f.label :name
.rightlist= f.text_field :name, :class => 'text_field'
.both
.leftlist= f.label :description, t("activerecord.attributes.product.description"), :class => :label
.leftlist= f.label :description
.rightlist= f.text_area :description, :class => 'text_field resizable', :cols => 80
.both
.leftlist= f.label :project, t("activerecord.attributes.product.project"), :class => :label
.leftlist= f.label :project
.rightlist= f.autocomplete_field :project, autocomplete_project_platform_products_path(@platform), :id_element => 'src_project_id', :name => 'src_project', :value => @product.project.try(:name_with_owner)
.both
= render 'def_fields', :f => f
.leftlist= f.label :autostart
.rightlist= f.select :autostart, Product::AUTOSTART_STATUSES.collect{|status| [Product.human_status(status), status]}, {:include_blank => true, :selected => @product.autostart}
.both
.button_block
= submit_tag t("layout.save")
%span.text_button_padding= t("layout.or")

View File

@ -11,6 +11,10 @@ en:
new_header: New product
edit_header: Product editing
confirm_delete: Are you sure you want to delete this product?
autostart_statuses:
once_a_12_hours: Once a 12 hours
once_a_day: Once a day
once_a_week: Once a week
flash:
product:
@ -25,6 +29,7 @@ en:
product: Product
attributes:
product:
autostart: Autostart
name: Name
description: Description
platform_id: Platform

View File

@ -11,6 +11,10 @@ ru:
new_header: Новый продукт
edit_header: Редактирование продукта
confirm_delete: Вы уверены, что хотите удалить этот продукт?
autostart_statuses:
once_a_12_hours: Раз в 12 часов
once_a_day: Раз в день
once_a_week: Раз в неделю
flash:
product:
@ -25,6 +29,7 @@ ru:
product: Продукт
attributes:
product:
autostart: Автостарт
name: Название
description: Описание
platform_id: Платформа

View File

@ -0,0 +1,6 @@
class AddAutostartAndNotDeleteToProductAndProductBuildList < ActiveRecord::Migration
def change
add_column :products, :autostart, :integer, :default => nil
add_column :product_build_lists, :not_delete, :boolean, :default => false
end
end

View File

@ -11,14 +11,14 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20130227102900) do
ActiveRecord::Schema.define(:version => 20130322132919) do
create_table "activity_feeds", :force => true do |t|
t.integer "user_id", :null => false
t.string "kind"
t.text "data"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "advisories", :force => true do |t|
@ -53,8 +53,8 @@ ActiveRecord::Schema.define(:version => 20130227102900) do
create_table "arches", :force => true do |t|
t.string "name", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "arches", ["name"], :name => "index_arches_on_name", :unique => true
@ -63,8 +63,8 @@ ActiveRecord::Schema.define(:version => 20130227102900) do
t.integer "user_id"
t.string "provider"
t.string "uid"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "authentications", ["provider", "uid"], :name => "index_authentications_on_provider_and_uid", :unique => true
@ -75,8 +75,8 @@ ActiveRecord::Schema.define(:version => 20130227102900) do
t.integer "level"
t.integer "status"
t.integer "build_list_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.string "version"
end
@ -110,8 +110,8 @@ ActiveRecord::Schema.define(:version => 20130227102900) do
t.integer "project_id"
t.integer "arch_id"
t.datetime "notified_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.boolean "is_circle", :default => false
t.text "additional_repos"
t.string "name"
@ -149,8 +149,8 @@ ActiveRecord::Schema.define(:version => 20130227102900) do
t.string "commentable_type"
t.integer "user_id"
t.text "body"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.decimal "commentable_id", :precision => 50, :scale => 0
t.integer "project_id"
t.text "data"
@ -168,8 +168,8 @@ ActiveRecord::Schema.define(:version => 20130227102900) do
t.string "controller"
t.string "action"
t.text "message"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "flash_notifies", :force => true do |t|
@ -183,8 +183,8 @@ ActiveRecord::Schema.define(:version => 20130227102900) do
create_table "groups", :force => true do |t|
t.integer "owner_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.string "uname"
t.integer "own_projects_count", :default => 0, :null => false
t.text "description"
@ -201,8 +201,8 @@ ActiveRecord::Schema.define(:version => 20130227102900) do
t.string "title"
t.text "body"
t.string "status", :default => "open"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.integer "user_id"
t.datetime "closed_at"
t.integer "closed_by"
@ -279,14 +279,14 @@ ActiveRecord::Schema.define(:version => 20130227102900) do
t.string "description"
t.string "name", :null => false
t.integer "parent_platform_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.boolean "released", :default => false, :null => false
t.integer "owner_id"
t.string "owner_type"
t.string "visibility", :default => "open", :null => false
t.string "platform_type", :default => "main", :null => false
t.string "distrib_type"
t.string "distrib_type", :null => false
end
add_index "platforms", ["name"], :name => "index_platforms_on_name", :unique => true, :case_sensitive => false
@ -295,16 +295,16 @@ ActiveRecord::Schema.define(:version => 20130227102900) do
t.integer "platform_id"
t.string "login"
t.string "password"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.integer "user_id"
end
create_table "product_build_lists", :force => true do |t|
t.integer "product_id"
t.integer "status", :default => 3, :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "status", :default => 2, :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.integer "project_id"
t.string "project_version"
t.string "commit_hash"
@ -314,6 +314,7 @@ ActiveRecord::Schema.define(:version => 20130227102900) do
t.integer "arch_id"
t.integer "time_living"
t.integer "user_id"
t.boolean "not_delete", :default => false
end
add_index "product_build_lists", ["product_id"], :name => "index_product_build_lists_on_product_id"
@ -321,13 +322,14 @@ ActiveRecord::Schema.define(:version => 20130227102900) do
create_table "products", :force => true do |t|
t.string "name", :null => false
t.integer "platform_id", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.text "description"
t.integer "project_id"
t.string "params"
t.string "main_script"
t.integer "time_living"
t.integer "autostart"
end
create_table "project_imports", :force => true do |t|
@ -335,8 +337,8 @@ ActiveRecord::Schema.define(:version => 20130227102900) do
t.string "name"
t.string "version"
t.datetime "file_mtime"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.integer "platform_id"
end
@ -355,27 +357,27 @@ ActiveRecord::Schema.define(:version => 20130227102900) do
create_table "project_to_repositories", :force => true do |t|
t.integer "project_id"
t.integer "repository_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "project_to_repositories", ["repository_id", "project_id"], :name => "index_project_to_repositories_on_repository_id_and_project_id", :unique => true
create_table "projects", :force => true do |t|
t.string "name"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.integer "owner_id"
t.string "owner_type"
t.string "visibility", :default => "open"
t.text "description"
t.string "ancestry"
t.boolean "has_issues", :default => true
t.boolean "has_wiki", :default => false
t.string "srpm_file_name"
t.string "srpm_content_type"
t.integer "srpm_file_size"
t.datetime "srpm_updated_at"
t.string "srpm_content_type"
t.boolean "has_wiki", :default => false
t.string "default_branch", :default => "master"
t.boolean "is_package", :default => true, :null => false
t.integer "average_build_time", :default => 0, :null => false
@ -406,8 +408,8 @@ ActiveRecord::Schema.define(:version => 20130227102900) do
t.string "token"
t.boolean "approved", :default => false
t.boolean "rejected", :default => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.string "interest"
t.text "more"
t.string "language"
@ -421,16 +423,16 @@ ActiveRecord::Schema.define(:version => 20130227102900) do
t.string "actor_type"
t.integer "target_id"
t.string "target_type"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.string "role"
end
create_table "repositories", :force => true do |t|
t.string "description", :null => false
t.integer "platform_id", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.string "name", :null => false
t.boolean "publish_without_qa", :default => true
end
@ -444,8 +446,8 @@ ActiveRecord::Schema.define(:version => 20130227102900) do
t.boolean "new_comment_reply", :default => true
t.boolean "new_issue", :default => true
t.boolean "issue_assign", :default => true
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.boolean "new_comment_commit_owner", :default => true
t.boolean "new_comment_commit_repo_owner", :default => true
t.boolean "new_comment_commit_commentor", :default => true
@ -468,8 +470,8 @@ ActiveRecord::Schema.define(:version => 20130227102900) do
create_table "subscribes", :force => true do |t|
t.string "subscribeable_type"
t.integer "user_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.boolean "status", :default => true
t.integer "project_id"
t.decimal "subscribeable_id", :precision => 50, :scale => 0
@ -477,21 +479,18 @@ ActiveRecord::Schema.define(:version => 20130227102900) do
create_table "users", :force => true do |t|
t.string "name"
t.string "email", :default => "", :null => false
t.string "encrypted_password", :default => "", :null => false
t.string "email", :default => "", :null => false
t.string "encrypted_password", :limit => 128, :default => "", :null => false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.text "ssh_key"
t.string "uname"
t.string "role"
t.string "language", :default => "en"
t.integer "own_projects_count", :default => 0, :null => false
t.string "confirmation_token"
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.string "language", :default => "en"
t.integer "own_projects_count", :default => 0, :null => false
t.text "professional_experience"
t.string "site"
t.string "company"
@ -500,11 +499,14 @@ ActiveRecord::Schema.define(:version => 20130227102900) do
t.string "avatar_content_type"
t.integer "avatar_file_size"
t.datetime "avatar_updated_at"
t.integer "failed_attempts", :default => 0
t.integer "failed_attempts", :default => 0
t.string "unlock_token"
t.datetime "locked_at"
t.string "confirmation_token"
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.string "authentication_token"
t.integer "build_priority", :default => 50
t.integer "build_priority", :default => 50
end
add_index "users", ["authentication_token"], :name => "index_users_on_authentication_token"