add synapses to XLS and CSV output

This commit is contained in:
Devin Howard 2015-03-01 20:25:23 -05:00
parent 657925e0e2
commit 44c8779d89
3 changed files with 38 additions and 2 deletions

View file

@ -84,14 +84,15 @@ class Map < ActiveRecord::Base
def to_csv(options = {})
CSV.generate(options) do |csv|
csv << ["id", "name", "metacode", "user.name", "permission"]
csv << ["id", "name", "metacode", "user.name", "permission", "synapses"]
self.topics.each do |topic|
csv << [
topic.id,
topic.name,
topic.metacode.name,
topic.user.name,
topic.permission
topic.permission,
topic.synapses_csv("text")
]
end
end

View file

@ -90,6 +90,37 @@ class Topic < ActiveRecord::Base
end
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 ######

View file

@ -5,6 +5,7 @@
<th>Metacode</th>
<th>Username</th>
<th>Permission</th>
<th>Synapses</th>
</tr>
<% @map.topics.each do |topic| %>
<tr>
@ -13,6 +14,9 @@
<td><%= topic.metacode.name %></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>