Skip to content

Commit e01e006

Browse files
committed
fix: solve canvas drag issues
1 parent 3f691e7 commit e01e006

2 files changed

Lines changed: 13 additions & 11 deletions

File tree

app/modules/strategy/controllers/tactical_boards_controller.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,14 @@ def apply_sorting(boards)
139139
end
140140

141141
def tactical_board_params
142-
# Support both nested format (tactical_board: {title:...}) and flat format (name:..., board_state:...)
143-
# The frontend may send data at the top level with different field names.
142+
# Support both nested format (tactical_board: {map_state:...}) and flat format (name:..., board_state:...)
143+
# Always prefer the nested tactical_board hash when present — even partial updates
144+
# (e.g. map_state only, no title) must read from tb, not from top-level params.
145+
# The previous check `tb[:title].present? || tb[:name].present?` fell back to
146+
# top-level params whenever an update omitted the title field, causing update({})
147+
# to be called silently and saving nothing despite returning 200 OK.
144148
tb = params[:tactical_board]
145-
source = tb.present? && (tb[:title].present? || tb[:name].present?) ? tb : params
149+
source = tb.present? ? tb : params
146150

147151
permitted = {
148152
title: source[:title] || source[:name],

app/modules/strategy/models/tactical_board.rb

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -220,15 +220,13 @@ def validate_annotation_structure(annotation, index)
220220
return
221221
end
222222

223-
unless annotation['type'] && annotation['x'] && annotation['y']
224-
errors.add(:annotations, "annotation at index #{index} must have type, x, and y")
225-
end
226-
227-
return unless annotation['x'] && annotation['y']
228-
229-
return if (0..100).cover?(annotation['x'].to_f) && (0..100).cover?(annotation['y'].to_f)
223+
# Only require 'type'. Canvas annotations are heterogeneous:
224+
# - circle / text: have x, y (relative or pixel coords)
225+
# - line / arrow / pen: use a 'points' array, no x/y
226+
# Requiring x/y and enforcing a 0-100 range breaks all point-based annotations.
227+
return if annotation['type'].present?
230228

231-
errors.add(:annotations, "annotation at index #{index} coordinates must be between 0 and 100")
229+
errors.add(:annotations, "annotation at index #{index} must have a type")
232230
end
233231

234232
def validate_coordinates!(x, y)

0 commit comments

Comments
 (0)