forked from fixin.me/fixin.me
Migrate all inline JS to Stimulus controllers
Add stimulus-rails gem and wire up 7 controllers: - measurements_view_controller: view toggle (compact/wide) via localStorage - measurements_controller: grouped rows MutationObserver - charts_controller: Plotly chart rendering - form_controller: keyboard shortcuts (Escape/Enter) and submit validation - details_controller: quantity picker state, focusout close, MutationObserver - readout_unit_controller: default unit button enable/disable + PATCH submission - drag_controller: drag-and-drop for quantity reparenting and unit rebasing Remove all inline onclick/onkeydown/ondrag*/onsubmit handlers from templates. Remove all window.* global exports from application.js. Remove bare <script> block from measurements/_form.html.erb. Remove turbo:load listeners for behavior now in controller connect(). application.js now only contains: Turbo Stream custom action definitions and the showPage visibility listener. Document Stimulus conventions in CLAUDE.md. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -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_id(readout.quantity, :new, :readout),
|
||||
data: {controller: 'readout-unit'} do %>
|
||||
<td>
|
||||
<%# TODO: add grayed readout index (in separate column?) %>
|
||||
<%= readout.quantity.relative_pathname(@superquantity) %>
|
||||
@@ -13,16 +13,18 @@
|
||||
<%= form.collection_select :unit_id, @user_units, :id,
|
||||
->(u){ sanitize(' ' * (u.base_id ? 1 : 0) + u.symbol) },
|
||||
{prompt: '', disabled: '', selected: readout.quantity.default_unit_id || ''}, required: true,
|
||||
data: {default_unit_id: readout.quantity.default_unit_id || ''},
|
||||
onchange: "readoutUnitChanged(this)" %>
|
||||
data: {default_unit_id: readout.quantity.default_unit_id || '',
|
||||
readout_unit_target: 'select',
|
||||
action: 'change->readout-unit#unitChanged'} %>
|
||||
</td>
|
||||
<td class="flex">
|
||||
<%# TODO: change to _link_ after giving up displaying relative paths %>
|
||||
<%= image_button_tag '', 'check-circle-outline',
|
||||
class: 'set-default-unit', name: nil, type: 'button', disabled: true,
|
||||
title: t('readouts.form.set_default_unit'),
|
||||
data: {path: quantity_path(readout.quantity)},
|
||||
onclick: 'setDefaultUnit(this)' %>
|
||||
data: {path: quantity_path(readout.quantity),
|
||||
readout_unit_target: 'button',
|
||||
action: 'click->readout-unit#setDefault'} %>
|
||||
<%= image_button_tag '', 'delete-outline', class: 'dangerous', name: nil,
|
||||
formaction: discard_readouts_path(readout.quantity),
|
||||
formmethod: :get, formnovalidate: true, data: {turbo_stream: true} %>
|
||||
|
||||
Reference in New Issue
Block a user