metamaps--metamaps/app/helpers/application_helper.rb

51 lines
1.7 KiB
Ruby
Raw Normal View History

2016-09-24 03:00:46 +00:00
# frozen_string_literal: true
2016-03-25 04:26:07 +00:00
module ApplicationHelper
2016-09-24 04:27:34 +00:00
def metacodeset
metacodes = current_user.settings.metacodes
2016-09-24 04:27:34 +00:00
return false unless metacodes[0].include?('metacodeset')
return 'Most' if metacodes[0].sub('metacodeset-', '') == 'Most'
return 'Recent' if metacodes[0].sub('metacodeset-', '') == 'Recent'
2016-09-24 04:27:34 +00:00
MetacodeSet.find(metacodes[0].sub('metacodeset-', '').to_i)
end
def user_metacodes
2016-03-25 04:26:07 +00:00
@m = current_user.settings.metacodes
2016-09-24 04:27:34 +00:00
set = metacodeset
@metacodes = if set && set == 'Most'
Metacode.where(id: current_user.most_used_metacodes).to_a
elsif set && set == 'Recent'
Metacode.where(id: current_user.recent_metacodes).to_a
elsif set
set.metacodes.to_a
else
Metacode.where(id: @m).to_a
end
@metacodes.sort! { |m1, m2| m2.name.downcase <=> m1.name.downcase }.rotate!(-1)
end
2016-09-18 15:22:51 +00:00
def user_metacode
current_user.settings.metacode_focus ? Metacode.find(current_user.settings.metacode_focus.to_i) || user_metacodes()[0] : user_metacodes()[0]
end
2016-03-25 04:26:07 +00:00
def user_most_used_metacodes
@metacodes = current_user.most_used_metacodes.map { |id| Metacode.find(id) }
end
def user_recent_metacodes
@metacodes = current_user.recent_metacodes.map { |id| Metacode.find(id) }
end
2016-09-24 04:27:34 +00:00
def invite_link
"#{request.base_url}/join" + (current_user ? "?code=#{current_user.code}" : '')
2016-03-25 04:26:07 +00:00
end
def user_unread_notification_count
return 0 if current_user.nil?
2016-12-11 22:29:48 +00:00
@uunc ||= current_user.mailboxer_notification_receipts.reduce(0) do |total, receipt|
receipt.is_read ? total : total + 1
end
end
2012-09-23 02:39:12 +00:00
end