Added Measurement readouts action
This commit is contained in:
parent
9268b2dcc1
commit
40e9c6f8ae
@ -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
|
||||
|
4
app/views/measurements/_contextual.html.erb
Normal file
4
app/views/measurements/_contextual.html.erb
Normal file
@ -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 %>
|
@ -16,7 +16,9 @@
|
||||
<%= m.taken_at.getlocal.strftime("%F <small>%R</small>").html_safe %>
|
||||
</td>
|
||||
<td class="name">
|
||||
<div style="float:left;"><%= m.name %></div>
|
||||
<div style="float:left;">
|
||||
<%= link_to m.name, readouts_measurement_path(m) %>
|
||||
</div>
|
||||
<div style="float:right;">
|
||||
<small><%= " (#{pluralize(m.readouts.size, 'readout')})" %></small>
|
||||
</div>
|
||||
|
@ -3,12 +3,7 @@
|
||||
<% end %>
|
||||
|
||||
<div class="contextual">
|
||||
<% 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' %>
|
||||
</div>
|
||||
|
||||
<div id="new-measurement">
|
||||
|
19
app/views/measurements/readouts.html.erb
Normal file
19
app/views/measurements/readouts.html.erb
Normal file
@ -0,0 +1,19 @@
|
||||
<% content_for :sidebar do %>
|
||||
<%= render partial: 'body_trackers/sidebar' %>
|
||||
<% end %>
|
||||
|
||||
<div class="contextual">
|
||||
<%= render partial: 'measurements/contextual' %>
|
||||
</div>
|
||||
|
||||
<div id="new-measurement">
|
||||
</div>
|
||||
|
||||
<h2>
|
||||
<%= link_to t("measurements.index.heading"), project_measurements_path(@project) %>
|
||||
>
|
||||
<%= @measurements.first.name %>
|
||||
</h2>
|
||||
<div id='measurements'>
|
||||
<%= render partial: 'measurements/index' %>
|
||||
</div>
|
@ -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'
|
||||
|
@ -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
|
||||
|
2
init.rb
2
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],
|
||||
|
Reference in New Issue
Block a user