metamaps--metamaps/app/helpers/synapses_helper.rb
2016-09-24 11:00:46 +08:00

34 lines
954 B
Ruby

# frozen_string_literal: true
module SynapsesHelper
## this one is for building our custom JSON autocomplete format for typeahead
def autocomplete_synapse_generic_json(unique)
temp = []
unique.each do |s|
synapse = {}
synapse['label'] = s.desc
synapse['value'] = s.desc
temp.push synapse
end
temp
end
## this one is for building our custom JSON autocomplete format for typeahead
def autocomplete_synapse_array_json(synapses)
temp = []
synapses.each do |s|
synapse = {}
synapse['id'] = s.id
synapse['label'] = s.desc.nil? || s.desc == '' ? '(no description)' : s.desc
synapse['value'] = s.desc
synapse['permission'] = s.permission
synapse['mapCount'] = s.maps.count
synapse['originator'] = s.user.name
synapse['originatorImage'] = s.user.image.url(:thirtytwo)
synapse['rtype'] = 'synapse'
temp.push synapse
end
temp
end
end