2012-10-26 10:04:52 +00:00
|
|
|
module MapsHelper
|
2014-01-29 03:46:58 +00:00
|
|
|
|
|
|
|
## this one is for building our custom JSON autocomplete format for typeahead
|
|
|
|
def autocomplete_map_array_json(maps)
|
|
|
|
temp = []
|
|
|
|
maps.each do |m|
|
|
|
|
map = {}
|
|
|
|
map['id'] = m.id
|
|
|
|
map['label'] = m.name
|
2014-02-05 03:03:24 +00:00
|
|
|
map['value'] = m.name
|
2014-01-29 03:46:58 +00:00
|
|
|
map['description'] = m.desc.truncate(30)
|
|
|
|
map['permission'] = m.permission
|
|
|
|
map['topicCount'] = m.topics.count
|
|
|
|
map['synapseCount'] = m.synapses.count
|
|
|
|
map['contributorCount'] = m.contributors.count
|
2014-02-02 19:56:07 +00:00
|
|
|
map['rtype'] = "map"
|
2014-01-29 03:46:58 +00:00
|
|
|
|
2014-11-23 00:35:03 +00:00
|
|
|
contributorTip = ''
|
2014-11-24 03:28:29 +00:00
|
|
|
firstContributorImage = '/assets/user.png'
|
2014-11-23 00:35:03 +00:00
|
|
|
if m.contributors.count > 0
|
2014-11-25 20:06:30 +00:00
|
|
|
firstContributorImage = m.contributors[0].image.url(:thirtytwo)
|
2014-11-23 00:35:03 +00:00
|
|
|
m.contributors.each_with_index do |c, index|
|
2014-11-25 20:06:30 +00:00
|
|
|
userImage = c.image.url(:thirtytwo)
|
2014-11-23 00:35:03 +00:00
|
|
|
name = c.name
|
2014-11-23 04:05:31 +00:00
|
|
|
contributorTip += '<li> <img class="tipUserImage" width="25" height="25" src=' + userImage + ' />' + '<span>' + name + '</span> </li>'
|
2014-11-23 00:35:03 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
map['contributorTip'] = contributorTip
|
2014-11-24 03:28:29 +00:00
|
|
|
map['mapContributorImage'] = firstContributorImage
|
|
|
|
|
2014-01-29 03:46:58 +00:00
|
|
|
temp.push map
|
|
|
|
end
|
|
|
|
return temp
|
|
|
|
end
|
|
|
|
|
2015-01-24 21:37:40 +00:00
|
|
|
def linkeddata(map)
|
|
|
|
|
|
|
|
@alltopics = map.topics.delete_if {|t| t.permission == "private" && (!authenticated? || (authenticated? && @current.id != t.user_id)) }
|
|
|
|
|
|
|
|
js = Hash.new()
|
|
|
|
|
|
|
|
js['@context'] = { "@vocab" => "http://schema.org/", "mm" => "http://ns.metamaps.cc/", "mmc" => "http://metamaps.cc/metacodes/" }
|
|
|
|
js['@id'] = "http://metamaps.cc/maps/" + map.id.to_s
|
|
|
|
js['@type'] = [ "CreativeWork", "mm:Metamap" ]
|
|
|
|
js['name'] = map.name
|
|
|
|
js['description'] = map.desc
|
|
|
|
|
|
|
|
graph = []
|
|
|
|
|
|
|
|
@alltopics.each do |t|
|
|
|
|
topic = Hash.new()
|
|
|
|
topic['@id'] = 'http://metamaps.cc/topics/' + t.id.to_s
|
|
|
|
topic['@type'] = [
|
|
|
|
'mmc:' + t.metacode_id.to_s
|
|
|
|
]
|
|
|
|
topic['name'] = t.name
|
|
|
|
|
|
|
|
t.synapses2.each do |s|
|
|
|
|
topic['http://metamaps.cc/synapses/' + s.id.to_s] = [ 'http://metamaps.cc/topics/' + s.node1_id.to_s ]
|
|
|
|
end
|
|
|
|
|
|
|
|
graph.push(topic)
|
|
|
|
end
|
|
|
|
|
|
|
|
js['@graph'] = graph
|
|
|
|
|
|
|
|
return js
|
|
|
|
end
|
2012-10-26 10:04:52 +00:00
|
|
|
end
|
2015-01-24 21:37:40 +00:00
|
|
|
|
|
|
|
|