add synapses to XLS and CSV output
This commit is contained in:
parent
657925e0e2
commit
44c8779d89
3 changed files with 38 additions and 2 deletions
|
@ -84,14 +84,15 @@ class Map < ActiveRecord::Base
|
||||||
|
|
||||||
def to_csv(options = {})
|
def to_csv(options = {})
|
||||||
CSV.generate(options) do |csv|
|
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|
|
self.topics.each do |topic|
|
||||||
csv << [
|
csv << [
|
||||||
topic.id,
|
topic.id,
|
||||||
topic.name,
|
topic.name,
|
||||||
topic.metacode.name,
|
topic.metacode.name,
|
||||||
topic.user.name,
|
topic.user.name,
|
||||||
topic.permission
|
topic.permission,
|
||||||
|
topic.synapses_csv("text")
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -91,6 +91,37 @@ class Topic < ActiveRecord::Base
|
||||||
return result
|
return result
|
||||||
end
|
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 ######
|
##### PERMISSIONS ######
|
||||||
|
|
||||||
# returns false if user not allowed to 'show' Topic, Synapse, or Map
|
# returns false if user not allowed to 'show' Topic, Synapse, or Map
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
<th>Metacode</th>
|
<th>Metacode</th>
|
||||||
<th>Username</th>
|
<th>Username</th>
|
||||||
<th>Permission</th>
|
<th>Permission</th>
|
||||||
|
<th>Synapses</th>
|
||||||
</tr>
|
</tr>
|
||||||
<% @map.topics.each do |topic| %>
|
<% @map.topics.each do |topic| %>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -13,6 +14,9 @@
|
||||||
<td><%= topic.metacode.name %></td>
|
<td><%= topic.metacode.name %></td>
|
||||||
<td><%= topic.user.name %></td>
|
<td><%= topic.user.name %></td>
|
||||||
<td><%= topic.permission %></td>
|
<td><%= topic.permission %></td>
|
||||||
|
<% topic.synapses_csv.each do |s_text| %>
|
||||||
|
<td><%= s_text %></td>
|
||||||
|
<% end %>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</table>
|
</table>
|
||||||
|
|
Loading…
Reference in a new issue