1
0
This repository has been archived on 2023-12-07. You can view files and clone it, but cannot push or open issues or pull requests.
body_tracking/app/controllers/readouts_controller.rb
2021-05-19 22:39:04 +02:00

40 lines
1.0 KiB
Ruby

class ReadoutsController < ApplicationController
layout 'body_tracking'
menu_item :body_trackers
helper :body_trackers
helper :measurements
include Concerns::Finders
before_action :find_measurement_routine_by_measurement_routine_id,
only: [:index, :toggle_exposure]
before_action :find_quantity_by_quantity_id, only: [:toggle_exposure]
before_action :authorize
def index
prepare_readouts
end
def toggle_exposure
@routine.readout_exposures.toggle!(@quantity)
prepare_readouts
end
private
def prepare_readouts
@quantities = @routine.quantities.includes(:formula)
@measurements, @filter_q = @routine.measurements.includes(:routine, :source)
.filter(session[:m_filters], @quantities)
# Keep only non-nil readouts and their ancestors
@measurements.each do |measurement, readouts|
ancestors = {}
readouts.keys.sort_by(&:depth).reverse_each do |q|
readouts[q] || ancestors[q] ? ancestors[q.parent] = true : readouts.delete(q)
end
end
end
end