Meals index, WIP
This commit is contained in:
parent
3ff36df168
commit
50b89de904
@ -6,7 +6,7 @@ class MealsController < ApplicationController
|
||||
include Concerns::Finders
|
||||
|
||||
before_action :find_project_by_project_id, only: [:index, :new, :create]
|
||||
before_action :find_meal, only: [:edit, :update, :destroy]
|
||||
before_action :find_meal, only: [:edit, :update, :destroy, :note, :toggle_eaten]
|
||||
before_action :authorize
|
||||
|
||||
def index
|
||||
@ -29,9 +29,18 @@ class MealsController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def destroy
|
||||
end
|
||||
|
||||
def note
|
||||
end
|
||||
|
||||
def toggle_eaten
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def meal_params
|
||||
|
@ -33,7 +33,7 @@ class MeasurementsController < ApplicationController
|
||||
@measurement.routine.project = @project
|
||||
@routine = @measurement.routine
|
||||
if @measurement.save
|
||||
if @routine.exposures.empty?
|
||||
if @routine.readout_exposures.empty?
|
||||
@routine.quantities << @measurement.readouts.map(&:quantity).first(6)
|
||||
end
|
||||
|
||||
@ -83,7 +83,7 @@ class MeasurementsController < ApplicationController
|
||||
end
|
||||
|
||||
def toggle_column
|
||||
@routine.exposures.toggle!(@quantity)
|
||||
@routine.readout_exposures.toggle!(@quantity)
|
||||
prepare_readouts
|
||||
end
|
||||
|
||||
|
@ -1,9 +1,18 @@
|
||||
module MealsHelper
|
||||
def meal_links(m)
|
||||
delete_link(meal_path(m), {remote: true, data: {}}) if m.persisted?
|
||||
link_to(l(:button_edit), edit_meal_path(m),
|
||||
{remote: true, class: "icon icon-edit"}) +
|
||||
delete_link(meal_path(m), {remote: true, data: {}})
|
||||
end
|
||||
def adjust_ingredient_link(i, adjustment)
|
||||
link_to "%+d" % adjustment, adjust_ingredient_path(i, adjustment: adjustment),
|
||||
{remote: true, method: :post}
|
||||
|
||||
def adjust_ingredient_links(i)
|
||||
[-10, -1, 0, 1, 10].map do |v|
|
||||
if v != 0
|
||||
link_to "%+d" % v, adjust_ingredient_path(i, adjustment: v),
|
||||
{remote: true, method: :post, class: "button #{v>0 ? 'green' : 'red'}"}
|
||||
else
|
||||
yield.to_s
|
||||
end
|
||||
end.reduce(:+)
|
||||
end
|
||||
end
|
||||
|
@ -1,4 +1,23 @@
|
||||
module QuantitiesHelper
|
||||
def order_links(q)
|
||||
[:up, :down, :left, :right].map do |direction|
|
||||
if q.movable?(direction)
|
||||
link_to '', move_quantity_path(q, direction),
|
||||
{remote: true, method: :post, class: "icon icon-move icon-move-#{direction}"}
|
||||
else
|
||||
link_to '', '', {class: "icon", style: "visibility: hidden;"}
|
||||
end
|
||||
end.reduce(:+)
|
||||
end
|
||||
|
||||
def action_links(q)
|
||||
link_to(l(:button_child), new_child_quantity_path(q),
|
||||
{remote: true, class: "icon icon-add"}) +
|
||||
link_to(l(:button_edit), edit_quantity_path(q),
|
||||
{remote: true, class: "icon icon-edit"}) +
|
||||
delete_link(quantity_path(q), {remote: true, data: {}})
|
||||
end
|
||||
|
||||
def domain_options
|
||||
translations = t('quantities.form.domains')
|
||||
Quantity.domains.map do |k,v|
|
||||
|
@ -1,35 +1,34 @@
|
||||
<% if @meals.any? { |m| m.persisted? } %>
|
||||
<table id="meals" class="odd-even">
|
||||
<table id="meals" class="odd-even list">
|
||||
<tbody>
|
||||
<% @meals.group_by { |m| m.eaten_at.date if m.eaten_at }.each do |d, meals| %>
|
||||
<% meals.each_with_index do |m, index| %>
|
||||
<% next if m.new_record? %>
|
||||
<tr id="meal-<%= m.id %>" class="primary meal">
|
||||
<td class="name" colspan="2">
|
||||
<h4>
|
||||
<%= "#{t '.label_meal'}" %><%= index ? " ##{index+1}" : " (new)" %>
|
||||
<%= ", #{m.eaten_at.time}" if m.eaten_at %>
|
||||
</h4>
|
||||
<b><%= "#{t '.label_meal'} ##{index+1}" %></b>
|
||||
<% if m.eaten_at %>
|
||||
<%= " - #{m.eaten_at.time}" %>
|
||||
<%= link_to '', toggle_eaten_meal_path(m),
|
||||
{remote: true, class: "icon icon-close"} %>
|
||||
<% else %>
|
||||
<%= link_to l(:button_eat), toggle_eaten_meal_path(m),
|
||||
{remote: true, class: "icon icon-ok"} %>
|
||||
<% end %>
|
||||
<%= link_to l(:button_note), note_meal_path(m),
|
||||
{remote: true, class: "icon icon-wiki-page"} %>
|
||||
<div style="float: right; position: relative;">
|
||||
<%= meal_links(m) %>
|
||||
</div>
|
||||
</td>
|
||||
<td class="action unwrappable" style="width:5%"><%= meal_links(m) %></td>
|
||||
</tr>
|
||||
<% m.ingredients.each do |i| %>
|
||||
<tr id="ingredient-<%= i.id %>" class="ingredient">
|
||||
<td class="name" style="width: 100%;">
|
||||
<p>
|
||||
<tr id="ingredient-<%= i.id %>" class="ingredient project idnt idnt-1">
|
||||
<td class="name unwrappable" style="width: 5%;">
|
||||
<%= i.food.name %>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p style='white-space: nowrap;'>
|
||||
<%= adjust_ingredient_link(i, -5) %>
|
||||
<%= adjust_ingredient_link(i, -1) %>
|
||||
<%= i.amount %>
|
||||
<%= adjust_ingredient_link(i, 1) %>
|
||||
<%= adjust_ingredient_link(i, 5) %>
|
||||
</p>
|
||||
</td>
|
||||
<td class="action unwrappable" style="width:5%">
|
||||
<td style="text-align: left;" class="unwrappable">
|
||||
<%= adjust_ingredient_links(i) { raw " #{i.amount} " } %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
|
@ -27,35 +27,11 @@
|
||||
<%= q.name %>
|
||||
</div>
|
||||
</td>
|
||||
<td class="order">
|
||||
<% [:up, :down, :left, :right].each do |direction| %>
|
||||
<%=
|
||||
if q.movable?(direction)
|
||||
link_to '', move_quantity_path(q, direction), {
|
||||
remote: true,
|
||||
method: :post,
|
||||
class: "icon icon-move icon-move-#{direction}"
|
||||
}
|
||||
else
|
||||
link_to '', '', {class: "icon", style: "visibility: hidden;"}
|
||||
end
|
||||
%>
|
||||
<% end %>
|
||||
</td>
|
||||
<td class="order"><%= order_links(q) %></td>
|
||||
<td class="domain"><%= q.domain %></td>
|
||||
<td class="description"><%= q.description %></td>
|
||||
<td class="formula"><%= checked_image q.formula %></td>
|
||||
<td class="action unwrappable">
|
||||
<%= link_to l(:button_child), new_child_quantity_path(q), {
|
||||
remote: true,
|
||||
class: "icon icon-add"
|
||||
} %>
|
||||
<%= link_to l(:button_edit), edit_quantity_path(q), {
|
||||
remote: true,
|
||||
class: "icon icon-edit"
|
||||
} %>
|
||||
<%= delete_link quantity_path(q), {remote: true, data: {}} %>
|
||||
</td>
|
||||
<td class="action unwrappable"><%= action_links(q) %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
|
@ -25,6 +25,22 @@ table.list td.form {
|
||||
|
||||
fieldset#filters table.filter td {padding-left: 8px;}
|
||||
|
||||
a.icon:not(.icon-move) {margin-left: 0.3em;}
|
||||
a.button {
|
||||
margin: 0 0.2em;
|
||||
border: 0.1em solid;
|
||||
border-radius: 0.2em;
|
||||
text-align: center;
|
||||
text-decoration: none;
|
||||
font-size: 0.8em;
|
||||
display: inline-block;
|
||||
width: 2.6em;
|
||||
}
|
||||
a.button.green {border-color: green; color: green;}
|
||||
a.button.green:hover {background-color: green; color: white;}
|
||||
a.button.red {border-color: firebrick; color: firebrick;}
|
||||
a.button.red:hover {background-color: firebrick; color: white;}
|
||||
|
||||
|
||||
.icon-move-left { background-image: url(../images/1leftarrow.png); }
|
||||
.icon-move-right { background-image: url(../images/1rightarrow.png); }
|
||||
|
@ -18,6 +18,8 @@ en:
|
||||
field_formula: 'Formula'
|
||||
field_code: 'Formula'
|
||||
field_shortname: 'Short name'
|
||||
button_eat: 'Eat'
|
||||
button_note: 'Note'
|
||||
button_retake: 'Retake'
|
||||
button_child: 'Child'
|
||||
activerecord:
|
||||
|
@ -10,7 +10,12 @@ resources :projects, shallow: true do
|
||||
resources :ingredients, only: [] do
|
||||
post 'adjust/:adjustment', to: 'ingredients#adjust', as: :adjust, on: :member
|
||||
end
|
||||
resources :meals, only: [:index, :new, :create, :edit, :update, :destroy]
|
||||
resources :meals, only: [:index, :new, :create, :edit, :update, :destroy] do
|
||||
member do
|
||||
post 'note'
|
||||
post 'toggle_eaten'
|
||||
end
|
||||
end
|
||||
resources :measurement_routines, only: [:show, :edit] do
|
||||
member do
|
||||
get 'readouts', to: 'measurements#readouts'
|
||||
|
2
init.rb
2
init.rb
@ -24,7 +24,7 @@ Redmine::Plugin.register :body_tracking do
|
||||
permission :manage_common, {
|
||||
body_trackers: [:defaults],
|
||||
ingredients: [:adjust],
|
||||
meals: [:new, :create, :edit, :update, :destroy],
|
||||
meals: [:new, :create, :edit, :update, :destroy, :note, :toggle_eaten],
|
||||
measurement_routines: [:edit],
|
||||
measurements: [:new, :create, :edit, :update, :destroy, :retake, :toggle_column],
|
||||
foods: [:new, :create, :edit, :update, :destroy, :toggle, :toggle_column,
|
||||
|
Reference in New Issue
Block a user