Class: Workarea::Admin::ActivityViewModel

Inherits:
ApplicationViewModel
  • Object
show all
Defined in:
app/view_models/workarea/admin/activity_view_model.rb

Instance Method Summary collapse

Instance Method Details

#admin_optionsObject



16
17
18
19
# File 'app/view_models/workarea/admin/activity_view_model.rb', line 16

def admin_options
  [[t('workarea.admin.activities.filters.everyone'), nil]] +
    User.admins.map { |u| [u.name, u.id] }
end

#daysObject



21
22
23
24
25
26
27
28
# File 'app/view_models/workarea/admin/activity_view_model.rb', line 21

def days
  @days ||= entries.reduce({}) do |memo, entry|
    day = entry.created_at.to_date
    memo[day] ||= []
    memo[day] << entry
    memo
  end
end

#entriesObject



4
5
6
# File 'app/view_models/workarea/admin/activity_view_model.rb', line 4

def entries
  @entries ||= scoped_entries.page(page).per(per_page)
end

#hide_first_header?Boolean

Returns:

  • (Boolean)


34
35
36
37
38
39
# File 'app/view_models/workarea/admin/activity_view_model.rb', line 34

def hide_first_header?
  return false if page == 1

  previous_entry = scoped_entries.skip(entries.offset_value - 1).first
  previous_entry.created_at.to_date == entries.first.created_at.to_date
end

#pageObject



30
31
32
# File 'app/view_models/workarea/admin/activity_view_model.rb', line 30

def page
  (options[:page].presence || 1).to_i
end

#type_optionsObject



8
9
10
11
12
13
14
# File 'app/view_models/workarea/admin/activity_view_model.rb', line 8

def type_options
  [[t('workarea.admin.activities.filters.all_types'), nil]] +
    types.map do |type|
      name = ActiveModel::Naming.param_key(type.constantize)
      [name.titleize.downcase, type]
    end
end