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 -*-
class Platforms::ProductsController < Platforms::BaseController
include GitHelper
before_filter :authenticate_user!
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
items.select! {|e| e.repo.branches.count > 0}
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

View File

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

View File

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

View File

@ -39,6 +39,8 @@ class ProductBuildList < ActiveRecord::Base
# see: Issue #6
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,
:status,
:project_id,

View File

@ -9,7 +9,7 @@
.both
.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
= 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)
.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
.leftlist= f.label :autostart_status

View File

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

View File

@ -32,6 +32,7 @@ ru:
autostart_status: Автостарт
name: Название
description: Описание
project_version: Версия
platform_id: Платформа
build_status: Статус последней сборки
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.
ActiveRecord::Schema.define(:version => 20130322132919) do
ActiveRecord::Schema.define(:version => 20130327120129) do
create_table "activity_feeds", :force => true do |t|
t.integer "user_id", :null => false
@ -331,6 +331,7 @@ ActiveRecord::Schema.define(:version => 20130322132919) do
t.string "main_script"
t.integer "time_living"
t.integer "autostart_status"
t.string "project_version"
end
create_table "project_imports", :force => true do |t|

View File

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

View File

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