diff --git a/app/models/map.rb b/app/models/map.rb index ddcefb86..280fcef3 100644 --- a/app/models/map.rb +++ b/app/models/map.rb @@ -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 diff --git a/app/models/topic.rb b/app/models/topic.rb index 7e5fff94..b4218202 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -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 ###### diff --git a/app/views/maps/show.xls.erb b/app/views/maps/show.xls.erb index f455ff1d..55b89552 100644 --- a/app/views/maps/show.xls.erb +++ b/app/views/maps/show.xls.erb @@ -5,6 +5,7 @@