1
0

Added is_binding attribute to Goal

Fixed test_index to check for data rows only
This commit is contained in:
cryptogopher
2020-08-18 17:40:46 +02:00
parent 955125b843
commit 59a14043c8
13 changed files with 43 additions and 21 deletions

View File

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

View File

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

View File

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