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 = {})
|
||||
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
|
||||
|
|
|
@ -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 ######
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue