List binding goal targets
This commit is contained in:
parent
7f87b3bc84
commit
09e27eb754
@ -5,13 +5,13 @@ class TargetsController < ApplicationController
|
||||
|
||||
include Concerns::Finders
|
||||
|
||||
before_action :find_binding_goal_by_project_id, only: [:index, :new, :edit]
|
||||
before_action :find_binding_goal_by_project_id, only: [:new, :edit]
|
||||
before_action :find_project_by_project_id, only: [:create, :subthresholds]
|
||||
before_action :find_quantity_by_quantity_id, only: [:toggle_exposure]
|
||||
#, if: ->{ params[:project_id].present? }
|
||||
#before_action :find_goal, only: [:index, :new],
|
||||
# unless: -> { @goal }
|
||||
before_action :find_goal, only: [:toggle_exposure]
|
||||
before_action :find_goal, only: [:index, :toggle_exposure]
|
||||
before_action :authorize
|
||||
#before_action :set_view_params
|
||||
|
||||
@ -104,7 +104,7 @@ class TargetsController < ApplicationController
|
||||
@quantities = @goal.quantities.includes(:formula)
|
||||
|
||||
@targets_by_date = Hash.new { |h,k| h[k] = {} }
|
||||
@project.targets.includes(:item, thresholds: [:quantity]).reject(&:new_record?)
|
||||
@goal.targets.includes(:item, thresholds: [:quantity]).reject(&:new_record?)
|
||||
.each { |t| @targets_by_date[t.effective_from][t.thresholds.first.quantity] = t }
|
||||
end
|
||||
|
||||
|
@ -14,7 +14,7 @@ class Goal < ActiveRecord::Base
|
||||
after_initialize do
|
||||
if new_record?
|
||||
self.is_binding = false if self.is_binding.nil?
|
||||
self.targets.new if self.targets.empty?
|
||||
self.targets.new if !self.is_binding && self.targets.empty?
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -5,7 +5,10 @@ class QuantityValue < ActiveRecord::Base
|
||||
# to allow for accessing registry item without knowing QuantityValue (subitem)
|
||||
# type, e.g. qv.registry.completed_at
|
||||
belongs_to :registry, polymorphic: true
|
||||
belongs_to :quantity, ->(qv) { where(domain: qv.class::DOMAIN) }, required: true
|
||||
belongs_to :quantity, required: true
|
||||
validate do
|
||||
errors.add(:quantity, :domain_mismatch) unless self.class::DOMAIN == quantity.domain
|
||||
end
|
||||
belongs_to :unit, required: true
|
||||
|
||||
# Uniqueness is checked exclusively on the other end of association level.
|
||||
|
@ -1 +1 @@
|
||||
<%= title t(:body_trackers_title), t(".heading") %>
|
||||
<%= title t(".heading") %>
|
||||
|
@ -9,7 +9,7 @@
|
||||
<div id="new-food">
|
||||
</div>
|
||||
|
||||
<%= title t(:body_trackers_title), t(".heading") %>
|
||||
<%= title t(".heading") %>
|
||||
<div id='foods'>
|
||||
<%= render partial: 'foods/index' %>
|
||||
</div>
|
||||
|
@ -9,7 +9,7 @@
|
||||
<div id="new-food">
|
||||
</div>
|
||||
|
||||
<%= title t(:body_trackers_title), t(".heading") %>
|
||||
<%= title t(".heading") %>
|
||||
<div id='nutrients'>
|
||||
<%= render partial: 'foods/nutrients' %>
|
||||
</div>
|
||||
|
@ -12,7 +12,7 @@
|
||||
<tr id="goal-<%= g.id %>" class="primary goal">
|
||||
<td class="name unwrappable">
|
||||
<div style="float:left;">
|
||||
<%= checked_image g.is_binding %><%= link_to g.name, g %>
|
||||
<%= checked_image g.is_binding %><%= link_to g.name, targets_goal_path(g) %>
|
||||
</div>
|
||||
<div style="float:right;">
|
||||
<%# TODO: display # of active targets/targeted quantities %>
|
||||
|
@ -7,7 +7,7 @@
|
||||
<div id="new-goal">
|
||||
</div>
|
||||
|
||||
<%= title t(:body_trackers_title), t(".heading") %>
|
||||
<%= title t(".heading") %>
|
||||
<div id='goals'>
|
||||
<%= render partial: 'goals/index' %>
|
||||
</div>
|
||||
|
@ -5,7 +5,7 @@
|
||||
<div id="new-meal">
|
||||
</div>
|
||||
|
||||
<%= title t(:body_trackers_title), t(".heading") %>
|
||||
<%= title t(".heading") %>
|
||||
<div id='meals'>
|
||||
<%= render partial: 'meals/index' %>
|
||||
</div>
|
||||
|
@ -5,7 +5,7 @@
|
||||
<div id="new-measurement">
|
||||
</div>
|
||||
|
||||
<%= title t(:body_trackers_title), t(".heading") %>
|
||||
<%= title t(".heading") %>
|
||||
<div id='measurements'>
|
||||
<%= render partial: 'measurements/index' %>
|
||||
</div>
|
||||
|
@ -5,8 +5,7 @@
|
||||
<div id="new-measurement">
|
||||
</div>
|
||||
|
||||
<%= title t(:body_trackers_title),
|
||||
[t("measurements.index.heading"), project_measurements_path(@project)],
|
||||
<%= title [t("measurements.index.heading"), project_measurements_path(@project)],
|
||||
@routine.name %>
|
||||
<div id='readouts'>
|
||||
<%= render partial: 'measurements/readouts' %>
|
||||
|
@ -8,7 +8,7 @@
|
||||
<div id="new-quantity">
|
||||
</div>
|
||||
|
||||
<%= title t(:body_trackers_title), t(".heading") %>
|
||||
<%= title t(".heading") %>
|
||||
<div id='quantities'>
|
||||
<%= render partial: 'quantities/index' %>
|
||||
</div>
|
||||
|
@ -19,7 +19,7 @@
|
||||
<hr>
|
||||
</div>
|
||||
|
||||
<%= title t(:body_trackers_title), t(".heading") %>
|
||||
<%= title t(".heading") %>
|
||||
<% if @sources.any? { |s| s.persisted? } %>
|
||||
<table class="list">
|
||||
<thead>
|
||||
|
@ -5,7 +5,7 @@
|
||||
<div id="new-target">
|
||||
</div>
|
||||
|
||||
<%= title t(:body_trackers_title), t(".heading") %>
|
||||
<%= title [t("goals.index.heading"), project_goals_path(@project)], @goal.name %>
|
||||
<div id='targets'>
|
||||
<%= render partial: 'targets/index' %>
|
||||
</div>
|
||||
|
@ -19,7 +19,7 @@
|
||||
<hr>
|
||||
</div>
|
||||
|
||||
<%= title t(:body_trackers_title), t(".heading") %>
|
||||
<%= title t(".heading") %>
|
||||
<% if @units.any? { |u| u.persisted? } %>
|
||||
<table class="list">
|
||||
<thead>
|
||||
|
@ -1,7 +1,6 @@
|
||||
# English strings go here for Rails i18n
|
||||
en:
|
||||
body_trackers_menu_caption: 'Body trackers'
|
||||
body_trackers_title: 'Body trackers'
|
||||
field_goal: 'Goal'
|
||||
field_target: 'Target'
|
||||
field_effective_from: 'Effective from'
|
||||
@ -50,6 +49,10 @@ en:
|
||||
attributes:
|
||||
nutrients:
|
||||
duplicated_quantity: 'you can define each nutrient quantity only once per food'
|
||||
threshold:
|
||||
attributes:
|
||||
quantity:
|
||||
domain_mismatch: 'domain has to match model domain'
|
||||
quantity:
|
||||
attributes:
|
||||
parent:
|
||||
|
@ -9,6 +9,7 @@ resources :projects, shallow: true do
|
||||
end
|
||||
resources :goals do
|
||||
member do
|
||||
get 'targets', controller: :targets, action: :index, as: :targets
|
||||
post 'toggle_exposure', controller: :targets
|
||||
end
|
||||
end
|
||||
|
@ -31,7 +31,7 @@ module BodyTracking::ProjectPatch
|
||||
|
||||
has_many :goals, dependent: :destroy do
|
||||
def binding
|
||||
find_or_create_by(is_binding: true) do |goal|
|
||||
find_or_create_by!(is_binding: true) do |goal|
|
||||
goal.name = I18n.t('goals.binding.name')
|
||||
goal.description = I18n.t('goals.binding.description')
|
||||
end
|
||||
|
Reference in New Issue
Block a user