1
0

Add GoalController: #index, #new, #create

This commit is contained in:
cryptogopher
2021-02-21 18:10:15 +01:00
parent ea308a1e4a
commit 7f87b3bc84
20 changed files with 182 additions and 76 deletions

View File

@@ -1,13 +1,10 @@
<div class="tabular">
<%= fields_for 'measurement[routine_attributes]', routine do |ff| %>
<%= ff.hidden_field :id %>
<p>
<label><%= l(:field_name) %><span class="required"> *</span></label>
<%= ff.text_field :name, required: true, style: "width: 95%;" %>
</p>
<p>
<label><%= l(:field_description) %></label>
<%= ff.text_area :description, cols: 40, rows: 3, style: "width: 95%;" %>
</p>
<% end %>
<%= error_messages_for @goal %>
<div class="box tabular">
<p><%= goal_f.text_field :name, required: true, style: "width: 95%;" %></p>
<p><%= goal_f.text_area :description, rows: 3, style: "width: 95%;" %></p>
<hr style="width: 95%;">
<%= render partial: 'targets/form', locals: {goal_f: goal_f} %>
</div>

View File

@@ -0,0 +1,32 @@
<% if @goals.any? %>
<table id="goals" class="list odd-even">
<thead>
<tr>
<th><%= l(:field_name) %></th>
<th><%= l(:field_description) %></th>
<th style="width:5%"><%= l(:field_action) %></th>
</tr>
</thead>
<tbody>
<% @goals.each do |g| %>
<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 %>
</div>
<div style="float:right;">
<%# TODO: display # of active targets/targeted quantities %>
<small><%#= " (#{pluralize(m.readouts.size, 'readout')})" %></small>
</div>
</td>
<td class="description ellipsible"><%= g.description %></td>
<td class="action unwrappable">
<%= delete_link(g, {remote: true, data: {}}) unless g.is_binding %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% else %>
<p class="nodata"><%= l(:label_no_data) %></p>
<% end %>

View File

@@ -0,0 +1,16 @@
<h2><%= t ".heading_new_goal" %></h2>
<%= labelled_form_for [@project, @goal], remote: true,
html: {id: 'new-goal-form', name: 'new-goal-form'} do |goal_f| %>
<%= render partial: 'goals/form', locals: {goal_f: goal_f} %>
<div class="tabular">
<p>
<%= submit_tag l(:button_create) %>
<%= link_to l(:button_cancel), "#",
onclick: "$('#new-goal').empty(); return false;" %>
</p>
</div>
<% end %>
<hr>

View File

@@ -0,0 +1,2 @@
$('#new-goal').empty();
$('#goals').html('<%= j render partial: 'goals/index' %>');

View File

@@ -0,0 +1,13 @@
<div class="contextual">
<%= link_to_if User.current.allowed_to?(:manage_body_trackers, @project),
t(".link_new_goal"), new_project_goal_path(@project),
{remote: true, class: 'icon icon-add'} %>
</div>
<div id="new-goal">
</div>
<%= title t(:body_trackers_title), t(".heading") %>
<div id='goals'>
<%= render partial: 'goals/index' %>
</div>

View File

@@ -0,0 +1 @@
$('#new-goal').html('<%= j render partial: 'goals/new_form' %>');

View File

@@ -17,8 +17,7 @@
<li>
<%= link_to t(".link_targets"), project_targets_path(@project) %>
/
<%#= link_to t(".link_goals"), nutrients_project_foods_path(@project) %>
Goals
<%= link_to t(".link_goals"), project_goals_path(@project) %>
</li>
<li><%= link_to t(".link_quantities"), project_quantities_path(@project) %></li>
<li><%= link_to t(".link_units"), project_units_path(@project) %></li>

View File

@@ -1,42 +1,30 @@
<%= error_messages_for *@targets %>
<% if goal_f.object.is_binding? %>
<p>
<%= date_field :effective_from, value: @effective_from %>
</p>
<% end %>
<div class="box">
<div id='goal-form' class="tabular">
<% if goal_f.object.persisted? %>
<p><%= render partial: 'goals/show_form', locals: {goal_f: goal_f} %></p>
<p><%= goal_f.date_field :effective_from, value: @effective_from,
disabled: !goal_f.object.is_binding? %></p>
<% else %>
<%= render partial: 'goals/form' %>
<% end %>
</div>
<%= goal_f.fields_for :targets, @targets, child_index: '' do |target_f| %>
<p class="target">
<%= target_f.hidden_field :_destroy %>
<em class="info"><%= t ".choose_quantity" %></em>
<%= target_f.select :quantity_id, quantity_options,
{include_blank: true, required: true, label: :field_target},
onchange: "showQuantityPath(event);" %>
<hr style="width: 95%;">
<%= render partial: 'targets/thresholds_form',
locals: {target_f: target_f,
last_quantity: target_f.object.thresholds.last.quantity} %>
<div class="tabular">
<p class="target">
<%= goal_f.fields_for :targets, @targets, child_index: '' do |target_f| %>
<%= target_f.hidden_field :_destroy %>
<em class="info"><%= t ".choose_quantity" %></em>
<%= target_f.select :quantity_id, quantity_options,
{include_blank: true, required: true, label: :field_target},
onchange: "showQuantityPath(event);" %>
<%= render partial: 'targets/thresholds_form',
locals: {target_f: target_f,
last_quantity: target_f.object.thresholds.last.quantity} %>
<%= link_to t(".button_delete_target"), '#', class: 'icon icon-del',
style: (@targets.many? ? "" : "display:none"),
onclick: "deleteTarget(); return false;" %>
<% end %>
</p>
<p>
<%= link_to t(".button_new_target"), '#', class: 'icon icon-add',
onclick: 'newTarget(); return false;' %>
</p>
</div>
</div>
<%= link_to t(".button_delete_target"), '#', class: 'icon icon-del',
style: (@targets.many? ? "" : "display:none"),
onclick: "deleteTarget(); return false;" %>
</p>
<% end %>
<p>
<%= link_to t(".button_new_target"), '#', class: 'icon icon-add',
onclick: 'newTarget(); return false;' %>
</p>
<%= javascript_tag do %>
function showQuantityPath(event) {

View File

@@ -4,7 +4,10 @@
<%= labelled_form_for [@project, @goal], remote: true,
html: {id: 'new-target-form', name: 'new-target-form'} do |goal_f| %>
<%= render partial: 'targets/form', locals: {goal_f: goal_f} %>
<%= error_messages_for *@targets %>
<div class="box tabular">
<%= render partial: 'targets/form', locals: {goal_f: goal_f} %>
</div>
<div class="tabular">
<p>