Module: Locomotive::Shared::ActivitiesHelper

Defined in:
app/helpers/locomotive/shared/activities_helper.rb

Instance Method Summary collapse

Instance Method Details

#activity_bulk_content_assets(params) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
# File 'app/helpers/locomotive/shared/activities_helper.rb', line 92

def activity_bulk_content_assets(params)
  list = params[:assets].map do |asset|
    if asset[:image] && asset[:id] && current_site.content_assets.where(_id: asset[:id]).exists?
      (:li, link_to(image_tag(Locomotive::Dragonfly.resize_url(asset[:url], '60x60#'), alt: asset[:name]), asset[:url]))
    else
      (:li, link_to(truncate(asset[:name], length: 20), asset[:url]))
    end
  end.join("\n").html_safe

  (:ul, list, class: 'assets') + (:div, '', class: 'clearfix')
end

#activity_bulk_editable_elements_options(params) ⇒ Object



67
68
69
70
71
72
73
# File 'app/helpers/locomotive/shared/activities_helper.rb', line 67

def activity_bulk_editable_elements_options(params)
  pages = params[:pages].map do |page|
    link_to truncate(page[:title]), editable_elements_path(current_site, page[:_id])
  end.join(', ').html_safe

  { pages: pages }
end

#activity_content_entry_options(params, locale) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'app/helpers/locomotive/shared/activities_helper.rb', line 75

def activity_content_entry_options(params, locale)
  entry = if params[:_id]
    path = edit_content_entry_path(current_site, params[:content_type_slug], params[:_id], content_locale: locale)
    link_to(params[:label], path)
  elsif params[:label]
    activity_emphasize(params[:label])
  elsif params[:labels]
    activity_emphasize(params[:labels].join(', '))
  else
    nil
  end

  content_type = link_to(params[:content_type], content_entries_path(current_site, params[:content_type_slug]))

  { entry: entry, content_type: content_type }
end

#activity_emphasize(text) ⇒ Object



48
49
50
# File 'app/helpers/locomotive/shared/activities_helper.rb', line 48

def activity_emphasize(text)
  (:strong, text)
end

#activity_key_to_sentence(key, options = nil) ⇒ Object



44
45
46
# File 'app/helpers/locomotive/shared/activities_helper.rb', line 44

def activity_key_to_sentence(key, options = nil)
  I18n.t(key, (options || {}).merge(scope: 'locomotive.activity')).html_safe
end

#activity_page_content_options(params, locale) ⇒ Object



62
63
64
65
# File 'app/helpers/locomotive/shared/activities_helper.rb', line 62

def activity_page_content_options(params, locale)
  path = edit_page_content_path(current_site, params[:_id], content_locale: locale)
  { page: link_to(truncate(params[:title]), path).html_safe }
end

#activity_page_options(params) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'app/helpers/locomotive/shared/activities_helper.rb', line 52

def activity_page_options(params)
  if params[:_id]
    { page: link_to(params[:title], editable_elements_path(current_site, params[:_id])) }
  elsif params[:title]
    { page: activity_emphasize(params[:title]) }
  else
    nil
  end
end

#activity_to_icon(activity) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'app/helpers/locomotive/shared/activities_helper.rb', line 5

def activity_to_icon(activity)
  case activity.domain
  when 'site'             then 'fa-cog'
  when 'page'             then 'fa-file-alt'
  when 'page_content'     then 'fa-file-alt'
  when 'editable_element' then 'fa-file-alt'
  when 'content_entry'    then activity.action == 'created_public' ? 'fa-comment' : 'fa-archive'
  when 'content_asset'    then 'fa-image'
  when 'membership'       then 'fa-user'
  when 'site_metafields'  then current_site_metafields_ui[:icon]
  end
end

#render_activity_additional_information(activity) ⇒ Object



36
37
38
39
40
41
42
# File 'app/helpers/locomotive/shared/activities_helper.rb', line 36

def render_activity_additional_information(activity)
  case activity.key
  when 'content_asset.created_bulk' then activity_bulk_content_assets(activity.parameters)
  # when 'editable_element.updated_bulk' then activity_bulk_editable_elements(activity.parameters)
  else nil
  end
end

#render_activity_sentence(activity) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/helpers/locomotive/shared/activities_helper.rb', line 18

def render_activity_sentence(activity)
  params = activity.parameters
  locale = activity.locale

  options = case activity.key
  when /\Apage\./                       then activity_page_options(params)
  when /\Acontent_entry\./              then activity_content_entry_options(params, locale)
  when 'page_content.updated'           then activity_page_content_options(params, locale)
  when 'editable_element.updated_bulk'  then activity_bulk_editable_elements_options(params)
  when 'content_asset.created_bulk'     then { count: activity_emphasize(params[:assets].size) }
  when 'content_asset.destroyed'        then { name: activity_emphasize(params[:name]) }
  when 'membership.created'             then { name: activity_emphasize(params[:name]) }
  when 'site_metafields.updated'        then { label: current_site_metafields_ui[:label].downcase }
  end

  activity_key_to_sentence(activity.key, options)
end