1
0

Restyled quantity header

Exposure close button removed, toggling only from select
This commit is contained in:
cryptogopher 2020-04-29 22:26:48 +02:00
parent 9f3f90e4f0
commit da11c0f626
6 changed files with 40 additions and 20 deletions

View File

@ -92,9 +92,10 @@ class MealsController < ApplicationController
[i, [n_amount && n_amount * i.amount / i.food.ref_amount, n_unit]] [i, [n_amount && n_amount * i.amount / i.food.ref_amount, n_unit]]
end.to_h end.to_h
max_value = @nutrients[q].values.max_by { |a, u| a || 0 }.first 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][:mfu_unit] = @nutrients[q]
@nutrients[q][:precision] = [3 - max_value.exponent, 0].max .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 end
@meals_by_date = @project.meals.reject { |m,*| m.new_record? } @meals_by_date = @project.meals.reject { |m,*| m.new_record? }

View File

@ -19,13 +19,17 @@ module BodyTrackersHelper
end end
def toggle_exposure_options(enabled, domain) def toggle_exposure_options(enabled, domain)
disabled = [] enabled = enabled.map { |q| [q.name, q.id] }
enabled = enabled.to_a enabled_ids = enabled.map(&:last)
options = nested_set_options(@project.quantities.send(domain)) do |q|
disabled << q.id if enabled.include?(q) options = [[t('body_trackers.helpers.exposures_available'), 0]]
options += nested_set_options(@project.quantities.send(domain)) do |q|
raw("#{'&ensp;' * q.level}#{q.name}") raw("#{'&ensp;' * q.level}#{q.name}")
end 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 end
def unit_options def unit_options

View File

@ -10,23 +10,27 @@
<% total_width = 4 + @quantities.length %> <% total_width = 4 + @quantities.length %>
<% @meals_by_date.reverse_each do |date, meals| %> <% @meals_by_date.reverse_each do |date, meals| %>
<tr id="date-<%= date.strftime('%Y%m%d') %>" class="date"> <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> <h3><%= date == Date.current ? 'Today' : date.strftime('%F') %></h3>
</td> </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> <b><%= l(:field_amount) %></b>
</td> </td>
<% @quantities.each do |q| %> <% @quantities.each do |q| %>
<td style="width:<%= 100/total_width %>%; text-align: left;" class="closable"> <td class="quantityhead closable" style="width: <%= 100/total_width %>%;"
<div style="float: right; position: relative;"> title="<%= q.description %>">
<%= link_to '', <%= q.name %>
toggle_exposure_project_meals_path(@project, quantity_id: q.id), </td>
{class: "icon icon-close", method: :post, remote: true} %> <% end %>
</div> <td style="width:<%= 100/total_width %>%" rowspan="2"></td>
<b><%= q.name %></b> </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> </td>
<% end %> <% end %>
<td style="width:<%= 100/total_width %>%"></td>
</tr> </tr>
<% meals.each_with_index do |m, index| %> <% meals.each_with_index do |m, index| %>

View File

@ -10,7 +10,7 @@
<td style="width:100%"></td> <td style="width:100%"></td>
<td><%= select_tag 'quantity_id', <td><%= select_tag 'quantity_id',
toggle_exposure_options(@project.meal_quantities, :diet) %></td> toggle_exposure_options(@project.meal_quantities, :diet) %></td>
<td><%= submit_tag l(:button_add) %></td> <td><%= submit_tag l(:button_toggle) %></td>
</tr> </tr>
</table> </table>
<% end %> <% end %>

View File

@ -5,11 +5,18 @@ table.list tr.food.hidden {opacity: 0.4}
table.list .date, table.list .date,
table.list .name, table.list .name,
table.list .quantity {text-align: left;} 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 .action,
table.list .value {text-align: right;} 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 .unwrappable {white-space: nowrap;}
table.list .ellipsible { table.list .ellipsible {
overflow: hidden; overflow: hidden;

View File

@ -23,6 +23,7 @@ en:
button_notes: 'Notes' button_notes: 'Notes'
button_retake: 'Retake' button_retake: 'Retake'
button_child: 'Child' button_child: 'Child'
button_toggle: 'Toggle'
activerecord: activerecord:
errors: errors:
models: models:
@ -56,6 +57,9 @@ en:
body_trackers: body_trackers:
index: index:
heading: 'Summary' heading: 'Summary'
helpers:
exposures_enabled: '--- enabled ---'
exposures_available: '--- available ---'
layouts: layouts:
sidebar: sidebar:
heading_body_trackers: 'Body trackers' heading_body_trackers: 'Body trackers'