Skip to content

Commit

Permalink
Add the ability to export CSVs of all collections
Browse files Browse the repository at this point in the history
Conflicts:

	config/locales/rails_admin.lv.yml
	rails_admin.gemspec
  • Loading branch information
benlangfeld authored and bbenezech committed May 31, 2011
1 parent 785df95 commit 9efb364
Show file tree
Hide file tree
Showing 20 changed files with 41 additions and 5 deletions.
23 changes: 18 additions & 5 deletions app/controllers/rails_admin/main_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,29 @@ def list
format.js { render :layout => 'rails_admin/plain.html.erb' }
format.json do
if params[:compact]
objects = []

@objects.each do |object|
objects << { :id => object.id, :label => object.send(@model_config.object_label_method) }
render :json => @objects.map do |object|
{ :id => object.id, :label => object.send(@model_config.object_label_method) }
end
render :json => objects
else
render :json => @objects.to_json(:only => visible.call)
end
end
format.csv do
csv_string = (CSV.const_defined?(:Reader) ? FasterCSV : CSV).generate do |csv|
csv << visible.call

@objects.each do |object|
csv << [object.id].tap do |row|
visible.call.each do |field|
row << object.send(field)
end
end
end
end

send_data csv_string, :type => 'text/csv; charset=iso-8859-1; header=present',
:disposition => "attachment; filename=#{@abstract_model.pretty_name.downcase}s.csv"
end
format.xml { render :xml => @objects.to_json(:only => visible.call) }
end
end
Expand Down
3 changes: 3 additions & 0 deletions app/views/rails_admin/main/list.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
<%= render(:partial => 'layouts/rails_admin/flash', :locals => {:flash => flash}) -%>
<div class="ra-block-toolbar ui-state-highlight">
<ul>
<li>
<%= link_to(t("admin.list.export_csv"), rails_admin_list_path(:model_name => @abstract_model.to_param, :format => :csv), :class => "ra-button") %>
</li>
<li>
<%= link_to(t("admin.history.name"), rails_admin_history_model_path, :class => "ra-button") %>
</li>
Expand Down
3 changes: 3 additions & 0 deletions config/initializers/mime_types.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require 'csv'
require 'fastercsv' if RUBY_VERSION =~ /^1\.8\./
Mime::Type.register 'text/csv', :csv
1 change: 1 addition & 0 deletions config/locales/rails_admin.bg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ bg:
edit_action: "Редактирай"
delete_action: "Изтрий"
add_new: "Добави"
export_csv: "Export as CSV"
search: "ТЪРСИ"
select: "Избор на %{name} за редакция"
show_all: "Покажи всички"
Expand Down
1 change: 1 addition & 0 deletions config/locales/rails_admin.da.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ da:
edit_action: "Rediger"
delete_action: "Slet"
add_new: "Tilføj ny"
export_csv: "Export as CSV"
search: "SØG"
select: "Vælg %{name} der skal redigeres"
show_all: "Vis alle"
Expand Down
1 change: 1 addition & 0 deletions config/locales/rails_admin.de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ de:
select_action: "Auswählen"
delete_selected: "Auswahl löschen"
add_new: "Neu hinzufügen"
export_csv: "Export as CSV"
search: "Suchen"
select: "Auswählen %{name} zum Bearbeiten"
show_all: "Alle anzeigen"
Expand Down
1 change: 1 addition & 0 deletions config/locales/rails_admin.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ en:
select_action: "Select"
delete_selected: "Delete selected"
add_new: "Add new"
export_csv: "Export as CSV"
search: "Search"
select: "Select %{name} to edit"
show_all: "Show all"
Expand Down
1 change: 1 addition & 0 deletions config/locales/rails_admin.es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ es:
edit_action: "Editar"
delete_action: "Eliminar"
add_new: "Agregar"
export_csv: "Export as CSV"
search: "BUSCAR"
select: "Seleccione %{name} para editar"
show_all: "Mostrar todos"
Expand Down
1 change: 1 addition & 0 deletions config/locales/rails_admin.fi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ fi:
select_action: "Valitse"
delete_selected: "Poista valitut"
add_new: "Lisää uusi"
export_csv: "Export as CSV"
search: "HAKU"
select: "Valitse muokattava %{name}"
show_all: "Näytä kaikki"
Expand Down
1 change: 1 addition & 0 deletions config/locales/rails_admin.fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ fr:
edit_action: "Éditer"
delete_action: "Supprimer"
add_new: "Nouveau"
export_csv: "Export as CSV"
search: "Recherche"
select: "Sélectionner un(e) %{name} pour modification"
show_all: "Afficher tous"
Expand Down
1 change: 1 addition & 0 deletions config/locales/rails_admin.lt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ lt:
select_action: "Pasirinkti"
delete_selected: "Pašalinti pasirinktus"
add_new: "Pridėti"
export_csv: "Export as CSV"
search: "IEŠKOTI"
select: "Pasirinkti %{name} redagavimui"
show_all: "Rodyti visus įrašus"
Expand Down
1 change: 1 addition & 0 deletions config/locales/rails_admin.lv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ lv:
select_action: "Izvēlies"
delete_selected: "Dzēst izvēlētos"
add_new: "Pievienot jaunu"
export_csv: "Export as CSV"
search: "Meklēt"
select: "Izvēlieties %{name}, lai labotu"
show_all: "Parādīt visu"
Expand Down
1 change: 1 addition & 0 deletions config/locales/rails_admin.pl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pl:
edit_action: "Edytuj"
delete_action: "Usuń"
add_new: "Dodaj"
export_csv: "Export as CSV"
search: "SZUKAJ"
select: "Wybierz %{name} do edycji"
show_all: "Wybierz wszystkie"
Expand Down
1 change: 1 addition & 0 deletions config/locales/rails_admin.pt-BR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pt-BR:
edit_action: "Alterar"
delete_action: "Excluir"
add_new: "Adicionar"
export_csv: "Export as CSV"
search: "BUSCAR"
select: "Selecione %{name} para alterar"
show_all: "Exibir todos"
Expand Down
1 change: 1 addition & 0 deletions config/locales/rails_admin.pt-PT.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pt-PT:
edit_action: "Editar"
delete_action: "Remover"
add_new: "Adicionar"
export_csv: "Export as CSV"
search: "PROCURAR"
select: "Selecione %{name} para editar"
show_all: "Exibir todos"
Expand Down
1 change: 1 addition & 0 deletions config/locales/rails_admin.ru.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ ru:
select_action: "Выбрать"
delete_selected: "Удалить выбранные"
add_new: "Добавить"
export_csv: "Export as CSV"
search: "ПОИСК"
select: "Выберите %{name} для редактирования"
show_all: "Показать все"
Expand Down
1 change: 1 addition & 0 deletions config/locales/rails_admin.sv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ sv:
select_action: "Marker"
delete_selected: "Ta bort markerade"
add_new: "Lägg till ny"
export_csv: "Export as CSV"
search: "SÖK"
select: "Markera %{name} för att redigera"
show_all: "Visa alla"
Expand Down
1 change: 1 addition & 0 deletions config/locales/rails_admin.tr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ tr:
edit_action: "Düzenle"
delete_action: "Sil"
add_new: "Yeni ekle"
export_csv: "Export as CSV"
search: "ARA"
select: "Düzenlemek için seçin: %{name}"
show_all: "Hepsini göster"
Expand Down
1 change: 1 addition & 0 deletions config/locales/rails_admin.uk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ uk:
edit_action: "Редагувати"
delete_action: "Видалити"
add_new: "Створити"
export_csv: "Export as CSV"
search: "ПОШУК"
select: "Оберіть %{name} для редагування"
show_all: "Показати все"
Expand Down
1 change: 1 addition & 0 deletions rails_admin.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Gem::Specification.new do |gem|
gem.add_development_dependency 'yard', '~> 0.7'
gem.add_development_dependency 'ZenTest', '~> 4.5'
gem.add_runtime_dependency 'builder', '~> 2.1.0'
gem.add_runtime_dependency 'fastercsv'
gem.add_runtime_dependency 'rails', '~> 3.0.7'
gem.authors = ["Erik Michaels-Ober", "Bogdan Gaza", "Petteri Kääpä"]
gem.description = %q{RailsAdmin is a Rails engine that provides an easy-to-use interface for managing your data}
Expand Down

0 comments on commit 9efb364

Please sign in to comment.