Merge pull request #61 from abf/rosa-build:31-add-project_version-into-product

#31: Add project_version into Product
This commit is contained in:
avm 2013-03-27 21:37:38 +04:00
commit 6a264e0b81
13 changed files with 47 additions and 11 deletions

View File

@ -0,0 +1,14 @@
$(document).ready(function() {
$('#product_project').bind('railsAutocomplete.select', function(event, data){
var ppv = $("#product_project_version").empty().append('<option value=""></option>');
$(data.item.project_versions).each(function(k, i) {
var optgroup = $('<optgroup label="' + i[0] + '"></optgroup>');
$(i[1]).each(function(k, b) {
optgroup.append('<option value="' + b + '">' + b + '</option>');
});
ppv.append(optgroup);
});
});
});

View File

@ -1,5 +1,6 @@
# -*- encoding : utf-8 -*- # -*- encoding : utf-8 -*-
class Platforms::ProductsController < Platforms::BaseController class Platforms::ProductsController < Platforms::BaseController
include GitHelper
before_filter :authenticate_user! before_filter :authenticate_user!
skip_before_filter :authenticate_user!, :only => [:index, :show] if APP_CONFIG['anonymous_access'] skip_before_filter :authenticate_user!, :only => [:index, :show] if APP_CONFIG['anonymous_access']
@ -55,7 +56,12 @@ class Platforms::ProductsController < Platforms::BaseController
search(params[:term]).search_order search(params[:term]).search_order
items.select! {|e| e.repo.branches.count > 0} items.select! {|e| e.repo.branches.count > 0}
render :json => items.map{ |p| render :json => items.map{ |p|
{:id => p.id, :label => p.name_with_owner, :value => p.name_with_owner} {
:id => p.id,
:label => p.name_with_owner,
:value => p.name_with_owner,
:project_versions => versions_for_group_select(p)
}
} }
end end

View File

@ -68,6 +68,7 @@ module GitHelper
end end
def versions_for_group_select(project) def versions_for_group_select(project)
return [] unless project
[ ['Branches', project.repo.branches.map(&:name)], [ ['Branches', project.repo.branches.map(&:name)],
['Tags', project.repo.tags.map(&:name)] ] ['Tags', project.repo.tags.map(&:name)] ]
end end

View File

@ -31,7 +31,8 @@ class Product < ActiveRecord::Base
:main_script, :main_script,
:params, :params,
:platform_id, :platform_id,
:autostart_status :autostart_status,
:project_version
attr_readonly :platform_id attr_readonly :platform_id
def full_clone(attrs = {}) def full_clone(attrs = {})
@ -63,7 +64,7 @@ class Product < ActiveRecord::Base
def self.autostart_iso_builds(autostart_status) def self.autostart_iso_builds(autostart_status)
Product.where(:autostart_status => autostart_status).each do |product| Product.where(:autostart_status => autostart_status).each do |product|
pbl = product.product_build_lists.new pbl = product.product_build_lists.new
[:params, :main_script, :project].each do |k| [:params, :main_script, :project, :project_version].each do |k|
pbl.send "#{k}=", product.send(k) pbl.send "#{k}=", product.send(k)
end end
owner = product.platform.owner owner = product.platform.owner
@ -71,7 +72,6 @@ class Product < ActiveRecord::Base
pbl.autostarted = true pbl.autostarted = true
pbl.base_url = "http://#{product.platform.default_host}" pbl.base_url = "http://#{product.platform.default_host}"
pbl.time_living = product.time_living / 60 pbl.time_living = product.time_living / 60
pbl.project_version = product.project.default_branch
pbl.save pbl.save
end end
end end

View File

@ -39,6 +39,8 @@ class ProductBuildList < ActiveRecord::Base
# see: Issue #6 # see: Issue #6
before_validation lambda { self.arch_id = Arch.find_by_name('x86_64').id }, :on => :create before_validation lambda { self.arch_id = Arch.find_by_name('x86_64').id }, :on => :create
# field "not_delete" can be changed only if build has been completed
before_validation lambda { self.not_delete = false unless build_completed?; true }
validates :product_id, validates :product_id,
:status, :status,
:project_id, :project_id,

View File

@ -9,7 +9,7 @@
.both .both
.leftlist= f.label :project_version, t("activerecord.attributes.product_build_list.project_version"), :class => :label .leftlist= f.label :project_version, t("activerecord.attributes.product_build_list.project_version"), :class => :label
.rightlist= f.select :project_version, versions_for_group_select(pbl.project), :selected => params[:product_build_lists].try(:fetch, :project_version) || pbl.project.default_branch .rightlist= f.select :project_version, versions_for_group_select(pbl.project), :selected => params[:product_build_lists].try(:fetch, :project_version) || @product.project_version || pbl.project.default_branch
.both .both
= render 'platforms/products/def_fields', :f => f = render 'platforms/products/def_fields', :f => f

View File

@ -10,6 +10,10 @@
.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) .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 .both
.leftlist= f.label :project_version
.rightlist= f.select :project_version, versions_for_group_select(@product.project), {:selected => params[:products].try(:fetch, :project_version) || @product.project_version, :include_blank => true}
.both
= render 'def_fields', :f => f = render 'def_fields', :f => f
.leftlist= f.label :autostart_status .leftlist= f.label :autostart_status

View File

@ -32,6 +32,7 @@ en:
autostart_status: Autostart autostart_status: Autostart
name: Name name: Name
description: Description description: Description
project_version: Version
platform_id: Platform platform_id: Platform
build_status: Build status build_status: Build status
created_at: Created created_at: Created

View File

@ -32,6 +32,7 @@ ru:
autostart_status: Автостарт autostart_status: Автостарт
name: Название name: Название
description: Описание description: Описание
project_version: Версия
platform_id: Платформа platform_id: Платформа
build_status: Статус последней сборки build_status: Статус последней сборки
created_at: Создан created_at: Создан

View File

@ -0,0 +1,5 @@
class AddProjectVersionToProduct < ActiveRecord::Migration
def change
add_column :products, :project_version, :string
end
end

View File

@ -11,7 +11,7 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20130322132919) do ActiveRecord::Schema.define(:version => 20130327120129) do
create_table "activity_feeds", :force => true do |t| create_table "activity_feeds", :force => true do |t|
t.integer "user_id", :null => false t.integer "user_id", :null => false
@ -331,6 +331,7 @@ ActiveRecord::Schema.define(:version => 20130322132919) do
t.string "main_script" t.string "main_script"
t.integer "time_living" t.integer "time_living"
t.integer "autostart_status" t.integer "autostart_status"
t.string "project_version"
end end
create_table "project_imports", :force => true do |t| create_table "project_imports", :force => true do |t|

View File

@ -2,8 +2,9 @@
require 'spec_helper' require 'spec_helper'
describe ProductBuildList do describe ProductBuildList do
before(:all) do before do
stub_symlink_methods stub_symlink_methods
FactoryGirl.create(:product_build_list)
end end
it { should belong_to(:product) } it { should belong_to(:product) }
@ -29,9 +30,8 @@ describe ProductBuildList do
# see app/ability.rb # see app/ability.rb
# can :read, ProductBuildList#, :product => {:platform => {:visibility => 'open'}} # double nested hash don't work # can :read, ProductBuildList#, :product => {:platform => {:visibility => 'open'}} # double nested hash don't work
it 'should generate correct sql to get product build lists' do it 'should generate correct sql to get product build lists' do
stub_symlink_methods
user = FactoryGirl.create(:user) user = FactoryGirl.create(:user)
ability = Ability.new user ability = Ability.new user
ProductBuildList.accessible_by(ability).count.should == 0 ProductBuildList.accessible_by(ability).count.should == 1
end end
end end

View File

@ -32,8 +32,9 @@ describe Product do
before do before do
stub_symlink_methods stub_symlink_methods
stub_redis stub_redis
product.update_attributes(:autostart_status => Product::ONCE_A_12_HOURS, :main_script => 'text.sh') params = {:main_script => 'text.sh', :project_version => product.project.default_branch}
FactoryGirl.create(:product, :autostart_status => Product::ONCE_A_DAY, :main_script => 'text.sh') product.update_attributes params.merge(:autostart_status => Product::ONCE_A_12_HOURS)
FactoryGirl.create :product, params.merge(:autostart_status => Product::ONCE_A_DAY)
end end
it 'should be created only one product_build_list' do it 'should be created only one product_build_list' do