Module: Integral::Backend::BaseHelper
- Includes:
- SupportHelper, Webpacker::Helper
- Defined in:
- app/helpers/integral/backend/base_helper.rb
Overview
Base Backend Helper
Instance Method Summary collapse
-
#body_data_attributes ⇒ Object
Data which is embedded into the backend <body> tag.
- #create_menu_items ⇒ Object
- #current_user_authorized_for_menu_item?(item) ⇒ Boolean
- #current_webpacker_instance ⇒ Object
-
#dataset_dashboard_last_week ⇒ Object
Line graph - Last week.
- #decorated_current_user ⇒ Object
-
#google_tag_manager(type = :script) ⇒ String
Backend Google Tag Manager Snippet.
- #grouped_page_alternate_options ⇒ Object
- #grouped_page_parent_options ⇒ Object
- #grouped_post_alternate_options ⇒ Object
-
#link_to(name = nil, options = nil, html_options = nil, &block) ⇒ Object
Handles extra optional options to ‘link_to` - Font awesome icons & wrapper.
- #main_menu_items ⇒ Object
-
#page_title ⇒ String
Title provided through yield or i18n scoped to controller namespace & action.
- #recent_activity_grid(options) ⇒ Object
-
#recent_site_activity_grid ⇒ Array
Returns array of VersionDecorators subclassed depending on the Version subclass.
-
#recent_user_activity_grid ⇒ Array
Returns array of VersionDecorators subclassed depending on the Version subclass.
- #recent_user_notifications ⇒ Object
-
#render_card(partial, locals = {}) ⇒ String
Integral card.
-
#render_data_grid ⇒ Object
Renders a grid from a local partial within a datagrid container.
-
#render_donut_chart(dataset) ⇒ Object
Renders a donut chart.
-
#render_line_chart(dataset) ⇒ Object
Renders a line chart.
-
#render_resource_grid(locals = {}) ⇒ String
Resource Grid.
-
#render_resource_grid_form(&block) ⇒ String
Resource Grid Form.
- #storage_file_content_type_options ⇒ Object
Methods included from SupportHelper
#anchor_to, #display_media_query_indicator?, #icon, #method_missing, #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_attributes ⇒ Object
Data which is embedded into the backend <body> tag
149 150 151 152 153 154 155 156 157 158 |
# File 'app/helpers/integral/backend/base_helper.rb', line 149 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, 'flash-type' => flash.first&.first, 'flash-message' => flash.first&.second } end |
#create_menu_items ⇒ Object
203 204 205 |
# File 'app/helpers/integral/backend/base_helper.rb', line 203 def (Integral::ActsAsIntegral., :integral_backend_create_menu_item).sort_by { |item| item[:order] } end |
#current_user_authorized_for_menu_item?(item) ⇒ Boolean
189 190 191 192 193 194 195 196 197 |
# File 'app/helpers/integral/backend/base_helper.rb', line 189 def (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 |
#current_webpacker_instance ⇒ Object
42 43 44 |
# File 'app/helpers/integral/backend/base_helper.rb', line 42 def current_webpacker_instance Integral.webpacker end |
#dataset_dashboard_last_week ⇒ Object
Line graph - Last week
177 178 179 180 181 182 183 184 185 186 187 |
# File 'app/helpers/integral/backend/base_helper.rb', line 177 def dataset_dashboard_last_week data = [ { scope: Integral::Page, label: 'Pages' }, { scope: Integral::List, label: 'Lists' }, { scope: Integral::Storage::File, label: 'Files' }, { scope: Integral::User, label: 'Users' } ] data.prepend(scope: Integral::Post, label: 'Posts') if Integral.blog_enabled? data end |
#decorated_current_user ⇒ Object
46 47 48 |
# File 'app/helpers/integral/backend/base_helper.rb', line 46 def decorated_current_user @decorated_current_user ||= current_user.decorate end |
#google_tag_manager(type = :script) ⇒ String
Backend Google Tag Manager Snippet
162 163 164 |
# File 'app/helpers/integral/backend/base_helper.rb', line 162 def google_tag_manager(type = :script) GoogleTagManager.render(Integral.gtm_container_id, type) end |
#grouped_page_alternate_options ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'app/helpers/integral/backend/base_helper.rb', line 33 def Integral::Page.published.where.not(id: @resource.id).order('updated_at DESC').group_by(&:locale).map do |result| [ t("integral.language.#{result[0]}"), result[1].map { |page| ["#{page.title} - #{page.path} (##{page.id})", page.id, {disabled: @resource.alternate_ids.include?(page.id), data: { title: page.title, description: page.description, path: page.path, url: backend_page_url(page.id) } }] } ] end.to_h end |
#grouped_page_parent_options ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'app/helpers/integral/backend/base_helper.rb', line 15 def @resource.available_parents.order('updated_at DESC').group_by(&:locale).map do |result| [ t("integral.language.#{result[0]}"), result[1].map { |page| [ "#{page.title} - #{page.path} (##{page.id})", page.id ] } ] end.to_h end |
#grouped_post_alternate_options ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'app/helpers/integral/backend/base_helper.rb', line 24 def Integral::Post.published.where.not(id: @resource.id).order('updated_at DESC').group_by(&:locale).map do |result| [ t("integral.language.#{result[0]}"), result[1].map { |post| ["#{post.title} - #{post.slug} (##{post.id})", post.id, {disabled: @resource.alternate_ids.include?(post.id), data: { title: post.title, description: post.description, path: post.slug, url: backend_post_url(post.id) } }] } ] end.to_h end |
#link_to(name = nil, options = nil, html_options = nil, &block) ⇒ Object
Handles extra optional options to ‘link_to` - Font awesome icons & wrapper
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/helpers/integral/backend/base_helper.rb', line 55 def link_to(name = nil, = nil, = nil, &block) return super if block_given? return super if .nil? if [:icon] name = content_tag(:span, name) name.prepend(icon(.delete(:icon))) end if [:wrapper] wrapper = .delete(:wrapper) if wrapper == :cell content_tag(:div, super(name, , , &block), class: 'cell') else content_tag(wrapper, super(name, , , &block)) end else super(name, , , &block) end end |
#main_menu_items ⇒ Object
199 200 201 |
# File 'app/helpers/integral/backend/base_helper.rb', line 199 def (Integral::ActsAsIntegral., :integral_backend_main_menu_item).sort_by { |item| item[:order] } end |
#page_title ⇒ String
Returns title provided through yield or i18n scoped to controller namespace & action.
126 127 128 129 130 131 132 133 134 135 |
# File 'app/helpers/integral/backend/base_helper.rb', line 126 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
119 120 121 122 123 |
# File 'app/helpers/integral/backend/base_helper.rb', line 119 def recent_activity_grid() Integral::Grids::ActivitiesGrid.new do |scope| scope.where.not(whodunnit: nil) end end |
#recent_site_activity_grid ⇒ Array
Returns array of VersionDecorators subclassed depending on the Version subclass
109 110 111 112 113 114 115 116 117 |
# File 'app/helpers/integral/backend/base_helper.rb', line 109 def recent_site_activity_grid @recent_site_activity_grid ||= begin = {} [:object] = resource_klass.to_s if resource_klass.present? [:item_id] = @resource.id if @resource.present? recent_activity_grid() end end |
#recent_user_activity_grid ⇒ Array
Returns array of VersionDecorators subclassed depending on the Version subclass
98 99 100 101 102 103 104 105 106 |
# File 'app/helpers/integral/backend/base_helper.rb', line 98 def recent_user_activity_grid @recent_user_activity_grid ||= begin = { user: current_user.id } [:object] = resource_klass.to_s if resource_klass.present? [:item_id] = @resource.id if @resource.present? recent_activity_grid() end end |
#recent_user_notifications ⇒ Object
50 51 52 |
# File 'app/helpers/integral/backend/base_helper.rb', line 50 def recent_user_notifications @recent_user_notifications ||= current_user.notifications.recent end |
#render_card(partial, locals = {}) ⇒ String
Returns Integral card.
93 94 95 |
# File 'app/helpers/integral/backend/base_helper.rb', line 93 def render_card(partial, locals = {}) render(partial: "integral/backend/shared/cards/#{partial}", locals: locals) end |
#render_data_grid ⇒ Object
Renders a grid from a local partial within a datagrid container
138 139 140 141 142 143 144 145 146 |
# File 'app/helpers/integral/backend/base_helper.rb', line 138 def render_data_grid unless block_given? return content_tag(:div, render(partial: 'grid', locals: { grid: @grid }), data: { 'controller' => 'grid', 'form' => 'grid_form' }, class: 'grid-container') end content_tag(:div, data: { 'controller' => 'grid', 'form' => 'grid_form' }, class: 'grid-container') do yield end end |
#render_donut_chart(dataset) ⇒ Object
Renders a donut chart
172 173 174 |
# File 'app/helpers/integral/backend/base_helper.rb', line 172 def render_donut_chart(dataset) ChartRenderer::Donut.render(dataset) end |
#render_line_chart(dataset) ⇒ Object
Renders a line chart
167 168 169 |
# File 'app/helpers/integral/backend/base_helper.rb', line 167 def render_line_chart(dataset) ChartRenderer::Line.render(dataset) end |
#render_resource_grid(locals = {}) ⇒ String
Returns Resource Grid.
86 87 88 89 90 |
# File 'app/helpers/integral/backend/base_helper.rb', line 86 def render_resource_grid(locals = {}) render_data_grid do render(partial: "integral/backend/shared/grid/grid", locals: locals) end end |
#render_resource_grid_form(&block) ⇒ String
Returns Resource Grid Form.
77 78 79 80 81 82 83 |
# File 'app/helpers/integral/backend/base_helper.rb', line 77 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 |
#storage_file_content_type_options ⇒ Object
11 12 13 |
# File 'app/helpers/integral/backend/base_helper.rb', line 11 def ActiveStorage::Blob.distinct.pluck(:content_type).sort end |