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
|
||||
|
||||
validates :target_exposures, presence: true
|
||||
validates :is_binding, uniqueness: {scope: :project_id}, if: :is_binding?
|
||||
validates :name, presence: true, uniqueness: {scope: :project_id}
|
||||
|
||||
def is_binding?
|
||||
self == project.goals.binding
|
||||
after_initialize do
|
||||
if new_record?
|
||||
self.is_binding = false if self.is_binding.nil?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -3,7 +3,7 @@
|
||||
<% @targets.group_by(&:goal).each do |goal, targets| %>
|
||||
<div class="box">
|
||||
<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>
|
||||
<%#= t '.effective_from' %>
|
||||
<p><%= f.date_field :effective_from, disabled: !goal.is_binding? %></p>
|
||||
|
@ -9,33 +9,35 @@
|
||||
<%= error_messages_for *formulas %>
|
||||
|
||||
<table id="targets" class="list odd-even">
|
||||
<tbody>
|
||||
<thead>
|
||||
<% total_width = 3 + @quantities.length %>
|
||||
<% header = quantities_table_header(@quantities) %>
|
||||
<% header.each_with_index do |row, i| %>
|
||||
<tr class="header">
|
||||
<% if i == 0 %>
|
||||
<td class="quantityhead" rowspan="<%= header.length %>"
|
||||
style="width:<%= 2 * 100/total_width %>%"><%= l(:field_effective_from) %></td>
|
||||
<th class="quantity" rowspan="<%= header.length %>"
|
||||
style="width:<%= 2 * 100/total_width %>%"><%= l(:field_effective_from) %></th>
|
||||
<% end %>
|
||||
|
||||
<% row.each do |q, span| %>
|
||||
<td class="<%= span ? 'quantityhead' : 'quantityheadempty' %>"
|
||||
<th class="quantity <%= 'empty' unless span %>"
|
||||
<%= "colspan=#{span}" if span && span > 0 %>
|
||||
<%= "rowspan=#{-span}" if span && span < 0 %>
|
||||
style="width: <%= (span && span > 0 ? span : 1) * 100/total_width %>%;"
|
||||
title="<%= q.description %>">
|
||||
<%= q.name if span %>
|
||||
</td>
|
||||
</th>
|
||||
<% end %>
|
||||
|
||||
<% if i == 0 %>
|
||||
<td rowspan="<%= header.length %>"
|
||||
style="width:<%= 100/total_width %>%;border:none;"><%= l(:field_action) %></td>
|
||||
<th rowspan="<%= header.length %>"
|
||||
style="width:<%= 100/total_width %>%;border:none;"><%= l(:field_action) %></th>
|
||||
<% end %>
|
||||
</tr>
|
||||
<% end %>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<% @targets_by_date.each do |date, targets| %>
|
||||
<% row_class = "date #{cycle('odd', 'even')}" %>
|
||||
<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 .name,
|
||||
table.list .quantity {text-align: left;}
|
||||
/* TODO: merge with .closable */
|
||||
table.list .quantityhead {
|
||||
/* TODO: merge with .closable and/or remove .closable */
|
||||
/* TODO: replace .quantityhead(empty) with th.quantity/.empty */
|
||||
table.list .quantityhead, table.list th.quantity {
|
||||
text-align: center;
|
||||
position: relative;
|
||||
padding: 2px 0;
|
||||
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 .value {text-align: right; padding-right: 2px;}
|
||||
|
@ -74,6 +74,7 @@ class CreateSchema <
|
||||
t.integer :group
|
||||
t.references :source
|
||||
t.string :source_ident
|
||||
# TODO: rename to is_hidden
|
||||
t.boolean :hidden
|
||||
t.decimal :ready_amount, precision: 12, scale: 6
|
||||
t.timestamps null: false
|
||||
@ -96,6 +97,7 @@ class CreateSchema <
|
||||
|
||||
create_table :goals do |t|
|
||||
t.references :project
|
||||
t.boolean :is_binding
|
||||
t.string :name
|
||||
t.text :description
|
||||
t.timestamps null: false
|
||||
|
@ -31,7 +31,7 @@ module BodyTracking::ProjectPatch
|
||||
|
||||
has_many :goals, dependent: :destroy do
|
||||
def binding
|
||||
find_or_create_by(name: "- binding -")
|
||||
find_or_initialize_by(is_binding: true) { |g| g.name = "- binding -" }
|
||||
end
|
||||
end
|
||||
has_many :targets, through: :goals
|
||||
|
@ -21,7 +21,7 @@ class BodyTrackingSystemTestCase < ApplicationSystemTestCase
|
||||
end
|
||||
|
||||
fixtures :projects
|
||||
plugin_fixtures :quantities, :units, :exposures, :targets, :quantity_values
|
||||
plugin_fixtures :quantities, :units, :goals, :exposures, :targets, :quantity_values
|
||||
|
||||
include AbstractController::Translation
|
||||
|
||||
|
2
test/fixtures/exposures.yml
vendored
2
test/fixtures/exposures.yml
vendored
@ -1,4 +1,4 @@
|
||||
exposures_01:
|
||||
view_type: Goal
|
||||
view_id: <%= Project.find(1).goals.binding.id %>
|
||||
view: goals_binding
|
||||
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:
|
||||
project: projects_001
|
||||
project_id: 1
|
||||
domain: diet
|
||||
parent: null
|
||||
lft: 1
|
||||
|
2
test/fixtures/targets.yml
vendored
2
test/fixtures/targets.yml
vendored
@ -1,4 +1,4 @@
|
||||
targets_01:
|
||||
goal_id: <%= Project.find(1).goals.binding.id %>
|
||||
goal: goals_binding
|
||||
condition: '=='
|
||||
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:
|
||||
project: projects_001
|
||||
project_id: 1
|
||||
name: 'gram'
|
||||
shortname: 'g'
|
||||
|
||||
units_percent:
|
||||
project: projects_001
|
||||
project_id: 1
|
||||
name: 'percent'
|
||||
shortname: '%'
|
||||
|
||||
units_kcal:
|
||||
project: projects_001
|
||||
project_id: 1
|
||||
name: 'kilocalorie'
|
||||
shortname: 'kcal'
|
||||
|
@ -18,11 +18,14 @@ class TargetsTest < BodyTrackingSystemTestCase
|
||||
assert_not_equal 0, @project1.targets.count
|
||||
visit 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
|
||||
|
||||
def test_index_without_targets
|
||||
#assert_equal 0, @project1.targets.count
|
||||
#assert_selector 'div#targets', visible: :yes, exact_text: l(:label_no_data)
|
||||
end
|
||||
|
||||
def test_create_saves_binding_goal_if_nonexistent
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user