Add text fields to character sheets
This commit is contained in:
parent
de37a7e81f
commit
8e1a16bb06
|
@ -11,6 +11,7 @@ class CountersController < ApplicationController
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@counter = @section.counters.new(counter_params)
|
@counter = @section.counters.new(counter_params)
|
||||||
|
@editable = true
|
||||||
unless @counter.save
|
unless @counter.save
|
||||||
render :new, status: :unprocessable_entity
|
render :new, status: :unprocessable_entity
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,6 +11,7 @@ class StatsController < ApplicationController
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@stat = @section.stats.new(stat_params)
|
@stat = @section.stats.new(stat_params)
|
||||||
|
@editable = true
|
||||||
unless @stat.save
|
unless @stat.save
|
||||||
render :new, status: :unprocessable_entity
|
render :new, status: :unprocessable_entity
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class TextFieldsController < ApplicationController
|
||||||
|
before_action :set_section, only: [ :new, :create ]
|
||||||
|
before_action :set_character, only: [ :new, :create ]
|
||||||
|
before_action :set_text_field, only: [ :update, :destroy ]
|
||||||
|
|
||||||
|
def new
|
||||||
|
@text_field = @section.text_fields.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
@text_field = @section.text_fields.new(text_field_params)
|
||||||
|
@editable = true
|
||||||
|
unless @text_field.save
|
||||||
|
render :new, status: :unprocessable_entity
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
@text_field.update(text_field_params)
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
@id = helpers.dom_id(@text_field)
|
||||||
|
@text_field.destroy
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def set_character
|
||||||
|
@character = @section.character
|
||||||
|
end
|
||||||
|
|
||||||
|
def set_section
|
||||||
|
@section = Current.user.character_sheet_sections.find(params[:character_sheet_section_id])
|
||||||
|
end
|
||||||
|
|
||||||
|
def set_text_field
|
||||||
|
@text_field = Current.user.text_fields.find(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
def text_field_params
|
||||||
|
params.require(:text_field).permit(
|
||||||
|
:name,
|
||||||
|
:content,
|
||||||
|
:character_sheet_section_id,
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
|
@ -12,6 +12,7 @@ class User < ApplicationRecord
|
||||||
has_many :counters, through: :character_sheet_sections
|
has_many :counters, through: :character_sheet_sections
|
||||||
has_many :stats, through: :character_sheet_sections
|
has_many :stats, through: :character_sheet_sections
|
||||||
has_many :tables, through: :players
|
has_many :tables, through: :players
|
||||||
|
has_many :text_fields, through: :character_sheet_sections
|
||||||
has_rich_text :profile
|
has_rich_text :profile
|
||||||
has_one_attached :avatar do |attachable|
|
has_one_attached :avatar do |attachable|
|
||||||
attachable.variant :standard, resize_to_limit: [ 100, 100 ], preprocessed: true
|
attachable.variant :standard, resize_to_limit: [ 100, 100 ], preprocessed: true
|
||||||
|
|
|
@ -10,6 +10,9 @@
|
||||||
<div id="<%= dom_id(character_sheet_section) %>_counters" class="counters">
|
<div id="<%= dom_id(character_sheet_section) %>_counters" class="counters">
|
||||||
<%= render character_sheet_section.counters %>
|
<%= render character_sheet_section.counters %>
|
||||||
</div>
|
</div>
|
||||||
|
<div id="<%= dom_id(character_sheet_section) %>_text_fields" class="text-fields">
|
||||||
|
<%= render character_sheet_section.text_fields %>
|
||||||
|
</div>
|
||||||
<div id="<%= dom_id(character_sheet_section) %>_sections">
|
<div id="<%= dom_id(character_sheet_section) %>_sections">
|
||||||
<%= render character_sheet_section.character_sheet_subsections %>
|
<%= render character_sheet_section.character_sheet_subsections %>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
new_character_sheet_section_stat_path(section), data: { turbo_stream: true }, class: "add-stat" %>
|
new_character_sheet_section_stat_path(section), data: { turbo_stream: true }, class: "add-stat" %>
|
||||||
<%= link_to t(".add_counter"),
|
<%= link_to t(".add_counter"),
|
||||||
new_character_sheet_section_counter_path(section), data: { turbo_stream: true }, class: "add-counter" %>
|
new_character_sheet_section_counter_path(section), data: { turbo_stream: true }, class: "add-counter" %>
|
||||||
|
<%= link_to t(".add_text_field"),
|
||||||
|
new_character_sheet_section_text_field_path(section), data: { turbo_stream: true }, class: "add-text-field" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% unless id == "character_sheet_add_section" %>
|
<% unless id == "character_sheet_add_section" %>
|
||||||
<%= link_to t(".delete_section", name: section.name), character_sheet_section_path(section),
|
<%= link_to t(".delete_section", name: section.name), character_sheet_section_path(section),
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
<%= content_target = "#{dom_id(@section)}_counters" %>
|
<% content_target = "#{dom_id(@section)}_counters" %>
|
||||||
<%= turbo_stream.append(content_target) do %>
|
<%= turbo_stream.append(content_target) do %>
|
||||||
<%= render @counter %>
|
<%= render @counter %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= form_target = "#{dom_id(@section)}_add_section" %>
|
<% form_target = "#{dom_id(@section)}_add_section" %>
|
||||||
<%= turbo_stream.replace(form_target) do %>
|
<%= turbo_stream.replace(form_target) do %>
|
||||||
<div id="#{dom_id(@section)}_add_section">
|
<div id="<%= dom_id(@section) %>_add_section">
|
||||||
<%= render partial: "character_sheet_sections/edit_links", locals: { section: @section, parent: @section.parent_section, id: nil} %>
|
<%= render partial: "character_sheet_sections/edit_links", locals: { section: @section, parent: @section.parent_section, id: nil} %>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
<%= form_target = "#{dom_id(@section)}_add_section" %>
|
<%= form_target = "#{dom_id(@section)}_add_section" %>
|
||||||
<%= turbo_stream.replace(form_target) do %>
|
<%= turbo_stream.replace(form_target) do %>
|
||||||
<div id="#{dom_id(@section)}_add_section">
|
<div id="<%= dom_id(@section) %>_add_section">
|
||||||
<%= render partial: "character_sheet_sections/edit_links", locals: { section: @section, parent: @section.parent_section, id: nil} %>
|
<%= render partial: "character_sheet_sections/edit_links", locals: { section: @section, parent: @section.parent_section, id: nil} %>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
<section class="inset">
|
||||||
|
<%= form_with model: @text_field, url: character_sheet_section_text_fields_path(@section) do |f| %>
|
||||||
|
<%= f.hidden_field :character_sheet_section_id, value: @section.id %>
|
||||||
|
|
||||||
|
<%= f.label :name %>
|
||||||
|
<%= f.text_field :name %>
|
||||||
|
<%= display_form_errors(@section, :name) %>
|
||||||
|
|
||||||
|
<%= f.submit button_text %>
|
||||||
|
<% end %>
|
||||||
|
</section>
|
|
@ -0,0 +1,17 @@
|
||||||
|
<div class="text-field" id="<%= dom_id(text_field) %>">
|
||||||
|
<% if @editable %>
|
||||||
|
<%= link_to t(".delete"), text_field,
|
||||||
|
data: { turbo_method: :delete, turbo_confirm: t(".confirm_delete", name: text_field.name) } %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<h6><%= text_field.name %></h6>
|
||||||
|
<% if @editable %>
|
||||||
|
<%= form_with model: text_field, class: "text-field-form" do |f| %>
|
||||||
|
<%= f.rich_text_area :content %>
|
||||||
|
<%= f.submit t(".save") %>
|
||||||
|
<% end %>
|
||||||
|
<% else %>
|
||||||
|
<p><%= text_field.content %></p>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
<% content_target = "#{dom_id(@section)}_text_fields" %>
|
||||||
|
<%= turbo_stream.append(content_target) do %>
|
||||||
|
<%= render @text_field %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<% form_target = "#{dom_id(@section)}_add_section" %>
|
||||||
|
<%= turbo_stream.replace(form_target) do %>
|
||||||
|
<div id="<% dom_id(@section) %>_add_section">
|
||||||
|
<%= render partial: "character_sheet_sections/edit_links", locals: { section: @section, parent: @section.parent_section, id: nil} %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
|
@ -0,0 +1 @@
|
||||||
|
<%= turbo_stream.remove @id %>
|
|
@ -0,0 +1,6 @@
|
||||||
|
<% target = "#{dom_id(@text_field.character_sheet_section)}_add_section" %>
|
||||||
|
<%= turbo_stream.replace(target) do %>
|
||||||
|
<div id="<%= target %>">
|
||||||
|
<%= render partial: "form", locals: { button_text: t(".create_text_field") } %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
|
@ -0,0 +1,3 @@
|
||||||
|
<%= turbo_stream.replace dom_id(@text_field) do %>
|
||||||
|
<%= render @text_field %>
|
||||||
|
<% end %>
|
|
@ -65,6 +65,7 @@ en:
|
||||||
confirm_delete: Are you sure you want to delete this section?
|
confirm_delete: Are you sure you want to delete this section?
|
||||||
add_stat: Add stat
|
add_stat: Add stat
|
||||||
add_counter: Add counter
|
add_counter: Add counter
|
||||||
|
add_text_field: Add text field
|
||||||
index:
|
index:
|
||||||
edit: Edit character sheet
|
edit: Edit character sheet
|
||||||
stop_editing: Stop editing
|
stop_editing: Stop editing
|
||||||
|
@ -213,6 +214,13 @@ en:
|
||||||
destroy:
|
destroy:
|
||||||
success: Deleted table “%{name}”.
|
success: Deleted table “%{name}”.
|
||||||
error: Failed to delete table.
|
error: Failed to delete table.
|
||||||
|
text_fields:
|
||||||
|
text_field:
|
||||||
|
delete: Delete text field
|
||||||
|
confirm_delete: Are you sure you want to delete %{name}?
|
||||||
|
save: Save
|
||||||
|
new:
|
||||||
|
create_text_field: Create text field
|
||||||
users:
|
users:
|
||||||
validations:
|
validations:
|
||||||
email_format: "must be a valid email address"
|
email_format: "must be a valid email address"
|
||||||
|
|
|
@ -18,6 +18,7 @@ Rails.application.routes.draw do
|
||||||
resources :character_sheet_sections, only: [ :destroy ] do
|
resources :character_sheet_sections, only: [ :destroy ] do
|
||||||
resources :counters, only: [ :new, :create ]
|
resources :counters, only: [ :new, :create ]
|
||||||
resources :stats, only: [ :new, :create ]
|
resources :stats, only: [ :new, :create ]
|
||||||
|
resources :text_fields, only: [ :new, :create ]
|
||||||
end
|
end
|
||||||
resources :characters do
|
resources :characters do
|
||||||
resources :character_sheet_sections, only: [ :index, :new, :create ]
|
resources :character_sheet_sections, only: [ :index, :new, :create ]
|
||||||
|
@ -33,6 +34,7 @@ Rails.application.routes.draw do
|
||||||
resources :events, only: [ :index ]
|
resources :events, only: [ :index ]
|
||||||
resources :table_invites, only: [ :new, :create ]
|
resources :table_invites, only: [ :new, :create ]
|
||||||
end
|
end
|
||||||
|
resources :text_fields, only: [ :update, :destroy ]
|
||||||
|
|
||||||
resources :admin, only: [ :index ]
|
resources :admin, only: [ :index ]
|
||||||
namespace :admin do
|
namespace :admin do
|
||||||
|
|
9
todo.md
9
todo.md
|
@ -1,9 +1,12 @@
|
||||||
|
- don't roll when no roll set
|
||||||
|
- set orders on sheets
|
||||||
|
- easily edit text fields without entering edit mode
|
||||||
|
- add roll command to counters (e.g. luck)
|
||||||
- test for rolls controller & system tests
|
- test for rolls controller & system tests
|
||||||
- table notifications for rolls
|
- Show individual dice on dice roll
|
||||||
- roll on click
|
- customise trix bar
|
||||||
- Sheets
|
- Sheets
|
||||||
- Lists
|
- Lists
|
||||||
- Text fields
|
|
||||||
- Weapons/spells
|
- Weapons/spells
|
||||||
- Character avatars
|
- Character avatars
|
||||||
- default avatars
|
- default avatars
|
||||||
|
|
Loading…
Reference in New Issue