Prevent moving features beyond section bounds
This commit is contained in:
parent
a0271f0b69
commit
dd850813cb
|
@ -17,11 +17,7 @@ class CharacterSheetFeature < ApplicationRecord
|
|||
|
||||
def move(to:)
|
||||
return if to == order_index
|
||||
|
||||
unless character_sheet_section.character_sheet_features.exists?(order_index: to)
|
||||
update!(order_index: to)
|
||||
return
|
||||
end
|
||||
return if to < character_sheet_section.lowest_order_index || to > character_sheet_section.highest_order_index
|
||||
|
||||
if to < order_index
|
||||
character_sheet_section.character_sheet_features.where(order_index: to...order_index)
|
||||
|
|
|
@ -17,4 +17,12 @@ class CharacterSheetSection < ApplicationRecord
|
|||
length: { maximum: 255 }
|
||||
|
||||
scope :top_level, -> { where.missing(:parent_section) }
|
||||
|
||||
def lowest_order_index
|
||||
character_sheet_features.minimum(:order_index) || 1
|
||||
end
|
||||
|
||||
def highest_order_index
|
||||
character_sheet_features.maximum(:order_index) || 1
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,6 +7,18 @@ stats-strength:
|
|||
featurable: strength (Stat)
|
||||
order_index: 1
|
||||
|
||||
stats-dexterity:
|
||||
<<: *DEFAULTS
|
||||
character_sheet_section: stats
|
||||
featurable: dexterity (Stat)
|
||||
order_index: 2
|
||||
|
||||
stats-constitution:
|
||||
<<: *DEFAULTS
|
||||
character_sheet_section: stats
|
||||
featurable: constitution (Stat)
|
||||
order_index: 3
|
||||
|
||||
text_field:
|
||||
<<: *DEFAULTS
|
||||
character_sheet_section: info
|
||||
|
|
|
@ -10,3 +10,7 @@ subsection:
|
|||
info:
|
||||
name: Info
|
||||
character: nardren
|
||||
|
||||
empty:
|
||||
name: Empty
|
||||
character: nardren
|
||||
|
|
|
@ -2,3 +2,13 @@ strength:
|
|||
name: Strength
|
||||
value: 10
|
||||
roll_command: d20+self
|
||||
|
||||
dexterity:
|
||||
name: Dexterity
|
||||
value: 10
|
||||
roll_command: d20+self
|
||||
|
||||
constitution:
|
||||
name: Constitution
|
||||
value: 10
|
||||
roll_command: d20+self
|
||||
|
|
|
@ -3,7 +3,4 @@
|
|||
require "test_helper"
|
||||
|
||||
class CharacterSheetFeatureTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
|
|
|
@ -6,4 +6,14 @@ class CharacterSheetSectionTest < ActiveSupport::TestCase
|
|||
test "name must exist" do
|
||||
assert_must_exist(character_sheet_sections(:stats), "name")
|
||||
end
|
||||
|
||||
test "returns correct order index" do
|
||||
assert_equal 3, character_sheet_sections(:stats).highest_order_index
|
||||
assert_equal 1, character_sheet_sections(:stats).lowest_order_index
|
||||
end
|
||||
|
||||
test "an empty section returns 1 for lowest/highest order index" do
|
||||
assert_equal 1, character_sheet_sections(:empty).lowest_order_index
|
||||
assert_equal 1, character_sheet_sections(:empty).highest_order_index
|
||||
end
|
||||
end
|
||||
|
|
5
todo.md
5
todo.md
|
@ -1,11 +1,6 @@
|
|||
- request invite
|
||||
- don't move down/up top/bottom features
|
||||
- auto save text fields
|
||||
- indicate save status on titlebar
|
||||
- easily edit text fields without entering edit mode
|
||||
- add roll command to counters (e.g. luck)
|
||||
- test for rolls controller & system tests
|
||||
- Show individual dice on dice roll
|
||||
- Sheets
|
||||
- Lists
|
||||
- Weapons/spells
|
||||
|
|
Loading…
Reference in New Issue