Module: UsersHelper

Defined in:
app/helpers/users_helper.rb

Instance Method Summary collapse

Instance Method Details

#project_users_select_tag(user_element, default_name = nil) ⇒ Object



72
73
74
75
# File 'app/helpers/users_helper.rb', line 72

def project_users_select_tag(user_element, default_name = nil)
  user_id_list = User.in_project(sessions_current_project_id)
  user_select_tag(user_element, user_id_list, default_name)
end

#user_autocomplete_tag(user) ⇒ Object



35
36
37
# File 'app/helpers/users_helper.rb', line 35

def user_autocomplete_tag(user)
  user.name + ' ' + (:span, user.email, class: [:feedback, 'feedback-thin', 'feedback-primary']).html_safe
end

#user_avatar(user, size = :default) ⇒ Object



26
27
28
29
30
31
32
33
# File 'app/helpers/users_helper.rb', line 26

def user_avatar(user, size = :default)
  inactive = user.is_flagged_for_password_reset
  classes = ['avatar', "avatar--#{size}"]
  classes << 'inactive' if inactive
  title = state_title = inactive ? 'Inactive (Flagged for password reset)' : 'Active'

  (:div, user_initials(user), class: classes, title: title)
end

#user_data(user, weeks_ago: nil, target: :created, base: 10) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'app/helpers/users_helper.rb', line 85

def user_data(user, weeks_ago: nil, target: :created, base: 10)
  data = []

  r = ApplicationEnumeration.klass_reflections(User)

  case target
  when :created
    r.delete_if{|a,b| !(a.name.to_s =~ /created/) }
  when :updated
    r.delete_if{|a,b| !(a.name.to_s =~ /updated/) }
  end

  r.each do |r|
    q = user.send(r.name)
    q = q.where("#{target == :created ? 'created_at' : 'updated_at'} > ?", weeks_ago.to_i.weeks.ago) if weeks_ago

    t = 1 / Math::log(base, q&.count )

    if t > 0
      data.push(
        [ r.name.to_s.humanize.gsub( (target == :created ? 'Created ' : 'Updated ' ).titleize, ''),
          t
        ])
    end
  end
  data
end

#user_email_tag(user) ⇒ Object



39
40
41
# File 'app/helpers/users_helper.rb', line 39

def user_email_tag(user)
  user_autocomplete_tag(user)
end

#user_initials(user) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'app/helpers/users_helper.rb', line 16

def user_initials(user)
  return '' if user.nil? || user.name.blank?

  user.name
      .split(/\s+/)
      .map { |p| p[0].upcase }
      .first(3)
      .join
end

#user_last_seen_tag(user) ⇒ Object



43
44
45
46
47
48
49
# File 'app/helpers/users_helper.rb', line 43

def user_last_seen_tag(user)
  if user.last_seen_at.present?
    time_ago_in_words(user.last_seen_at) + '  ago'
  else
    (:em, 'never')
  end
end


8
9
10
11
12
13
14
# File 'app/helpers/users_helper.rb', line 8

def user_link(user)
  if sessions_current_user == user || sessions_current_user.is_administrator?
    link_to(user_tag(user), user)
  else
     :span, user_tag(user), class: :subtle
  end
end

#user_select_tag(user_element, user_id_list, default_name = nil) ⇒ HTML

Parameters:

  • user_element (Symbol, String)
  • user_id_list (Array)
  • default_name, (String)

    if supplied, must be a user.name, user.email, or user.if

Returns:

  • (HTML)


64
65
66
67
68
69
70
# File 'app/helpers/users_helper.rb', line 64

def user_select_tag(user_element, user_id_list, default_name = nil)
  select_tag(user_element,
             options_for_select(user_id_list
    .collect { |u| [User.find(u).name, User.find(u).id] }
    .unshift(['All users', 'All users']),
  default_name))
end

#user_select_tag_2(user_element, *users) ⇒ Object



77
78
79
80
81
82
83
# File 'app/helpers/users_helper.rb', line 77

def user_select_tag_2(user_element, *users)
  a = users
  select_tag(user_element, options_for_select(
    User
    .in_project(sessions_current_project_id)
    .collect { |u| [User.find(u).name, User.find(u).id] }))
end

#user_tag(user) ⇒ Object



3
4
5
6
# File 'app/helpers/users_helper.rb', line 3

def user_tag(user)
  return nil if user.nil?
  user.name
end

#user_time_active(user) ⇒ Object



51
52
53
54
55
56
57
58
# File 'app/helpers/users_helper.rb', line 51

def user_time_active(user)
  total = user.time_active.to_i
  hours   = total / 3600
  minutes = (total % 3600) / 60
  seconds = total % 60

  '%02d:%02d:%02d' % [hours, minutes, seconds]
end