diff --git a/app/assets/stylesheets/design/custom.scss b/app/assets/stylesheets/design/custom.scss index 4475219a4..9746f9b30 100644 --- a/app/assets/stylesheets/design/custom.scss +++ b/app/assets/stylesheets/design/custom.scss @@ -1094,3 +1094,25 @@ form.mass_build section.right { .packages_info_container ul.platforms { padding: 0; } + +/* remove this lines after change to backbone */ +table.tablesorter.advisories thead tr.search th { + padding: 0 5px; +} + +table.tablesorter.advisories thead tr.search th input[type='text'] { + width: 640px; +} + +table.tablesorter.advisories thead tr.search th form { + float: left; +} + +table.tablesorter.advisories thead tr.search th form.button_to { + padding: 3px 0 0 7px; +} + +table.tablesorter tr td.no_results { + text-align: center; +} +/* end */ diff --git a/app/controllers/advisories_controller.rb b/app/controllers/advisories_controller.rb index 69e73cc96..c0a6dbe23 100644 --- a/app/controllers/advisories_controller.rb +++ b/app/controllers/advisories_controller.rb @@ -6,7 +6,9 @@ class AdvisoriesController < ApplicationController authorize_resource def index - @advisories = @advisories.scoped(:include => :platforms).paginate(:page => params[:page]) + @advisories = @advisories.scoped(:include => :platforms) + @advisories = @advisories.search_by_id(params[:q]) if params[:q] + @advisories = @advisories.paginate(:page => params[:page]) respond_to do |format| format.html format.atom diff --git a/app/models/advisory.rb b/app/models/advisory.rb index 2dc3a3110..facedbb91 100644 --- a/app/models/advisory.rb +++ b/app/models/advisory.rb @@ -12,6 +12,7 @@ class Advisory < ActiveRecord::Base TYPES = {'security' => 'SA', 'bugfix' => 'A'} scope :by_project, lambda {|p| where('project_id' => p.try(:id) || p)} + scope :search_by_id, lambda { |aid| where('advisory_id ILIKE ?', "%#{aid.to_s.strip}%") } default_scope order('created_at DESC') def to_param diff --git a/app/views/advisories/_list.html.haml b/app/views/advisories/_list.html.haml index b6d80ebc9..c19ff66b9 100644 --- a/app/views/advisories/_list.html.haml +++ b/app/views/advisories/_list.html.haml @@ -4,5 +4,29 @@ %th.th1= t("activerecord.attributes.advisory.advisory_id") %th.th2= t("layout.advisories.affected_versions") %th.th3= t("activerecord.attributes.advisory.description") + %tr.search + -# TODO: change filter to Backbone.js + %th{:colspan => 3, :rowspan => 1} + = 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') + %input{:type => 'submit', :value => t("layout.search.header")} + =# link_to t('layout.back'), advisories_path, :class => 'button' + = button_to t('layout.clear'), {:action => :index} , :method => :get + %tbody - = render :partial => 'list_item', :collection => list, :as => :advisory + - if list.size > 0 + = render :partial => 'list_item', :collection => list, :as => :advisory + - else + %tr.odd + %td.no_results{:colspan => 3} + = t("layout.search.no_results", :query => params[:q]) + +:javascript + $(function() { + var $search = $('tr.search > th input[type="text"]'); + $search.on('blur focus', function() { + if ($search.val() === '') { + $search.toggleClass('gray black'); + } + }); + }); diff --git a/config/locales/layout.en.yml b/config/locales/layout.en.yml index 3e1625958..d5ff40b31 100644 --- a/config/locales/layout.en.yml +++ b/config/locales/layout.en.yml @@ -14,6 +14,7 @@ en: read_access: read-only by: by + clear: Clear remove: Remove diff --git a/config/locales/layout.ru.yml b/config/locales/layout.ru.yml index ba70c945d..a9782afcd 100644 --- a/config/locales/layout.ru.yml +++ b/config/locales/layout.ru.yml @@ -14,6 +14,7 @@ ru: read_access: только чтение by: '' + clear: Очистить remove: Убрать diff --git a/config/locales/layout/search.en.yml b/config/locales/layout/search.en.yml index 91a1a7a63..177ee6cba 100644 --- a/config/locales/layout/search.en.yml +++ b/config/locales/layout/search.en.yml @@ -4,6 +4,7 @@ en: header: Search advanced: Advanced search all: Show All + no_results: Nothing found for "%{query}". types: all: All projects: Projects diff --git a/config/locales/layout/search.ru.yml b/config/locales/layout/search.ru.yml index 2850bd5bd..53df60bcd 100644 --- a/config/locales/layout/search.ru.yml +++ b/config/locales/layout/search.ru.yml @@ -4,6 +4,7 @@ ru: header: Поиск advanced: Расширенный поиск all: Показать все + no_results: По запросу "%{query}" ничего не найдено. types: all: Все projects: Проекты diff --git a/config/locales/models/advisory.en.yml b/config/locales/models/advisory.en.yml index dcd4b133d..40e2228a0 100644 --- a/config/locales/models/advisory.en.yml +++ b/config/locales/models/advisory.en.yml @@ -10,6 +10,7 @@ en: ref_comment: Add links one by row no_: No new: New + search_by_id: Search advisory by it's ID flash: advisories: diff --git a/config/locales/models/advisory.ru.yml b/config/locales/models/advisory.ru.yml index 749b5622e..1cb0e5a4b 100644 --- a/config/locales/models/advisory.ru.yml +++ b/config/locales/models/advisory.ru.yml @@ -10,6 +10,7 @@ ru: ref_comment: Вставляйте ссылки по одной на строку no_: Нет new: Новый + search_by_id: Искать бюллетень по его ID flash: advisories: