2016-09-24 11:00:46 +08:00
|
|
|
# frozen_string_literal: true
|
2012-10-26 06:04:52 -04:00
|
|
|
module MapsHelper
|
2014-01-28 22:46:58 -05: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-04 22:03:24 -05:00
|
|
|
map['value'] = m.name
|
2016-06-15 12:17:32 +08:00
|
|
|
map['description'] = m.desc.try(:truncate, 30)
|
2014-01-28 22:46:58 -05:00
|
|
|
map['permission'] = m.permission
|
|
|
|
map['topicCount'] = m.topics.count
|
|
|
|
map['synapseCount'] = m.synapses.count
|
|
|
|
map['contributorCount'] = m.contributors.count
|
2016-07-26 08:14:23 +08:00
|
|
|
map['rtype'] = 'map'
|
|
|
|
|
2014-11-22 19:35:03 -05:00
|
|
|
contributorTip = ''
|
2015-11-08 23:14:53 +08:00
|
|
|
firstContributorImage = 'https://s3.amazonaws.com/metamaps-assets/site/user.png'
|
2016-09-24 11:00:46 +08:00
|
|
|
if m.contributors.count.positive?
|
2014-11-25 15:06:30 -05:00
|
|
|
firstContributorImage = m.contributors[0].image.url(:thirtytwo)
|
2016-07-26 08:14:23 +08:00
|
|
|
m.contributors.each_with_index do |c, _index|
|
2014-11-25 15:06:30 -05:00
|
|
|
userImage = c.image.url(:thirtytwo)
|
2014-11-22 19:35:03 -05:00
|
|
|
name = c.name
|
2016-07-26 08:14:23 +08:00
|
|
|
contributorTip += '<li> <img class="tipUserImage" width="25" height="25" src=' + userImage + ' />' + '<span>' + name + '</span> </li>'
|
2014-11-22 19:35:03 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
map['contributorTip'] = contributorTip
|
2014-11-23 22:28:29 -05:00
|
|
|
map['mapContributorImage'] = firstContributorImage
|
|
|
|
|
2014-01-28 22:46:58 -05:00
|
|
|
temp.push map
|
|
|
|
end
|
2016-07-26 08:14:23 +08:00
|
|
|
temp
|
2014-01-28 22:46:58 -05:00
|
|
|
end
|
2012-10-26 06:04:52 -04:00
|
|
|
end
|