2013-01-01 22:45:35 +00:00
|
|
|
module TopicsHelper
|
2014-01-29 03:46:58 +00:00
|
|
|
## this one is for building our custom JSON autocomplete format for typeahead
|
|
|
|
def autocomplete_array_json(topics)
|
|
|
|
temp = []
|
|
|
|
topics.each do |t|
|
|
|
|
topic = {}
|
|
|
|
topic['id'] = t.id
|
|
|
|
topic['label'] = t.name
|
2014-02-05 03:03:24 +00:00
|
|
|
topic['value'] = t.name
|
2016-03-25 06:36:57 +00:00
|
|
|
topic['description'] = t.desc ? t.desc.truncate(70) : '' # make this return matched results
|
2014-01-29 03:46:58 +00:00
|
|
|
topic['type'] = t.metacode.name
|
2014-05-30 15:00:31 +00:00
|
|
|
topic['typeImageURL'] = t.metacode.icon
|
2014-01-29 03:46:58 +00:00
|
|
|
topic['permission'] = t.permission
|
|
|
|
topic['mapCount'] = t.maps.count
|
|
|
|
topic['synapseCount'] = t.synapses.count
|
|
|
|
topic['originator'] = t.user.name
|
2014-11-25 20:06:30 +00:00
|
|
|
topic['originatorImage'] = t.user.image.url(:thirtytwo)
|
2016-07-26 00:14:23 +00:00
|
|
|
topic['rtype'] = 'topic'
|
2014-11-26 19:44:31 +00:00
|
|
|
topic['inmaps'] = t.inmaps
|
2014-11-27 20:02:44 +00:00
|
|
|
topic['inmapsLinks'] = t.inmapsLinks
|
2016-07-26 00:14:23 +00:00
|
|
|
|
2014-01-29 03:46:58 +00:00
|
|
|
temp.push topic
|
|
|
|
end
|
2016-07-26 00:14:23 +00:00
|
|
|
temp
|
2014-01-29 03:46:58 +00:00
|
|
|
end
|
|
|
|
|
2016-07-26 00:14:23 +00:00
|
|
|
# find all nodes in any given nodes network
|
2013-01-01 22:45:35 +00:00
|
|
|
def network(node, array, count)
|
2016-07-26 00:14:23 +00:00
|
|
|
# recurse starting with a node to find all connected nodes and return an array of topics that constitutes the starting nodes network
|
|
|
|
|
|
|
|
# if the array of nodes is empty initialize it
|
|
|
|
array = [] if array.nil?
|
|
|
|
|
|
|
|
# add the node to the array
|
|
|
|
array.push(node)
|
|
|
|
|
|
|
|
return array if count == 0
|
|
|
|
|
|
|
|
count -= 1
|
|
|
|
|
|
|
|
# check if each relative is already in the array and if not, call the network function again
|
|
|
|
if !node.relatives.empty?
|
|
|
|
if (node.relatives - array).empty?
|
|
|
|
return array
|
|
|
|
else
|
|
|
|
(node.relatives - array).each do |relative|
|
|
|
|
array = (array | network(relative, array, count))
|
|
|
|
end
|
|
|
|
return array
|
|
|
|
end
|
|
|
|
|
|
|
|
elsif node.relatives.empty?
|
|
|
|
return array
|
|
|
|
end
|
2013-01-01 22:45:35 +00:00
|
|
|
end
|
|
|
|
end
|