Allow to reparent Quantity everywhere

Closes #61
This commit is contained in:
cryptogopher 2025-01-14 15:57:12 +01:00
parent 8524beefdc
commit 201359de3e
4 changed files with 11 additions and 4 deletions

View File

@ -43,6 +43,11 @@ class ApplicationController < ActionController::Base
private
def render_no_content(record)
helpers.render_errors(record)
render html: nil, layout: true
end
def rescue_turbo(exception)
raise unless request.format.to_sym == :turbo_stream

View File

@ -43,7 +43,8 @@ class QuantitiesController < ApplicationController
permitted = params.require(:quantity).permit(:parent_id)
@previous_ancestors = @quantity.ancestors
@quantity.update!(permitted)
# Until UI blocks all disallowed reparents, render error messages if present
render_no_content(@quantity) unless @quantity.update(permitted)
@ancestors = @quantity.ancestors
@quantity.depth = @ancestors.length

View File

@ -2,8 +2,7 @@
ondragstart: "dragStart(event)", ondragend: "dragEnd(event)",
ondragover: "dragOver(event)", ondrop: "drop(event)",
ondragenter: "dragEnter(event)", ondragleave: "dragLeave(event)",
data: {drag_path: reparent_quantity_path(quantity),
drop_id: dom_id(quantity.parent || quantity),
data: {drag_path: reparent_quantity_path(quantity), drop_id: dom_id(quantity),
drop_id_param: "quantity[parent_id]"} do %>
<td class="link" style="--depth:<%= quantity.depth %>">

View File

@ -31,8 +31,10 @@ en:
taken: has to be unique
quantity:
attributes:
name:
taken: has to be unique among siblings
parent:
descendant_reference: of the quantity cannot be its descendant
descendant_reference: cannot be changed to any of descendants
self_reference: of the quantitiy cannot be the quantity itself
user_mismatch: has to belong to the same user as quantity
actioncontroller: