Class: Admin::DashboardWidgetsController

Inherits:
BaseController
  • Object
show all
Defined in:
lib/generators/open_loam/install/templates/admin/dashboard_widgets_controller.rb

Overview

Dashboard settings (OpenLoam::DashboardWidget) — manager-only. Choose which registered widgets appear and in what order for this tenant.

Constant Summary

Constants included from Pagination

Pagination::PER_PAGE

Instance Method Summary collapse

Methods inherited from BaseController

skip_authorization!

Methods included from Pagination

#paginate

Instance Method Details

#index ⇒ Object



7
8
9
10
# File 'lib/generators/open_loam/install/templates/admin/dashboard_widgets_controller.rb', line 7

def index
  @registered = OpenLoam::Widgets.registered
  @config = OpenLoam::DashboardWidget.all.index_by(&:widget_key)
end

#update ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/generators/open_loam/install/templates/admin/dashboard_widgets_controller.rb', line 12

def update
  OpenLoam::Widgets.keys.each do |key|
    attrs = params.dig(:widgets, key) || {}
    row = OpenLoam::DashboardWidget.find_or_initialize_by(widget_key: key)
    row.active = attrs[:active] == "1"
    row.position = attrs[:position].to_i
    row.save!
  end
  redirect_to admin_root_path, notice: "Dashboard updated."
end