Preliminary Measurement edit/update
This commit is contained in:
parent
54040a2764
commit
7cb3ac4134
@ -2,7 +2,7 @@ class MeasurementsController < ApplicationController
|
|||||||
menu_item :body_trackers
|
menu_item :body_trackers
|
||||||
|
|
||||||
before_action :find_project_by_project_id, only: [:index, :create]
|
before_action :find_project_by_project_id, only: [:index, :create]
|
||||||
before_action :find_measurement, only: [:destroy, :retake]
|
before_action :find_measurement, only: [:edit, :update, :destroy, :retake]
|
||||||
before_action :authorize
|
before_action :authorize
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@ -25,6 +25,19 @@ class MeasurementsController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def edit
|
||||||
|
prepare_measurements
|
||||||
|
render :index
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
if @measurement.update(measurement_params)
|
||||||
|
flash[:notice] = 'Updated measurement'
|
||||||
|
end
|
||||||
|
prepare_measurements
|
||||||
|
render :index
|
||||||
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
# FIXME: don't destroy if there are any readout values
|
# FIXME: don't destroy if there are any readout values
|
||||||
if @measurement.destroy
|
if @measurement.destroy
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
<table class="list">
|
<table class="list">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th><%= l(:field_name) %></th>
|
|
||||||
<th><%= l(:field_taken_at_date) %></th>
|
<th><%= l(:field_taken_at_date) %></th>
|
||||||
|
<th><%= l(:field_name) %></th>
|
||||||
<th><%= l(:field_source) %></th>
|
<th><%= l(:field_source) %></th>
|
||||||
<th style="width:10%"><%= l(:field_action) %></th>
|
<th style="width:10%"><%= l(:field_action) %></th>
|
||||||
</tr>
|
</tr>
|
||||||
@ -12,17 +12,45 @@
|
|||||||
<% @measurements.each do |m| %>
|
<% @measurements.each do |m| %>
|
||||||
<% next if m.new_record? %>
|
<% next if m.new_record? %>
|
||||||
<tr id="measurement-<%= m.id %>" class="measurement <%= 'hidden' if m.hidden %>">
|
<tr id="measurement-<%= m.id %>" class="measurement <%= 'hidden' if m.hidden %>">
|
||||||
<td class="name"><%= m.name %></td>
|
|
||||||
<td class="date"><%= m.taken_at.strftime("%F %R") %></td>
|
<td class="date"><%= m.taken_at.strftime("%F %R") %></td>
|
||||||
|
<td class="name"><%= m.name %></td>
|
||||||
<td class="source"><%= m.source.name if m.source.present? %></td>
|
<td class="source"><%= m.source.name if m.source.present? %></td>
|
||||||
<td class="action">
|
<td class="action">
|
||||||
<%= link_to l(:button_retake), retake_measurement_path(m), {
|
<%= link_to l(:button_retake), retake_measurement_path(m), {
|
||||||
remote: true,
|
remote: true,
|
||||||
class: "icon icon-reload"
|
class: "icon icon-reload"
|
||||||
} %>
|
} %>
|
||||||
|
<%= link_to l(:button_edit), edit_measurement_path(m), {
|
||||||
|
remote: true,
|
||||||
|
class: "icon icon-edit"
|
||||||
|
} %>
|
||||||
<%= delete_link measurement_path(m), {remote: true, data: {}} %>
|
<%= delete_link measurement_path(m), {remote: true, data: {}} %>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<% next unless (m == @measurement) &&
|
||||||
|
((action_name == "edit") ||
|
||||||
|
(action_name == "update" && @measurement.errors.present?)) %>
|
||||||
|
<tr>
|
||||||
|
<td class="form" colspan="4">
|
||||||
|
<div id="edit-measurement">
|
||||||
|
<%= labelled_form_for @measurement,
|
||||||
|
url: measurement_path(@measurement),
|
||||||
|
method: :patch, remote: true,
|
||||||
|
html: {id: 'measurement-edit-form', name: 'measurement-edit-form'} do |f| %>
|
||||||
|
|
||||||
|
<%= render partial: 'measurements/form', locals: {f: f} %>
|
||||||
|
|
||||||
|
<div class="tabular">
|
||||||
|
<p>
|
||||||
|
<%= submit_tag l(:button_save) %>
|
||||||
|
<%= link_to l(:button_cancel), "#",
|
||||||
|
onclick: '$(this).closest("tr").remove(); return false;' %>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
@ -50,18 +50,16 @@
|
|||||||
<td class="description"><%= q.description %></td>
|
<td class="description"><%= q.description %></td>
|
||||||
<td class="formula"><%= checked_image q.formula.present? %></td>
|
<td class="formula"><%= checked_image q.formula.present? %></td>
|
||||||
<td class="action">
|
<td class="action">
|
||||||
<%=
|
<%= link_to l(:button_edit), edit_quantity_path(q), {
|
||||||
link_to l(:button_edit), edit_quantity_path(q), {
|
remote: true,
|
||||||
remote: true,
|
class: "icon icon-edit"
|
||||||
class: "icon icon-edit"
|
} %>
|
||||||
}
|
|
||||||
%>
|
|
||||||
<%= delete_link quantity_path(q), {remote: true, data: {}} %>
|
<%= delete_link quantity_path(q), {remote: true, data: {}} %>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<% next unless (q == @quantity) &&
|
<% next unless (q == @quantity) &&
|
||||||
((action_name == "edit") || (action_name == "update" && @quantity.errors.present?))
|
((action_name == "edit") ||
|
||||||
%>
|
(action_name == "update" && @quantity.errors.present?)) %>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="form" colspan="6">
|
<td class="form" colspan="6">
|
||||||
<div id="edit-quantity">
|
<div id="edit-quantity">
|
||||||
|
@ -5,7 +5,7 @@ resources :projects, shallow: true do
|
|||||||
resources :body_trackers, only: [:index] do
|
resources :body_trackers, only: [:index] do
|
||||||
collection do
|
collection do
|
||||||
post 'defaults'
|
post 'defaults'
|
||||||
resources :measurements, only: [:index, :create, :destroy] do
|
resources :measurements, only: [:index, :create, :edit, :update, :destroy] do
|
||||||
get 'retake', on: :member
|
get 'retake', on: :member
|
||||||
end
|
end
|
||||||
resources :ingredients, only: [:index, :create, :destroy] do
|
resources :ingredients, only: [:index, :create, :destroy] do
|
||||||
|
2
init.rb
2
init.rb
@ -24,7 +24,7 @@ Redmine::Plugin.register :body_tracking do
|
|||||||
}, read: true
|
}, read: true
|
||||||
permission :manage_common, {
|
permission :manage_common, {
|
||||||
body_trackers: [:defaults],
|
body_trackers: [:defaults],
|
||||||
measurements: [:create, :destroy, :retake],
|
measurements: [:create, :edit, :update, :destroy, :retake],
|
||||||
ingredients: [:create, :destroy, :toggle, :import, :toggle_nutrient_column],
|
ingredients: [:create, :destroy, :toggle, :import, :toggle_nutrient_column],
|
||||||
sources: [:create, :destroy],
|
sources: [:create, :destroy],
|
||||||
quantities: [:create, :edit, :update, :destroy, :toggle, :move],
|
quantities: [:create, :edit, :update, :destroy, :toggle, :move],
|
||||||
|
Reference in New Issue
Block a user