Class: Jpi::V1::Admin::Impac::WidgetsController

Inherits:
BaseResourceController
  • Object
show all
Defined in:
app/controllers/mno_enterprise/jpi/v1/admin/impac/widgets_controller.rb

Overview

From the Admin panel, an admin can:

  • add widgets to staff dashboards (passing the dashboard id)

  • add widgets to template dashboards (passing the dashboard template id)

  • update any widget (passing its id)

  • delete any widget (passing its id)

Instance Method Summary collapse

Instance Method Details

#createObject

POST /mnoe/jpi/v1/admin/impac/dashboard_templates/:id/widgets POST /mnoe/jpi/v1/admin/impac/dashboards/:id/widgets



11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/mno_enterprise/jpi/v1/admin/impac/widgets_controller.rb', line 11

def create
  return render json: { errors: { message: "#{container} not found" } }, status: :not_found unless dashboard.present?

  @widget = dashboard.widgets.create(widget_create_params)
  return render json: { errors: (widget && widget.errors).to_a }, status: :bad_request unless widget.present? && widget.valid?

  MnoEnterprise::EventLogger.info('widget_create', current_user.id, "#{container} Widget Creation", widget)
  @no_content = true
  render 'show'
end

#destroyObject

DELETE /mnoe/jpi/v1/admin/impac/widgets/:id



34
35
36
37
38
39
40
41
# File 'app/controllers/mno_enterprise/jpi/v1/admin/impac/widgets_controller.rb', line 34

def destroy
  unless widget.present? && widget.destroy
    return render json: { errors: 'Cannot delete widget' }, status: :bad_request
  end

  MnoEnterprise::EventLogger.info('widget_delete', current_user.id, "#{container} Widget Deletion", widget)
  head status: :ok
end

#updateObject

PUT /mnoe/jpi/v1/admin/impac/widgets/:id



23
24
25
26
27
28
29
30
31
# File 'app/controllers/mno_enterprise/jpi/v1/admin/impac/widgets_controller.rb', line 23

def update
  unless widget.present? && widget.update(widget_update_params)
    return render json: { errors: 'Cannot update widget' }, status: :bad_request
  end

  MnoEnterprise::EventLogger.info('widget_update', current_user.id, "#{container} Widget Update", widget)
  @nocontent = !params['metadata']
  render 'show'
end