Module: Integral::Backend::BaseHelper

Includes:
SupportHelper
Defined in:
app/helpers/integral/backend/base_helper.rb

Overview

Base Backend Helper

Instance Method Summary collapse

Methods included from SupportHelper

#anchor_to, #display_media_query_indicator?, #method_missing, #render_flashes, #respond_to?

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Integral::SupportHelper

Instance Method Details

#body_data_attributesObject

Data which is embedded into the backend <body> tag



114
115
116
117
118
119
120
121
# File 'app/helpers/integral/backend/base_helper.rb', line 114

def body_data_attributes
  {
    locale: I18n.locale,
    'user-name' => current_user.name,
    'user-email' => current_user.email,
    'user-created-at' => current_user.created_at.to_i
  }
end

#current_user_authorized_for_menu_item?(item) ⇒ Boolean

Returns:

  • (Boolean)


152
153
154
155
156
157
158
159
160
# File 'app/helpers/integral/backend/base_helper.rb', line 152

def current_user_authorized_for_menu_item?(item)
  if item[:authorize]
    instance_eval(&item[:authorize])
  elsif item[:authorize_class] && item[:authorize_action]
    Pundit.policy(current_user, item[:authorize_class]).public_send("#{item[:authorize_action]}?")
  else
    true
  end
end

#dataset_dashboard_last_weekObject

Line graph - Last week



140
141
142
143
144
145
146
147
148
149
150
# File 'app/helpers/integral/backend/base_helper.rb', line 140

def dataset_dashboard_last_week
  data = [
    { scope: Integral::Page, label: 'Pages' },
    { scope: Integral::List, label: 'Lists' },
    { scope: Integral::Image, label: 'Images' },
    { scope: Integral::User, label: 'Users' }
  ]

  data.prepend(scope: Integral::Post, label: 'Posts') if Integral.blog_enabled?
  data
end

#google_tag_manager(type = :script) ⇒ String

Backend Google Tag Manager Snippet

Returns:

  • (String)

    GTM Container if ID has been supplied



125
126
127
# File 'app/helpers/integral/backend/base_helper.rb', line 125

def google_tag_manager(type = :script)
  GoogleTagManager.render(Integral.gtm_container_id, type)
end

Handles extra optional options to ‘link_to` - Font awesome icons & wrapper



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/helpers/integral/backend/base_helper.rb', line 21

def link_to(name = nil, options = nil, html_options = nil, &block)
  return super if block_given?
  return super if html_options.nil?

  if html_options[:icon]
    name = (:span, name)
    name.prepend(icon(html_options.delete(:icon)))
  end

  if html_options[:wrapper]
    wrapper = html_options.delete(:wrapper)
    if wrapper == :cell
      (:div, super(name, options, html_options, &block), class: 'cell')
    else
      (wrapper, super(name, options, html_options, &block))
    end
  else
    super(name, options, html_options, &block)
  end
end

#page_titleString

Returns title provided through yield or i18n scoped to controller namespace & action.

Returns:

  • (String)

    title provided through yield or i18n scoped to controller namespace & action



91
92
93
94
95
96
97
98
99
100
# File 'app/helpers/integral/backend/base_helper.rb', line 91

def page_title
  return content_for(:title) if content_for?(:title)
  return t("devise.#{controller_name}.#{action_name}.title") if devise_controller?

  # Scope is set to current controller namespace & action
  t('title', scope: "#{controller_path.tr('/', '.')}.#{action_name}",
             default: I18n.t("integral.backend.titles.#{action_name}",
                             type_singular: resource_klass.model_name.human.capitalize,
                             type_plural: resource_klass.model_name.human(count: 2).capitalize))
end

#recent_activity_grid(options) ⇒ Object



83
84
85
86
87
88
# File 'app/helpers/integral/backend/base_helper.rb', line 83

def recent_activity_grid(options)
  #Integral::Grids::ActivitiesGrid.new(options)
  Integral::Grids::ActivitiesGrid.new options do |scope|
    scope.where.not(whodunnit: nil)
  end
end

#recent_site_activity_gridArray

Returns array of VersionDecorators subclassed depending on the Version subclass

Returns:

  • (Array)

    returns array of VersionDecorators subclassed depending on the Version subclass



73
74
75
76
77
78
79
80
81
# File 'app/helpers/integral/backend/base_helper.rb', line 73

def recent_site_activity_grid
  @recent_site_activity_grid ||= begin
                                options = {}
                                options[:object] = resource_klass.to_s if resource_klass.present?
                                options[:item_id] = @resource.id if @resource.present?

                                recent_activity_grid(options)
                              end
end

#recent_user_activity_gridArray

Returns array of VersionDecorators subclassed depending on the Version subclass

Returns:

  • (Array)

    returns array of VersionDecorators subclassed depending on the Version subclass



62
63
64
65
66
67
68
69
70
# File 'app/helpers/integral/backend/base_helper.rb', line 62

def recent_user_activity_grid
  @recent_user_activity_grid ||= begin
                                options = { user: current_user.id }
                                options[:object] = resource_klass.to_s if resource_klass.present?
                                options[:item_id] = @resource.id if @resource.present?

                                recent_activity_grid(options)
                              end
end

#recent_user_notificationsObject



16
17
18
# File 'app/helpers/integral/backend/base_helper.rb', line 16

def recent_user_notifications
  @recent_user_notifications ||= current_user.notifications.recent
end

#render_card(partial, locals = {}) ⇒ String

Returns Integral card.

Returns:

  • (String)

    Integral card



57
58
59
# File 'app/helpers/integral/backend/base_helper.rb', line 57

def render_card(partial, locals = {})
  render(partial: "integral/backend/shared/cards/#{partial}", locals: locals)
end

#render_create_menuObject



12
13
14
# File 'app/helpers/integral/backend/base_helper.rb', line 12

def render_create_menu
  render_menu(extract_menu_items(Integral::ActsAsIntegral.backend_create_menu_items, :integral_backend_create_menu_item))
end

#render_data_gridObject

Renders a grid from a local partial within a datagrid container



103
104
105
106
107
108
109
110
111
# File 'app/helpers/integral/backend/base_helper.rb', line 103

def render_data_grid
  unless block_given?
    return (:div, render(partial: 'grid', locals: { grid: @grid }), data: { 'grid' => true, 'form' => 'grid_form' })
  end

   :div, data: { 'grid' => true, 'form' => 'grid_form' } do
    yield
  end
end

#render_donut_chart(dataset) ⇒ Object

Renders a donut chart



135
136
137
# File 'app/helpers/integral/backend/base_helper.rb', line 135

def render_donut_chart(dataset)
  ChartRenderer::Donut.render(dataset)
end

#render_line_chart(dataset) ⇒ Object

Renders a line chart



130
131
132
# File 'app/helpers/integral/backend/base_helper.rb', line 130

def render_line_chart(dataset)
  ChartRenderer::Line.render(dataset)
end

#render_main_menuObject



8
9
10
# File 'app/helpers/integral/backend/base_helper.rb', line 8

def render_main_menu
  render_menu(extract_menu_items(Integral::ActsAsIntegral.backend_main_menu_items, :integral_backend_main_menu_item))
end

#render_resource_grid(locals = {}) ⇒ String

Returns Resource Grid.

Returns:

  • (String)

    Resource Grid



52
53
54
# File 'app/helpers/integral/backend/base_helper.rb', line 52

def render_resource_grid(locals = {})
  render(partial: "integral/backend/shared/grid/grid", locals: locals)
end

#render_resource_grid_form(&block) ⇒ String

Returns Resource Grid Form.

Returns:

  • (String)

    Resource Grid Form



43
44
45
46
47
48
49
# File 'app/helpers/integral/backend/base_helper.rb', line 43

def render_resource_grid_form(&block)
  if block_given?
    render(layout: "integral/backend/shared/grid/form", &block)
  else
    render(partial: "integral/backend/shared/grid/form")
  end
end