metamaps--metamaps/app/helpers/maps_helper.rb

43 lines
1.2 KiB
Ruby
Raw Permalink Normal View History

2016-09-24 03:00:46 +00:00
# frozen_string_literal: true
module MapsHelper
2016-09-24 04:27:34 +00:00
# JSON autocomplete format for typeahead
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',
contributorTip: contributor_tip(map),
mapContributorImage: first_contributor_image(map)
}
end
end
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
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
end
2016-09-24 04:27:34 +00:00
output
end
end