From bb2bef99685b7ae2f334a60f65efe15b163c58cd Mon Sep 17 00:00:00 2001 From: Jan Peterka Date: Sun, 29 Sep 2024 14:29:28 +0200 Subject: [PATCH] Move logic to SessionWindow controller --- .../dashboard/dashboards_controller.rb | 11 ----------- .../dashboard/session_windows_controller.rb | 17 +++++++++++++++++ .../dashboard/dashboards/index.html.erb | 4 ++-- .../show.html.erb | 0 config/routes.rb | 3 ++- 5 files changed, 21 insertions(+), 14 deletions(-) create mode 100644 app/controllers/spectator_sport/dashboard/session_windows_controller.rb rename app/views/spectator_sport/dashboard/{dashboards => session_windows}/show.html.erb (100%) diff --git a/app/controllers/spectator_sport/dashboard/dashboards_controller.rb b/app/controllers/spectator_sport/dashboard/dashboards_controller.rb index 0080d91..afdd5dd 100644 --- a/app/controllers/spectator_sport/dashboard/dashboards_controller.rb +++ b/app/controllers/spectator_sport/dashboard/dashboards_controller.rb @@ -4,17 +4,6 @@ class DashboardsController < ApplicationController def index @session_windows = SessionWindow.order(:created_at).limit(50).reverse_order end - - def show - @session_window = SessionWindow.find(params[:id]) - end - - def destroy - @session_window = SessionWindow.find(params[:id]) - @session_window.events.delete_all - @session_window.delete - redirect_to action: :index - end end end end diff --git a/app/controllers/spectator_sport/dashboard/session_windows_controller.rb b/app/controllers/spectator_sport/dashboard/session_windows_controller.rb new file mode 100644 index 0000000..68912ad --- /dev/null +++ b/app/controllers/spectator_sport/dashboard/session_windows_controller.rb @@ -0,0 +1,17 @@ +module SpectatorSport + module Dashboard + class SessionWindowsController < ApplicationController + def show + @session_window = SessionWindow.find(params[:id]) + end + + def destroy + @session_window = SessionWindow.find(params[:id]) + @session_window.events.delete_all + @session_window.delete + + redirect_to "/spectator_sport_dashboard" + end + end + end +end diff --git a/app/views/spectator_sport/dashboard/dashboards/index.html.erb b/app/views/spectator_sport/dashboard/dashboards/index.html.erb index eaeff72..3f53cfe 100644 --- a/app/views/spectator_sport/dashboard/dashboards/index.html.erb +++ b/app/views/spectator_sport/dashboard/dashboards/index.html.erb @@ -4,8 +4,8 @@ <% @session_windows.each do |session_window| %>
  • - <%= link_to "Session (##{session_window.session_id}) Window (##{session_window.id})", dashboard_path(session_window.id) %> - <%= button_to "X", { action: :destroy, id: session_window.id }, method: :delete, form: { style: "display: inline-block" } %> + <%= link_to "Session (##{session_window.session_id}) Window (##{session_window.id})", session_window_path(session_window.id) %> + <%= button_to "X", session_window, method: :delete, form: { style: "display: inline-block" } %>
  • <% end %> diff --git a/app/views/spectator_sport/dashboard/dashboards/show.html.erb b/app/views/spectator_sport/dashboard/session_windows/show.html.erb similarity index 100% rename from app/views/spectator_sport/dashboard/dashboards/show.html.erb rename to app/views/spectator_sport/dashboard/session_windows/show.html.erb diff --git a/config/routes.rb b/config/routes.rb index 8d89149..73af541 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,5 +4,6 @@ SpectatorSport::Dashboard::Engine.routes.draw do get "/", to: "dashboards#index" - resources :dashboards, only: [ :show, :destroy ] + # resources :dashboards, only: [ :show, :destroy ] + resources :session_windows, only: [ :show, :destroy ] end