From a79d946b6b5198ac2d206197c648b846f6aa6867 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Fri, 25 May 2012 19:56:26 +0400 Subject: [PATCH] [refs #442] Mass build refactor and fixes --- app/assets/stylesheets/design/custom.scss | 4 ++ .../platforms/platforms_controller.rb | 20 +++--- app/helpers/application_helper.rb | 4 +- app/models/mass_build.rb | 15 ++++- .../platforms/platforms/build_all.html.haml | 64 +++++++------------ .../build_lists/_build_list.html.haml | 2 +- config/locales/models/mass_build.en.yml | 4 ++ config/locales/models/mass_build.ru.yml | 4 ++ config/locales/models/platform.en.yml | 1 + config/locales/models/platform.ru.yml | 1 + ..._set_mass_build_user_id_to_first_if_nil.rb | 8 +++ 11 files changed, 71 insertions(+), 56 deletions(-) create mode 100644 db/migrate/20120524132504_set_mass_build_user_id_to_first_if_nil.rb diff --git a/app/assets/stylesheets/design/custom.scss b/app/assets/stylesheets/design/custom.scss index a8f27ec09..acd75d9f6 100644 --- a/app/assets/stylesheets/design/custom.scss +++ b/app/assets/stylesheets/design/custom.scss @@ -953,3 +953,7 @@ form.mass_build input[type="checkbox"] { width: 10px; height: 11px; } + +.bottom_20 { + margin-bottom: 20px; +} diff --git a/app/controllers/platforms/platforms_controller.rb b/app/controllers/platforms/platforms_controller.rb index aeb805269..c1ff5abce 100644 --- a/app/controllers/platforms/platforms_controller.rb +++ b/app/controllers/platforms/platforms_controller.rb @@ -7,14 +7,18 @@ class Platforms::PlatformsController < Platforms::BaseController autocomplete :user, :uname def build_all - mass_build = MassBuild.create!(:platform => @platform, :user => current_user) - mass_build.delay.build_all( - :user => current_user, - :repositories => params[:repositories], - :arches => params[:arches], - :auto_publish => params[:auto_publish] - ) - redirect_to(mass_builds_platform_path(@platform), :notice => t("flash.platform.build_all_success")) + mass_build = MassBuild.new(:platform => @platform, :user => current_user) + if mass_build.build_all( + :repositories => params[:repositories], + :arches => params[:arches], + :auto_publish => params[:auto_publish] + ) + redirect_to(mass_builds_platform_path(@platform), :notice => t("flash.platform.build_all_success")) + else + @mass_builds = MassBuild.paginate(:page => params[:page], :per_page => 20) + flash[:warning] = mass_build.errors.full_messages.join('. ') + flash[:error] = t("flash.platform.build_all_error") + end end def mass_builds diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 3474973bf..74a0c3229 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -8,8 +8,8 @@ module ApplicationHelper 'right slim' when controller_name == 'build_lists' && ['new', 'create'].include?(action_name) nil - #when controller_name == 'platforms' && action_name == 'build_all' - # nil + when controller_name == 'platforms' && ['build_all', 'mass_builds'].include?(action_name) + nil when controller_name == 'platforms' && action_name == 'show' 'right bigpadding' when controller_name == 'platforms' && action_name == 'clone' diff --git a/app/models/mass_build.rb b/app/models/mass_build.rb index 9c6f5751b..3332208ca 100644 --- a/app/models/mass_build.rb +++ b/app/models/mass_build.rb @@ -5,11 +5,19 @@ class MassBuild < ActiveRecord::Base scope :by_platform, lambda { |platform| where(:platform_id => platform.id) } + attr_accessor :repositories_ids + + validates :platform_id, :auto_publish, :arch_names, :name, :user_id, :repositories_ids, :presence => true + + def build_all(opts={}) auto_publish = opts[:auto_publish] || false - set_data opts[:repositories], opts[:arches], auto_publish - - platform.build_all opts.merge({:mass_build_id => self.id}) + if set_data(opts[:repositories], opts[:arches], auto_publish) + platform.delay.build_all opts.merge({:mass_build_id => self.id, :user => self.user}) + true + else + false + end end private @@ -19,6 +27,7 @@ class MassBuild < ActiveRecord::Base self.name = "#{Date.today.strftime("%d.%b")}-#{platform.name}(#{rep_names})" self.arch_names = Arch.where(:id => arches).map(&:name).join(", ") self.auto_publish = auto_publish + self.repositories_ids = repositories_ids self.save end end diff --git a/app/views/platforms/platforms/build_all.html.haml b/app/views/platforms/platforms/build_all.html.haml index a35fe5f06..1804db2de 100644 --- a/app/views/platforms/platforms/build_all.html.haml +++ b/app/views/platforms/platforms/build_all.html.haml @@ -1,46 +1,26 @@ -- content_for(:sidebar) do - = form_for :build, :url => build_all_platform_path(@platform), :html => { :class => 'form mass_build', :method => :post } do |f| - .bordered.nopadding - .table - %h3= t("activerecord.attributes.build_list.build_for_platform") - - @platform.repositories.each do |rep| - .lefter - = check_box_tag "repositories[]", rep.id, (params[:repositories]||[]).include?(rep.id.to_s), :id => "repositories_#{rep.id}" - = label_tag "repositories_#{rep.id}", rep.name - .both - .both - .table - %h3= t("activerecord.attributes.build_list.arch") - - Arch.recent.each do |arch| - .lefter - = check_box_tag "arches[]", arch.id, (params[:arches]||[]).include?(arch.id.to_s), :id => "arches_#{arch.id}" - = label_tag "arches_#{arch.id}", arch.name - .both - .both - .table - %h3= t("activerecord.attributes.build_list.preferences") - .lefter - = check_box_tag :auto_publish, true, params[:auto_publish].present? ? params[:auto_publish].present? : true, :id => 'auto_publish' - = label_tag t('activerecord.attributes.mass_build.auto_publish') - .both += form_for :build, :url => build_all_platform_path(@platform), :html => { :class => 'form mass_build', :method => :post } do |f| + %section.left + %h3= t("layout.mass_builds.repositories") + - @platform.repositories.each do |rep| .both - %br - = f.submit t("layout.projects.build_button") + = check_box_tag "repositories[]", rep.id, (params[:repositories]||[]).include?(rep.id.to_s), :id => "repositories_#{rep.id}" + = label_tag "repositories_#{rep.id}", rep.name + %br + = f.submit t("layout.projects.build_button") + %section.right + %h3= t("activerecord.attributes.build_list.arch") + - Arch.recent.each do |arch| + .lefter + = check_box_tag "arches[]", arch.id, (params[:arches]||[]).include?(arch.id.to_s), :id => "arches_#{arch.id}" + = label_tag "arches_#{arch.id}", arch.name + .both + %h3= t("activerecord.attributes.build_list.preferences") + .both.bottom_20 + = check_box_tag :auto_publish, true, params[:auto_publish].present? ? params[:auto_publish].present? : true, :id => 'auto_publish' + = label_tag :auto_publish - %br - %br - .bordered.nopadding - .table - - ['BuildList::BUILD_PUBLISHED', 'BuildServer::SUCCESS', 'BuildServer::BUILD_STARTED', 'BuildList::BUILD_PENDING', 'BuildServer::BUILD_ERROR'].each do |state| - .lefter - = t("layout.build_lists.statuses.#{state.demodulize.downcase}") - .righter - = BuildList.for_status(state.constantize).for_user(current_user).for_platform(@platform).count - .both - %br - = link_to t("layout.activity_feed.all_my_builds"), build_lists_path - -%h3.fix= t("layout.platforms.mass_build") +%br +%br %table.tablesorter.unbordered %thead @@ -54,7 +34,7 @@ %tr %td= link_to mass_build.name, build_lists_path(:filter => {:mass_build_id => mass_build.id}) %td= mass_build.arch_names - %td= mass_build.user.name + %td= mass_build.user.uname %td= mass_build.auto_publish %td= mass_build.created_at = will_paginate @mass_builds diff --git a/app/views/projects/build_lists/_build_list.html.haml b/app/views/projects/build_lists/_build_list.html.haml index 452a1728c..abb5f43b8 100644 --- a/app/views/projects/build_lists/_build_list.html.haml +++ b/app/views/projects/build_lists/_build_list.html.haml @@ -1,6 +1,6 @@ %tr{:id => "row#{build_list_counter}", :class => "#{build_list_status_color(build_list.status)}"} %td= link_to (build_list.bs_id.present? ? build_list.bs_id : t("layout.build_lists.bs_id_not_set")), build_list - %td= build_list.mass_build_id ? build_list.mass_build.name : "" + %td= build_list.mass_build_id ? link_to(build_list.mass_build.name, mass_builds_platform_path(build_list.save_to_platform)) : "" %td= build_list.human_status %td= link_to build_list.project.name, build_list.project %td= link_to build_list.project_version, "#" diff --git a/config/locales/models/mass_build.en.yml b/config/locales/models/mass_build.en.yml index 6d016ea58..1e920427e 100644 --- a/config/locales/models/mass_build.en.yml +++ b/config/locales/models/mass_build.en.yml @@ -1,4 +1,7 @@ en: + layout: + mass_builds: + repositories: Repositories activerecord: models: mass_build: Mass Build @@ -10,3 +13,4 @@ en: arch_names: Architectures user: User auto_publish: Auto Publish + repositories_ids: Repositories diff --git a/config/locales/models/mass_build.ru.yml b/config/locales/models/mass_build.ru.yml index 79eb33015..349048d41 100644 --- a/config/locales/models/mass_build.ru.yml +++ b/config/locales/models/mass_build.ru.yml @@ -1,4 +1,7 @@ ru: + layout: + mass_builds: + repositories: Репозитории activerecord: models: mass_build: Массовая Сборка @@ -10,3 +13,4 @@ ru: arch_names: Архитектуры user: Пользователь auto_publish: Авто Публикация + repositories_ids: Репозитории diff --git a/config/locales/models/platform.en.yml b/config/locales/models/platform.en.yml index bba971e98..af51cd808 100644 --- a/config/locales/models/platform.en.yml +++ b/config/locales/models/platform.en.yml @@ -58,6 +58,7 @@ en: unfreeze_error: Platform unfreezing error, try again destroyed: Platform deleted build_all_success: All project build in progress + build_all_error: Mass build failed clone_success: Cloned successfully members: already_added: "%{name} is already a member of platform" diff --git a/config/locales/models/platform.ru.yml b/config/locales/models/platform.ru.yml index fdc2b610a..387b2c0f9 100644 --- a/config/locales/models/platform.ru.yml +++ b/config/locales/models/platform.ru.yml @@ -58,6 +58,7 @@ ru: unfreeze_error: Не удалось разморозить платформу, попробуйте еще раз destroyed: Платформа успешно удалена build_all_success: Все проекты успешно отправлены на сборку + build_all_error: Сборка не удалась! clone_success: Клонирование успешно members: already_added: "%{name} уже является участником платформы" diff --git a/db/migrate/20120524132504_set_mass_build_user_id_to_first_if_nil.rb b/db/migrate/20120524132504_set_mass_build_user_id_to_first_if_nil.rb new file mode 100644 index 000000000..d4c053170 --- /dev/null +++ b/db/migrate/20120524132504_set_mass_build_user_id_to_first_if_nil.rb @@ -0,0 +1,8 @@ +class SetMassBuildUserIdToFirstIfNil < ActiveRecord::Migration + def up + MassBuild.update_all(:user_id => nil, :user_id => 1) + end + + def down + end +end