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



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

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_data(user, weeks_ago: nil, target: :created, base: 10) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/helpers/users_helper.rb', line 49

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_last_seen_tag(user) ⇒ Object



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

def user_last_seen_tag(user)
  if !user.last_seen_at.blank?
    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)


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

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



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

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