From c2c733fcec555d6272bc7b09dd93ef1be9664238 Mon Sep 17 00:00:00 2001 From: Trevor Vallender Date: Wed, 12 Jun 2024 18:20:14 +0100 Subject: [PATCH] Add tab logic to tables --- app/controllers/characters_controller.rb | 5 +++++ app/controllers/tables_controller.rb | 6 ++++++ app/views/layouts/application.html.erb | 3 ++- app/views/layouts/table.html.erb | 19 +++++++++++++++++++ app/views/tables/show.html.erb | 2 -- config/locales/en.yml | 2 ++ config/routes.rb | 1 + 7 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 app/views/layouts/table.html.erb diff --git a/app/controllers/characters_controller.rb b/app/controllers/characters_controller.rb index 0c5ec8f..d27d772 100644 --- a/app/controllers/characters_controller.rb +++ b/app/controllers/characters_controller.rb @@ -22,6 +22,11 @@ class CharactersController < ApplicationController end def show + if params[:table_id].present? + @table = Current.user.tables.find(params[:table_id]) + @characters = Current.user.characters.where(table: @table) + render layout: "table" + end end def edit diff --git a/app/controllers/tables_controller.rb b/app/controllers/tables_controller.rb index 8064c83..98522a9 100644 --- a/app/controllers/tables_controller.rb +++ b/app/controllers/tables_controller.rb @@ -2,6 +2,7 @@ class TablesController < ApplicationController before_action :set_table, only: [ :show, :edit, :update, :destroy ] + before_action :set_characters, only: [ :show ] def index @tables = Current.user.tables @@ -9,6 +10,7 @@ class TablesController < ApplicationController def show @table_invites = @table.table_invites.not_responded + render layout: "table" end def new @@ -52,6 +54,10 @@ class TablesController < ApplicationController @table = Current.user.tables.find(params[:id]) end + def set_characters + @characters = Current.user.characters.where(table: @table) + end + def table_params params.require(:table).permit( :name, diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index bed8668..94cf450 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -35,7 +35,8 @@
<%= render partial: "shared/flash_messages" %> <%= yield(:submenu) if content_for?(:submenu) %> - <%= yield %> + <%= yield(:main) if content_for?(:main) %> + <%= yield unless content_for?(:main) %>
diff --git a/app/views/layouts/table.html.erb b/app/views/layouts/table.html.erb new file mode 100644 index 0000000..bdba9df --- /dev/null +++ b/app/views/layouts/table.html.erb @@ -0,0 +1,19 @@ +<% content_for :submenu do %> +

<%= @table.name %>

+ +<% end %> + +<% content_for :main do %> + <%= turbo_frame_tag("table-content") do %> + <%= yield %> + <% end %> +<% end %> + +<%= render template: "layouts/application" %> diff --git a/app/views/tables/show.html.erb b/app/views/tables/show.html.erb index 6e57ce7..ddeba70 100644 --- a/app/views/tables/show.html.erb +++ b/app/views/tables/show.html.erb @@ -1,7 +1,5 @@ <% content_for :title, @table.name %> -

<%= @table.name %>

- <%= link_to t(".invite_user"), new_table_table_invite_path(@table) %> <%= link_to t(".edit_table"), edit_table_path(@table) %> diff --git a/config/locales/en.yml b/config/locales/en.yml index db67e7b..7f3d53e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -25,6 +25,8 @@ en: See you soon, The Tabletop Companion team sign_off_html: "

See you soon,
The Tabletop Companion team

" + table: + overview: Overview account_verifications: show: success: "Thanks for verifying your email address! You can now log in." diff --git a/config/routes.rb b/config/routes.rb index f0a1ba9..a7c0576 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -26,6 +26,7 @@ Rails.application.routes.draw do resources :stats, only: [ :update, :destroy ] resources :table_invites, only: [ :index, :edit, :update ] resources :tables do + resources :characters, only: [ :show ] resources :table_invites, only: [ :new, :create ] end