1
0
This repository has been archived on 2023-12-07. You can view files and clone it, but cannot push or open issues or pull requests.
body_tracking/app/views/targets/_index.html.erb
2021-01-24 15:05:54 +01:00

112 lines
4.5 KiB
Plaintext

<%#= 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">
<thead>
<% total_width = 3 + @quantities.length %>
<% header = quantities_table_header(@quantities) %>
<% header.each_with_index do |row, i| %>
<tr class="header">
<% if i == 0 %>
<th rowspan="<%= header.length %>" style="width:<%= 2 * 100/total_width %>%">
<%= l(:field_effective_from) %>
</th>
<% end %>
<% row.each do |q, span| %>
<% row_classes = [] %>
<% row_classes << 'interim' if (i < header.length-1) && (span >= 0) %>
<% row_classes << (span == 0 ? 'empty' : 'closable ellipsible') %>
<th <%= raw "class=\"#{row_classes.join(' ')}\"" unless row_classes.empty? %>
<%= "colspan=#{span}" if span > 0 %>
<%= "rowspan=#{-span}" if span < 0 %>
style="width: <%= [span, 1].max * 100/total_width %>%;"
title="<%= q.description %>">
<% unless span == 0 %>
<div style="float:right;position:relative;">
<% button_classes = 'icon' %>
<% if (i == header.length-1) || header[i+1].has_key?(q) || (span < -1) %>
<% button_classes += ' icon-close' %>
<% else %>
<% button_classes += ' icon-bullet-closed' %>
<% end %>
<%= link_to '', toggle_exposure_goal_path(@goal, quantity_id: q.id),
{class: button_classes, method: :post, remote: true} %>
</div>
<%= q.name %>
<% end %>
</th>
<% end %>
<% if i == 0 %>
<th rowspan="<%= header.length %>" style="width:<%= 100/total_width %>%;">
<%= 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 %>" 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>
<% next if @quantities.empty? %>
<% 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 %>
<p class="nodata"><%= l(:label_no_data) %></p>
<% end %>