Class: Workarea::Admin::UserViewModel

Inherits:
ApplicationViewModel
  • Object
show all
Includes:
ActionView::Helpers::DateHelper, CommentableViewModel
Defined in:
app/view_models/workarea/admin/user_view_model.rb

Instance Method Summary collapse

Methods included from CommentableViewModel

#comment_count, #comments, #has_comments?, #new_comments_for?

Instance Method Details

#activityObject



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_byObject



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

Returns:

  • (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

#insightsObject



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_byObject



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_loginObject



15
16
17
18
19
20
21
22
23
24
# File 'app/view_models/workarea/admin/user_view_model.rb', line 15

def 
  if .present?
    t(
      'workarea.admin.users.login.time_ago',
      period: time_ago_in_words()
    )
  else
    t('workarea.admin.users.login.never')
  end
end

#nameObject



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

#ordersObject



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_profileObject



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_categoriesObject



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_productsObject



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_searchesObject



79
80
81
# File 'app/view_models/workarea/admin/user_view_model.rb', line 79

def recent_searches
  activity.searches
end

#roleObject



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

#timelineObject



48
49
50
# File 'app/view_models/workarea/admin/user_view_model.rb', line 48

def timeline
  @timeline ||= TimelineViewModel.wrap(model)
end