forked from fixin.me/fixin.me
Replace the toggle-view approach and hidden DOM data carrier with a proper dedicated Charts page: - Move Charts out of Measurements view toggles into its own nav tab and route (GET /charts) - ChartsController serializes readout data as JSON (ordered by taken_at); the view embeds it in a <script type="application/json"> element instead of rendering a hidden copy of the measurements partial just to ferry data attributes to JS - buildCharts() reads from the JSON element directly — no DOM parsing, no sorting in JS (server already orders the data) - Turbo load handler detects the charts page via #charts-data presence - Add controller tests (authentication, data shape, ordering, data isolation between users) and system tests Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
13 lines
380 B
Ruby
13 lines
380 B
Ruby
class ChartsController < ApplicationController
|
|
def index
|
|
readouts = current_user.readouts.includes(:quantity, :unit).order(:taken_at, :id)
|
|
@readouts_json = readouts.map { |r|
|
|
{ takenAt: r.taken_at&.iso8601,
|
|
quantityId: r.quantity_id,
|
|
quantityName: r.quantity.name,
|
|
value: r.value.to_f,
|
|
unit: r.unit.symbol }
|
|
}.to_json
|
|
end
|
|
end
|