Class: Tiler::Api::V1::DashboardsController

Inherits:
ActionController::API
  • Object
show all
Defined in:
app/controllers/tiler/api/v1/dashboards_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



18
19
20
21
22
23
24
25
# File 'app/controllers/tiler/api/v1/dashboards_controller.rb', line 18

def create
  @dashboard = Tiler::Dashboard.new(dashboard_params)
  if @dashboard.save
    render json: serialize(@dashboard), status: :created
  else
    render json: { errors: @dashboard.errors.full_messages }, status: :unprocessable_entity
  end
end

#destroyObject



35
36
37
38
# File 'app/controllers/tiler/api/v1/dashboards_controller.rb', line 35

def destroy
  @dashboard.destroy!
  head :no_content
end

#indexObject



10
11
12
# File 'app/controllers/tiler/api/v1/dashboards_controller.rb', line 10

def index
  render json: Tiler::Dashboard.by_name.map { |d| serialize(d) }
end

#settingsObject

PATCH /tiler/api/v1/dashboards/:id/settings Body: { settings: { tv_mode: true } } Merges into existing settings (does not replace) so callers can ship one key at a time.



44
45
46
47
48
49
50
51
52
# File 'app/controllers/tiler/api/v1/dashboards_controller.rb', line 44

def settings
  incoming = params.require(:settings).permit!.to_h
  merged   = @dashboard.settings_hash.merge(incoming)
  if @dashboard.update(settings: merged.to_json)
    render json: serialize(@dashboard)
  else
    render json: { errors: @dashboard.errors.full_messages }, status: :unprocessable_entity
  end
end

#showObject



14
15
16
# File 'app/controllers/tiler/api/v1/dashboards_controller.rb', line 14

def show
  render json: serialize(@dashboard)
end

#updateObject



27
28
29
30
31
32
33
# File 'app/controllers/tiler/api/v1/dashboards_controller.rb', line 27

def update
  if @dashboard.update(dashboard_params)
    render json: serialize(@dashboard)
  else
    render json: { errors: @dashboard.errors.full_messages }, status: :unprocessable_entity
  end
end