Add project name and bs_id filters for the build_lists list. Refactor and code cleanup to close #2

This commit is contained in:
Pavel Chipiga 2011-12-08 00:46:01 +02:00
parent 26689f3bd2
commit b89416e125
4 changed files with 69 additions and 64 deletions

View File

@ -76,6 +76,7 @@ class BuildList < ActiveRecord::Base
where(["notified_at <= ?", end_date])
end
}
scope :scoped_to_project_name, lambda {|project_name| joins(:project).where('projects.name LIKE ?', "%#{project_name}%")}
serialize :additional_repos

View File

@ -1,32 +1,30 @@
class BuildList::Filter
def initialize(project, options = {})
@project = project
set_options(options)
end
def find
if @project.nil?
build_lists = BuildList.recent
else
build_lists = @project.build_lists.recent
end
build_lists = @project ? @project.build_lists : BuildList.scoped
if @options[:bs_id]
build_lists = build_lists.where(:bs_id => @options[:bs_id])
else
build_lists = build_lists.for_status(@options[:status]) if @options[:status]
build_lists = build_lists.scoped_to_arch(@options[:arch_id]) if @options[:arch_id]
build_lists = build_lists.scoped_to_project_version(@options[:project_version]) if @options[:project_version]
build_lists = build_lists.scoped_to_is_circle(@options[:is_circle]) if @options[:is_circle].present?
build_lists = build_lists.scoped_to_project_name(@options[:project_name]) if @options[:project_name]
if @options[:created_at_start] || @options[:created_at_end]
build_lists = build_lists.for_creation_date_period(@options[:created_at_start], @options[:created_at_end])
end
if @options[:notified_at_start] || @options[:notified_at_end]
build_lists = build_lists.for_notified_date_period(@options[:notified_at_start], @options[:notified_at_end])
end
end
build_lists
build_lists.recent
end
def respond_to?(name)
@ -39,6 +37,7 @@ class BuildList::Filter
end
private
def set_options(options)
@options = HashWithIndifferentAccess.new(options.reverse_merge({
:status => nil,
@ -48,7 +47,9 @@ class BuildList::Filter
:notified_at_end => nil,
:arch_id => nil,
:is_circle => nil,
:project_version => nil
:project_version => nil,
:bs_id => nil,
:project_name => nil
}))
@options[:status] = @options[:status].present? ? @options[:status].to_i : nil
@ -56,9 +57,11 @@ class BuildList::Filter
@options[:created_at_end] = build_date_from_params(:created_at_end, @options)
@options[:notified_at_start] = build_date_from_params(:notified_at_start, @options)
@options[:notified_at_end] = build_date_from_params(:notified_at_end, @options)
@options[:project_version] = @options[:project_version].present? ? @options[:project_version] : nil
@options[:project_version] = @options[:project_version].presence
@options[:arch_id] = @options[:arch_id].present? ? @options[:arch_id].to_i : nil
@options[:is_circle] = @options[:is_circle].present? ? @options[:is_circle] == "1" : nil
@options[:bs_id] = @options[:bs_id].presence
@options[:project_name] = @options[:project_name].presence
end
def build_date_from_params(field_name, params)
@ -70,5 +73,4 @@ class BuildList::Filter
nil
end
end
end

View File

@ -3,48 +3,48 @@
= form_for :filter, :url => @action_url, :html => { :method => :get, :class => :form } do |f|
.columns.wat-cf
.column.left
.group
= f.label :status, t("activerecord.attributes.build_list.status"), :class => :label
= f.select :status, BuildList::STATUSES.collect{|status| [BuildList.human_status(status), status]}, :include_blank => true, :selected => @filter.status
.group
= f.label :arch_id, t("activerecord.attributes.build_list.arch"), :class => :label
= f.select :arch_id, @arches.collect{|arch| [arch.name, arch.id]}, :include_blank => true, :selected => @filter.arch_id
.column.right
- if @project_versions
.group
= f.label :project_version, t("activerecord.attributes.build_list.project_version"), :class => :label
= f.select :project_version, @project_versions, :include_blank => true, :selected => @filter.project_version
.group
= f.label :is_circle, t("activerecord.attributes.build_list.is_circle"), :class => :label
= f.select :is_circle, [[t("layout.yes_"), 1], [t("layout.no_"), 0]], :include_blank => true, :selected => @filter.is_circle.present? ? (@filter.is_circle ? "1" : "0") : nil
.columns.wat-cf
.column.left
.group
= f.label :status, t("layout.build_lists.created_at_start"), :class => :label
= f.date_select(:created_at_start, :include_blank => true, :selected => @filter.created_at_start)
.group
= f.label :status, t("layout.build_lists.notified_at_start"), :class => :label
= f.date_select(:notified_at_start, :include_blank => true, :selected => @filter.notified_at_start)
.column.right
.group
= f.label :status, t("layout.build_lists.created_at_end"), :class => :label
= f.date_select(:created_at_end, :include_blank => true, :selected => @filter.created_at_end)
.group
= f.label :status, t("layout.build_lists.notified_at_end"), :class => :label
= f.date_select(:notified_at_end, :include_blank => true, :selected => @filter.notified_at_end)
.columns.wat-cf
.column.left
.group
= f.label :status, t("layout.build_lists.created_at_start"), :class => :label
= date_select("filter", :created_at_start, :include_blank => true, :selected => @filter.created_at_start)
.group
= f.label :status, t("layout.build_lists.notified_at_start"), :class => :label
= date_select("filter", :notified_at_start, :include_blank => true, :selected => @filter.notified_at_start)
= f.label :status, t("layout.build_lists.bs_id"), :class => :label
= f.text_field :bs_id, :class => :text_field
.column.right
.group
= f.label :status, t("layout.build_lists.created_at_end"), :class => :label
= date_select("filter", :created_at_end, :include_blank => true, :selected => @filter.created_at_end)
= f.label :status, t("layout.build_lists.project_name"), :class => :label
= f.text_field :project_name, :class => :text_field
.group
= f.label :status, t("layout.build_lists.notified_at_end"), :class => :label
= date_select("filter", :notified_at_end, :include_blank => true, :selected => @filter.notified_at_end)
.grou.navform.wat-cf
.group.navform.wat-cf
%button.button{ :type => "submit" }
= image_tag("web-app-theme/icons/tick.png", :alt => "Save")
= t("layout.search")

View File

@ -279,6 +279,8 @@ ru:
created_at_end: "Время постановки на сборку по:"
notified_at_start: "Время последнего обновления от BS с:"
notified_at_end: "Время последнего обновления от BS по:"
bs_id: 'Id в ядре'
project_name: 'Название проекта'
bs_id_not_set: Id еще не присвоен
items_header: Элементы сборки
no_items_data: Данных нет