Added is_binding attribute to Goal
Fixed test_index to check for data rows only
This commit is contained in:
parent
955125b843
commit
59a14043c8
@ -7,9 +7,12 @@ class Goal < ActiveRecord::Base
|
|||||||
has_many :quantities, -> { order "lft" }, through: :target_exposures
|
has_many :quantities, -> { order "lft" }, through: :target_exposures
|
||||||
|
|
||||||
validates :target_exposures, presence: true
|
validates :target_exposures, presence: true
|
||||||
|
validates :is_binding, uniqueness: {scope: :project_id}, if: :is_binding?
|
||||||
validates :name, presence: true, uniqueness: {scope: :project_id}
|
validates :name, presence: true, uniqueness: {scope: :project_id}
|
||||||
|
|
||||||
def is_binding?
|
after_initialize do
|
||||||
self == project.goals.binding
|
if new_record?
|
||||||
|
self.is_binding = false if self.is_binding.nil?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
<% @targets.group_by(&:goal).each do |goal, targets| %>
|
<% @targets.group_by(&:goal).each do |goal, targets| %>
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<div id='goal-form' class="tabular">
|
<div id='goal-form' class="tabular">
|
||||||
<% if goal.persisted? %>
|
<% if goal.persisted? || goal.is_binding? %>
|
||||||
<p><%= render partial: 'goals/show_form', locals: {goal: goal} %></p>
|
<p><%= render partial: 'goals/show_form', locals: {goal: goal} %></p>
|
||||||
<%#= t '.effective_from' %>
|
<%#= t '.effective_from' %>
|
||||||
<p><%= f.date_field :effective_from, disabled: !goal.is_binding? %></p>
|
<p><%= f.date_field :effective_from, disabled: !goal.is_binding? %></p>
|
||||||
|
@ -9,33 +9,35 @@
|
|||||||
<%= error_messages_for *formulas %>
|
<%= error_messages_for *formulas %>
|
||||||
|
|
||||||
<table id="targets" class="list odd-even">
|
<table id="targets" class="list odd-even">
|
||||||
<tbody>
|
<thead>
|
||||||
<% total_width = 3 + @quantities.length %>
|
<% total_width = 3 + @quantities.length %>
|
||||||
<% header = quantities_table_header(@quantities) %>
|
<% header = quantities_table_header(@quantities) %>
|
||||||
<% header.each_with_index do |row, i| %>
|
<% header.each_with_index do |row, i| %>
|
||||||
<tr class="header">
|
<tr class="header">
|
||||||
<% if i == 0 %>
|
<% if i == 0 %>
|
||||||
<td class="quantityhead" rowspan="<%= header.length %>"
|
<th class="quantity" rowspan="<%= header.length %>"
|
||||||
style="width:<%= 2 * 100/total_width %>%"><%= l(:field_effective_from) %></td>
|
style="width:<%= 2 * 100/total_width %>%"><%= l(:field_effective_from) %></th>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% row.each do |q, span| %>
|
<% row.each do |q, span| %>
|
||||||
<td class="<%= span ? 'quantityhead' : 'quantityheadempty' %>"
|
<th class="quantity <%= 'empty' unless span %>"
|
||||||
<%= "colspan=#{span}" if span && span > 0 %>
|
<%= "colspan=#{span}" if span && span > 0 %>
|
||||||
<%= "rowspan=#{-span}" if span && span < 0 %>
|
<%= "rowspan=#{-span}" if span && span < 0 %>
|
||||||
style="width: <%= (span && span > 0 ? span : 1) * 100/total_width %>%;"
|
style="width: <%= (span && span > 0 ? span : 1) * 100/total_width %>%;"
|
||||||
title="<%= q.description %>">
|
title="<%= q.description %>">
|
||||||
<%= q.name if span %>
|
<%= q.name if span %>
|
||||||
</td>
|
</th>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% if i == 0 %>
|
<% if i == 0 %>
|
||||||
<td rowspan="<%= header.length %>"
|
<th rowspan="<%= header.length %>"
|
||||||
style="width:<%= 100/total_width %>%;border:none;"><%= l(:field_action) %></td>
|
style="width:<%= 100/total_width %>%;border:none;"><%= l(:field_action) %></th>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
</thead>
|
||||||
|
|
||||||
|
<tbody>
|
||||||
<% @targets_by_date.each do |date, targets| %>
|
<% @targets_by_date.each do |date, targets| %>
|
||||||
<% row_class = "date #{cycle('odd', 'even')}" %>
|
<% row_class = "date #{cycle('odd', 'even')}" %>
|
||||||
<tr id="date-<%= date.strftime('%Y%m%d') %>" class="primary <%= row_class %>">
|
<tr id="date-<%= date.strftime('%Y%m%d') %>" class="primary <%= row_class %>">
|
||||||
|
@ -5,14 +5,22 @@ table.list tr.food.hidden {opacity: 0.4}
|
|||||||
table.list .date,
|
table.list .date,
|
||||||
table.list .name,
|
table.list .name,
|
||||||
table.list .quantity {text-align: left;}
|
table.list .quantity {text-align: left;}
|
||||||
/* TODO: merge with .closable */
|
/* TODO: merge with .closable and/or remove .closable */
|
||||||
table.list .quantityhead {
|
/* TODO: replace .quantityhead(empty) with th.quantity/.empty */
|
||||||
|
table.list .quantityhead, table.list th.quantity {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
position: relative;
|
position: relative;
|
||||||
padding: 2px 0;
|
padding: 2px 0;
|
||||||
border-bottom: none;
|
border-bottom: none;
|
||||||
}
|
}
|
||||||
table.list .quantityheadempty {border-top: none; border-bottom: none;}
|
table.list .quantityheadempty {border-top: none; border-bottom: none;}
|
||||||
|
table.list th.quantity {
|
||||||
|
text-align: center;
|
||||||
|
position: relative;
|
||||||
|
padding: 2px 0;
|
||||||
|
border-bottom: none;
|
||||||
|
}
|
||||||
|
table.list th.empty {border-top: none;}
|
||||||
|
|
||||||
table.list .action,
|
table.list .action,
|
||||||
table.list .value {text-align: right; padding-right: 2px;}
|
table.list .value {text-align: right; padding-right: 2px;}
|
||||||
|
@ -74,6 +74,7 @@ class CreateSchema <
|
|||||||
t.integer :group
|
t.integer :group
|
||||||
t.references :source
|
t.references :source
|
||||||
t.string :source_ident
|
t.string :source_ident
|
||||||
|
# TODO: rename to is_hidden
|
||||||
t.boolean :hidden
|
t.boolean :hidden
|
||||||
t.decimal :ready_amount, precision: 12, scale: 6
|
t.decimal :ready_amount, precision: 12, scale: 6
|
||||||
t.timestamps null: false
|
t.timestamps null: false
|
||||||
@ -96,6 +97,7 @@ class CreateSchema <
|
|||||||
|
|
||||||
create_table :goals do |t|
|
create_table :goals do |t|
|
||||||
t.references :project
|
t.references :project
|
||||||
|
t.boolean :is_binding
|
||||||
t.string :name
|
t.string :name
|
||||||
t.text :description
|
t.text :description
|
||||||
t.timestamps null: false
|
t.timestamps null: false
|
||||||
|
@ -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(name: "- binding -")
|
find_or_initialize_by(is_binding: true) { |g| g.name = "- binding -" }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
has_many :targets, through: :goals
|
has_many :targets, through: :goals
|
||||||
|
@ -21,7 +21,7 @@ class BodyTrackingSystemTestCase < ApplicationSystemTestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
fixtures :projects
|
fixtures :projects
|
||||||
plugin_fixtures :quantities, :units, :exposures, :targets, :quantity_values
|
plugin_fixtures :quantities, :units, :goals, :exposures, :targets, :quantity_values
|
||||||
|
|
||||||
include AbstractController::Translation
|
include AbstractController::Translation
|
||||||
|
|
||||||
|
2
test/fixtures/exposures.yml
vendored
2
test/fixtures/exposures.yml
vendored
@ -1,4 +1,4 @@
|
|||||||
exposures_01:
|
exposures_01:
|
||||||
view_type: Goal
|
view_type: Goal
|
||||||
view_id: <%= Project.find(1).goals.binding.id %>
|
view: goals_binding
|
||||||
quantity: quantities_energy
|
quantity: quantities_energy
|
||||||
|
4
test/fixtures/goals.yml
vendored
Normal file
4
test/fixtures/goals.yml
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
goals_binding:
|
||||||
|
project_id: 1
|
||||||
|
is_binding: true
|
||||||
|
name: '- binding -'
|
2
test/fixtures/quantities.yml
vendored
2
test/fixtures/quantities.yml
vendored
@ -1,5 +1,5 @@
|
|||||||
quantities_energy:
|
quantities_energy:
|
||||||
project: projects_001
|
project_id: 1
|
||||||
domain: diet
|
domain: diet
|
||||||
parent: null
|
parent: null
|
||||||
lft: 1
|
lft: 1
|
||||||
|
2
test/fixtures/targets.yml
vendored
2
test/fixtures/targets.yml
vendored
@ -1,4 +1,4 @@
|
|||||||
targets_01:
|
targets_01:
|
||||||
goal_id: <%= Project.find(1).goals.binding.id %>
|
goal: goals_binding
|
||||||
condition: '=='
|
condition: '=='
|
||||||
effective_from: <%= 1.week.ago.to_s(:db) %>
|
effective_from: <%= 1.week.ago.to_s(:db) %>
|
||||||
|
6
test/fixtures/units.yml
vendored
6
test/fixtures/units.yml
vendored
@ -1,14 +1,14 @@
|
|||||||
units_gram:
|
units_gram:
|
||||||
project: projects_001
|
project_id: 1
|
||||||
name: 'gram'
|
name: 'gram'
|
||||||
shortname: 'g'
|
shortname: 'g'
|
||||||
|
|
||||||
units_percent:
|
units_percent:
|
||||||
project: projects_001
|
project_id: 1
|
||||||
name: 'percent'
|
name: 'percent'
|
||||||
shortname: '%'
|
shortname: '%'
|
||||||
|
|
||||||
units_kcal:
|
units_kcal:
|
||||||
project: projects_001
|
project_id: 1
|
||||||
name: 'kilocalorie'
|
name: 'kilocalorie'
|
||||||
shortname: 'kcal'
|
shortname: 'kcal'
|
||||||
|
@ -18,11 +18,14 @@ class TargetsTest < BodyTrackingSystemTestCase
|
|||||||
assert_not_equal 0, @project1.targets.count
|
assert_not_equal 0, @project1.targets.count
|
||||||
visit project_targets_path(@project1)
|
visit project_targets_path(@project1)
|
||||||
assert_current_path project_targets_path(@project1)
|
assert_current_path project_targets_path(@project1)
|
||||||
assert_selector 'table#targets tr', count: @project1.targets.count
|
assert_selector 'table#targets tbody tr', count: @project1.targets.count
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_index_without_targets
|
def test_index_without_targets
|
||||||
#assert_equal 0, @project1.targets.count
|
#assert_equal 0, @project1.targets.count
|
||||||
#assert_selector 'div#targets', visible: :yes, exact_text: l(:label_no_data)
|
#assert_selector 'div#targets', visible: :yes, exact_text: l(:label_no_data)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_create_saves_binding_goal_if_nonexistent
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user