Restyled quantity header
Exposure close button removed, toggling only from select
This commit is contained in:
parent
9f3f90e4f0
commit
da11c0f626
@ -92,9 +92,10 @@ class MealsController < ApplicationController
|
||||
[i, [n_amount && n_amount * i.amount / i.food.ref_amount, n_unit]]
|
||||
end.to_h
|
||||
max_value = @nutrients[q].values.max_by { |a, u| a || 0 }.first
|
||||
@nutrients[q][:mfu_unit] = @nutrients[q].values.map(&:last)
|
||||
.each_with_object(Hash.new(0)) { |u, h| h[u] += 1 }.max_by(&:last).first
|
||||
@nutrients[q][:precision] = [3 - max_value.exponent, 0].max
|
||||
|
||||
@nutrients[q][:mfu_unit] = @nutrients[q]
|
||||
.each_with_object(Hash.new(0)) { |(i, v), h| h[v.last] += 1 }.max_by(&:last).first
|
||||
@nutrients[q][:precision] = max_value && [3 - max_value.exponent, 0].max
|
||||
end
|
||||
|
||||
@meals_by_date = @project.meals.reject { |m,*| m.new_record? }
|
||||
|
@ -19,13 +19,17 @@ module BodyTrackersHelper
|
||||
end
|
||||
|
||||
def toggle_exposure_options(enabled, domain)
|
||||
disabled = []
|
||||
enabled = enabled.to_a
|
||||
options = nested_set_options(@project.quantities.send(domain)) do |q|
|
||||
disabled << q.id if enabled.include?(q)
|
||||
enabled = enabled.map { |q| [q.name, q.id] }
|
||||
enabled_ids = enabled.map(&:last)
|
||||
|
||||
options = [[t('body_trackers.helpers.exposures_available'), 0]]
|
||||
options += nested_set_options(@project.quantities.send(domain)) do |q|
|
||||
raw("#{' ' * q.level}#{q.name}")
|
||||
end
|
||||
options_for_select(options, disabled: disabled)
|
||||
options.collect! { |name, id| [name, enabled_ids.include?(id) ? 0 : id] }
|
||||
|
||||
options = [[t('body_trackers.helpers.exposures_enabled'), 0]] + enabled + options
|
||||
options_for_select(options, disabled: 0)
|
||||
end
|
||||
|
||||
def unit_options
|
||||
|
@ -10,23 +10,27 @@
|
||||
<% total_width = 4 + @quantities.length %>
|
||||
<% @meals_by_date.reverse_each do |date, meals| %>
|
||||
<tr id="date-<%= date.strftime('%Y%m%d') %>" class="date">
|
||||
<td class="date" colspan="2" style="width:<%= 3 * 100/total_width %>%">
|
||||
<td class="date" colspan="2" style="width:<%= 3 * 100/total_width %>%" rowspan="2">
|
||||
<h3><%= date == Date.current ? 'Today' : date.strftime('%F') %></h3>
|
||||
</td>
|
||||
<td style="width:<%= 100/total_width %>%; text-align: left;">
|
||||
<td style="width:<%= 100/total_width %>%; text-align: left;" rowspan="2">
|
||||
<b><%= l(:field_amount) %></b>
|
||||
</td>
|
||||
<% @quantities.each do |q| %>
|
||||
<td style="width:<%= 100/total_width %>%; text-align: left;" class="closable">
|
||||
<div style="float: right; position: relative;">
|
||||
<%= link_to '',
|
||||
toggle_exposure_project_meals_path(@project, quantity_id: q.id),
|
||||
{class: "icon icon-close", method: :post, remote: true} %>
|
||||
</div>
|
||||
<b><%= q.name %></b>
|
||||
<td class="quantityhead closable" style="width: <%= 100/total_width %>%;"
|
||||
title="<%= q.description %>">
|
||||
<%= q.name %>
|
||||
</td>
|
||||
<% end %>
|
||||
<td style="width:<%= 100/total_width %>%" rowspan="2"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<% @quantities.each do |q| %>
|
||||
<td class="quantityhead" style="width: <%= 100/total_width %>%;">
|
||||
<% mfu_unit = @nutrients[q][:mfu_unit] %>
|
||||
<%= "[#{ mfu_unit ? mfu_unit.shortname : '-'}]" %>
|
||||
</td>
|
||||
<% end %>
|
||||
<td style="width:<%= 100/total_width %>%"></td>
|
||||
</tr>
|
||||
|
||||
<% meals.each_with_index do |m, index| %>
|
||||
|
@ -10,7 +10,7 @@
|
||||
<td style="width:100%"></td>
|
||||
<td><%= select_tag 'quantity_id',
|
||||
toggle_exposure_options(@project.meal_quantities, :diet) %></td>
|
||||
<td><%= submit_tag l(:button_add) %></td>
|
||||
<td><%= submit_tag l(:button_toggle) %></td>
|
||||
</tr>
|
||||
</table>
|
||||
<% end %>
|
||||
|
@ -5,11 +5,18 @@ 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 {
|
||||
text-align: center;
|
||||
vertical-align: bottom;
|
||||
position: relative;
|
||||
padding: 2px 0;
|
||||
}
|
||||
|
||||
table.list .action,
|
||||
table.list .value {text-align: right;}
|
||||
|
||||
table.list th.closable {padding-right: 0;}
|
||||
table.list .closable {padding-right: 0;}
|
||||
table.list .unwrappable {white-space: nowrap;}
|
||||
table.list .ellipsible {
|
||||
overflow: hidden;
|
||||
|
@ -23,6 +23,7 @@ en:
|
||||
button_notes: 'Notes'
|
||||
button_retake: 'Retake'
|
||||
button_child: 'Child'
|
||||
button_toggle: 'Toggle'
|
||||
activerecord:
|
||||
errors:
|
||||
models:
|
||||
@ -56,6 +57,9 @@ en:
|
||||
body_trackers:
|
||||
index:
|
||||
heading: 'Summary'
|
||||
helpers:
|
||||
exposures_enabled: '--- enabled ---'
|
||||
exposures_available: '--- available ---'
|
||||
layouts:
|
||||
sidebar:
|
||||
heading_body_trackers: 'Body trackers'
|
||||
|
Reference in New Issue
Block a user