fix searching in external article database (#772)
This commit is contained in:
parent
661fab0e0c
commit
4043433539
4 changed files with 7 additions and 13 deletions
|
@ -215,10 +215,10 @@ class ArticlesController < ApplicationController
|
||||||
#
|
#
|
||||||
def shared
|
def shared
|
||||||
# build array of keywords, required for ransack _all suffix
|
# build array of keywords, required for ransack _all suffix
|
||||||
params[:q][:name_cont_all] = params[:q][:name_cont_all].split(' ') if params[:q]
|
q = params.fetch(:q, {})
|
||||||
# Build search with meta search plugin
|
q[:name_cont_all] = params.fetch(:name_cont_all_joined, '').split(' ')
|
||||||
@search = @supplier.shared_supplier.shared_articles.search(params[:q])
|
search = @supplier.shared_supplier.shared_articles.ransack(q)
|
||||||
@articles = @search.result.page(params[:page]).per(10)
|
@articles = search.result.page(params[:page]).per(10)
|
||||||
render :layout => false
|
render :layout => false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -12,10 +12,4 @@ module ArticlesHelper
|
||||||
classes << "just-updated" if article.recently_updated && article.availability
|
classes << "just-updated" if article.recently_updated && article.availability
|
||||||
classes.join(" ")
|
classes.join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
# Flatten search params, used in import from external database
|
|
||||||
def search_params
|
|
||||||
return {} unless params[:q]
|
|
||||||
Hash[params[:q].map { |k,v| [k, (v.is_a?(Array) ? v.join(" ") : v)] }]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
- if @articles.empty?
|
- if @articles.empty?
|
||||||
%p= t '.not_found'
|
%p= t '.not_found'
|
||||||
- else
|
- else
|
||||||
= pagination_links_remote @articles, :params => {:q => search_params}
|
= pagination_links_remote @articles
|
||||||
%table.table.table-striped
|
%table.table.table-striped
|
||||||
%thead
|
%thead
|
||||||
%tr
|
%tr
|
||||||
|
@ -15,7 +15,7 @@
|
||||||
%tbody
|
%tbody
|
||||||
- for article in @articles
|
- for article in @articles
|
||||||
%tr{id: "shared_article_#{article.id}"}
|
%tr{id: "shared_article_#{article.id}"}
|
||||||
%td= highlight article.name, search_params[:name_cont_all]
|
%td= highlight article.name, params.fetch(:name_cont_all_joined, '').split(' ')
|
||||||
%td= article.origin
|
%td= article.origin
|
||||||
%td= article.manufacturer
|
%td= article.manufacturer
|
||||||
%td{title: article.note}= truncate(article.note, length: 11)
|
%td{title: article.note}= truncate(article.note, length: 11)
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
= form_tag shared_supplier_articles_path(@supplier), method: :get, remote: true, class: 'form-search',
|
= form_tag shared_supplier_articles_path(@supplier), method: :get, remote: true, class: 'form-search',
|
||||||
'data-submit-onchange' => true do
|
'data-submit-onchange' => true do
|
||||||
%h3{style: 'display: inline; vertical-align: middle; margin-right: 1em;'}= t('.import.title') + ' '
|
%h3{style: 'display: inline; vertical-align: middle; margin-right: 1em;'}= t('.import.title') + ' '
|
||||||
= text_field_tag "q[name_cont_all]", "", class: 'input-medium search-query',
|
= text_field_tag "name_cont_all_joined", "", class: 'input-medium search-query',
|
||||||
placeholder: t('.import.placeholder')
|
placeholder: t('.import.placeholder')
|
||||||
%label.checkbox
|
%label.checkbox
|
||||||
= check_box_tag "q[origin_eq]", "REG", false
|
= check_box_tag "q[origin_eq]", "REG", false
|
||||||
|
|
Loading…
Reference in a new issue