Compare commits

...

2 Commits

Author SHA1 Message Date
Trevor Vallender a0271f0b69 Edit text field in modal 2024-06-21 10:57:03 +01:00
Trevor Vallender 7c269ac78e Remove counters (just use stats) 2024-06-21 10:25:41 +01:00
27 changed files with 58 additions and 208 deletions

View File

@ -50,14 +50,14 @@
}
}
.stats, .counters {
.stats {
display: flex;
flex-wrap: wrap;
gap: .2em;
justify-content: center;
}
.stat, .counter, .text-field {
.stat, .text-field {
display: flex;
flex-direction: column;
border-radius: var(--border-radius);
@ -89,6 +89,7 @@
max-width: 20em;
overflow-y: scroll;
font-size: .8em;
align-content: center;
}
input[type=submit] {
width: 100%;
@ -96,6 +97,9 @@
height: auto;
padding: auto;
}
a:link, a:visited {
text-decoration: none;
}
}
.feature-edit-buttons {

View File

@ -41,13 +41,26 @@ form, fieldset {
}
}
form.stat-form, form.counter-form {
form.stat-form {
display: flex;
flex-direction: column;
}
.feature-box form.stat-form {
.feature-box trix-toolbar {
display: block;
}
.feature-box form.stat-form, .feature-box form.text-field-form {
display: block;
margin: 1em auto;
width: fit-content;
}
.feature-box form.text-field-form {
width: 100%;
.trix-content, .trix-editor {
width: 100%;
max-width: 100%;
margin-bottom: 1em;
}
}

View File

@ -113,7 +113,7 @@ hr {
z-index: 5000;
}
#modal div {
#modal > div {
position: absolute;
top: 50%;
left: 50%;
@ -133,6 +133,10 @@ hr {
text-align: center;
}
.feature-box trix-editor {
grid-column: 1/3;
}
.nf {
color: var(--text-color);
}
@ -143,8 +147,3 @@ hr {
cursor: pointer;
box-shadow: 0 0 5px var(--shadow-color);
}
.roll-button::before {
content: "YO";
background-color: red;
}

View File

@ -1,52 +0,0 @@
# frozen_string_literal: true
class CountersController < ApplicationController
before_action :set_section, only: [ :new, :create ]
before_action :set_character, only: [ :new, :create ]
before_action :set_counter, only: [ :update, :destroy ]
def new
@counter = @section.counters.new
@counter.build_character_sheet_feature
end
def create
@counter = @section.counters.new(counter_params)
@editable = true
unless @counter.save
render :new, status: :unprocessable_entity
end
end
def update
@counter.update(counter_params)
end
def destroy
@id = helpers.dom_id(@counter)
@counter.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_counter
@counter = Current.user.counters.find(params[:id])
end
def counter_params
params.require(:counter).permit(
:name,
:value,
character_sheet_feature_attributes: [
:id, :featurable_id, :featurable_type, :character_sheet_section_id, :_destroy,
],
)
end
end

View File

@ -3,7 +3,7 @@
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 ]
before_action :set_text_field, only: [ :show, :update, :destroy ]
def new
@text_field = @section.text_fields.new
@ -18,6 +18,9 @@ class TextFieldsController < ApplicationController
end
end
def show
end
def update
@text_field.update(text_field_params)
end

View File

@ -8,8 +8,6 @@ class CharacterSheetSection < ApplicationRecord
foreign_key: :parent_section_id,
dependent: :destroy
has_many :character_sheet_features
has_many :counters, dependent: :destroy, through: :character_sheet_features,
source: :featurable, source_type: "Counter"
has_many :stats, dependent: :destroy, through: :character_sheet_features,
source: :featurable, source_type: "Stat"
has_many :text_fields, dependent: :destroy, through: :character_sheet_features,

View File

@ -1,12 +0,0 @@
# frozen_string_literal: true
class Counter < ApplicationRecord
has_one :character_sheet_feature, as: :featurable, dependent: :destroy
has_one :character_sheet_section, through: :character_sheet_feature
accepts_nested_attributes_for :character_sheet_feature, allow_destroy: true
validates :name, presence: true,
length: { maximum: 100 }
validates :value, presence: true,
numericality: true
end

View File

@ -3,6 +3,7 @@
class TextField < ApplicationRecord
has_one :character_sheet_feature, as: :featurable, dependent: :destroy
has_one :character_sheet_section, through: :character_sheet_feature
has_one :character, through: :character_sheet_section
accepts_nested_attributes_for :character_sheet_feature, allow_destroy: true
has_rich_text :content

View File

@ -10,7 +10,6 @@ class User < ApplicationRecord
has_many :character_sheet_features, through: :character_sheet_sections
has_many :owned_tables, foreign_key: :owner_id, class_name: "Table"
has_many :players, dependent: :destroy
has_many :counters, through: :character_sheet_sections
has_many :stats, through: :character_sheet_sections
has_many :tables, through: :players
has_many :text_fields, through: :character_sheet_sections

View File

@ -5,8 +5,6 @@
<% if section.present? %>
<%= link_to t(".add_stat"),
new_character_sheet_section_stat_path(section), data: { turbo_stream: true }, class: "add-stat" %>
<%= link_to t(".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 %>

View File

@ -1,17 +0,0 @@
<div class="counter" id="<%= dom_id(counter) %>">
<% if @editable %>
<div class="feature-edit-buttons">
<%= icon_link_to("cod-triangle_left", reorder_down_character_sheet_feature_path(counter),
data: { turbo_method: :patch }) %>
<%= icon_link_to("md-delete", counter,
data: { turbo_method: :delete, turbo_confirm: t(".confirm_delete", name: counter.name) }) %>
<%= icon_link_to("cod-triangle_right", reorder_up_character_sheet_feature_path(counter),
data: { turbo_method: :patch }) %>
</div>
<% end %>
<h6><%= counter.name %></h6>
<%= form_with model: counter, class: "counter-form",
data: { controller: "auto-update", auto_update_update_url_value: counter_path(counter) } do |f| %>
<%= f.number_field :value %>
<% end %>
</div>

View File

@ -1,16 +0,0 @@
<section class="inset">
<%= form_with model: @counter, url: character_sheet_section_counters_path(@section) do |f| %>
<% if @counter.new_record? %>
<%= f.fields_for :character_sheet_feature do |ff| %>
<%= ff.hidden_field :featurable_id, value: @counter.id %>
<%= ff.hidden_field :character_sheet_section_id, value: @section.id %>
<% end %>
<% end %>
<%= f.label :name %>
<%= f.text_field :name %>
<%= display_form_errors(@section, :name) %>
<%= f.submit button_text %>
<% end %>
</section>

View File

@ -1,11 +0,0 @@
<% content_target = "#{dom_id(@section)}_features" %>
<%= turbo_stream.append(content_target) do %>
<%= render @counter %>
<% 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 %>

View File

@ -1 +0,0 @@
<%= turbo_stream.remove @id %>

View File

@ -1,6 +0,0 @@
<% target = "#{dom_id(@section)}_add_section" %>
<%= turbo_stream.replace(target) do %>
<div id="<%= target %>">
<%= render partial: "form", locals: { button_text: t(".create_counter") } %>
</div>
<% end %>

View File

@ -1,3 +0,0 @@
<%= turbo_stream.replace dom_id(@counter) do %>
<%= render @counter %>
<% end %>

View File

@ -17,7 +17,9 @@
<%= f.submit t(".save") %>
<% end %>
<% else %>
<%= text_field.content %>
<%= link_to text_field, data: { turbo_frame: :modal } do %>
<%= text_field.content %>
<% end %>
<% end %>
</div>

View File

@ -0,0 +1,13 @@
<%= turbo_frame_tag :modal do %>
<div class="feature-box text-field">
<%= icon_link_to "fa-close",
table_character_character_sheet_sections_path(@text_field.character.table, @text_field.character),
class: "icon-link" %>
<h2><%= @text_field.name %></h2>
<%= form_with model: @text_field, class: "text-field-form",
data: { controller: "dice-roll modal-closer", action: "modal-closer#closeModal" } do |f| %>
<%= f.rich_text_area :content %>
<%= f.submit t(".save") %>
<% end %>
</div>
<% end %>

View File

@ -64,7 +64,6 @@ en:
delete_section: Delete %{name}
confirm_delete: Are you sure you want to delete this section?
add_stat: Add stat
add_counter: Add counter
add_text_field: Add text field
index:
edit: Edit character sheet
@ -102,12 +101,6 @@ en:
destroy:
success: Deleted “%{name}”
error: Could not delete your character
counters:
counter:
delete: Delete counter
confirm_delete: Are you sure you want to delete %{name}?
new:
create_counter: Create counter
password_resets:
new:
reset_password: Reset your password
@ -224,6 +217,8 @@ en:
delete: Delete text field
confirm_delete: Are you sure you want to delete %{name}?
save: Save
show:
save: Save
new:
create_text_field: Create text field
users:

View File

@ -22,14 +22,12 @@ Rails.application.routes.draw do
end
end
resources :character_sheet_sections, only: [ :destroy ] do
resources :counters, only: [ :new, :create ]
resources :stats, only: [ :new, :create ]
resources :text_fields, only: [ :new, :create ]
end
resources :characters do
resources :character_sheet_sections, only: [ :index, :new, :create ]
end
resources :counters, only: [ :update, :destroy ]
resources :stats, only: [ :show, :update, :destroy ]
resources :table_invites, only: [ :index, :edit, :update ]
resources :tables do
@ -40,7 +38,7 @@ Rails.application.routes.draw do
resources :events, only: [ :index ]
resources :table_invites, only: [ :new, :create ]
end
resources :text_fields, only: [ :update, :destroy ]
resources :text_fields, only: [ :show, :update, :destroy ]
resources :admin, only: [ :index ]
namespace :admin do

View File

@ -0,0 +1,7 @@
# frozen_string_literal: true
class DropCounters < ActiveRecord::Migration[7.1]
def change
drop_table :counters
end
end

10
db/schema.rb generated
View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.1].define(version: 2024_06_19_190424) do
ActiveRecord::Schema[7.1].define(version: 2024_06_21_091420) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -88,14 +88,6 @@ ActiveRecord::Schema[7.1].define(version: 2024_06_19_190424) do
t.check_constraint "length(name::text) <= 200", name: "chk_character_name_max_length"
end
create_table "counters", force: :cascade do |t|
t.string "name", null: false
t.integer "value", default: 0, null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.check_constraint "length(name::text) <= 100", name: "chk_counter_name_max_length"
end
create_table "dice_rolls", force: :cascade do |t|
t.string "rollable_type"
t.bigint "rollable_id"

View File

@ -1,28 +0,0 @@
# frozen_string_literal: true
require "test_helper"
class CountersControllerTest < ActionDispatch::IntegrationTest
test "should render new turbo stream" do
sign_in users(:trevor)
get new_character_sheet_section_counter_url(character_sheet_sections(:counters)), as: :turbo_stream
assert_response :success
end
test "should create counter" do
sign_in users(:trevor)
assert_difference "Counter.count", 1 do
post character_sheet_section_counters_url(character_sheet_sections(:counters)),
params: { counter: { name: "Ammo", character_sheet_section_id: character_sheet_sections(:counters).id } },
as: :turbo_stream
end
end
test "should delete counter" do
sign_in users(:trevor)
assert_difference "Counter.count", -1 do
delete counter_url(Counter.first), as: :turbo_stream
assert_response :success
end
end
end

View File

@ -7,12 +7,6 @@ stats-strength:
featurable: strength (Stat)
order_index: 1
counter:
<<: *DEFAULTS
character_sheet_section: counters
featurable: hp (Counter)
order_index: 2
text_field:
<<: *DEFAULTS
character_sheet_section: info

View File

@ -2,10 +2,6 @@ stats:
name: Stats
character: nardren
counters:
name: Status
character: nardren
subsection:
name: Subsection
character: nardren

View File

@ -1,3 +0,0 @@
hp:
name: HP
value: 10

View File

@ -1,13 +0,0 @@
# frozen_string_literal: true
require "test_helper"
class CounterTest < ActiveSupport::TestCase
test "name must exist" do
assert_must_exist(counters(:hp), :name)
end
test "value must exist" do
assert_must_exist(counters(:hp), :value)
end
end