added platform cloning and system_wide flag

This commit is contained in:
Timothy N. Tsvetkov 2011-04-14 21:04:32 +04:00
parent 7944904ce9
commit 577cb2e126
9 changed files with 77 additions and 8 deletions

View File

@ -27,6 +27,14 @@ class ProductsController < ApplicationController
@product.build = DEFAULT_BUILD
end
def clone
@template = @platform.products.find(params[:id])
@product = @platform.products.new
@product.clone_from!(@template)
render :template => "products/new"
end
def edit
@product = @platform.products.find params[:id]
end

View File

@ -3,6 +3,8 @@ class Product < ActiveRecord::Base
BUILD_COMPLETED = 0
BUILD_FAILED = 1
ATTRS_TO_CLONE = [ 'build_path', 'build', 'build', 'counter', 'ks', 'menu', 'tar' ]
validates :name, :presence => true, :uniqueness => true
validates :platform_id, :presence => true
validates :build_status, :inclusion => { :in => [ NEVER_BUILT, BUILD_COMPLETED, BUILD_FAILED ] }
@ -26,6 +28,23 @@ class Product < ActiveRecord::Base
@delete_tar = value
end
def can_clone?
is_template?
end
def can_build?
!is_template?
end
def clone_from!(template)
attrs = ATTRS_TO_CLONE.inject({}) {|result, attr|
result[attr] = template.send(attr)
result
}
self.attributes = attrs
end
protected
def destroy_tar?

View File

@ -79,7 +79,7 @@
%td
= link_to product.name, edit_platform_product_path(@platform, product)
%td.last
#{link_to t("layout.show"), platform_product_path(@platform, product)} | #{link_to t("layout.delete"), platform_product_path(@platform, product), :method => :delete, :confirm => t("layout.products.confirm_delete")}
#{link_to t("layout.show"), platform_product_path(@platform, product)} | #{link_to t("layout.delete"), platform_product_path(@platform, product), :method => :delete, :confirm => t("layout.products.confirm_delete")} #{(product.can_clone? ? "| #{link_to t("layout.products.clone"), clone_platform_product_path(@platform, product)}" : "").html_safe }
.actions-bar.wat-cf
.actions
-#- content_for :sidebar do

View File

@ -22,6 +22,13 @@
= link_to @product.tar_file_name, @product.tar.url
= f.check_box :delete_tar
= f.label :delete_tar, t('layout.delete')
.group
= f.label :is_template, :class => :label
= f.check_box :is_template, :class => 'check_box'
.group
= f.label :system_wide, :class => :label
= f.check_box :system_wide, :class => 'check_box'
.group.navform.wat-cf
%button.button{:type => "submit"}

View File

@ -11,6 +11,21 @@
= t("activerecord.attributes.product.name")
\:
= @product.name
.wat-cf
= link_to image_tag("web-app-theme/icons/cross.png", :alt => t("layout.delete")) + " " + t("layout.delete"), platform_product_path(@platform, @product), :method => "delete", :class => "button", :confirm => t("layout.products.confirm_delete")
%p
%b
= t("activerecord.attributes.product.is_template")
\:
= t("layout.#{@product.is_template?}_")
%p
%b
= t("activerecord.attributes.product.system_wide")
\:
= t("layout.#{@product.system_wide?}_")
.wat-cf
= link_to image_tag("web-app-theme/icons/application_edit.png", :alt => t("layout.edit")) + " " + t("layout.edit"), edit_platform_product_path(@platform, @product), :class => "button"
= link_to image_tag("web-app-theme/icons/cross.png", :alt => t("layout.delete")) + " " + t("layout.delete"), platform_product_path(@platform, @product), :method => "delete", :class => "button", :confirm => t("layout.products.confirm_delete")
- if @product.can_clone?
= link_to t("layout.products.clone"), clone_platform_product_path(@platform, @product), :class => "button"

View File

@ -58,6 +58,7 @@ ru:
list: Список
new: Новый продукт
list_header: Продукты
clone: Клонировать
new_header: Новый продукт
edit_header: Редактирование продукта
confirm_delete: Вы уверены, что хотите удалить этот продукт?
@ -202,6 +203,8 @@ ru:
build: Содержимое build
menu: Содержимое .menu.xml
tar: Tar.gz файл
is_template: Темплейт
system_wide: Общесистемный
arch:
name: Название

View File

@ -7,7 +7,11 @@ Rosa::Application.routes.draw do
get 'unfreeze'
end
resources :products
resources :products do
member do
get :clone
end
end
resources :repositories do
resources :projects do

View File

@ -0,0 +1,11 @@
class AddTemplateColumnsToProducts < ActiveRecord::Migration
def self.up
add_column :products, :is_template, :boolean, :default => false
add_column :products, :system_wide, :boolean, :default => false
end
def self.down
remove_column :products, :is_template
remove_column :products, :system_wide
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20110412074038) do
ActiveRecord::Schema.define(:version => 20110414145300) do
create_table "arches", :force => true do |t|
t.string "name", :null => false
@ -83,9 +83,9 @@ ActiveRecord::Schema.define(:version => 20110412074038) do
end
create_table "products", :force => true do |t|
t.string "name", :null => false
t.integer "platform_id", :null => false
t.integer "build_status", :default => 2, :null => false
t.string "name", :null => false
t.integer "platform_id", :null => false
t.integer "build_status", :default => 2, :null => false
t.string "build_path"
t.datetime "created_at"
t.datetime "updated_at"
@ -97,6 +97,8 @@ ActiveRecord::Schema.define(:version => 20110412074038) do
t.string "tar_content_type"
t.integer "tar_file_size"
t.datetime "tar_updated_at"
t.boolean "is_template", :default => false
t.boolean "system_wide", :default => false
end
create_table "projects", :force => true do |t|