Add CSV download for ordergroups

This commit is contained in:
Patrick Gansterer 2018-12-21 01:12:43 +01:00
parent 389f205a6b
commit 71fd6f2a24
4 changed files with 56 additions and 2 deletions

View file

@ -1,10 +1,14 @@
# encoding: utf-8
class Admin::OrdergroupsController < Admin::BaseController
inherit_resources
def index
@ordergroups = Ordergroup.undeleted.order('name ASC')
if request.format.csv?
send_data OrdergroupsCsv.new(@ordergroups).to_csv, filename: 'ordergroups.csv', type: 'text/csv'
end
# if somebody uses the search field:
unless params[:query].blank?
@ordergroups = @ordergroups.where('name LIKE ?', "%#{params[:query]}%")

View file

@ -39,6 +39,12 @@ class Ordergroup < Group
.group('groups.id')
end
def self.custom_fields
fields = FoodsoftConfig[:custom_fields] && FoodsoftConfig[:custom_fields][:ordergroup]
return [] unless fields
fields.map(&:deep_symbolize_keys)
end
def last_user_activity
last_active_user = users.order('users.last_activity DESC').first
if last_active_user

View file

@ -2,6 +2,9 @@
- content_for :actionbar do
= link_to t('.new_ordergroup'), new_admin_ordergroup_path, class: 'btn btn-primary'
= link_to url_for(search: params[:q], format: :csv), class: 'btn' do
= glyph :download
CSV
- content_for :sidebar do
%p= t('.first_paragraph', url: link_to(t('.new_ordergroups'), new_admin_ordergroup_path)).html_safe
@ -12,4 +15,4 @@
= text_field_tag :query, params[:query], class: 'input-medium search-query',
placeholder: t('admin.search_placeholder')
#ordergroups
= render "ordergroups"
= render "ordergroups"