From 987d68198cd0d4711d25693b5c2cf0d0fc7f6ecc Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Fri, 12 Feb 2016 15:57:34 +0800 Subject: [PATCH] update xls/csv format to better serialize topics and synapses --- app/models/map.rb | 23 +++++++++++++++++++++-- app/views/maps/show.xls.erb | 35 ++++++++++++++++++++++++++++++----- 2 files changed, 51 insertions(+), 7 deletions(-) diff --git a/app/models/map.rb b/app/models/map.rb index 166afb4a..980173cc 100644 --- a/app/models/map.rb +++ b/app/models/map.rb @@ -81,12 +81,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, @@ -94,6 +99,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 diff --git a/app/views/maps/show.xls.erb b/app/views/maps/show.xls.erb index d00dd36e..4b22257e 100644 --- a/app/views/maps/show.xls.erb +++ b/app/views/maps/show.xls.erb @@ -1,26 +1,51 @@ + + + - - <% @map.topics.each do |topic| %> + <% @map.topicmappings.each do |mapping| %> + <% topic = mapping.mappable %> + <% next if topic.nil? %> + + - <% topic.synapses_csv.each do |s_text| %> - - <% end %> + + <% end %> + + + + + + + + + + + + <% @map.synapses.each do |synapse| %> + + + + + + + + <% end %>
Topics
ID Name MetacodeXY Description Link Username PermissionSynapses
<%= topic.id %> <%= topic.name %> <%= topic.metacode.name %><%= mapping.xloc %><%= mapping.yloc %> <%= topic.desc %> <%= topic.link %> <%= topic.user.name %> <%= topic.permission %><%= s_text %>
Synapses
IDDescriptionCategoryTopic1Topic2UsernamePermission
<%= synapse.id %><%= synapse.desc %><%= synapse.category %><%= synapse.node1_id %><%= synapse.node2_id %><%= synapse.user.name %><%= synapse.permission %>