Class: DashboardController

Inherits:
ApplicationController show all
Includes:
Foreman::Controller::AutoCompleteSearch, Foreman::Controller::Parameters::Widget
Defined in:
app/controllers/dashboard_controller.rb

Instance Attribute Summary

Attributes inherited from ApplicationController

#original_search_parameter

Instance Method Summary collapse

Methods included from Foreman::Controller::AutoCompleteSearch

#auto_complete_search, #invalid_search_query, #reset_redirect_to_url, #store_redirect_to_url

Methods inherited from ApplicationController

#api_request?, #current_user, parameter_filter_context, #resource_path, #welcome

Methods included from ApplicationShared

#current_permission, #find_default_taxonomy, #find_session_taxonomy, #set_current_taxonomy, #set_current_user, #set_taxonomy, #store_default_taxonomy, #store_taxonomy

Methods included from FindCommon

#controller_permission, #find_resource, #resource_class, #resource_class_for, #resource_finder, #resource_scope, #scope_for

Methods included from Foreman::ThreadSession::Cleaner

#clear_thread

Methods included from Foreman::Controller::Timezone

#set_timezone

Methods included from Foreman::Controller::TopbarSweeper

#set_topbar_sweeper_controller

Methods included from Foreman::Controller::Session

#backup_session_content, #expire_session, #ignore_api_request?, #session_expiry, #set_activity_time, #update_activity_time

Methods included from Foreman::Controller::Authentication

#authenticate, #authorized, #available_sso, #check_user_enabled, #is_admin?, #path_to_authenticate, #require_login

Methods included from Foreman::Controller::MigrationChecker

needs_migration?

Instance Method Details

#createObject


27
28
29
30
31
32
33
34
35
# File 'app/controllers/dashboard_controller.rb', line 27

def create
  widget = Dashboard::Manager.find_default_widget_by_name(params[:name])
  unless widget.present?
    not_found
    return
  end
  Dashboard::Manager.add_widget_to_user(User.current, widget.first)
  render :json => { :name => params[:name] }, :status => :ok
end

#destroyObject


37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/dashboard_controller.rb', line 37

def destroy
  if @widget.present? && @widget.user == User.current
    User.current.widgets.destroy(@widget)
    status = :ok
  else
    status = :forbidden
    logger.warn "#{User.current} attempted to remove widget id #{params[:id]} and failed."
  end
  respond_to do |format|
    format.json { render :json => params[:id], :status => status }
  end
end

#indexObject


9
10
11
12
13
14
15
# File 'app/controllers/dashboard_controller.rb', line 9

def index
  respond_to do |format|
    format.html
    format.yaml { render :plain => @report.to_yaml }
    format.json
  end
end

#reset_defaultObject


50
51
52
53
# File 'app/controllers/dashboard_controller.rb', line 50

def reset_default
  Dashboard::Manager.reset_user_to_default(User.current)
  redirect_to root_path
end

#resource_nameObject


74
75
76
# File 'app/controllers/dashboard_controller.rb', line 74

def resource_name
  "widget"
end

#save_positionsObject


55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/controllers/dashboard_controller.rb', line 55

def save_positions
  errors = []
  filter = self.class.widget_params_filter
  params.fetch(:widgets, []).each do |id, values|
    widget = User.current.widgets.where(:id => id).first
    values = filter.filter_params(values, parameter_filter_context, :none)
    errors << widget.errors unless widget.update(values)
  end
  respond_to do |format|
    if errors.empty?
      format.json { render :json => {}, :status => :ok }
    else
      format.json { render :json => errors, :status => :bad_request }
    end
  end
rescue => exception
  process_ajax_error exception, 'save positions'
end

#showObject


17
18
19
20
21
22
23
24
25
# File 'app/controllers/dashboard_controller.rb', line 17

def show
  if @widget.present? && @widget.user == User.current
    render(:partial => @widget.template, :locals => @widget.data)
  else
    render_403 "User #{User.current} attempted to access another user's widget"
  end
rescue ActionView::MissingTemplate, ActionView::Template::Error => exception
  process_ajax_error exception, "load widget"
end