1
0

Added Targets index

This commit is contained in:
cryptogopher
2020-08-06 21:52:33 +02:00
parent ffcc9553d5
commit cf3bbb205d
15 changed files with 245 additions and 45 deletions

View File

@@ -0,0 +1,27 @@
<% total_width = 4 + @quantities.length %>
<% header = quantities_table_header(@quantities) %>
<% header.each_with_index do |row, i| %>
<tr class="header">
<% if i == 0 %>
<td colspan="2" rowspan="<%= 1 + header.length %>"
style="width:<%= 3 * 100/total_width %>%; border: none;"></td>
<td class="quantityhead" rowspan="<%= header.length %>"
style="width:<%= 100/total_width %>%;"><%= l(:field_amount) %></td>
<% end %>
<% row.each do |q, span| %>
<td class="<%= span ? 'quantityhead' : 'quantityheadempty' %>"
<%= "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>
<% end %>
<% if i == 0 %>
<td rowspan="<%= 1 + header.length %>"
style="width:<%= 100/total_width %>%; border: none;"></td>
<% end %>
</tr>
<% end %>

View File

@@ -8,7 +8,7 @@
<table id="meals" class="list odd-even">
<tbody>
<% total_width = 4 + @quantities.length %>
<% header = table_header_spec(@quantities) %>
<% header = quantities_table_header(@quantities) %>
<% @meals_by_date.reverse_each do |date, meals| %>
<% header.each_with_index do |row, i| %>
<tr class="header">

View File

@@ -6,7 +6,7 @@
<% if goal.persisted? %>
<p><%= render partial: 'goals/show_form', locals: {goal: goal} %></p>
<%#= 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>
<% else %>
<%= render partial: 'goals/form', locals: {goal: goal} %>
<% end %>

View File

@@ -1,32 +1,87 @@
<% if @targets.any? { |t| t.persisted? } %>
<table class="list">
<thead>
<tr>
<th style="width:5%"><%= l(:field_taken_at_date) %></th>
<th><%= l(:field_name) %></th>
<th><%= l(:field_notes) %></th>
<th><%= l(:field_source) %></th>
<th style="width:5%"><%= l(:field_action) %></th>
</tr>
</thead>
<%#= render partial: 'measurements/filters',
locals: {url: filter_project_measurements_path(@project, @view_params)} %>
<% if @targets_by_date.any? %>
<%= render partial: 'targets/options' %>
<% formulas = @quantities.map { |q| q.formula } %>
<%# formulas.unshift(@filter_q.formula) if @filter_q %>
<%= error_messages_for *formulas %>
<table id="targets" class="list odd-even">
<tbody>
<% @measurements.each do |m| %>
<% next if m.new_record? %>
<tr id="measurement-<%= m.id %>" class="primary measurement">
<td class="date unwrappable"><%= format_datetime(m) %></td>
<td class="name">
<div style="float:left;">
<%= link_to m.routine.name, readouts_measurement_routine_path(m.routine) %>
</div>
<div style="float:right;">
<small><%= " (#{pluralize(m.readouts.size, 'readout')})" %></small>
</div>
</td>
<td class="notes ellipsible"><%= m.notes %></td>
<td class="source"><%= m.source.name if m.source.present? %></td>
<td class="action unwrappable"><%= action_links(m) %></td>
<% 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>
<% end %>
<% row.each do |q, span| %>
<td class="<%= span ? 'quantityhead' : 'quantityheadempty' %>"
<%= "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>
<% end %>
<% if i == 0 %>
<td rowspan="<%= header.length %>"
style="width:<%= 100/total_width %>%;border:none;"><%= l(:field_action) %></td>
<% end %>
</tr>
<% end %>
<% @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 %>">
<td class="date unwrappable" style="cursor: pointer;"
onclick="$(this).closest('tr').toggle();
$(this).closest('tr').nextUntil('tr.primary', '.date').toggle();
return false;">
<span class="icon icon-bullet-closed"><%= format_date(date) %></span>
</td>
<% @quantities.each do |q| %>
<td class="primary value ellipsible"><%= targets[q] %></td>
<% end %>
<td class="action unwrappable"><%= action_links(date) %></td>
</tr>
<tr class="<%= row_class %>" style="display:none">
<% rows = @quantities.empty? ? 1 : (targets.length - 1) / @quantities.length + 1 %>
<td rowspan="<%= rows %>" class="date unwrappable" style="cursor: pointer;"
onclick="$(this).closest('tr').prev('tr.primary').toggle();
$(this).closest('tr').prev('tr.primary')
.nextUntil('tr.primary', '.date').toggle();
return false;">
<span class="icon icon-bullet-open"><%= format_date(date) %></span>
</td>
<% @quantities.each do |q| %>
<td class="primary quantity ellipsible">
<%= q.name %><p class="value"><%= targets.delete(q) %></p>
</td>
<% end %>
<td rowspan="<%= rows %>" class="action unwrappable"><%= action_links(date) %></td>
</tr>
<% targets.each_slice(@quantities.length) do |extras| %>
<tr class="extra <%= row_class %>" style="display:none">
<% extras.each do |q, t| %>
<td class="extra quantity ellipsible">
<%= q.name %><p class="value"><%= t %></p>
</td>
<% end %>
<% if @quantities.length > extras.length %>
<td class="space" colspan="<%= @quantities.length - extras.length %>"></td>
<% end %>
</tr>
<% end %>
<% end %>
</tbody>
</table>
<% else %>

View File

@@ -0,0 +1,33 @@
<% if @targets.any? %>
<table class="list">
<thead>
<tr>
<th style="width:5%"><%= l(:field_effective_from) %></th>
<th><%= l(:field_name) %></th>
<th><%= l(:field_notes) %></th>
<th><%= l(:field_source) %></th>
<th style="width:5%"><%= l(:field_action) %></th>
</tr>
</thead>
<tbody>
<% @targets.select(&:persisted?).each do |t| %>
<tr id="target-<%= t.id %>" class="primary target">
<td class="date unwrappable"><%= format_date(t.effective_from) %></td>
<td class="name">
<div style="float:left;">
<%= link_to m.routine.name, readouts_measurement_routine_path(m.routine) %>
</div>
<div style="float:right;">
<small><%= " (#{pluralize(m.readouts.size, 'readout')})" %></small>
</div>
</td>
<td class="notes ellipsible"><%= m.notes %></td>
<td class="source"><%= m.source.name if m.source.present? %></td>
<td class="action unwrappable"><%= action_links(m) %></td>
</tr>
<% end %>
</tbody>
</table>
<% else %>
<p class="nodata"><%= l(:label_no_data) %></p>
<% end %>

View File

@@ -0,0 +1,18 @@
<fieldset id="options" class="collapsible">
<legend onclick="toggleFieldset(this);"><%= l(:label_options) %></legend>
<div>
<%= form_tag toggle_exposure_goal_path(current_goal, @view_params),
id: 'toggle-exposure-form', name: 'toggle-exposure-form',
method: :post, remote: true do %>
<table>
<tr>
<td style="width:100%"></td>
<td><%= select_tag 'quantity_id',
toggle_exposure_options(current_goal.quantities) %></td>
<td><%= submit_tag l(:button_add) %></td>
</tr>
</table>
<% end %>
</div>
</fieldset>

View File

@@ -1,7 +1,7 @@
$('#new-targets').empty();
<% case @view_params[:view] %>
<% when :by_date %>
$('#targets').html('<%= j render partial: 'targets/by_date' %>');
$('#targets').html('<%= j render partial: 'targets/by_effective_date' %>');
<% else %>
$('#targets').html('<%= j render partial: 'targets/index' %>');
<% end %>