Module: Workarea::Admin::ActivitiesHelper

Defined in:
app/helpers/workarea/admin/activities_helper.rb

Instance Method Summary collapse

Instance Method Details

#activity_model_name(entry) ⇒ Object



58
59
60
# File 'app/helpers/workarea/admin/activities_helper.rb', line 58

def activity_model_name(entry)
  entry.audited_type.gsub(/Workarea::/, '').gsub(/::/, ' ').titleize
end

#activity_time(value) ⇒ Object



50
51
52
53
54
55
56
# File 'app/helpers/workarea/admin/activities_helper.rb', line 50

def activity_time(value)
  if value.to_date == Time.zone.today
    local_time_ago(value)
  else
    local_time(value, :time_only)
  end
end

#fields_clause_for(changes) ⇒ Object



46
47
48
# File 'app/helpers/workarea/admin/activities_helper.rb', line 46

def fields_clause_for(changes)
  ChangesViewModel.new(changes).to_html
end


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/helpers/workarea/admin/activities_helper.rb', line 20

def link_to_modifier(entry, &block)
  content = if block_given?
              capture(&block)
            elsif entry.modifier.present?
              entry.modifier.name
            elsif entry.modifier_id.present?
              t('workarea.admin.activities.modifiers.no_longer_exists')
            elsif entry.try(:release).present?
              entry.release.name
            else
              t('workarea.admin.activities.modifiers.unknown')
            end

  if entry.modifier.present? && !entry.modifier.system?
    if entry.modifier.persisted?
      link_to content, user_path(entry.modifier)
    else
      (:span, content)
    end
  elsif entry.try(:release).present?
    link_to content, release_path(entry.release)
  else
    content
  end
end


62
63
64
65
66
67
68
69
70
# File 'app/helpers/workarea/admin/activities_helper.rb', line 62

def link_to_restore_for(entry)
  if entry.restorable? && current_user.can_restore?
    link_to(
      t('workarea.admin.activities.restore'),
      restore_trash_path(entry),
      data: { method: 'post' }
    )
  end
end

#render_activity_category_value(attributes) ⇒ Object



12
13
14
15
16
17
18
# File 'app/helpers/workarea/admin/activities_helper.rb', line 12

def render_activity_category_value(attributes)
  name = attributes['name'][I18n.locale.to_s]
  ids = attributes['value'][I18n.locale.to_s].split(',').reject(&:blank?)
  return ids unless name == 'category'

  Catalog::Category.where(:id.in => ids).map(&:name).to_sentence
end

#render_activity_entry(entry) ⇒ Object



4
5
6
7
8
9
10
# File 'app/helpers/workarea/admin/activities_helper.rb', line 4

def render_activity_entry(entry)
  model_key = ActiveModel::Naming.param_key(entry.audited_type.constantize)
  partial_name = "#{model_key}_#{entry.action}"
  render "workarea/admin/activities/#{partial_name}", entry: entry
rescue ActionView::MissingTemplate
  render "workarea/admin/activities/#{entry.action}", entry: entry
end