Remove counters (just use stats)

This commit is contained in:
Trevor Vallender 2024-06-21 10:25:41 +01:00
parent 810ebcbed3
commit 7c269ac78e
22 changed files with 11 additions and 198 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);

View File

@ -41,7 +41,7 @@ form, fieldset {
}
}
form.stat-form, form.counter-form {
form.stat-form {
display: flex;
flex-direction: column;
}

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

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

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

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

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

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