2016-09-24 03:00:46 +00:00
|
|
|
# frozen_string_literal: true
|
2017-11-06 16:15:18 +00:00
|
|
|
|
2012-10-26 10:04:52 +00:00
|
|
|
module MapsHelper
|
2016-09-24 04:27:34 +00:00
|
|
|
# JSON autocomplete format for typeahead
|
2014-01-29 03:46:58 +00:00
|
|
|
def autocomplete_map_array_json(maps)
|
2016-09-24 04:27:34 +00:00
|
|
|
maps.map do |m|
|
|
|
|
{
|
|
|
|
id: m.id,
|
|
|
|
label: m.name,
|
|
|
|
value: m.name,
|
|
|
|
description: m.desc.try(:truncate, 30),
|
|
|
|
permission: m.permission,
|
|
|
|
topicCount: m.topics.count,
|
|
|
|
synapseCount: m.synapses.count,
|
|
|
|
contributorCount: m.contributors.count,
|
|
|
|
rtype: 'map',
|
2016-10-31 20:41:37 +00:00
|
|
|
contributorTip: contributor_tip(m),
|
|
|
|
mapContributorImage: first_contributor_image(m)
|
2016-09-24 04:27:34 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2016-07-26 00:14:23 +00:00
|
|
|
|
2016-09-24 04:27:34 +00:00
|
|
|
def first_contributor_image(map)
|
|
|
|
if map.contributors.count.positive?
|
|
|
|
return map.contributors[0].image.url(:thirtytwo)
|
|
|
|
end
|
|
|
|
'https://s3.amazonaws.com/metamaps-assets/site/user.png'
|
|
|
|
end
|
2014-11-24 03:28:29 +00:00
|
|
|
|
2016-09-24 04:27:34 +00:00
|
|
|
def contributor_tip(map)
|
|
|
|
output = ''
|
|
|
|
if map.contributors.count.positive?
|
|
|
|
map.contributors.each_with_index do |contributor, _index|
|
|
|
|
user_image = contributor.image.url(:thirtytwo)
|
|
|
|
output += '<li>'
|
|
|
|
output += %(<img class="tipUserImage" width="25" height="25" src="#{user_image}" />)
|
|
|
|
output += "<span>#{contributor.name}</span>"
|
|
|
|
output += '</li>'
|
|
|
|
end
|
2014-01-29 03:46:58 +00:00
|
|
|
end
|
2016-09-24 04:27:34 +00:00
|
|
|
output
|
2014-01-29 03:46:58 +00:00
|
|
|
end
|
2012-10-26 10:04:52 +00:00
|
|
|
end
|