1
0

Added Measurement readouts action

This commit is contained in:
cryptogopher 2019-12-08 01:00:54 +01:00
parent 9268b2dcc1
commit 40e9c6f8ae
8 changed files with 42 additions and 11 deletions

View File

@ -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

View 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 %>

View File

@ -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>

View File

@ -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">

View 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>

View File

@ -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'

View File

@ -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

View File

@ -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],