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?, #subscribed_users

Instance Method Details

#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)


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

def email_signup?
   ||= Email.signed_up?(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

#metricsObject 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

#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



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_productsObject



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_searchesObject



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

#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