Allow editing of stats

This commit is contained in:
Trevor Vallender 2024-06-27 14:03:56 +01:00
parent 1834854dc0
commit 2170122805
6 changed files with 39 additions and 4 deletions

View File

@ -129,6 +129,12 @@ hr {
background-color: var(--inset-bg-color); background-color: var(--inset-bg-color);
} }
.feature-box-icons {
display: flex;
gap: 1em;
flex-direction: row-reverse;
}
.feature-box h2 { .feature-box h2 {
text-align: center; text-align: center;
} }

View File

@ -3,7 +3,7 @@
class StatsController < ApplicationController class StatsController < ApplicationController
before_action :set_section, only: [ :new, :create ] before_action :set_section, only: [ :new, :create ]
before_action :set_character, only: [ :new, :create ] before_action :set_character, only: [ :new, :create ]
before_action :set_stat, only: [ :show, :update, :destroy ] before_action :set_stat, only: [ :show, :edit, :update, :destroy ]
def new def new
@stat = @section.stats.new @stat = @section.stats.new
@ -21,6 +21,9 @@ class StatsController < ApplicationController
def show def show
end end
def edit
end
def update def update
@editable = ActiveModel::Type::Boolean.new.cast(params[:editable]) @editable = ActiveModel::Type::Boolean.new.cast(params[:editable])
@stat.update!(stat_params) @stat.update!(stat_params)

View File

@ -0,0 +1,19 @@
<%= turbo_frame_tag :modal do %>
<div class="feature-box ">
<%= icon_link_to "fa-close", table_character_character_sheet_sections_path(@stat.character.table, @stat.character),
class: "icon-link" %>
<h2><%= @stat.name %></h2>
<%= form_with model: @stat, data: { controller: "auto-update" } do |f| %>
<%= f.label :name %>
<%= f.text_field :name %>
<%= f.label :min_allowed, t(".min_allowed") %>
<%= f.number_field :min_allowed %>
<%= f.label :max_allowed, t(".max_allowed") %>
<%= f.number_field :max_allowed %>
<%= f.label :roll_command %>
<%= f.text_field :roll_command %>
<% end %>
<h4><%= t(".dice_roll_types") %></h4>
<p>TODO: Add additional roll types here</p>
</div>
<% end %>

View File

@ -1,7 +1,10 @@
<%= turbo_frame_tag :modal do %> <%= turbo_frame_tag :modal do %>
<div class="feature-box stat"> <div class="feature-box stat">
<%= icon_link_to "fa-close", table_character_character_sheet_sections_path(@stat.character.table, @stat.character), <div class="feature-box-icons">
class: "icon-link" %> <%= icon_link_to "fa-close", table_character_character_sheet_sections_path(@stat.character.table, @stat.character),
class: "icon-link" %>
<%= icon_link_to "fa-edit", edit_stat_path(@stat), class: "icon-link" %>
</div>
<h2><%= @stat.name %></h2> <h2><%= @stat.name %></h2>
<%= form_with model: @stat, class: "stat-form", data: { controller: "auto-update" } do |f| %> <%= form_with model: @stat, class: "stat-form", data: { controller: "auto-update" } do |f| %>
<%= f.number_field :value, min: @stat.min_allowed, max: @stat.max_allowed %> <%= f.number_field :value, min: @stat.min_allowed, max: @stat.max_allowed %>

View File

@ -151,6 +151,10 @@ en:
confirm_delete: Are you sure you want to delete %{name}? confirm_delete: Are you sure you want to delete %{name}?
new: new:
create_stat: Create stat create_stat: Create stat
edit:
dice_roll_types: Other rolls
min_allowed: Minimum
max_allowed: Maximum
table_invite_mailer: table_invite_mailer:
invite_new_user: invite_new_user:
subject: Youve been invited to join a game on Tabletop Companion! subject: Youve been invited to join a game on Tabletop Companion!

View File

@ -28,7 +28,7 @@ Rails.application.routes.draw do
resources :characters do resources :characters do
resources :character_sheet_sections, only: [ :index, :new, :create ] resources :character_sheet_sections, only: [ :index, :new, :create ]
end end
resources :stats, only: [ :show, :update, :destroy ] resources :stats, only: [ :show, :edit, :update, :destroy ]
resources :table_invites, only: [ :index, :edit, :update ] resources :table_invites, only: [ :index, :edit, :update ]
resources :tables do resources :tables do
resources :characters, only: [] do resources :characters, only: [] do