Product management. Step 2

This commit is contained in:
Alexey Nayden 2011-04-14 11:23:08 +04:00
parent 73f7d4c0dd
commit 856b93d3d8
15 changed files with 96 additions and 11 deletions

View File

@ -51,5 +51,6 @@ gem "russian"
gem "grit"
gem 'unicorn'
gem 'delayed_job'
gem 'paperclip', "~> 2.3"
gem 'jammit'

View File

@ -88,6 +88,9 @@ GEM
net-ssh (2.1.3)
net-ssh-gateway (1.0.1)
net-ssh (>= 1.99.1)
paperclip (2.3.8)
activerecord
activesupport
pg (0.10.1)
polyglot (0.3.1)
rack (1.2.1)
@ -155,6 +158,7 @@ DEPENDENCIES
hoptoad_notifier (~> 2.3)
hpricot
jammit
paperclip (~> 2.3)
pg
rails (= 3.0.5)
rspec-rails (>= 2.0.1)

View File

@ -27,17 +27,25 @@ class ProductsController < ApplicationController
@product.build = DEFAULT_BUILD
end
def edit
@product = @platform.products.find params[:id]
end
def create
@product = @platform.products.new params[:product]
if @product.save
flash[:notice] = ''
flash[:notice] = t('flash.product.saved')
redirect_to @platform
else
flash[:error] = ''
flash[:error] = t('flash.product.save_error')
render :action => :new
end
end
def show
@product = Product.find params[:id]
end
protected
def find_product_by_name

View File

@ -9,5 +9,17 @@ class Product < ActiveRecord::Base
belongs_to :platform
has_attached_file :tar
validates_attachment_content_type :tar, :content_type => ["application/gnutar", "application/x-compressed", "application/x-gzip"], :message => I18n.t('layout.products.invalid_content_type')
after_validation :merge_tar_errors
scope :recent, order("name ASC")
protected
def merge_tar_errors
errors[:tar] += errors[:tar_content_type]
errors[:tar_content_type] = []
end
end

View File

@ -77,7 +77,7 @@
- @platform.products.recent.each do |product|
%tr{:class => cycle("odd", "even")}
%td
= link_to product.name, platform_product_path(@platform, product)
= 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")}
.actions-bar.wat-cf

View File

@ -13,6 +13,9 @@
.group
= f.label :menu, t("activerecord.attributes.product.menu"), :class => :label
= f.text_area :menu, :class => 'text_field', :cols => 80
.group
= f.label :tar, t("activerecord.attributes.product.tar"), :class => :label
= f.file_field :tar, :class => 'file_field'
.group.navform.wat-cf
%button.button{:type => "submit"}

View File

@ -0,0 +1,12 @@
.block
.secondary-navigation
%ul.wat-cf
%li.first= link_to @platform.name, platform_path(@platform) + "#products"
%li.active= link_to @product.name, edit_platform_product_path(@platform, @product)
.content
%h2.title= t("layout.products.edit_header")
.inner
= form_for [@platform, @product], :html => { :class => :form, :multipart => true } do |f|
= render :partial => "form", :locals => {:f => f}
-#- content_for :sidebar, render(:partial => 'sidebar')

View File

@ -6,7 +6,7 @@
.content
%h2.title= t("layout.products.new_header")
.inner
= form_for [@platform, @product], :html => { :class => :form } do |f|
= form_for [@platform, @product], :html => { :class => :form, :multipart => true } do |f|
= render :partial => "form", :locals => {:f => f}
-#- content_for :sidebar, render(:partial => 'sidebar')

View File

@ -0,0 +1,16 @@
.block
.secondary-navigation
%ul.wat-cf
%li.first= link_to @platform.name, platform_path(@platform) + "#products"
%li.active= link_to @product.name, platform_product_path(@platform, @product)
.content
.inner
%p
%b
= 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")

View File

@ -59,7 +59,9 @@ ru:
new: Новый продукт
list_header: Продукты
new_header: Новый продукт
edit_header: Редактирование продукта
confirm_delete: Вы уверены, что хотите удалить этот продукт?
invalid_content_type: имеет неверный тип
projects:
list: Список
list_header: Проекты
@ -138,6 +140,9 @@ ru:
saved: Репозиторий успешно добавлен
save_error: Не удалось добавить репозиторий
destroyed: Репозиторий успешно удален
product:
saved: Продукт успешно сохранен
save_error: Не удалось сохранить изменения
platform:
saved: Платформа успешно добавлена
saved_error: Не удалось создать платформу
@ -196,6 +201,7 @@ ru:
counter: Содержимое .counter
build: Содержимое build
menu: Содержимое .menu.xml
tar: Tar.gz файл
arch:
name: Название

View File

@ -0,0 +1,15 @@
class AddAttachmentTarToProduct < ActiveRecord::Migration
def self.up
add_column :products, :tar_file_name, :string
add_column :products, :tar_content_type, :string
add_column :products, :tar_file_size, :integer
add_column :products, :tar_updated_at, :datetime
end
def self.down
remove_column :products, :tar_file_name
remove_column :products, :tar_content_type
remove_column :products, :tar_file_size
remove_column :products, :tar_updated_at
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 => 20110411160955) do
ActiveRecord::Schema.define(:version => 20110412074038) do
create_table "arches", :force => true do |t|
t.string "name", :null => false
@ -93,6 +93,10 @@ ActiveRecord::Schema.define(:version => 20110411160955) do
t.text "counter"
t.text "ks"
t.text "menu"
t.string "tar_file_name"
t.string "tar_content_type"
t.integer "tar_file_size"
t.datetime "tar_updated_at"
end
create_table "projects", :force => true do |t|

View File

@ -15,12 +15,16 @@ class BuildServer
SRPM_NOT_FOUND = 12800
def self.client
@@client ||= XMLRPC::Client.new3(:host => APP_CONFIG['build_server_ip'], :port => APP_CONFIG['build_server_port'], :path => APP_CONFIG['build_server_path'])
Rails.logger.info "Client called"
@@client ||= XMLRPC::Client.new3('host' => APP_CONFIG['build_server_ip'], 'port' => APP_CONFIG['build_server_port'], 'path' => APP_CONFIG['build_server_path'])
Rails.logger.info "Client finished"
end
def self.add_platform name, root_folder, repos = [], git_path = nil
Rails.logger.info "add_platform start"
self.client.call('add_platform', name, git_path, root_folder, repos)
Rails.logger.info "add_platform ok"
end

View File

@ -1 +1 @@
/* Override here any style defined by web-app-theme */
/* Override here any style defined by web-app-theme */ .form input.file_field:hover { -webkit-box-shadow: rgba(0,0,0,0.0) 0 0 0px; -moz-box-shadow: rgba(0,0,0,0.0) 0 0 0px; box-shadow: 0 0 0px rgba(0, 0, 0, 0.0); border: 0px solid #a2a294; }

Binary file not shown.