diff --git a/app/assets/stylesheets/characters.css b/app/assets/stylesheets/characters.css index b14232c..2554bfa 100644 --- a/app/assets/stylesheets/characters.css +++ b/app/assets/stylesheets/characters.css @@ -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); diff --git a/app/assets/stylesheets/forms.css b/app/assets/stylesheets/forms.css index 6885b73..9f7ce33 100644 --- a/app/assets/stylesheets/forms.css +++ b/app/assets/stylesheets/forms.css @@ -41,7 +41,7 @@ form, fieldset { } } -form.stat-form, form.counter-form { +form.stat-form { display: flex; flex-direction: column; } diff --git a/app/controllers/counters_controller.rb b/app/controllers/counters_controller.rb deleted file mode 100644 index 975227a..0000000 --- a/app/controllers/counters_controller.rb +++ /dev/null @@ -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 diff --git a/app/models/character_sheet_section.rb b/app/models/character_sheet_section.rb index d7a6dc2..930c025 100644 --- a/app/models/character_sheet_section.rb +++ b/app/models/character_sheet_section.rb @@ -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, diff --git a/app/models/counter.rb b/app/models/counter.rb deleted file mode 100644 index b8999e0..0000000 --- a/app/models/counter.rb +++ /dev/null @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index 4b25495..e8563ed 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/app/views/character_sheet_sections/_edit_links.html.erb b/app/views/character_sheet_sections/_edit_links.html.erb index df661e4..9d5c58b 100644 --- a/app/views/character_sheet_sections/_edit_links.html.erb +++ b/app/views/character_sheet_sections/_edit_links.html.erb @@ -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 %> diff --git a/app/views/counters/_counter.html.erb b/app/views/counters/_counter.html.erb deleted file mode 100644 index 941ac76..0000000 --- a/app/views/counters/_counter.html.erb +++ /dev/null @@ -1,17 +0,0 @@ -
- <% if @editable %> -
- <%= 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 }) %> -
- <% end %> -
<%= counter.name %>
- <%= 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 %> -
diff --git a/app/views/counters/_form.html.erb b/app/views/counters/_form.html.erb deleted file mode 100644 index 49a113e..0000000 --- a/app/views/counters/_form.html.erb +++ /dev/null @@ -1,16 +0,0 @@ -
- <%= 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 %> -
diff --git a/app/views/counters/create.turbo_stream.erb b/app/views/counters/create.turbo_stream.erb deleted file mode 100644 index b5ff8b6..0000000 --- a/app/views/counters/create.turbo_stream.erb +++ /dev/null @@ -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 %> -
- <%= render partial: "character_sheet_sections/edit_links", locals: { section: @section, parent: @section.parent_section, id: nil} %> -
-<% end %> diff --git a/app/views/counters/destroy.turbo_stream.erb b/app/views/counters/destroy.turbo_stream.erb deleted file mode 100644 index f50ff4a..0000000 --- a/app/views/counters/destroy.turbo_stream.erb +++ /dev/null @@ -1 +0,0 @@ -<%= turbo_stream.remove @id %> diff --git a/app/views/counters/new.turbo_stream.erb b/app/views/counters/new.turbo_stream.erb deleted file mode 100644 index 68fdf4d..0000000 --- a/app/views/counters/new.turbo_stream.erb +++ /dev/null @@ -1,6 +0,0 @@ -<% target = "#{dom_id(@section)}_add_section" %> -<%= turbo_stream.replace(target) do %> -
- <%= render partial: "form", locals: { button_text: t(".create_counter") } %> -
-<% end %> diff --git a/app/views/counters/update.turbo_stream.erb b/app/views/counters/update.turbo_stream.erb deleted file mode 100644 index 92a6c47..0000000 --- a/app/views/counters/update.turbo_stream.erb +++ /dev/null @@ -1,3 +0,0 @@ -<%= turbo_stream.replace dom_id(@counter) do %> - <%= render @counter %> -<% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index e80e249..55fe893 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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 diff --git a/config/routes.rb b/config/routes.rb index 9c32de6..cba1964 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/db/migrate/20240621091420_drop_counters.rb b/db/migrate/20240621091420_drop_counters.rb new file mode 100644 index 0000000..53c35f1 --- /dev/null +++ b/db/migrate/20240621091420_drop_counters.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class DropCounters < ActiveRecord::Migration[7.1] + def change + drop_table :counters + end +end diff --git a/db/schema.rb b/db/schema.rb index 9276d39..d25a79a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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" diff --git a/test/controllers/counters_controller_test.rb b/test/controllers/counters_controller_test.rb deleted file mode 100644 index b994630..0000000 --- a/test/controllers/counters_controller_test.rb +++ /dev/null @@ -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 diff --git a/test/fixtures/character_sheet_features.yml b/test/fixtures/character_sheet_features.yml index c0988a9..b55c6d0 100644 --- a/test/fixtures/character_sheet_features.yml +++ b/test/fixtures/character_sheet_features.yml @@ -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 diff --git a/test/fixtures/character_sheet_sections.yml b/test/fixtures/character_sheet_sections.yml index 75fa540..435831a 100644 --- a/test/fixtures/character_sheet_sections.yml +++ b/test/fixtures/character_sheet_sections.yml @@ -2,10 +2,6 @@ stats: name: Stats character: nardren -counters: - name: Status - character: nardren - subsection: name: Subsection character: nardren diff --git a/test/fixtures/counters.yml b/test/fixtures/counters.yml deleted file mode 100644 index 513ddf7..0000000 --- a/test/fixtures/counters.yml +++ /dev/null @@ -1,3 +0,0 @@ -hp: - name: HP - value: 10 diff --git a/test/models/counter_test.rb b/test/models/counter_test.rb deleted file mode 100644 index 8da615e..0000000 --- a/test/models/counter_test.rb +++ /dev/null @@ -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