Class: Workarea::Admin::UserViewModel
- Inherits:
-
ApplicationViewModel
- Object
- ApplicationViewModel
- Workarea::Admin::UserViewModel
show all
- Includes:
- ActionView::Helpers::DateHelper, CommentableViewModel
- Defined in:
- app/view_models/workarea/admin/user_view_model.rb
Instance Method Summary
collapse
#comment_count, #comments, #has_comments?, #new_comments_for?, #subscribed_users
Instance Method Details
#created_by ⇒ Object
41
42
43
44
45
46
|
# File 'app/view_models/workarea/admin/user_view_model.rb', line 41
def created_by
return nil unless created_by_id.present?
@created_by ||= UserViewModel.wrap(User.find(created_by_id))
rescue Mongoid::Errors::DocumentNotFound
@created_by ||= nil
end
|
#email_signup? ⇒ Boolean
80
81
82
|
# File 'app/view_models/workarea/admin/user_view_model.rb', line 80
def email_signup?
@email_signup ||= Email.signed_up?(email)
end
|
#last_impersonated_by ⇒ Object
34
35
36
37
38
39
|
# File 'app/view_models/workarea/admin/user_view_model.rb', line 34
def last_impersonated_by
return nil unless model.last_impersonated_by_id.present?
@last_impersonated_by ||= User
.where(id: model.last_impersonated_by_id)
.first
end
|
#last_login ⇒ Object
15
16
17
18
19
20
21
22
23
24
|
# File 'app/view_models/workarea/admin/user_view_model.rb', line 15
def last_login
if last_login_at.present?
t(
'workarea.admin.users.login.time_ago',
period: time_ago_in_words(last_login_at)
)
else
t('workarea.admin.users.login.never')
end
end
|
#metrics ⇒ Object
Also known as:
insights
63
64
65
|
# File 'app/view_models/workarea/admin/user_view_model.rb', line 63
def metrics
@metrics ||= Metrics::User.find_or_initialize_by(id: model.email)
end
|
#name ⇒ Object
7
8
9
10
11
12
13
|
# File 'app/view_models/workarea/admin/user_view_model.rb', line 7
def name
if first_name.present? && last_name.present?
"#{first_name} #{last_name}"
else
email
end
end
|
#orders ⇒ Object
58
59
60
61
|
# File 'app/view_models/workarea/admin/user_view_model.rb', line 58
def orders
return [] unless model.email.present?
@orders ||= OrderViewModel.wrap(Order.recent(model.id, 50))
end
|
#payment_profile ⇒ Object
52
53
54
55
56
|
# File 'app/view_models/workarea/admin/user_view_model.rb', line 52
def payment_profile
@payment_profile ||= Payment::Profile.lookup(
PaymentReference.new(model)
)
end
|
#recent_categories ⇒ Object
72
73
74
|
# File 'app/view_models/workarea/admin/user_view_model.rb', line 72
def recent_categories
@recent_categories ||= Catalog::Category.find_ordered(metrics.viewed.recent_category_ids)
end
|
#recent_products ⇒ Object
68
69
70
|
# File 'app/view_models/workarea/admin/user_view_model.rb', line 68
def recent_products
@recent_products ||= Catalog::Product.find_ordered(metrics.viewed.recent_product_ids)
end
|
#recent_searches ⇒ Object
76
77
78
|
# File 'app/view_models/workarea/admin/user_view_model.rb', line 76
def recent_searches
@recent_searches ||= metrics.viewed.recent_search_ids
end
|
#role ⇒ Object
26
27
28
29
30
31
32
|
# File 'app/view_models/workarea/admin/user_view_model.rb', line 26
def role
if model.admin?
t('workarea.admin.users.roles.admin')
else
t('workarea.admin.users.roles.customer')
end
end
|
#timeline ⇒ Object
48
49
50
|
# File 'app/view_models/workarea/admin/user_view_model.rb', line 48
def timeline
@timeline ||= TimelineViewModel.wrap(model)
end
|