From ce163f89a939553cce5f18fe5d02c44e458eccf5 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Thu, 28 Jun 2012 19:23:33 +0400 Subject: [PATCH] [refs #442] Add rep_name field. Add cancel builds ability --- app/controllers/platforms/platforms_controller.rb | 7 +++++++ app/models/mass_build.rb | 12 +++++++++--- app/views/platforms/platforms/build_all.html.haml | 5 +++++ config/locales/models/mass_build.en.yml | 3 +++ config/locales/models/mass_build.ru.yml | 3 +++ config/locales/models/platform.en.yml | 1 + config/locales/models/platform.ru.yml | 1 + config/routes.rb | 1 + .../20120622092725_add_counters_to_mass_builds.rb | 12 ++++++------ .../20120628142723_add_rep_names_to_mass_builds.rb | 5 +++++ db/schema.rb | 3 ++- 11 files changed, 43 insertions(+), 10 deletions(-) create mode 100644 db/migrate/20120628142723_add_rep_names_to_mass_builds.rb diff --git a/app/controllers/platforms/platforms_controller.rb b/app/controllers/platforms/platforms_controller.rb index 14058ba36..5f77f09f2 100644 --- a/app/controllers/platforms/platforms_controller.rb +++ b/app/controllers/platforms/platforms_controller.rb @@ -31,6 +31,13 @@ class Platforms::PlatformsController < Platforms::BaseController render :action => :build_all end + def cancel_mass_build + @mass_build = MassBuild.find params[:mass_build_id] + @mass_build.cancel_all + flash[:notice] = t("flash.platform.cancel_mass_build") + redirect_to mass_builds_platform_path(@mass_build.platform) + end + def failed_builds_list @mass_build = MassBuild.find params[:mass_build_id] render :text => @mass_build.generate_failed_builds_list diff --git a/app/models/mass_build.rb b/app/models/mass_build.rb index 3c13d754a..eac383a10 100644 --- a/app/models/mass_build.rb +++ b/app/models/mass_build.rb @@ -7,7 +7,7 @@ class MassBuild < ActiveRecord::Base attr_accessor :repositories, :arches - validates :platform_id, :arch_names, :name, :user_id, :repositories, :presence => true + validates :platform_id, :arch_names, :name, :user_id, :repositories, :rep_names, :presence => true validates_inclusion_of :auto_publish, :in => [true, false] after_create :build_all @@ -25,8 +25,8 @@ class MassBuild < ActiveRecord::Base super if new_record? - rep_names = Repository.where(:id => self.repositories).map(&:name).join(", ") - self.name = "#{Time.now.utc.to_date.strftime("%d.%b")}-#{platform.name}(#{rep_names})" + self.rep_names = Repository.where(:id => self.repositories).map(&:name).join(", ") + self.name = "#{Time.now.utc.to_date.strftime("%d.%b")}-#{platform.name}" self.arch_names = Arch.where(:id => self.arches).map(&:name).join(", ") end end @@ -50,4 +50,10 @@ class MassBuild < ActiveRecord::Base end report end + + def cancel_all + self.build_lists.find_each do |bl| + bl.cancel + end + end end diff --git a/app/views/platforms/platforms/build_all.html.haml b/app/views/platforms/platforms/build_all.html.haml index 67b275ac9..412613607 100644 --- a/app/views/platforms/platforms/build_all.html.haml +++ b/app/views/platforms/platforms/build_all.html.haml @@ -32,6 +32,7 @@ %th.lpadding16= t('activerecord.attributes.mass_build.name') %th.lpadding16= t("layout.mass_builds.statuses") %th.lpadding16= t("layout.mass_builds.failed_builds_list") + %th.lpadding16= t("layout.mass_builds.cancel_mass_build") %th.lpadding16= t("layout.mass_builds.extended_data") - @mass_builds.each do |mass_build| %tr @@ -43,12 +44,16 @@ = mass_build.read_attribute "#{status}_count" .both %td= link_to t("layout.mass_builds.failed_builds_list"), failed_builds_list_platforms_path(:mass_build_id => mass_build.id), :target => "_blank" + %td= link_to t("layout.mass_builds.cancel_mass_build"), cancel_mass_build_platforms_path(:mass_build_id => mass_build.id), :method => :post, :confirm => t("layout.mass_builds.cancel_confirm") %td %a.toggle_btn{:href => "#toggle_#{ mass_build.id }", :'data-target' => "#toggle_#{ mass_build.id }"}= t("layout.mass_builds.extended_data") .toggle{:id => "toggle_#{ mass_build.id }"} = t('activerecord.attributes.mass_build.arch_names') + ": " = mass_build.arch_names .both + = t('activerecord.attributes.mass_build.rep_names') + ": " + = mass_build.rep_names + .both = t('activerecord.attributes.mass_build.user') + ": " = link_to mass_build.user.fullname, mass_build.user .both diff --git a/config/locales/models/mass_build.en.yml b/config/locales/models/mass_build.en.yml index 508bc8507..39419e928 100644 --- a/config/locales/models/mass_build.en.yml +++ b/config/locales/models/mass_build.en.yml @@ -5,6 +5,8 @@ en: extended_data: Extended data failed_builds_list: Failed Builds List statuses: Statuses + cancel_mass_build: Cancel + cancel_confirm: Are you sure you want to cancel all builds? activerecord: models: mass_build: Mass Build @@ -18,3 +20,4 @@ en: user: User auto_publish: Auto Publish repositories: Repositories + rep_names: Repository names diff --git a/config/locales/models/mass_build.ru.yml b/config/locales/models/mass_build.ru.yml index b5d0fee6f..e4144b94e 100644 --- a/config/locales/models/mass_build.ru.yml +++ b/config/locales/models/mass_build.ru.yml @@ -5,6 +5,8 @@ ru: extended_data: Параметры задания failed_builds_list: Список ошибок сборок statuses: Статусы + cancel_mass_build: Отмена + cancel_confirm: Вы уверены, что хотите отменить все сборки? activerecord: models: mass_build: Массовая Сборка @@ -18,3 +20,4 @@ ru: user: Пользователь auto_publish: Авто Публикация repositories: Репозитории + rep_names: Названия репозиториев diff --git a/config/locales/models/platform.en.yml b/config/locales/models/platform.en.yml index af51cd808..cf44b6550 100644 --- a/config/locales/models/platform.en.yml +++ b/config/locales/models/platform.en.yml @@ -59,6 +59,7 @@ en: destroyed: Platform deleted build_all_success: All project build in progress build_all_error: Mass build failed + cancel_mass_build: Mass build canceled 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 387b2c0f9..6c04bbca8 100644 --- a/config/locales/models/platform.ru.yml +++ b/config/locales/models/platform.ru.yml @@ -59,6 +59,7 @@ ru: destroyed: Платформа успешно удалена build_all_success: Все проекты успешно отправлены на сборку build_all_error: Сборка не удалась! + cancel_mass_build: Массовая сборка отменена clone_success: Клонирование успешно members: already_added: "%{name} уже является участником платформы" diff --git a/config/routes.rb b/config/routes.rb index f6fec3ff7..2fe9dbf92 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -57,6 +57,7 @@ Rosa::Application.routes.draw do end collection do get :failed_builds_list + post :cancel_mass_build end get :autocomplete_user_uname, :on => :collection resources :repositories do diff --git a/db/migrate/20120622092725_add_counters_to_mass_builds.rb b/db/migrate/20120622092725_add_counters_to_mass_builds.rb index 5b0ed2e73..afed190ac 100644 --- a/db/migrate/20120622092725_add_counters_to_mass_builds.rb +++ b/db/migrate/20120622092725_add_counters_to_mass_builds.rb @@ -1,10 +1,10 @@ class AddCountersToMassBuilds < ActiveRecord::Migration def change - add_column :mass_builds, :build_lists_count, :integer, :default => 0 - add_column :mass_builds, :build_published_count, :integer, :default => 0 - add_column :mass_builds, :build_pending_count, :integer, :default => 0 - add_column :mass_builds, :build_started_count, :integer, :default => 0 - add_column :mass_builds, :build_publish_count, :integer, :default => 0 - add_column :mass_builds, :build_error_count, :integer, :default => 0 + add_column :mass_builds, :build_lists_count, :integer, :default => 0, :null => false + add_column :mass_builds, :build_published_count, :integer, :default => 0, :null => false + add_column :mass_builds, :build_pending_count, :integer, :default => 0, :null => false + add_column :mass_builds, :build_started_count, :integer, :default => 0, :null => false + add_column :mass_builds, :build_publish_count, :integer, :default => 0, :null => false + add_column :mass_builds, :build_error_count, :integer, :default => 0, :null => false end end diff --git a/db/migrate/20120628142723_add_rep_names_to_mass_builds.rb b/db/migrate/20120628142723_add_rep_names_to_mass_builds.rb new file mode 100644 index 000000000..12fdc158d --- /dev/null +++ b/db/migrate/20120628142723_add_rep_names_to_mass_builds.rb @@ -0,0 +1,5 @@ +class AddRepNamesToMassBuilds < ActiveRecord::Migration + def change + add_column :mass_builds, :rep_names, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 06ac06651..db00a3068 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20120622092725) do +ActiveRecord::Schema.define(:version => 20120628142723) do create_table "activity_feeds", :force => true do |t| t.integer "user_id", :null => false @@ -210,6 +210,7 @@ ActiveRecord::Schema.define(:version => 20120622092725) do t.integer "build_started_count", :default => 0 t.integer "build_publish_count", :default => 0 t.integer "build_error_count", :default => 0 + t.string "rep_names" end create_table "platforms", :force => true do |t|