Merge pull request #352 from abf/rosa-build:351-ability-to-search-by-package-name-in-advisory-list

#351: Ability to search by package name in advisory list
This commit is contained in:
avm 2014-02-13 00:13:54 +04:00
commit 89a90bda02
5 changed files with 12 additions and 6 deletions

View File

@ -5,9 +5,8 @@ class AdvisoriesController < ApplicationController
authorize_resource authorize_resource
def index def index
@advisories = @advisories.scoped(include: :platforms) @advisories = @advisories.includes(:platforms).search(params[:q]).
@advisories = @advisories.search_by_id(params[:q]) if params[:q] uniq.paginate(page: params[:page])
@advisories = @advisories.paginate(page: params[:page])
respond_to do |format| respond_to do |format|
format.html format.html
format.atom format.atom

View File

@ -13,6 +13,11 @@ class Advisory < ActiveRecord::Base
ID_STRING_TEMPLATE = 'ROSA-%<type>s-%<year>04s:%<id>04s' ID_STRING_TEMPLATE = 'ROSA-%<type>s-%<year>04s:%<id>04s'
TYPES = {'security' => 'SA', 'bugfix' => 'A'} TYPES = {'security' => 'SA', 'bugfix' => 'A'}
scope :search, lambda { |q|
q = q.to_s.strip
where("#{table_name}.advisory_id ILIKE :q OR #{table_name}.description ILIKE :q OR build_list_packages.fullname ILIKE :q", q: "%#{q}%").
joins(build_lists: :packages) if q.present?
}
scope :search_by_id, lambda { |aid| where("#{table_name}.advisory_id ILIKE ?", "%#{aid.to_s.strip}%") } scope :search_by_id, lambda { |aid| where("#{table_name}.advisory_id ILIKE ?", "%#{aid.to_s.strip}%") }
scope :by_update_type, lambda { |ut| where(update_type: ut) } scope :by_update_type, lambda { |ut| where(update_type: ut) }
default_scope order("#{table_name}.created_at DESC") default_scope order("#{table_name}.created_at DESC")

View File

@ -8,7 +8,7 @@
-# TODO: change filter to Backbone.js -# TODO: change filter to Backbone.js
%th{colspan: 3, rowspan: 1} %th{colspan: 3, rowspan: 1}
= form_tag advisories_path, method: :get do |f| = form_tag advisories_path, method: :get do |f|
= text_field_tag('q', params[:q], placeholder: t('layout.advisories.search_by_id'), class: params[:q].present? ? 'black' : 'gray', style: 'width:600px;') = text_field_tag('q', params[:q], placeholder: t('layout.advisories.search'), class: params[:q].present? ? 'black' : 'gray', style: 'width:600px;')
= submit_tag t('layout.search.header'), data: {'disable-with' => t('layout.processing')} = submit_tag t('layout.search.header'), data: {'disable-with' => t('layout.processing')}
=# link_to t('layout.back'), advisories_path, class: 'button' =# link_to t('layout.back'), advisories_path, class: 'button'
= button_to t('layout.clear'), {action: :index} , method: :get = button_to t('layout.clear'), {action: :index} , method: :get

View File

@ -14,6 +14,7 @@ en:
new: New new: New
existing: Existing existing: Existing
search_by_id: Search advisory by it's ID search_by_id: Search advisory by it's ID
search: Search advisory by it's ID, description or package name
search_hint: Paste full AdvisoryID into text field or enter there its uniq part. search_hint: Paste full AdvisoryID into text field or enter there its uniq part.
advisory_id_info: AdvisoryID is a string %{advisory_format}, where 'XXXX' (at least 4 symbols) is a uniq part. advisory_id_info: AdvisoryID is a string %{advisory_format}, where 'XXXX' (at least 4 symbols) is a uniq part.
publication_info: Advisory might be applied only to Build Lists with [%{update_types}] update types. publication_info: Advisory might be applied only to Build Lists with [%{update_types}] update types.

View File

@ -14,6 +14,7 @@ ru:
new: Новый new: Новый
existing: Существующий existing: Существующий
search_by_id: Искать бюллетень по его ID search_by_id: Искать бюллетень по его ID
search: Искать бюллетень по его ID, описанию или имени пакета
search_hint: Скопируйте в поле ввода полный AdvisoryID или введите его уникальную часть search_hint: Скопируйте в поле ввода полный AdvisoryID или введите его уникальную часть
advisory_id_info: AdvisoryID имеет формат %{advisory_format}, где 'XXXX' (минимум 4 символа) - это уникальная часть. advisory_id_info: AdvisoryID имеет формат %{advisory_format}, где 'XXXX' (минимум 4 символа) - это уникальная часть.
publication_info: Бюллетень может быть присоединен только к сборочному листу с типами обновления %{update_types}. publication_info: Бюллетень может быть присоединен только к сборочному листу с типами обновления %{update_types}.