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