implement CSV and XLS export for map topics
This commit is contained in:
parent
253ceb4b48
commit
b5b13841bc
5 changed files with 36 additions and 1 deletions
|
@ -2,7 +2,7 @@ class MapsController < ApplicationController
|
||||||
|
|
||||||
before_filter :require_user, only: [:create, :update, :screenshot, :destroy]
|
before_filter :require_user, only: [:create, :update, :screenshot, :destroy]
|
||||||
|
|
||||||
respond_to :html, :json
|
respond_to :html, :json, :csv
|
||||||
|
|
||||||
autocomplete :map, :name, :full => true, :extra_data => [:user_id]
|
autocomplete :map, :name, :full => true, :extra_data => [:user_id]
|
||||||
|
|
||||||
|
@ -86,6 +86,8 @@ class MapsController < ApplicationController
|
||||||
respond_with(@allmappers, @allmappings, @allsynapses, @alltopics, @map)
|
respond_with(@allmappers, @allmappings, @allsynapses, @alltopics, @map)
|
||||||
}
|
}
|
||||||
format.json { render json: @map }
|
format.json { render json: @map }
|
||||||
|
format.csv { send_data @map.to_csv }
|
||||||
|
format.xls
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -82,6 +82,20 @@ class Map < ActiveRecord::Base
|
||||||
json
|
json
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def to_csv(options = {})
|
||||||
|
CSV.generate(options) do |csv|
|
||||||
|
csv << ["id", "name", "permission", "user.name"]
|
||||||
|
self.topics.each do |topic|
|
||||||
|
csv << [
|
||||||
|
topic.id,
|
||||||
|
topic.name,
|
||||||
|
topic.permission,
|
||||||
|
topic.user.name
|
||||||
|
]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
##### PERMISSIONS ######
|
##### PERMISSIONS ######
|
||||||
|
|
||||||
def authorize_to_delete(user)
|
def authorize_to_delete(user)
|
||||||
|
|
16
app/views/maps/show.xls.erb
Normal file
16
app/views/maps/show.xls.erb
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<th>ID</th>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Permission</th>
|
||||||
|
<th>Username</th>
|
||||||
|
</tr>
|
||||||
|
<% @map.topics.each do |topic| %>
|
||||||
|
<tr>
|
||||||
|
<td><%= topic.id %></td>
|
||||||
|
<td><%= topic.name %></td>
|
||||||
|
<td><%= topic.permission %></td>
|
||||||
|
<td><%= topic.user.name %></td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</table>
|
|
@ -1,5 +1,6 @@
|
||||||
require File.expand_path('../boot', __FILE__)
|
require File.expand_path('../boot', __FILE__)
|
||||||
|
|
||||||
|
require 'csv'
|
||||||
require 'rails/all'
|
require 'rails/all'
|
||||||
|
|
||||||
if defined?(Bundler)
|
if defined?(Bundler)
|
||||||
|
|
|
@ -3,3 +3,5 @@
|
||||||
# Add new mime types for use in respond_to blocks:
|
# Add new mime types for use in respond_to blocks:
|
||||||
# Mime::Type.register "text/richtext", :rtf
|
# Mime::Type.register "text/richtext", :rtf
|
||||||
# Mime::Type.register_alias "text/html", :iphone
|
# Mime::Type.register_alias "text/html", :iphone
|
||||||
|
|
||||||
|
Mime::Type.register "application/xls", :xls
|
||||||
|
|
Loading…
Add table
Reference in a new issue