Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix searching in external article database (#772) #773

Merged
merged 1 commit into from
Oct 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions app/controllers/articles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,10 @@ def update_synchronized
#
def shared
# build array of keywords, required for ransack _all suffix
params[:q][:name_cont_all] = params[:q][:name_cont_all].split(' ') if params[:q]
# Build search with meta search plugin
@search = @supplier.shared_supplier.shared_articles.search(params[:q])
@articles = @search.result.page(params[:page]).per(10)
q = params.fetch(:q, {})
q[:name_cont_all] = params.fetch(:name_cont_all_joined, '').split(' ')
search = @supplier.shared_supplier.shared_articles.ransack(q)
@articles = search.result.page(params[:page]).per(10)
render :layout => false
end

Expand Down
6 changes: 0 additions & 6 deletions app/helpers/articles_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,4 @@ def row_classes(article)
classes << "just-updated" if article.recently_updated && article.availability
classes.join(" ")
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
4 changes: 2 additions & 2 deletions app/views/articles/_import_search_results.haml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
- if @articles.empty?
%p= t '.not_found'
- else
= pagination_links_remote @articles, :params => {:q => search_params}
= pagination_links_remote @articles
%table.table.table-striped
%thead
%tr
Expand All @@ -15,7 +15,7 @@
%tbody
- for article in @articles
%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.manufacturer
%td{title: article.note}= truncate(article.note, length: 11)
Expand Down
2 changes: 1 addition & 1 deletion app/views/articles/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
= form_tag shared_supplier_articles_path(@supplier), method: :get, remote: true, class: 'form-search',
'data-submit-onchange' => true do
%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')
%label.checkbox
= check_box_tag "q[origin_eq]", "REG", false
Expand Down