update xls/csv format to better serialize topics and synapses

This commit is contained in:
Devin Howard 2016-02-12 15:57:34 +08:00
parent 61262aaec2
commit 8f532708ce
2 changed files with 51 additions and 7 deletions

View file

@ -86,12 +86,17 @@ class Map < ActiveRecord::Base
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 << ["topics"]
csv << ["id", "name", "metacode", "x", "y", "desc", "link", "user.name", "permission"]
self.topicmappings.each do |mapping|
topic = mapping.mappable
next if topic.nil?
csv << [
topic.id,
topic.name,
topic.metacode.name,
mapping.x,
mapping.y,
topic.desc,
topic.link,
topic.user.name,
@ -99,6 +104,20 @@ class Map < ActiveRecord::Base
topic.synapses_csv("text")
]
end
csv << []
csv << ["synapses"]
csv << ["id", "description", "category", "topic1", "topic2", "username", "permission"]
self.synapses.each do |synapse|
csv << [
synapse.id,
synapse.desc,
synapse.category,
synapse.node1_id,
synapse.node2_id,
synapse.user.name,
synapse.permission
]
end
end
end

View file

@ -1,26 +1,51 @@
<table>
<tr><th>Topics</th></tr>
<tr>
<th>ID</th>
<th>Name</th>
<th>Metacode</th>
<th>X</th>
<th>Y</th>
<th>Description</th>
<th>Link</th>
<th>Username</th>
<th>Permission</th>
<th>Synapses</th>
</tr>
<% @map.topics.each do |topic| %>
<% @map.topicmappings.each do |mapping| %>
<% topic = mapping.mappable %>
<% next if topic.nil? %>
<tr>
<td><%= topic.id %></td>
<td><%= topic.name %></td>
<td><%= topic.metacode.name %></td>
<td><%= mapping.xloc %></td>
<td><%= mapping.yloc %></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 %>
<tr></tr>
<tr><th>Synapses</th></tr>
<tr>
<th>ID</th>
<th>Description</th>
<th>Category</th>
<th>Topic1</th>
<th>Topic2</th>
<th>Username</th>
<th>Permission</th>
</tr>
<% @map.synapses.each do |synapse| %>
<tr>
<td><%= synapse.id %></td>
<td><%= synapse.desc %></td>
<td><%= synapse.category %></td>
<td><%= synapse.node1_id %></td>
<td><%= synapse.node2_id %></td>
<td><%= synapse.user.name %></td>
<td><%= synapse.permission %></td>
</tr>
<% end %>
</table>