Add download for articles

This commit is contained in:
Patrick Gansterer 2020-06-22 16:03:32 +02:00
parent b6f5295267
commit 5a9cc811c9
5 changed files with 52 additions and 0 deletions

View file

@ -21,6 +21,12 @@ class ArticlesController < ApplicationController
end
@articles = Article.undeleted.where(supplier_id: @supplier, :type => nil).includes(:article_category).order(sort)
if request.format.csv?
send_data ArticlesCsv.new(@articles, encoding: 'utf-8').to_csv, filename: 'articles.csv', type: 'text/csv'
return
end
@articles = @articles.where('articles.name LIKE ?', "%#{params[:query]}%") unless params[:query].nil?
@articles = @articles.page(params[:page]).per(@per_page)

View file

@ -26,6 +26,7 @@
= link_to t('.new'), new_supplier_article_path(@supplier), remote: true, class: "btn #{'btn-primary' unless @supplier.shared_supplier}"
= link_to t('.edit_all'), edit_all_supplier_articles_path(@supplier), class: 'btn'
= link_to t('.upload'), upload_supplier_articles_path(@supplier), class: 'btn'
= link_to t('.download'), supplier_articles_path(@supplier, format: :csv), class: 'btn'
- if current_user.role_orders?
= link_to t('.new_order'), new_order_path(supplier_id: @supplier), class: 'btn'