1
0

Add Targets #show

Change css classes from subject-oriented to property-oriented
This commit is contained in:
cryptogopher
2021-05-05 12:42:30 +02:00
parent 8cac724694
commit e301665b6a
22 changed files with 132 additions and 130 deletions

View File

@@ -5,8 +5,8 @@ class TargetsController < ApplicationController
include Concerns::Finders
before_action :find_goal_by_goal_id,
only: [:index, :new, :create, :edit, :update, :destroy, :reapply, :toggle_exposure]
before_action :find_goal_by_goal_id, only: [:index, :new, :create, :show, :edit, :update,
:destroy, :reapply, :toggle_exposure]
before_action :find_quantity_by_quantity_id, only: [:toggle_exposure, :subthresholds]
before_action :authorize
#before_action :set_view_params
@@ -42,6 +42,24 @@ class TargetsController < ApplicationController
end
end
def show
# TODO: take into account nullified targets, after introduced
@effective_from = params[:date].to_date
targets = @goal.targets.joins(:quantity).where(
"(quantity_id, effective_from) IN (?)",
@goal.targets.select(:quantity_id, 'MAX(effective_from) as effective_from')
.where("effective_from <= ?", @effective_from).group(:quantity_id)
).reorder('quantities.depth DESC')
@quantities = {}
targets.each do |t|
unless @quantities.has_key?(t.quantity.parent)
t.quantity.ancestors.each { |q| @quantities[q] = nil }
end
@quantities[t.quantity] = t
end
end
def edit
@effective_from = params[:date].to_date
@targets = @goal.targets.joins(:quantity).where(effective_from: @effective_from)
@@ -123,7 +141,7 @@ class TargetsController < ApplicationController
@targets_by_date = Hash.new { |h,k| h[k] = {} }
@goal.targets.includes(:item, thresholds: [:quantity]).reject(&:new_record?)
.each { |t| @targets_by_date[t.effective_from][t.thresholds.first.quantity] = t }
.each { |t| @targets_by_date[t.effective_from][t.quantity] = t }
end
def set_view_params