Merge pull request #5 from warpc/build_lists_filter
New build lists filter (search by name and bs_id)
This commit is contained in:
commit
5e3711505c
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
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 = @project.build_lists.recent
|
||||
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.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?
|
||||
|
||||
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
|
||||
|
||||
build_lists
|
||||
build_lists.recent
|
||||
end
|
||||
|
||||
def respond_to?(name)
|
||||
|
@ -39,36 +37,40 @@ class BuildList::Filter
|
|||
end
|
||||
|
||||
private
|
||||
def set_options(options)
|
||||
@options = HashWithIndifferentAccess.new(options.reverse_merge({
|
||||
:status => nil,
|
||||
:created_at_start => nil,
|
||||
:created_at_end => nil,
|
||||
:notified_at_start => nil,
|
||||
:notified_at_end => nil,
|
||||
:arch_id => nil,
|
||||
:is_circle => nil,
|
||||
:project_version => nil
|
||||
}))
|
||||
|
||||
@options[:status] = @options[:status].present? ? @options[:status].to_i : nil
|
||||
@options[:created_at_start] = build_date_from_params(:created_at_start, @options)
|
||||
@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[:arch_id] = @options[:arch_id].present? ? @options[:arch_id].to_i : nil
|
||||
@options[:is_circle] = @options[:is_circle].present? ? @options[:is_circle] == "1" : nil
|
||||
def set_options(options)
|
||||
@options = HashWithIndifferentAccess.new(options.reverse_merge({
|
||||
:status => nil,
|
||||
:created_at_start => nil,
|
||||
:created_at_end => nil,
|
||||
:notified_at_start => nil,
|
||||
:notified_at_end => nil,
|
||||
:arch_id => nil,
|
||||
:is_circle => nil,
|
||||
:project_version => nil,
|
||||
:bs_id => nil,
|
||||
:project_name => nil
|
||||
}))
|
||||
|
||||
@options[:status] = @options[:status].present? ? @options[:status].to_i : nil
|
||||
@options[:created_at_start] = build_date_from_params(:created_at_start, @options)
|
||||
@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].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)
|
||||
if params["#{field_name}(1i)"].present? || params["#{field_name}(2i)"].present? || params["#{field_name}(3i)"].present?
|
||||
Date.civil((params["#{field_name}(1i)"].presence || Date.today.year).to_i,
|
||||
(params["#{field_name}(2i)"].presence || Date.today.mohth).to_i,
|
||||
(params["#{field_name}(3i)"].presence || Date.today.day).to_i)
|
||||
else
|
||||
nil
|
||||
end
|
||||
|
||||
def build_date_from_params(field_name, params)
|
||||
if params["#{field_name}(1i)"].present? || params["#{field_name}(2i)"].present? || params["#{field_name}(3i)"].present?
|
||||
Date.civil((params["#{field_name}(1i)"].presence || Date.today.year).to_i,
|
||||
(params["#{field_name}(2i)"].presence || Date.today.mohth).to_i,
|
||||
(params["#{field_name}(3i)"].presence || Date.today.day).to_i)
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -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
|
||||
= date_select("filter", :created_at_start, :include_blank => true, :selected => @filter.created_at_start)
|
||||
|
||||
= 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
|
||||
= date_select("filter", :notified_at_start, :include_blank => true, :selected => @filter.notified_at_start)
|
||||
|
||||
= 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
|
||||
= date_select("filter", :created_at_end, :include_blank => true, :selected => @filter.created_at_end)
|
||||
|
||||
= 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
|
||||
= date_select("filter", :notified_at_end, :include_blank => true, :selected => @filter.notified_at_end)
|
||||
= f.date_select(:notified_at_end, :include_blank => true, :selected => @filter.notified_at_end)
|
||||
|
||||
.grou.navform.wat-cf
|
||||
.columns.wat-cf
|
||||
.column.left
|
||||
.group
|
||||
= f.label :status, t("layout.build_lists.bs_id_search"), :class => :label
|
||||
= f.text_field :bs_id, :class => :text_field
|
||||
.column.right
|
||||
.group
|
||||
= f.label :status, t("layout.build_lists.project_name"), :class => :label
|
||||
= f.text_field :project_name, :class => :text_field
|
||||
|
||||
.group.navform.wat-cf
|
||||
%button.button{ :type => "submit" }
|
||||
= image_tag("web-app-theme/icons/tick.png", :alt => "Save")
|
||||
= t("layout.search")
|
|
@ -35,4 +35,4 @@ Rosa::Application.configure do
|
|||
config.active_support.deprecation = :stderr
|
||||
end
|
||||
|
||||
require 'stub_xml_rpc'
|
||||
require 'stub_xml_rpc' # TODO stub XML calls through stubbers
|
||||
|
|
|
@ -279,6 +279,8 @@ ru:
|
|||
created_at_end: "Время постановки на сборку по:"
|
||||
notified_at_start: "Время последнего обновления от BS с:"
|
||||
notified_at_end: "Время последнего обновления от BS по:"
|
||||
bs_id_search: 'Поиск по Id'
|
||||
project_name: 'Название проекта'
|
||||
bs_id_not_set: Id еще не присвоен
|
||||
items_header: Элементы сборки
|
||||
no_items_data: Данных нет
|
||||
|
|
|
@ -6,7 +6,6 @@ module XMLRPC
|
|||
case
|
||||
when args.first == 'get_status'
|
||||
{'client_count' => 1, 'count_new_task' => 2, 'count_build_task' => 3}
|
||||
# raise Timeout::Error
|
||||
else; 0
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,8 +2,6 @@ require 'spec_helper'
|
|||
|
||||
describe BuildListsController do
|
||||
context 'crud' do
|
||||
# let(:build_list) { Factory(:build_list) }
|
||||
|
||||
context 'for guest' do
|
||||
it 'should not be able to perform all action' do
|
||||
get :all
|
||||
|
@ -24,10 +22,37 @@ describe BuildListsController do
|
|||
before(:each) { set_session_for Factory(:admin) }
|
||||
|
||||
it "should be able to perform all action without exception" do
|
||||
any_instance_of(XMLRPC::Client) do |xml_rpc|
|
||||
stub(xml_rpc).call do |args|
|
||||
raise Timeout::Error
|
||||
end
|
||||
end
|
||||
get :all
|
||||
assigns[:build_server_status].should == {} # TODO stub to isolate
|
||||
assigns[:build_server_status].should == {}
|
||||
response.should be_success
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'filter' do
|
||||
let(:build_list1) { Factory(:build_list_core) }
|
||||
let(:build_list2) { Factory(:build_list_core) }
|
||||
let(:build_list3) { Factory(:build_list_core) }
|
||||
before(:each) { set_session_for Factory(:admin) }
|
||||
|
||||
it 'should filter by bs_id' do
|
||||
get :all, :filter => {:bs_id => build_list1.bs_id, :project_name => 'fdsfdf', :any_other_field => 'do not matter'}
|
||||
assigns[:build_lists].should include(build_list1)
|
||||
assigns[:build_lists].should_not include(build_list2)
|
||||
assigns[:build_lists].should_not include(build_list3)
|
||||
end
|
||||
|
||||
it 'should filter by project_name' do
|
||||
# Project.where(:id => build_list2.project.id).update_all(:name => 'project_name')
|
||||
get :all, :filter => {:project_name => build_list2.project.name}
|
||||
assigns[:build_lists].should_not include(build_list1)
|
||||
assigns[:build_lists].should include(build_list2)
|
||||
assigns[:build_lists].should_not include(build_list3)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -6,4 +6,8 @@ Factory.define(:build_list) do |p|
|
|||
p.project_version "1.0"
|
||||
p.build_requires true
|
||||
p.update_type 'security'
|
||||
end
|
||||
end
|
||||
|
||||
Factory.define(:build_list_core, :parent => :build_list) do |p|
|
||||
p.bs_id { Factory.next(:integer) }
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue