Add tab logic to tables

This commit is contained in:
Trevor Vallender 2024-06-12 18:20:14 +01:00
parent 1b90ed389f
commit c2c733fcec
7 changed files with 35 additions and 3 deletions

View File

@ -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

View File

@ -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,

View File

@ -35,7 +35,8 @@
<main>
<%= render partial: "shared/flash_messages" %>
<%= yield(:submenu) if content_for?(:submenu) %>
<%= yield %>
<%= yield(:main) if content_for?(:main) %>
<%= yield unless content_for?(:main) %>
</main>
</body>
</html>

View File

@ -0,0 +1,19 @@
<% content_for :submenu do %>
<h2><%= @table.name %></h2>
<nav>
<ul>
<li><%= link_to t(".overview"), @table %></li>
<% @characters.each do |character| %>
<li><%= link_to character.name, table_character_path(@table, character) %></li>
<% end %>
</ul>
</nav>
<% end %>
<% content_for :main do %>
<%= turbo_frame_tag("table-content") do %>
<%= yield %>
<% end %>
<% end %>
<%= render template: "layouts/application" %>

View File

@ -1,7 +1,5 @@
<% content_for :title, @table.name %>
<h2><%= @table.name %></h2>
<%= link_to t(".invite_user"), new_table_table_invite_path(@table) %>
<%= link_to t(".edit_table"), edit_table_path(@table) %>

View File

@ -25,6 +25,8 @@ en:
See you soon,
The Tabletop Companion team
sign_off_html: "<p>See you soon,<br>The Tabletop Companion team</p>"
table:
overview: Overview
account_verifications:
show:
success: "Thanks for verifying your email address! You can now log in."

View File

@ -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