From 2c845f35286f99718ced28a7dbf7ea9da287c014 Mon Sep 17 00:00:00 2001 From: cryptogopher Date: Sat, 17 Oct 2026 04:57:26 +0200 Subject: [PATCH] Replace patched #dom_id with #dom_target --- app/views/quantities/_quantity.html.erb | 26 +++++++-------- app/views/quantities/create.turbo_stream.erb | 2 +- app/views/quantities/edit.turbo_stream.erb | 6 ++-- app/views/quantities/index.html.erb | 3 +- app/views/quantities/new.turbo_stream.erb | 8 ++--- app/views/quantities/update.turbo_stream.erb | 2 +- app/views/readouts/_form.html.erb | 2 +- app/views/readouts/_form_repath.html.erb | 2 +- app/views/readouts/discard.turbo_stream.erb | 4 +-- app/views/readouts/new.turbo_stream.erb | 2 +- app/views/units/_unit.html.erb | 32 +++++++++---------- app/views/units/index.html.erb | 2 +- config/initializers/core_ext.rb | 4 --- .../record_identifier_with_suffix.rb | 10 ------ 14 files changed, 45 insertions(+), 60 deletions(-) delete mode 100644 lib/core_ext/action_view/record_identifier_with_suffix.rb diff --git a/app/views/quantities/_quantity.html.erb b/app/views/quantities/_quantity.html.erb index 43344e2..deb5e86 100644 --- a/app/views/quantities/_quantity.html.erb +++ b/app/views/quantities/_quantity.html.erb @@ -1,24 +1,24 @@ -<%= tag.tr id: dom_id(quantity), - 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), - drop_id_param: "quantity[parent_id]"} do %> + <%= link_to quantity, edit_quantity_path(quantity), class: 'link', onclick: 'this.blur();', data: {turbo_stream: true} %> - - <%= quantity.description %> + <%= quantity.description %> <% if current_user.at_least(:active) %> - <%= image_link_to t('.new_subquantity'), 'plus-outline', new_quantity_path(quantity), - id: dom_id(quantity, :new, :link), onclick: 'this.blur();', data: {turbo_stream: true} %> + <%= image_link_to t('.new_subquantity'), 'plus-outline', + new_quantity_path(quantity), id: dom_target(:new, quantity, :link), + onclick: 'this.blur();', data: {turbo_stream: true} %> <%= image_button_to_if quantity.destroyable?, t('.destroy'), 'delete-outline', quantity_path(quantity), method: :delete %> - - ⠿ + + ⠿ <% end %> -<% end %> diff --git a/app/views/quantities/create.turbo_stream.erb b/app/views/quantities/create.turbo_stream.erb index d70c0af..fa3482f 100644 --- a/app/views/quantities/create.turbo_stream.erb +++ b/app/views/quantities/create.turbo_stream.erb @@ -1,4 +1,4 @@ -<%= turbo_stream.close_form dom_id(@quantity.parent || Quantity, :new) %> +<%= turbo_stream.close_form dom_target(:new, @quantity.parent || :quantity) %> <%= turbo_stream.remove :no_items %> <% @ancestors.each do |ancestor| %> <%= turbo_stream.replace ancestor %> diff --git a/app/views/quantities/edit.turbo_stream.erb b/app/views/quantities/edit.turbo_stream.erb index 3d07525..5916a9a 100644 --- a/app/views/quantities/edit.turbo_stream.erb +++ b/app/views/quantities/edit.turbo_stream.erb @@ -1,7 +1,7 @@ -<% ids = {row: dom_id(@quantity, :edit), - hidden_row: dom_id(@quantity), +<% ids = {row: dom_target(:edit, @quantity), + hidden_row: dom_target(@quantity), link: nil, - form_tag: dom_id(@quantity, :edit, :form)} %> + form_tag: dom_target(:edit, @quantity, :form)} %> <%= turbo_stream.append :quantity_form do %> <%- tabular_form_with model: @quantity, html: {id: ids[:form_tag]} do %> diff --git a/app/views/quantities/index.html.erb b/app/views/quantities/index.html.erb index ecd3258..b0b67e2 100644 --- a/app/views/quantities/index.html.erb +++ b/app/views/quantities/index.html.erb @@ -1,8 +1,7 @@
<% if current_user.at_least(:active) %> <%= image_link_to t('.new_quantity'), 'plus-outline', new_quantity_path, - id: dom_id(Quantity, :new, :link), onclick: 'this.blur();', - data: {turbo_stream: true} %> + id: :new_quantity_link, onclick: 'this.blur();', data: {turbo_stream: true} %> <% end %> <%#= image_link_to t('.import_quantities'), 'download-outline', default_quantities_path, class: 'tools-area' %> diff --git a/app/views/quantities/new.turbo_stream.erb b/app/views/quantities/new.turbo_stream.erb index 5f3ebfd..7f08571 100644 --- a/app/views/quantities/new.turbo_stream.erb +++ b/app/views/quantities/new.turbo_stream.erb @@ -1,8 +1,8 @@ -<% dom_obj = @quantity.parent || @quantity %> -<% ids = {row: dom_id(dom_obj, :new), +<% target_id = dom_target(:new, @quantity.parent || :quantity) %> +<% ids = {row: target_id, hidden_row: nil, - link: dom_id(dom_obj, :new, :link), - form_tag: dom_id(dom_obj, :new, :form)} %> + link: dom_target(target_id, :link), + form_tag: dom_target(target_id, :form)} %> <%= turbo_stream.disable ids[:link] -%> diff --git a/app/views/quantities/update.turbo_stream.erb b/app/views/quantities/update.turbo_stream.erb index 3275ed3..4c2211b 100644 --- a/app/views/quantities/update.turbo_stream.erb +++ b/app/views/quantities/update.turbo_stream.erb @@ -1,4 +1,4 @@ -<%= turbo_stream.close_form dom_id(@quantity, :edit) %> +<%= turbo_stream.close_form dom_target(:edit, @quantity) %> <% @ancestors.push(@quantity).each do |ancestor| %> <%= turbo_stream.replace ancestor %> <% end %> diff --git a/app/views/readouts/_form.html.erb b/app/views/readouts/_form.html.erb index 79d1293..b53068c 100644 --- a/app/views/readouts/_form.html.erb +++ b/app/views/readouts/_form.html.erb @@ -1,6 +1,6 @@ <%# TODO: add readout reordering by dragging %> <%= tabular_fields_for 'readouts[]', readout do |form| %> - <%- tag.tr id: dom_id(readout.quantity, :new, :readout) do %> + <%- tag.tr id: dom_target(:new, readout.quantity, :readout) do %> <%# TODO: add grayed readout index (in separate column?) %> <%= readout.quantity.relative_pathname(@superquantity) %> diff --git a/app/views/readouts/_form_repath.html.erb b/app/views/readouts/_form_repath.html.erb index 5743dec..aba8381 100644 --- a/app/views/readouts/_form_repath.html.erb +++ b/app/views/readouts/_form_repath.html.erb @@ -1,7 +1,7 @@ <%= turbo_stream.update(:measurement_form_legend) { @superquantity&.pathname } %> <% @prev_quantities.each do |pq| %> - <%= turbo_stream.update dom_id(pq, nil, :pathname) do %> + <%= turbo_stream.update dom_target(pq, :pathname) do %> <%= pq.relative_pathname(@superquantity) %> <% end %> <% end %> diff --git a/app/views/readouts/discard.turbo_stream.erb b/app/views/readouts/discard.turbo_stream.erb index 6966b40..56586f2 100644 --- a/app/views/readouts/discard.turbo_stream.erb +++ b/app/views/readouts/discard.turbo_stream.erb @@ -1,4 +1,4 @@ <%= turbo_stream.disable :create_measurement_button if @prev_quantities.one? %> -<%= turbo_stream.remove dom_id(@quantity, :new, :readout) %> +<%= turbo_stream.remove dom_target(:new, @quantity, :readout) %> <%= render partial: 'form_repath' %> -<%= turbo_stream.unselect dom_id(@quantity) %> +<%= turbo_stream.unselect dom_target(@quantity) %> diff --git a/app/views/readouts/new.turbo_stream.erb b/app/views/readouts/new.turbo_stream.erb index 04ae31e..a6719a0 100644 --- a/app/views/readouts/new.turbo_stream.erb +++ b/app/views/readouts/new.turbo_stream.erb @@ -1,5 +1,5 @@ <% @readouts.each do |r| %> - <%= turbo_stream.disable dom_id(r.quantity) %> + <%= turbo_stream.disable dom_target(r.quantity) %> <% end %> <%= render partial: 'form_repath' %> <%= turbo_stream.append :readouts do %> diff --git a/app/views/units/_unit.html.erb b/app/views/units/_unit.html.erb index db656d9..96bfc0d 100644 --- a/app/views/units/_unit.html.erb +++ b/app/views/units/_unit.html.erb @@ -1,32 +1,32 @@ -<%= tag.tr id: dom_id(unit), - ondragstart: "dragStart(event)", ondragend: "dragEnd(event)", - ondragover: "dragOver(event)", ondrop: "drop(event)", - ondragenter: "dragEnter(event)", ondragleave: "dragLeave(event)", - data: {drag_path: rebase_unit_path(unit), - drop_id: dom_id(unit.base || unit), - drop_id_param: "unit[base_id]"} do %> + <%= link_to unit, edit_unit_path(unit), class: 'link', onclick: 'this.blur();', data: {turbo_stream: true} %> - - <%= unit.description %> + <%= unit.description %> + <%# Closing tag required to avoid whitespace inclusion for testing. %> <%= unit.multiplier.to_html if unit.base_id? %> <% if current_user.at_least(:active) %> <% unless unit.base_id? %> <%= image_link_to t('.new_subunit'), 'plus-outline', new_unit_path(unit), - id: dom_id(unit, :new, :link), onclick: 'this.blur();', data: {turbo_stream: true} %> + id: dom_target(:new, unit, :link), onclick: 'this.blur();', + data: {turbo_stream: true} %> <% end %> - <%= image_button_to_if unit.movable?, t('.destroy'), 'delete-outline', unit_path(unit), - method: :delete %> - + <%= image_button_to_if unit.movable?, t('.destroy'), 'delete-outline', + unit_path(unit), method: :delete %> + <% if unit.movable? %> - ⠿ + ⠿ <% else %> - + <% end %> <% end %> -<% end %> diff --git a/app/views/units/index.html.erb b/app/views/units/index.html.erb index 775fef8..3ffdf0f 100644 --- a/app/views/units/index.html.erb +++ b/app/views/units/index.html.erb @@ -1,7 +1,7 @@
<% if current_user.at_least(:active) %> <%= image_link_to t('.new_unit'), 'plus-outline', new_unit_path, - id: dom_id(Unit, :new, :link), onclick: 'this.blur();', data: {turbo_stream: true} %> + id: :new_unit_link, onclick: 'this.blur();', data: {turbo_stream: true} %> <% end %> <%= image_link_to t('.import_units'), 'download-outline', default_units_path, class: 'tools-area' %> diff --git a/config/initializers/core_ext.rb b/config/initializers/core_ext.rb index ca7c887..8778811 100644 --- a/config/initializers/core_ext.rb +++ b/config/initializers/core_ext.rb @@ -9,10 +9,6 @@ ActiveSupport.on_load :action_dispatch_system_test_case do XPath::DSL.prepend CoreExt::XPath::DSL::NormalizeSpaceDefault end -ActiveSupport.on_load :action_view do - ActionView::RecordIdentifier.prepend CoreExt::ActionView::RecordIdentifierWithSuffix -end - ActiveSupport.on_load :active_record do ActiveModel::Validations::NumericalityValidator .prepend CoreExt::ActiveModel::Validations::NumericalityValidatesPrecision diff --git a/lib/core_ext/action_view/record_identifier_with_suffix.rb b/lib/core_ext/action_view/record_identifier_with_suffix.rb deleted file mode 100644 index 5e2a853..0000000 --- a/lib/core_ext/action_view/record_identifier_with_suffix.rb +++ /dev/null @@ -1,10 +0,0 @@ -module CoreExt::ActionView::RecordIdentifierWithSuffix - # TODO: replace dom_id with dom_target, then remove this override - def dom_id(object, prefix = nil, suffix = nil) - if suffix - "#{super(object, prefix)}#{::ActionView::RecordIdentifier::JOIN}#{suffix}" - else - super(object, prefix) - end - end -end