rosa-build/app/controllers/products_controller.rb

94 lines
2.5 KiB
Ruby
Raw Normal View History

class ProductsController < ApplicationController
2011-04-22 15:22:44 +01:00
before_filter :authenticate_user!, :except => [:product_status]
2011-04-28 11:23:52 +01:00
before_filter :find_product, :only => [:show, :edit, :update, :build, :product_status, :destroy]
2011-04-28 11:26:10 +01:00
before_filter :find_platform, :except => [:product_status, :build]
2011-10-31 21:55:56 +00:00
before_filter :check_global_access, :only => [:new, :create]#:except => [:product_status]
2011-04-22 15:22:44 +01:00
def product_status
@product.build_status = params[:status] == "0" ? Product::BUILD_COMPLETED : Product::BUILD_FAILED
@product.save!
render :nothing => true, :status => 200
end
2011-04-11 17:55:52 +01:00
def new
@product = @platform.products.new
@product.ks = DEFAULT_KS
@product.menu = DEFAULT_MENU
@product.counter = DEFAULT_COUNTER
@product.build = DEFAULT_BUILD
end
def clone
2011-10-31 18:14:25 +00:00
can_perform? @platform if @platform
@template = @platform.products.find(params[:id])
@product = @platform.products.new
@product.clone_from!(@template)
render :template => "products/new"
end
2011-04-15 10:23:12 +01:00
def build
2011-10-31 18:14:25 +00:00
can_perform? @product if @product
2011-04-15 10:23:12 +01:00
flash[:notice] = t('flash.product.build_started')
2011-11-02 18:48:21 +00:00
ProductBuilder.create_product @product.id, @product.platform.unixname, @product.ks, @product.menu, @product.build, @product.counter, []
2011-04-15 10:23:12 +01:00
redirect_to :action => :show
end
2011-04-14 08:23:08 +01:00
def edit
2011-10-31 18:14:25 +00:00
can_perform? @product if @product
can_perform? @platform if @platform
2011-04-14 08:23:08 +01:00
end
2011-04-11 17:55:52 +01:00
def create
2011-10-31 18:14:25 +00:00
can_perform? @platform if @platform
2011-04-11 17:55:52 +01:00
@product = @platform.products.new params[:product]
if @product.save
2011-04-14 08:23:08 +01:00
flash[:notice] = t('flash.product.saved')
2011-04-11 17:55:52 +01:00
redirect_to @platform
else
2011-04-14 08:23:08 +01:00
flash[:error] = t('flash.product.save_error')
2011-04-11 17:55:52 +01:00
render :action => :new
end
end
2011-04-14 20:43:42 +01:00
def update
2011-10-31 18:14:25 +00:00
can_perform? @platform if @platform
can_perform? @product if @product
2011-04-14 20:43:42 +01:00
if @product.update_attributes(params[:product])
flash[:notice] = t('flash.product.saved')
redirect_to @platform
else
flash[:error] = t('flash.product.save_error')
render :action => "edit"
end
end
2011-04-14 08:23:08 +01:00
def show
2011-10-31 18:14:25 +00:00
can_perform? @platform if @platform
can_perform? @product if @product
2011-04-14 08:23:08 +01:00
end
2011-04-28 11:23:52 +01:00
def destroy
2011-10-31 18:14:25 +00:00
can_perform? @platform if @platform
can_perform? @product if @product
2011-04-28 11:23:52 +01:00
@product.destroy
flash[:notice] = t("flash.product.destroyed")
redirect_to @platform
end
protected
def find_product_by_name
@product = Product.find_by_name params[:product_name]
end
2011-04-11 17:55:52 +01:00
2011-04-14 20:43:42 +01:00
def find_product
@product = Product.find params[:id]
end
2011-04-11 17:55:52 +01:00
def find_platform
@platform = Platform.find params[:platform_id]
end
end