Merge pull request #409 from abf/rosa-build:408-successful-builds-list-for-mass-builds

#408: Successful builds list similar to the failed build list used for mass builds
This commit is contained in:
avokhmin 2014-06-27 12:48:43 +04:00
commit 6ba72db818
18 changed files with 236 additions and 92 deletions

View File

@ -1,4 +1,5 @@
class Platforms::MassBuildsController < Platforms::BaseController
include DatatableHelper
before_filter :authenticate_user!
skip_before_filter :authenticate_user!, only: [:index, :get_list] if APP_CONFIG['anonymous_access']
@ -8,10 +9,19 @@ class Platforms::MassBuildsController < Platforms::BaseController
def new
if params[:mass_build_id].present?
@mass_build = @platform.mass_builds.find(params[:mass_build_id]).dup
@mass_build.arches = Arch.where(name: @mass_build.arch_names.split(', ')).pluck(:id)
end
@mass_build.arches ||= @platform.platform_arch_settings.by_default.pluck(:arch_id)
@mass_build.arches.map!(&:to_s)
end
def show
end
def create
@mass_build.user, @mass_build.arches = current_user, params[:arches]
@mass_build.user, @mass_build.arches = current_user, params[:arches] || []
if @mass_build.save
redirect_to(platform_mass_builds_path(@platform), notice: t("flash.platform.build_all_success"))
@ -32,7 +42,13 @@ class Platforms::MassBuildsController < Platforms::BaseController
end
def index
@mass_builds = MassBuild.by_platform(@platform).order('created_at DESC').paginate(page: params[:page], per_page: 20)
if request.xhr?
@mass_builds = @platform.mass_builds
@total_mass_builds = @mass_builds.count
@mass_builds = @mass_builds.order("id #{sort_dir}")
@mass_builds = @mass_builds.search(params[:sSearch]).
paginate(page: page, per_page: per_page)
end
end
def cancel
@ -42,11 +58,14 @@ class Platforms::MassBuildsController < Platforms::BaseController
end
def get_list
text = if %w(failed_builds_list tests_failed_builds_list).include? params[:kind]
@mass_build.send "generate_#{params[:kind]}"
elsif %w(projects_list missed_projects_list).include? params[:kind]
@mass_build.send params[:kind]
end
text =
case params[:kind]
when 'failed_builds_list', 'tests_failed_builds_list', 'success_builds_list'
@mass_build.send "generate_#{params[:kind]}"
when 'projects_list', 'missed_projects_list'
@mass_build.send params[:kind]
end
render text: text
end
end

View File

@ -1,4 +1,5 @@
class Platforms::RepositoriesController < Platforms::BaseController
include DatatableHelper
include FileStoreHelper
include RepositoriesHelper
@ -115,10 +116,6 @@ class Platforms::RepositoriesController < Platforms::BaseController
FROM groups
) AS owner
ON projects.owner_id = owner.id AND projects.owner_type = owner.type"
colName = ['projects.name']
sort_col = params[:iSortCol_0] || 0
sort_dir = params[:sSortDir_0] == 'asc' ? 'asc' : 'desc'
order = "#{colName[sort_col.to_i]} #{sort_dir}"
if params[:added] == "true"
@projects = @repository.projects
@ -126,14 +123,11 @@ class Platforms::RepositoriesController < Platforms::BaseController
@projects = Project.joins(owner_subquery).addable_to_repository(@repository.id)
@projects = @projects.opened if @repository.platform.main? && !@repository.platform.hidden?
end
@projects = @projects.paginate(
page: (params[:iDisplayStart].to_i/(params[:iDisplayLength].present? ? params[:iDisplayLength] : 25).to_i).to_i + 1,
per_page: params[:iDisplayLength].present? ? params[:iDisplayLength] : 25
)
@projects = @projects.paginate(page: page, per_page: per_page)
@total_projects = @projects.count
@projects = @projects.by_owner(params[:owner_name]).
search(params[:sSearch]).order(order)
search(params[:sSearch]).order("projects.name #{sort_dir}")
respond_to do |format|
format.json {

View File

@ -1,4 +1,5 @@
class Projects::BuildListsController < Projects::BaseController
include DatatableHelper
include FileStoreHelper
NESTED_ACTIONS = [:index, :new, :create]
@ -166,15 +167,11 @@ class Projects::BuildListsController < Projects::BaseController
def list
@build_lists = @project.build_lists
sort_col = params[:ol_0] || 7
sort_dir = params[:sSortDir_0] == 'asc' ? 'asc' : 'desc'
order = "build_lists.updated_at #{sort_dir}"
@build_lists = @build_lists.paginate(page: (params[:iDisplayStart].to_i/params[:iDisplayLength].to_i).to_i + 1, per_page: params[:iDisplayLength])
@build_lists = @build_lists.paginate(page: page, per_page: per_page)
@total_build_lists = @build_lists.count
@build_lists = @build_lists.where(user_id: current_user) if params[:owner_filter] == 'true'
@build_lists = @build_lists.where(status: [BuildList::BUILD_ERROR, BuildList::FAILED_PUBLISH, BuildList::REJECTED_PUBLISH]) if params[:status_filter] == 'true'
@build_lists = @build_lists.order(order)
@build_lists = @build_lists.order("build_lists.updated_at #{sort_dir}")
render partial: 'build_lists_ajax', layout: false
end

View File

@ -1,4 +1,5 @@
class Projects::ProjectsController < Projects::BaseController
include DatatableHelper
include ProjectsHelper
before_filter :authenticate_user!
load_and_authorize_resource id_param: :name_with_owner # to force member actions load
@ -172,12 +173,6 @@ class Projects::ProjectsController < Projects::BaseController
def prepare_list(projects, groups, owners)
res = {}
colName = ['name']
sort_col = params[:iSortCol_0] || 0
sort_dir = params[:sSortDir_0] == "desc" ? 'desc' : 'asc'
order = "#{colName[sort_col.to_i]} #{sort_dir}"
res[:total_count] = projects.count
if groups.present? || owners.present?
@ -188,13 +183,9 @@ class Projects::ProjectsController < Projects::BaseController
res[:filtered_count] = projects.count
projects = projects.order(order)
projects = projects.order("name #{sort_dir}")
res[:projects] = if params[:iDisplayLength].present?
start = params[:iDisplayStart].present? ? params[:iDisplayStart].to_i : 0
length = params[:iDisplayLength].to_i
page = start/length + 1
projects.paginate(page: page, per_page: length)
projects.paginate(page: page, per_page: per_page)
else
projects
end

View File

@ -0,0 +1,14 @@
module DatatableHelper
def page
(params[:iDisplayStart].to_i/(params[:iDisplayLength].present? ? params[:iDisplayLength] : 25).to_i).to_i + 1
end
def per_page
params[:iDisplayLength].present? ? params[:iDisplayLength] : 25
end
def sort_dir
params[:sSortDir_0] == 'asc' ? 'asc' : 'desc'
end
end

View File

@ -1,7 +1,60 @@
module MassBuildHelper
COLUMNS = [
{
sortable: true
},
{
type: 'html',
sortable: false,
searchable: false
},
{
sortable: false,
searchable: false
},
{
sortable: false,
searchable: false
},
{
sortable: false,
searchable: false,
class: 'buttons'
}
]
def link_to_list platform, mass_build, which
link_to t("layout.mass_builds.#{which}"),
get_list_platform_mass_build_path(@platform, mass_build, kind: which, format: :txt),
get_list_platform_mass_build_path(platform, mass_build, kind: which, format: :txt),
target: "_blank" if can?(:get_list, mass_build)
end
def link_to_mass_build(mass_build)
link_to mass_build.name, build_lists_path+"#?#{{filter: {mass_build_id: mass_build.id, ownership: 'everything'}}.to_param}"
end
def mass_builds_datatable(platform)
datatable(
COLUMNS,
{
sort_by: "[0, 'asc']",
search_label: '',
placeholder: t('layout.mass_builds.placeholder.description'),
processing: t('layout.processing'),
pagination_labels: {
previous: t('datatables.previous_label'),
next: t('datatables.next_label')
},
empty_label: t('datatables.empty_label'),
info_label: t('datatables.info_label'),
info_empty_label: t('datatables.info_empty_label'),
filtered_label: t('datatables.filtered_label'),
table_dom_id: 'datatable',
auto_width: 'false',
ajax_source: platform_mass_builds_path(platform, format: :json)
}
)
end
end

View File

@ -10,11 +10,12 @@ class MassBuild < ActiveRecord::Base
scope :recent, -> { order(created_at: :desc) }
scope :by_platform, -> (platform) { where(save_to_platform_id: platform.id) }
scope :outdated, -> { where("#{table_name}.created_at < ?", Time.now + 1.day - BuildList::MAX_LIVE_TIME) }
scope :search, -> (q) { where("#{table_name}.description ILIKE ?", "%#{q}%") if q.present? }
attr_accessor :arches
attr_accessible :arches, :auto_publish, :projects_list, :build_for_platform_id,
:extra_repositories, :extra_build_lists, :increase_release_tag,
:use_cached_chroot, :use_extra_tests
:use_cached_chroot, :use_extra_tests, :description
validates :save_to_platform_id,
:build_for_platform_id,
@ -27,6 +28,9 @@ class MassBuild < ActiveRecord::Base
presence: true,
length: { maximum: 500_000 }
validates :description,
length: { maximum: 255 }
validates :auto_publish,
:increase_release_tag,
:use_cached_chroot,
@ -83,6 +87,10 @@ class MassBuild < ActiveRecord::Base
generate_list BuildList::TESTS_FAILED
end
def generate_success_builds_list
generate_list BuildList::SUCCESS
end
def cancel_all
update_column(:stop_build, true)
build_lists.find_each(batch_size: 100) do |bl|

View File

@ -3,59 +3,16 @@
= link_to t('layout.mass_builds.new'), new_platform_mass_build_path(@platform), class: 'button' if can? :create, @platform.mass_builds.build
%table.tablesorter.unbordered{cellpadding: "0", cellspacing: "0"}
= raw mass_builds_datatable(@platform)
%table#datatable.tablesorter{cellspacing: 0, cellpadding: 0}
%thead
%tr
%th.lpadding16= t('activerecord.attributes.mass_build.id')
%th.lpadding16= t('activerecord.attributes.mass_build.name')
%th.lpadding16= t("layout.mass_builds.statuses")
%th.lpadding16= t("layout.mass_builds.lists")
%th.lpadding16= t("layout.mass_builds.actions")
%th.lpadding16= t("layout.mass_builds.extended_data")
- @mass_builds.each do |mass_build|
%tr
%td= mass_build.id
%td= link_to mass_build.name, build_lists_path+"#?#{{filter: {mass_build_id: mass_build.id, ownership: 'everything'}}.to_param}"
%td.min_width_120
- MassBuild::COUNT_STATUSES.each do |status|
- path = build_lists_path+"#?#{{filter: {mass_build_id: mass_build.id, ownership: 'everything'}.merge(status != :build_lists ? {status: BuildList.status_by_human(status)} : {})}.to_param}"
= link_to t("layout.build_lists.statuses.#{status}") + ": ", path
= mass_build.send "#{status}_count"
.both
-if mass_build.projects_list.present?
=link_to_list @platform, mass_build, 'missed_projects_list'
= mass_build.send 'missed_projects_count'
%td
- if mass_build.projects_list.present?
= link_to_list @platform, mass_build, 'projects_list'
.both
%br
= link_to_list @platform, mass_build, 'failed_builds_list'
.both
%br
= link_to_list @platform, mass_build, 'tests_failed_builds_list'
%td.right.mass-build-actions
- if can?(:publish, mass_build)
- unless mass_build.auto_publish?
= link_to t('layout.mass_builds.publish_success'),
publish_platform_mass_build_path(@platform, mass_build.id),
method: :post, data: { confirm: t("layout.confirm") }, class: 'button'
= link_to t('layout.mass_builds.publish_test_failed'),
publish_platform_mass_build_path(@platform, mass_build.id, status: 'test_failed'),
method: :post, data: { confirm: t("layout.confirm") }, class: 'button'
- if can?(:cancel, mass_build)
= link_to t('layout.cancel'),
cancel_platform_mass_build_path(@platform, mass_build.id),
method: :post, class: 'button',
data: { 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.user') + ": "
= link_to mass_build.user.fullname, mass_build.user
- %i(arch_names auto_publish increase_release_tag use_cached_chroot use_extra_tests created_at).each do |field|
.both
= t("activerecord.attributes.mass_build.#{field}") + ": "
= mass_build.send field
= will_paginate @mass_builds
%th.th2= t('activerecord.attributes.mass_build.description')
%th.lpadding16= t('activerecord.attributes.mass_build.created_at')
%th.buttons &nbsp;
%tbody
%br

View File

@ -0,0 +1,18 @@
mass_builds = @mass_builds.map do |mass_build|
[
mass_build.id,
link_to_mass_build(mass_build),
mass_build.description,
mass_build.created_at.to_s,
link_to(t('layout.show'), platform_mass_build_path(@platform, mass_build.id))
]
end
json.sEcho params[:sEcho].to_i || -1
json.iTotalRecords @total_mass_builds
json.iTotalDisplayRecords @mass_builds.count
json.aaData mass_builds || []

View File

@ -10,6 +10,9 @@
.both
= check_box_tag "repositories[]", rep.id, (params[:repositories]||[]).include?(rep.id.to_s), id: "repositories_#{rep.id}", href: "#{projects_list_platform_repository_path(@platform, rep)}?text=true"
= label_tag "repositories_#{rep.id}", rep.name
%h3=t('activerecord.attributes.mass_build.description')
= f.text_area :description
%br
%h3=t('layout.mass_builds.projects_list')
= f.text_area :projects_list
%br
@ -18,7 +21,7 @@
%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}"
= check_box_tag "arches[]", arch.id, @mass_build.arches.include?(arch.id.to_s), id: "arches_#{arch.id}"
= label_tag "arches_#{arch.id}", arch.name
.both
- if @platform.personal?

View File

@ -0,0 +1,65 @@
-set_meta_tags title: title_object(@mass_build)
= render 'submenu'
= render 'sidebar'
%h3.fix
= t 'activerecord.models.mass_build'
%table.tablesorter.unbordered
%tr
%td
%b= t('activerecord.attributes.mass_build.name')
%td= link_to_mass_build(@mass_build)
- %i(id arch_names auto_publish increase_release_tag use_cached_chroot use_extra_tests created_at description).each do |field|
%tr
%td
%b= t("activerecord.attributes.mass_build.#{field}")
%td= @mass_build.send field
%tr
%td
%td
%tr
%td
%b= t('layout.mass_builds.statuses')
%td
- MassBuild::COUNT_STATUSES.each do |status|
- path = build_lists_path+"#?#{{filter: {mass_build_id: @mass_build.id, ownership: 'everything'}.merge(status != :build_lists ? {status: BuildList.status_by_human(status)} : {})}.to_param}"
%tr
%td
= link_to t("layout.build_lists.statuses.#{status}") + ": ", path
%td= @mass_build.send "#{status}_count"
%tr
%td
%td
%tr
%td
%b= t('layout.mass_builds.lists')
%td
- if @mass_build.projects_list.present?
= link_to_list @platform, @mass_build, 'projects_list'
.both
= link_to_list @platform, @mass_build, 'failed_builds_list'
.both
= link_to_list @platform, @mass_build, 'tests_failed_builds_list'
.both
= link_to_list @platform, @mass_build, 'success_builds_list'
.buttons_block
- if can?(:publish, @mass_build)
- unless @mass_build.auto_publish?
= link_to t('layout.mass_builds.publish_success'),
publish_platform_mass_build_path(@platform, @mass_build.id),
method: :post, data: { confirm: t("layout.confirm") }, class: 'button'
= link_to t('layout.mass_builds.publish_test_failed'),
publish_platform_mass_build_path(@platform, @mass_build.id, status: 'test_failed'),
method: :post, data: { confirm: t("layout.confirm") }, class: 'button'
- if can?(:cancel, @mass_build)
= link_to t('layout.cancel'),
cancel_platform_mass_build_path(@platform, @mass_build.id),
method: :post, class: 'button',
data: { confirm: t('layout.mass_builds.cancel_confirm') }
- if can? :create, @mass_build
= link_to t('layout.mass_builds.recreate'), new_platform_mass_build_path(@platform, mass_build_id: @mass_build.id), class: 'button'

View File

@ -2,18 +2,23 @@ en:
layout:
mass_builds:
new: New mass build
recreate: Recreate mass build
publish_success: Publish success builds
publish_test_failed: Publish test failed builds
repositories: Repositories
extended_data: Extended data
lists: Lists
failed_builds_list: Failed Builds List
success_builds_list: Completed Build Lists
tests_failed_builds_list: Tests failed Builds List
statuses: Statuses
actions: Actions
cancel_confirm: Are you sure you want to cancel mass build?
projects_list: Projects list
missed_projects_list: 'Missed projects: '
placeholder:
description: Description
activerecord:
models:
mass_build: Mass Build
@ -21,6 +26,7 @@ en:
mass_build:
id: Id
name: Name
description: Description
created_at: Created
updated_at: Updated
arch_names: Architectures

View File

@ -2,18 +2,24 @@ ru:
layout:
mass_builds:
new: Новая массовая сборка
recreate: Пересоздать массовую сборку
publish_success: Опубликовать успешные сборки
publish_test_failed: Опубликовать сборки с проваленными тестами
repositories: Репозитории
extended_data: Параметры задания
lists: Списки
failed_builds_list: Сборки с ошибками
success_builds_list: Успешные сборки
tests_failed_builds_list: Сборки с ошибками в тестах
statuses: Статусы
actions: Действия
cancel_confirm: Вы уверены, что хотите отменить массовую сборку?
projects_list: Проекты
missed_projects_list: 'Несуществующие проекты: '
placeholder:
description: Описание
activerecord:
models:
mass_build: Массовая Сборка
@ -21,6 +27,7 @@ ru:
mass_build:
id: Id
name: Название
description: Описание
created_at: Создан
updated_at: Обновлен
arch_names: Архитектуры

View File

@ -182,11 +182,11 @@ Rosa::Application.routes.draw do
end
end
resources :mass_builds, only: [:create, :new, :index] do
resources :mass_builds, only: [:create, :new, :index, :show] do
member do
post :cancel
post :publish
get '/:kind' => "mass_builds#get_list", as: :get_list, kind: /failed_builds_list|missed_projects_list|projects_list|tests_failed_builds_list/
get '/:kind' => "mass_builds#get_list", as: :get_list, kind: /failed_builds_list|missed_projects_list|projects_list|tests_failed_builds_list|success_builds_list/
end
end

View File

@ -0,0 +1,5 @@
class AddDescriptionToMassBuilds < ActiveRecord::Migration
def change
add_column :mass_builds, :description, :string
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20140625204136) do
ActiveRecord::Schema.define(version: 20140626195741) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -327,6 +327,7 @@ ActiveRecord::Schema.define(version: 20140625204136) do
t.boolean "increase_release_tag", default: false, null: false
t.boolean "use_cached_chroot", default: true, null: false
t.boolean "use_extra_tests", default: false, null: false
t.string "description"
end
create_table "users", force: true do |t|

View File

@ -6,6 +6,11 @@ shared_examples_for 'mass_build platform owner' do
response.should render_template(:index)
end
it 'should be able to perform show action' do
get :show, platform_id: @platform, id: @mass_build
response.should render_template(:show)
end
it 'should be able to perform new action' do
get :new, platform_id: @platform
response.should render_template(:new)

View File

@ -23,6 +23,7 @@ describe MassBuild do
it { should validate_presence_of(:projects_list)}
it { should ensure_length_of(:projects_list).is_at_most(500_000) }
it { should ensure_length_of(:description).is_at_most(255) }
it { should_not allow_mass_assignment_of(:name) }
it { should_not allow_mass_assignment_of(:arch_names) }