#408: added description to MassBuild

This commit is contained in:
Vokhmin Alexey V 2014-06-27 01:21:31 +04:00
parent 790ea62670
commit 7ded629ca6
16 changed files with 132 additions and 38 deletions

View File

@ -1,4 +1,5 @@
class Platforms::MassBuildsController < Platforms::BaseController class Platforms::MassBuildsController < Platforms::BaseController
include DatatableHelper
before_filter :authenticate_user! before_filter :authenticate_user!
skip_before_filter :authenticate_user!, only: [:index, :get_list] if APP_CONFIG['anonymous_access'] skip_before_filter :authenticate_user!, only: [:index, :get_list] if APP_CONFIG['anonymous_access']
@ -41,7 +42,13 @@ class Platforms::MassBuildsController < Platforms::BaseController
end end
def index 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 end
def cancel def cancel

View File

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

View File

@ -1,4 +1,5 @@
class Projects::BuildListsController < Projects::BaseController class Projects::BuildListsController < Projects::BaseController
include DatatableHelper
include FileStoreHelper include FileStoreHelper
NESTED_ACTIONS = [:index, :new, :create] NESTED_ACTIONS = [:index, :new, :create]
@ -166,15 +167,11 @@ class Projects::BuildListsController < Projects::BaseController
def list def list
@build_lists = @project.build_lists @build_lists = @project.build_lists
sort_col = params[:ol_0] || 7 @build_lists = @build_lists.paginate(page: page, per_page: per_page)
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])
@total_build_lists = @build_lists.count @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(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.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 render partial: 'build_lists_ajax', layout: false
end end

View File

@ -1,4 +1,5 @@
class Projects::ProjectsController < Projects::BaseController class Projects::ProjectsController < Projects::BaseController
include DatatableHelper
include ProjectsHelper include ProjectsHelper
before_filter :authenticate_user! before_filter :authenticate_user!
load_and_authorize_resource id_param: :name_with_owner # to force member actions load 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) def prepare_list(projects, groups, owners)
res = {} 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 res[:total_count] = projects.count
if groups.present? || owners.present? if groups.present? || owners.present?
@ -188,13 +183,9 @@ class Projects::ProjectsController < Projects::BaseController
res[:filtered_count] = projects.count res[:filtered_count] = projects.count
projects = projects.order(order) projects = projects.order("name #{sort_dir}")
res[:projects] = if params[:iDisplayLength].present? res[:projects] = if params[:iDisplayLength].present?
start = params[:iDisplayStart].present? ? params[:iDisplayStart].to_i : 0 projects.paginate(page: page, per_page: per_page)
length = params[:iDisplayLength].to_i
page = start/length + 1
projects.paginate(page: page, per_page: length)
else else
projects projects
end 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,11 +1,60 @@
module MassBuildHelper 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 def link_to_list platform, mass_build, which
link_to t("layout.mass_builds.#{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) target: "_blank" if can?(:get_list, mass_build)
end end
def link_to_mass_build(mass_build) 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}" link_to mass_build.name, build_lists_path+"#?#{{filter: {mass_build_id: mass_build.id, ownership: 'everything'}}.to_param}"
end 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 end

View File

@ -10,11 +10,12 @@ class MassBuild < ActiveRecord::Base
scope :recent, -> { order(created_at: :desc) } scope :recent, -> { order(created_at: :desc) }
scope :by_platform, -> (platform) { where(save_to_platform_id: platform.id) } 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 :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_accessor :arches
attr_accessible :arches, :auto_publish, :projects_list, :build_for_platform_id, attr_accessible :arches, :auto_publish, :projects_list, :build_for_platform_id,
:extra_repositories, :extra_build_lists, :increase_release_tag, :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, validates :save_to_platform_id,
:build_for_platform_id, :build_for_platform_id,
@ -27,6 +28,9 @@ class MassBuild < ActiveRecord::Base
presence: true, presence: true,
length: { maximum: 500_000 } length: { maximum: 500_000 }
validates :description,
length: { maximum: 255 }
validates :auto_publish, validates :auto_publish,
:increase_release_tag, :increase_release_tag,
:use_cached_chroot, :use_cached_chroot,

View File

@ -3,18 +3,16 @@
= link_to t('layout.mass_builds.new'), new_platform_mass_build_path(@platform), class: 'button' if can? :create, @platform.mass_builds.build = 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 %thead
%tr %tr
%th.lpadding16= t('activerecord.attributes.mass_build.id') %th.lpadding16= t('activerecord.attributes.mass_build.id')
%th.lpadding16= t('activerecord.attributes.mass_build.name') %th.lpadding16= t('activerecord.attributes.mass_build.name')
%th.th2= t('activerecord.attributes.mass_build.description')
%th.lpadding16= t('activerecord.attributes.mass_build.created_at') %th.lpadding16= t('activerecord.attributes.mass_build.created_at')
%th.lpadding16 %th.buttons &nbsp;
- @mass_builds.each do |mass_build| %tbody
%tr %br
%td= mass_build.id
%td= link_to_mass_build(mass_build)
%td= mass_build.created_at
%td.right.mass-build-actions
= link_to t('layout.show'), platform_mass_build_path(@platform, mass_build.id)
= will_paginate @mass_builds

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 .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" = 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 = 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') %h3=t('layout.mass_builds.projects_list')
= f.text_area :projects_list = f.text_area :projects_list
%br %br

View File

@ -11,7 +11,7 @@
%b= t('activerecord.attributes.mass_build.name') %b= t('activerecord.attributes.mass_build.name')
%td= link_to_mass_build(@mass_build) %td= link_to_mass_build(@mass_build)
- %i(id arch_names auto_publish increase_release_tag use_cached_chroot use_extra_tests created_at).each do |field| - %i(id arch_names auto_publish increase_release_tag use_cached_chroot use_extra_tests created_at description).each do |field|
%tr %tr
%td %td
%b= t("activerecord.attributes.mass_build.#{field}") %b= t("activerecord.attributes.mass_build.#{field}")

View File

@ -16,6 +16,9 @@ en:
cancel_confirm: Are you sure you want to cancel mass build? cancel_confirm: Are you sure you want to cancel mass build?
projects_list: Projects list projects_list: Projects list
missed_projects_list: 'Missed projects: ' missed_projects_list: 'Missed projects: '
placeholder:
description: Description
activerecord: activerecord:
models: models:
mass_build: Mass Build mass_build: Mass Build
@ -23,6 +26,7 @@ en:
mass_build: mass_build:
id: Id id: Id
name: Name name: Name
description: Description
created_at: Created created_at: Created
updated_at: Updated updated_at: Updated
arch_names: Architectures arch_names: Architectures

View File

@ -16,6 +16,10 @@ ru:
cancel_confirm: Вы уверены, что хотите отменить массовую сборку? cancel_confirm: Вы уверены, что хотите отменить массовую сборку?
projects_list: Проекты projects_list: Проекты
missed_projects_list: 'Несуществующие проекты: ' missed_projects_list: 'Несуществующие проекты: '
placeholder:
description: Описание
activerecord: activerecord:
models: models:
mass_build: Массовая Сборка mass_build: Массовая Сборка
@ -23,6 +27,7 @@ ru:
mass_build: mass_build:
id: Id id: Id
name: Название name: Название
description: Описание
created_at: Создан created_at: Создан
updated_at: Обновлен updated_at: Обновлен
arch_names: Архитектуры arch_names: Архитектуры

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. # 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 # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -327,6 +327,7 @@ ActiveRecord::Schema.define(version: 20140625204136) do
t.boolean "increase_release_tag", default: false, null: false t.boolean "increase_release_tag", default: false, null: false
t.boolean "use_cached_chroot", default: true, null: false t.boolean "use_cached_chroot", default: true, null: false
t.boolean "use_extra_tests", default: false, null: false t.boolean "use_extra_tests", default: false, null: false
t.string "description"
end end
create_table "users", force: true do |t| create_table "users", force: true do |t|

View File

@ -23,6 +23,7 @@ describe MassBuild do
it { should validate_presence_of(:projects_list)} it { should validate_presence_of(:projects_list)}
it { should ensure_length_of(:projects_list).is_at_most(500_000) } 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(:name) }
it { should_not allow_mass_assignment_of(:arch_names) } it { should_not allow_mass_assignment_of(:arch_names) }