Class: Tiler::DashboardsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Tiler::DashboardsController
- Defined in:
- app/controllers/tiler/dashboards_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #layout ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'app/controllers/tiler/dashboards_controller.rb', line 19 def create @dashboard = Dashboard.new(dashboard_params) if @dashboard.save redirect_to dashboard_path(@dashboard), notice: "Dashboard created." else render :new, status: :unprocessable_entity end end |
#destroy ⇒ Object
39 40 41 42 |
# File 'app/controllers/tiler/dashboards_controller.rb', line 39 def destroy @dashboard.destroy! redirect_to dashboards_path, notice: "Dashboard deleted." end |
#edit ⇒ Object
28 29 |
# File 'app/controllers/tiler/dashboards_controller.rb', line 28 def edit end |
#index ⇒ Object
6 7 8 |
# File 'app/controllers/tiler/dashboards_controller.rb', line 6 def index @dashboards = Dashboard.by_name end |
#layout ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/controllers/tiler/dashboards_controller.rb', line 44 def layout items = params[:items] unless items.is_a?(Array) return render json: { error: "items must be an array" }, status: :bad_request end applied = 0 skipped = 0 ActiveRecord::Base.transaction do items.each do |item| unless item.respond_to?(:[]) && item[:id].present? && !item[:x].nil? && !item[:y].nil? && !item[:w].nil? && !item[:h].nil? skipped += 1 next end panel = @dashboard.panels.find_by(id: item[:id]) unless panel skipped += 1 next end x = item[:x].to_i.clamp(0, 11) y = [ item[:y].to_i, 0 ].max w = item[:w].to_i.clamp(1, 12) h = item[:h].to_i.clamp(1, 12) panel.update_columns(x: x, y: y, width: w, height: h) applied += 1 end end # NB: we deliberately do NOT broadcast a refresh here. Layout PATCHes # come from the user dragging/resizing in their own browser — the local # gridstack already reflects the new geometry. Broadcasting back would # morph the same DOM mid-interaction, which destroys gridstack's resize # handle bindings on every other tile and locks subsequent resizes. # Other viewers pick up layout on next navigation; panel CRUD still # broadcasts via Panel#broadcasts_to. render json: { applied: applied, skipped: skipped }, status: :ok end |
#new ⇒ Object
15 16 17 |
# File 'app/controllers/tiler/dashboards_controller.rb', line 15 def new @dashboard = Dashboard.new(refresh_seconds: Tiler.configuration.default_refresh_seconds) end |
#show ⇒ Object
10 11 12 13 |
# File 'app/controllers/tiler/dashboards_controller.rb', line 10 def show @tv_mode = params[:tv].present? || @dashboard.tv_mode? session[:tiler_last_dashboard_slug] = @dashboard.slug end |
#update ⇒ Object
31 32 33 34 35 36 37 |
# File 'app/controllers/tiler/dashboards_controller.rb', line 31 def update if @dashboard.update(dashboard_params) redirect_to dashboard_path(@dashboard), notice: "Dashboard updated." else render :edit, status: :unprocessable_entity end end |