Merge 3473cf3736
into 9ce81df9f9
This commit is contained in:
commit
58c35c50e9
6 changed files with 209 additions and 129 deletions
|
@ -2,7 +2,7 @@ class MapsController < ApplicationController
|
|||
|
||||
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]
|
||||
|
||||
|
@ -86,6 +86,8 @@ class MapsController < ApplicationController
|
|||
respond_with(@allmappers, @allmappings, @allsynapses, @alltopics, @map)
|
||||
}
|
||||
format.json { render json: @map }
|
||||
format.csv { send_data @map.to_csv }
|
||||
format.xls
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -82,6 +82,24 @@ class Map < ActiveRecord::Base
|
|||
json
|
||||
end
|
||||
|
||||
def to_csv(options = {})
|
||||
CSV.generate(options) do |csv|
|
||||
csv << ["id", "name", "metacode", "desc", "link", "user.name", "permission", "synapses"]
|
||||
self.topics.each do |topic|
|
||||
csv << [
|
||||
topic.id,
|
||||
topic.name,
|
||||
topic.metacode.name,
|
||||
topic.desc,
|
||||
topic.link,
|
||||
topic.user.name,
|
||||
topic.permission,
|
||||
topic.synapses_csv("text")
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
##### PERMISSIONS ######
|
||||
|
||||
def authorize_to_delete(user)
|
||||
|
|
|
@ -91,6 +91,37 @@ class Topic < ActiveRecord::Base
|
|||
return result
|
||||
end
|
||||
|
||||
def synapses_csv(output_format = "array")
|
||||
output = []
|
||||
self.synapses.each do |synapse|
|
||||
if synapse.category == "from-to"
|
||||
if synapse.node1_id == self.id
|
||||
output << synapse.node1_id.to_s + "->" + synapse.node2_id.to_s
|
||||
elsif synapse.node2_id == self.id
|
||||
output << synapse.node2_id.to_s + "<-" + synapse.node1_id.to_s
|
||||
else
|
||||
abort("invalid synapse on topic in synapse_csv")
|
||||
end
|
||||
elsif synapse.category == "both"
|
||||
if synapse.node1_id == self.id
|
||||
output << synapse.node1_id.to_s + "<->" + synapse.node2_id.to_s
|
||||
elsif synapse.node2_id == self.id
|
||||
output << synapse.node2_id.to_s + "<->" + synapse.node1_id.to_s
|
||||
else
|
||||
abort("invalid synapse on topic in synapse_csv")
|
||||
end
|
||||
end
|
||||
end
|
||||
if output_format == "array"
|
||||
return output
|
||||
elsif output_format == "text"
|
||||
return output.join("; ")
|
||||
else
|
||||
abort("invalid argument to synapses_csv")
|
||||
end
|
||||
return output
|
||||
end
|
||||
|
||||
##### PERMISSIONS ######
|
||||
|
||||
# returns false if user not allowed to 'show' Topic, Synapse, or Map
|
||||
|
|
26
app/views/maps/show.xls.erb
Normal file
26
app/views/maps/show.xls.erb
Normal file
|
@ -0,0 +1,26 @@
|
|||
<table>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Name</th>
|
||||
<th>Metacode</th>
|
||||
<th>Description</th>
|
||||
<th>Link</th>
|
||||
<th>Username</th>
|
||||
<th>Permission</th>
|
||||
<th>Synapses</th>
|
||||
</tr>
|
||||
<% @map.topics.each do |topic| %>
|
||||
<tr>
|
||||
<td><%= topic.id %></td>
|
||||
<td><%= topic.name %></td>
|
||||
<td><%= topic.metacode.name %></td>
|
||||
<td><%= topic.desc %></td>
|
||||
<td><%= topic.link %></td>
|
||||
<td><%= topic.user.name %></td>
|
||||
<td><%= topic.permission %></td>
|
||||
<% topic.synapses_csv.each do |s_text| %>
|
||||
<td><%= s_text %></td>
|
||||
<% end %>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
|
@ -1,5 +1,6 @@
|
|||
require File.expand_path('../boot', __FILE__)
|
||||
|
||||
require 'csv'
|
||||
require 'rails/all'
|
||||
|
||||
if defined?(Bundler)
|
||||
|
|
|
@ -3,3 +3,5 @@
|
|||
# Add new mime types for use in respond_to blocks:
|
||||
# Mime::Type.register "text/richtext", :rtf
|
||||
# Mime::Type.register_alias "text/html", :iphone
|
||||
|
||||
Mime::Type.register "application/xls", :xls
|
||||
|
|
Loading…
Add table
Reference in a new issue