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
|
|
|
|
return false unless metacodes[0].include?('metacodeset')
|
2016-10-05 14:45:39 +00:00
|
|
|
if metacodes[0].sub('metacodeset-', '') == 'Most'
|
|
|
|
return 'Most'
|
|
|
|
elsif metacodes[0].sub('metacodeset-', '') == 'Recent'
|
|
|
|
return 'Recent'
|
|
|
|
end
|
2016-09-24 04:27:34 +00:00
|
|
|
MetacodeSet.find(metacodes[0].sub('metacodeset-', '').to_i)
|
2015-09-19 12:17:56 +00:00
|
|
|
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
|
2016-10-05 14:45:39 +00:00
|
|
|
@metacodes = if set && set == 'Most'
|
2016-11-13 22:29:07 +00:00
|
|
|
Metacode.where(id: current_user.most_used_metacodes).to_a
|
2016-10-05 14:45:39 +00:00
|
|
|
elsif set && set == 'Recent'
|
2016-11-13 22:29:07 +00:00
|
|
|
Metacode.where(id: current_user.recent_metacodes).to_a
|
2016-10-05 14:45:39 +00:00
|
|
|
elsif set
|
2016-07-26 00:14:23 +00:00
|
|
|
set.metacodes.to_a
|
|
|
|
else
|
|
|
|
Metacode.where(id: @m).to_a
|
|
|
|
end
|
|
|
|
@metacodes.sort! { |m1, m2| m2.name.downcase <=> m1.name.downcase }.rotate!(-1)
|
2015-09-19 12:17:56 +00:00
|
|
|
end
|
2016-03-25 04:26:07 +00:00
|
|
|
|
2016-10-05 14:45:39 +00:00
|
|
|
def user_most_used_metacodes
|
2016-11-13 22:29:07 +00:00
|
|
|
@metacodes = current_user.most_used_metacodes.map { |id| Metacode.find(id) }
|
2016-10-05 14:45:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def user_recent_metacodes
|
2016-11-13 22:29:07 +00:00
|
|
|
@metacodes = current_user.recent_metacodes.map { |id| Metacode.find(id) }
|
2016-10-05 14:45:39 +00:00
|
|
|
end
|
|
|
|
|
2016-09-24 04:27:34 +00:00
|
|
|
def invite_link
|
2016-07-26 00:14:23 +00:00
|
|
|
"#{request.base_url}/join" + (current_user ? "?code=#{current_user.code}" : '')
|
2016-03-25 04:26:07 +00:00
|
|
|
end
|
2016-11-24 16:07:57 +00:00
|
|
|
|
2016-11-24 16:43:50 +00:00
|
|
|
def user_unread_notification_count
|
|
|
|
return 0 if current_user.nil?
|
2016-12-11 23:03:59 +00:00
|
|
|
@uunc ||= current_user.mailboxer_notification_receipts.reduce(0) do |total, receipt|
|
2016-11-24 16:43:50 +00:00
|
|
|
receipt.is_read ? total : total + 1
|
|
|
|
end
|
|
|
|
end
|
2012-09-23 02:39:12 +00:00
|
|
|
end
|