1
0

List binding goal targets

This commit is contained in:
cryptogopher 2021-02-21 19:41:24 +01:00
parent 7f87b3bc84
commit 09e27eb754
18 changed files with 26 additions and 20 deletions

View File

@ -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

View File

@ -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

View File

@ -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.

View File

@ -1 +1 @@
<%= title t(:body_trackers_title), t(".heading") %>
<%= title t(".heading") %>

View File

@ -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>

View File

@ -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>

View File

@ -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 %>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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' %>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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:

View File

@ -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

View File

@ -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