diff --git a/app/models/build_list.rb b/app/models/build_list.rb index c8648d427..e8aacc4b2 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -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 diff --git a/app/models/build_list/filter.rb b/app/models/build_list/filter.rb index f974c3672..6340dc1b7 100644 --- a/app/models/build_list/filter.rb +++ b/app/models/build_list/filter.rb @@ -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 \ No newline at end of file diff --git a/app/views/build_lists/_filter.html.haml b/app/views/build_lists/_filter.html.haml index 08a35245e..366754f79 100644 --- a/app/views/build_lists/_filter.html.haml +++ b/app/views/build_lists/_filter.html.haml @@ -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"), :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") \ No newline at end of file diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 415a50305..3d3f379ad 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -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: Данных нет