diff --git a/app/controllers/measurements_controller.rb b/app/controllers/measurements_controller.rb index 8eead3f..d3adb1e 100644 --- a/app/controllers/measurements_controller.rb +++ b/app/controllers/measurements_controller.rb @@ -2,10 +2,11 @@ class MeasurementsController < ApplicationController menu_item :body_trackers before_action :find_project_by_project_id, only: [:index, :new, :create] - before_action :find_measurement, only: [:edit, :update, :destroy, :retake] + before_action :find_measurement, only: [:edit, :update, :destroy, :retake, :readouts] before_action :authorize def index + session[:m_scope] = {} prepare_measurements end @@ -53,6 +54,11 @@ class MeasurementsController < ApplicationController render :new end + def readouts + session[:m_scope] = {name: @measurement.name} + prepare_measurements + end + private def measurement_params @@ -81,5 +87,6 @@ class MeasurementsController < ApplicationController def prepare_measurements @measurements = @project.measurements.includes(:source, :readouts) + .where(session[:m_scope]) end end diff --git a/app/views/measurements/_contextual.html.erb b/app/views/measurements/_contextual.html.erb new file mode 100644 index 0000000..fc10feb --- /dev/null +++ b/app/views/measurements/_contextual.html.erb @@ -0,0 +1,4 @@ +<% if User.current.allowed_to?(:manage_common, @project) %> + <%= link_to t(".link_new_measurement"), new_project_measurement_path(@project), + {remote: true, class: 'icon icon-add'} %> +<% end %> diff --git a/app/views/measurements/_index.html.erb b/app/views/measurements/_index.html.erb index a4ddd07..5ce6b63 100644 --- a/app/views/measurements/_index.html.erb +++ b/app/views/measurements/_index.html.erb @@ -16,7 +16,9 @@ <%= m.taken_at.getlocal.strftime("%F %R").html_safe %> -
<%= m.name %>
+
+ <%= link_to m.name, readouts_measurement_path(m) %> +
<%= " (#{pluralize(m.readouts.size, 'readout')})" %>
diff --git a/app/views/measurements/index.html.erb b/app/views/measurements/index.html.erb index dd10925..26cdcdc 100644 --- a/app/views/measurements/index.html.erb +++ b/app/views/measurements/index.html.erb @@ -3,12 +3,7 @@ <% end %>
- <% if User.current.allowed_to?(:manage_common, @project) %> - <%= link_to t(".link_new_measurement"), new_project_measurement_path(@project), { - remote: true, - class: 'icon icon-add' - } %> - <% end %> + <%= render partial: 'measurements/contextual' %>
diff --git a/app/views/measurements/readouts.html.erb b/app/views/measurements/readouts.html.erb new file mode 100644 index 0000000..c834116 --- /dev/null +++ b/app/views/measurements/readouts.html.erb @@ -0,0 +1,19 @@ +<% content_for :sidebar do %> + <%= render partial: 'body_trackers/sidebar' %> +<% end %> + +
+ <%= render partial: 'measurements/contextual' %> +
+ +
+
+ +

+ <%= link_to t("measurements.index.heading"), project_measurements_path(@project) %> + > + <%= @measurements.first.name %> +

+
+ <%= render partial: 'measurements/index' %> +
diff --git a/config/locales/en.yml b/config/locales/en.yml index 56f2b80..bb63375 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -58,6 +58,8 @@ en: link_defaults: 'Load defaults' confirm_defaults: 'This will load default quantities and units. Continue?' measurements: + contextual: + link_new_measurement: 'New measurement' form: button_new_readout: 'Add readout' button_delete_readout: 'Delete' @@ -66,7 +68,6 @@ en: heading_new_measurement: 'New measurement' index: heading: 'Measurements' - link_new_measurement: 'New measurement' ingredients: contextual: link_import_ingredients: 'Import' diff --git a/config/routes.rb b/config/routes.rb index 9e23d26..22d9d5a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,7 +6,10 @@ resources :projects, shallow: true do collection do post 'defaults' resources :measurements, only: [:index, :new, :create, :edit, :update, :destroy] do - get 'retake', on: :member + member do + get 'retake' + get 'readouts' + end end resources :ingredients, only: [:index, :create, :destroy] do post 'toggle', on: :member diff --git a/init.rb b/init.rb index 0e840f7..4a9f9d5 100644 --- a/init.rb +++ b/init.rb @@ -16,7 +16,7 @@ Redmine::Plugin.register :body_tracking do project_module :body_tracking do permission :view_body_trackers, { body_trackers: [:index], - measurements: [:index], + measurements: [:index, :readouts], ingredients: [:index, :nutrients, :filter, :filter_nutrients], sources: [:index], quantities: [:index, :parents, :filter],