Replace JS-generated wide table with ERB partial and Turbo Streams

- Add _wide_table.html.erb partial (server-rendered pivot table)
- Add load_measurements helper in controller to prepare @wide_groups and
  @wide_quantities for all mutating actions
- Update index view to render the wide_table partial in #measurements-wide
- Add/update create, destroy, update turbo_stream views to refresh the
  wide table atomically after each mutation
- Remove buildWideTable() and editMeasurementWide() from application.js
- Fix create.turbo_stream.erb condition (empty readouts are vacuously all persisted)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-04 12:28:32 +00:00
parent 1bc75f5d40
commit 366662a948
7 changed files with 74 additions and 116 deletions

View File

@@ -6,7 +6,7 @@ class MeasurementsController < ApplicationController
end
def index
@measurements = current_user.readouts.includes(:quantity, :unit).order(taken_at: :desc, id: :desc)
load_measurements
end
def new
@@ -20,6 +20,7 @@ class MeasurementsController < ApplicationController
if @readouts.present? && @readouts.all?(&:valid?)
ActiveRecord::Base.transaction { @readouts.each(&:save!) }
load_measurements
flash.now[:notice] = t('.success', count: @readouts.size)
else
errors = @readouts.flat_map { |r| r.errors.full_messages }
@@ -33,6 +34,7 @@ class MeasurementsController < ApplicationController
def update
if @readout.update(params.require(:readout).permit(:value, :unit_id, :taken_at))
load_measurements
flash.now[:notice] = t('.success')
else
@user_units = current_user.units.ordered
@@ -42,6 +44,7 @@ class MeasurementsController < ApplicationController
def destroy
@readout.destroy!
load_measurements
flash.now[:notice] = t('.success')
end
@@ -50,4 +53,10 @@ class MeasurementsController < ApplicationController
def find_readout
@readout = current_user.readouts.find(params[:id])
end
def load_measurements
@measurements = current_user.readouts.includes(:quantity, :unit).order(taken_at: :desc, id: :desc)
@wide_groups = @measurements.group_by(&:taken_at)
@wide_quantities = @measurements.map(&:quantity).uniq.sort_by(&:name)
end
end