Class: Tiler::PanelsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/tiler/panels_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/tiler/panels_controller.rb', line 18

def create
  @panel = @dashboard.panels.build(panel_params)
  if @panel.save
    respond_to do |format|
      format.html         { redirect_to dashboard_path(@dashboard), notice: "Panel added." }
      format.json         { render json: panel_json(@panel), status: :created }
      format.turbo_stream # renders create.turbo_stream.erb (appends to grid)
    end
  else
    respond_to do |format|
      format.html do
        @data_sources = DataSource.active.by_name
        render :new, status: :unprocessable_entity
      end
      format.json { render json: { errors: @panel.errors.full_messages }, status: :unprocessable_entity }
      format.turbo_stream { render json: { errors: @panel.errors.full_messages }, status: :unprocessable_entity }
    end
  end
end

#destroyObject



51
52
53
54
# File 'app/controllers/tiler/panels_controller.rb', line 51

def destroy
  @panel.destroy!
  redirect_to dashboard_path(@dashboard), notice: "Panel removed."
end

#editObject



38
39
40
# File 'app/controllers/tiler/panels_controller.rb', line 38

def edit
  @data_sources = DataSource.active.by_name
end

#newObject



7
8
9
10
11
12
13
14
15
16
# File 'app/controllers/tiler/panels_controller.rb', line 7

def new
  next_y = (@dashboard.panels.maximum(:y) || -1) + 1
  requested_type = params.dig(:panel, :widget_type).presence
  widget_type = Tiler.widgets[requested_type] ? requested_type : Tiler.widgets.types.first
  @panel = @dashboard.panels.build(
    width: 6, height: 2, x: 0, y: next_y,
    widget_type: widget_type
  )
  @data_sources = DataSource.active.by_name
end

#previewObject



56
57
58
59
# File 'app/controllers/tiler/panels_controller.rb', line 56

def preview
  @data = @panel.data
  render partial: "tiler/panels/panel", locals: { panel: @panel, data: @data }
end

#updateObject



42
43
44
45
46
47
48
49
# File 'app/controllers/tiler/panels_controller.rb', line 42

def update
  if @panel.update(panel_params)
    redirect_to dashboard_path(@dashboard), notice: "Panel updated."
  else
    @data_sources = DataSource.active.by_name
    render :edit, status: :unprocessable_entity
  end
end