diff --git a/app/controllers/meals_controller.rb b/app/controllers/meals_controller.rb index 636257e..8315068 100644 --- a/app/controllers/meals_controller.rb +++ b/app/controllers/meals_controller.rb @@ -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 diff --git a/app/controllers/measurements_controller.rb b/app/controllers/measurements_controller.rb index be996d9..f19cb23 100644 --- a/app/controllers/measurements_controller.rb +++ b/app/controllers/measurements_controller.rb @@ -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 diff --git a/app/helpers/meals_helper.rb b/app/helpers/meals_helper.rb index 3c6f976..903215f 100644 --- a/app/helpers/meals_helper.rb +++ b/app/helpers/meals_helper.rb @@ -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 diff --git a/app/helpers/quantities_helper.rb b/app/helpers/quantities_helper.rb index cee9a01..b3c3815 100644 --- a/app/helpers/quantities_helper.rb +++ b/app/helpers/quantities_helper.rb @@ -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| diff --git a/app/views/meals/_index.html.erb b/app/views/meals/_index.html.erb index 446e560..94eb22f 100644 --- a/app/views/meals/_index.html.erb +++ b/app/views/meals/_index.html.erb @@ -1,35 +1,34 @@ <% if @meals.any? { |m| m.persisted? } %> - +
<% @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? %> - <% m.ingredients.each do |i| %> - - + - - <% end %> diff --git a/app/views/quantities/_index.html.erb b/app/views/quantities/_index.html.erb index 0feb4e8..cae4169 100644 --- a/app/views/quantities/_index.html.erb +++ b/app/views/quantities/_index.html.erb @@ -27,35 +27,11 @@ <%= q.name %> - + - + <% end %> diff --git a/assets/stylesheets/body_tracking.css b/assets/stylesheets/body_tracking.css index 6abefc6..813fe5f 100644 --- a/assets/stylesheets/body_tracking.css +++ b/assets/stylesheets/body_tracking.css @@ -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); } diff --git a/config/locales/en.yml b/config/locales/en.yml index d084d02..8cc3bff 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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: diff --git a/config/routes.rb b/config/routes.rb index 704ce03..7d416b6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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' diff --git a/init.rb b/init.rb index 4fdeaaf..b333a88 100644 --- a/init.rb +++ b/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,
-

- <%= "#{t '.label_meal'}" %><%= index ? " ##{index+1}" : " (new)" %> - <%= ", #{m.eaten_at.time}" if m.eaten_at %> -

+ <%= "#{t '.label_meal'} ##{index+1}" %> + <% 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"} %> +
+ <%= meal_links(m) %> +
<%= meal_links(m) %>
-

+

<%= i.food.name %> -

-

- <%= adjust_ingredient_link(i, -5) %> - <%= adjust_ingredient_link(i, -1) %> - <%= i.amount %> - <%= adjust_ingredient_link(i, 1) %> - <%= adjust_ingredient_link(i, 5) %> -

-
+ + <%= adjust_ingredient_links(i) { raw " #{i.amount} " } %>
- <% [: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 %> - <%= order_links(q) %> <%= q.domain %> <%= q.description %> <%= checked_image q.formula %> - <%= 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: {}} %> - <%= action_links(q) %>