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?
Instance Method Details
#activity ⇒ Object
67
68
69
|
# File 'app/view_models/workarea/admin/user_view_model.rb', line 67
def activity
@activity ||= Recommendation::UserActivity.find_or_initialize_by(id: model.id)
end
|
#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
83
84
85
|
# File 'app/view_models/workarea/admin/user_view_model.rb', line 83
def email_signup?
@email_signup ||= Email.signed_up?(email)
end
|
#insights ⇒ Object
63
64
65
|
# File 'app/view_models/workarea/admin/user_view_model.rb', line 63
def insights
@insights ||= Metrics::User.find_or_initialize_by(id: model.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
|
#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
75
76
77
|
# File 'app/view_models/workarea/admin/user_view_model.rb', line 75
def recent_categories
@recent_categories ||= Catalog::Category.any_in(id: activity.category_ids)
end
|
#recent_products ⇒ Object
71
72
73
|
# File 'app/view_models/workarea/admin/user_view_model.rb', line 71
def recent_products
@recent_products ||= Catalog::Product.any_in(id: activity.product_ids)
end
|
#recent_searches ⇒ Object
79
80
81
|
# File 'app/view_models/workarea/admin/user_view_model.rb', line 79
def recent_searches
activity.searches
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
|