1
0

Last changes on Redmine 4.0

This commit is contained in:
cryptogopher 2022-07-24 16:46:28 +02:00
parent 745e1f4264
commit 71bfc5a33a
18 changed files with 154 additions and 60 deletions

View File

@ -40,15 +40,6 @@ module Concerns::Finders
render_404
end
def find_measurement
@measurement = Measurement.find(params[:id])
# DON'T set @routine here: @routine is a context for :readouts view (set
# elsewhere), not a # @measurement.routine
@project = @measurement.routine.project
rescue ActiveRecord::RecordNotFound
render_404
end
def find_measurement_routine(id = params[:id])
@routine = MeasurementRoutine.find(id)
@project = @routine.project
@ -60,6 +51,17 @@ module Concerns::Finders
find_measurement_routine(params[:measurement_routine_id])
end
def find_measurement(id = params[:id])
@measurement = Measurement.find(id)
@project = @measurement.routine.project
rescue ActiveRecord::RecordNotFound
render_404
end
def find_measurement_by_measurement_id
find_measurement(params[:measurement_id])
end
def find_quantity(id = params[:id])
@quantity = Quantity.find(id)
@project = @quantity.project

View File

@ -9,7 +9,7 @@ class MeasurementsController < ApplicationController
before_action :find_project_by_project_id, only: [:index, :new, :create, :filter]
before_action :find_measurement, only: [:edit, :update, :destroy, :retake]
before_action :find_measurement_routine_by_measurement_routine_id,
only: [:new, :create, :edit, :update, :retake, :filter]
only: [:new, :create, :filter]
before_action :authorize
before_action :set_view_params

View File

@ -2,12 +2,12 @@ class ReadoutsController < ApplicationController
layout 'body_tracking'
menu_item :body_trackers
helper :body_trackers
helper :measurements
include Concerns::Finders
before_action :find_measurement_routine_by_measurement_routine_id,
only: [:index, :toggle_exposure]
before_action :find_measurement_by_measurement_id, only: [:edit, :update]
before_action :find_quantity_by_quantity_id, only: [:toggle_exposure]
before_action :authorize
@ -15,6 +15,22 @@ class ReadoutsController < ApplicationController
prepare_readouts
end
def edit
end
def update
if @measurement.update(measurement_params)
count = @measurement.readouts.target.count { |r| r.previous_changes.present? }
flash.now[:notice] = t('.success', count: count)
@routine = @measurement.routine
prepare_readouts
render :index
else
render :edit
end
end
def toggle_exposure
@routine.readout_exposures.toggle!(@quantity)
prepare_readouts
@ -22,6 +38,21 @@ class ReadoutsController < ApplicationController
private
def measurement_params
params.require(:measurement).permit(
:notes,
:source_id,
readouts_attributes:
[
:id,
:quantity_id,
:value,
:unit_id,
:_destroy
]
)
end
def prepare_readouts
@quantities = @routine.quantities.includes(:formula)

View File

@ -1,14 +1,8 @@
module MeasurementsHelper
def readout_markup(quantity, readout)
content = "#{'&emsp;'*quantity.depth}#{quantity.name} #{format_amount(readout)}"
classes = 'bolded' if @routine.quantities.include?(quantity)
content_tag(:span, content, {class: classes}, false)
end
def action_links(m)
link_to(l(:button_retake), retake_measurement_path(m, @view_params),
link_to(l(:button_retake), retake_measurement_path(m),
{remote: true, class: "icon icon-reload"}) +
link_to(l(:button_edit), edit_measurement_path(m, @view_params),
link_to(l(:button_edit), edit_measurement_path(m),
{remote: true, class: "icon icon-edit"}) +
delete_link(measurement_path(m), {remote: true, data: {}})
end

View File

@ -0,0 +1,15 @@
module ReadoutsHelper
def readout_markup(quantity, readout)
content = "#{'&emsp;'*quantity.depth}#{quantity.name} #{format_amount(readout)}"
classes = 'bolded' if @routine.quantities.include?(quantity)
content_tag(:span, content, {class: classes}, false)
end
def action_links(m)
link_to(l(:button_retake), retake_measurement_path(m),
{remote: true, class: "icon icon-reload"}) +
link_to(l(:button_edit), edit_measurement_readouts_path(m),
{remote: true, class: "icon icon-edit"}) +
delete_link(measurement_path(m), {remote: true, data: {}})
end
end

View File

@ -0,0 +1,9 @@
<div id='measurement-routine-form'>
<% if @measurement.routine.persisted? %>
<%= render partial: 'measurement_routines/show_form',
locals: {routine: @measurement.routine} %>
<% else %>
<%= render partial: 'measurement_routines/form',
locals: {routine: @measurement.routine} %>
<% end %>
</div>

View File

@ -1,13 +1,33 @@
<div class="tabular">
<%= fields_for 'measurement[routine_attributes]', routine do |ff| %>
<%= ff.hidden_field :id %>
<div id='measurement-routine-form' class="tabular">
<%= fields_for :routine do |routine_f| %>
<p>
<label><%= l(:field_name) %><span class="required"> *</span></label>
<%= ff.text_field :name, required: true, style: "width: 95%;" %>
</p>
<p>
<label><%= l(:field_description) %></label>
<%= ff.text_area :description, cols: 40, rows: 3, style: "width: 95%;" %>
<%= routine_f.select :id, options_from_collection_for_select(
@project.measurement_routines, :id, :name, @routine.id),
{required: true}, autocomplete: 'off',
onchange: "var mr_id = $('#measurement_routine_attributes_id').val();
$.ajax({
url: '#{measurement_routine_path(id: :mr_id)}'.replace('mr_id', mr_id),
dataType: 'script'
});
return false;" %>
<%= link_to_if l(:button_edit), '#',
onclick: "var mr_id = $('#measurement_routine_attributes_id').val();
$.ajax({
url: '#{edit_measurement_routine_path(id: :mr_id)}'.replace('mr_id', mr_id),
dataType: 'script'
});
return false;",
class: 'icon icon-edit' %>
<%= link_to_if l(:button_cancel), '#', onclick: "cancel edit" %>
</p>
<% if @routine.persisted? %>
<% if @routine.description? %>
<p style='white-space: pre-wrap;' ><%= @routine.description %></p>
<% end %>
<% else %>
<p><%= routine_f.text_field :name, required: true, style: "width: 95%;" %></p>
<p><%= ff.text_area :description, cols: 40, rows: 3, style: "width: 95%;" %></p>
<% end %>
<% end %>
</div>

View File

@ -1,8 +1,11 @@
<%= labelled_form_for @measurement, url: measurement_path(@measurement, @view_params),
<%= labelled_form_for @measurement, url: measurement_path(@measurement),
method: :patch, remote: true,
html: {id: 'edit-measurement-form', name: 'edit-measurement-form'} do |measurement_f| %>
<div class="box tabular">
<%= render partial: 'measurement_routines/form',
locals: {measurement_f: measurement_f} %>
<hr style="width: 95%;">
<%= render partial: 'measurements/form', locals: {measurement_f: measurement_f} %>
</div>

View File

@ -1,17 +1,5 @@
<%= error_messages_for @measurement %>
<div id='measurement-routine-form'>
<% if @measurement.routine.persisted? %>
<%= render partial: 'measurement_routines/show_form',
locals: {routine: @measurement.routine} %>
<% else %>
<%= render partial: 'measurement_routines/form',
locals: {routine: @measurement.routine} %>
<% end %>
</div>
<hr style="width: 95%;">
<div class="splitcontent">
<div class="splitcontentleft">
<p>

View File

@ -1,10 +1,10 @@
<%= render partial: 'measurements/filters',
locals: {url: filter_project_measurements_path(@project, @view_params)} %>
<% if @measurements.any? { |m| m.persisted? } %>
<% if @measurements.any? %>
<%= error_messages_for @filter_q.formula if @filter_q %>
<table class="list">
<table id="measurements" class="list">
<thead>
<tr>
<th style="width:5%"><%= l(:field_taken_at_date) %></th>
@ -16,8 +16,7 @@
</thead>
<tbody>
<% @measurements.each do |m| %>
<% next if m.new_record? %>
<tr id="measurement-<%= m.id %>" class="primary measurement">
<tr id="measurement-<%= m.id %>" class="measurement">
<td class="topleft unwrappable"><%= format_datetime(m.taken_at) %></td>
<td class="topleft">
<div style="float:left;">

View File

@ -1,8 +1,9 @@
$('tr[id=measurement-<%= @measurement.id %>]').nextUntil('tr.primary', ':not(.measurement)')
.remove();
var columns = $('table > thead > tr > th').length;
$('tr[id=measurement-<%= @measurement.id %>]').nextUntil('tr.primary').addBack().last().after(
'<tr><td class="form" colspan="'+columns+'"><div id="edit-measurement">' +
'<%= j render partial: 'measurements/edit_form' %>' +
'</div></td></tr>'
$('tr[id=measurement-<%= @measurement.id %>]').nextUntil('tr.measurement')
.remove().addBack().first().after(
'<tr>' +
'<td class="topleft symmetric"' +
'colspan="'+$('table#measurements tr:first-child td').length+'">' +
'<%= j render partial: 'measurements/edit_form' %>' +
'</td>' +
'</tr>'
);

View File

@ -1,5 +1 @@
<% if @view_params[:view] == :index %>
$('#measurements').html('<%= j render partial: 'measurements/index' %>');
<% else %>
$('#readouts').html('<%= j render partial: 'measurements/readouts' %>');
<% end %>
$('#measurements').html('<%= j render partial: 'measurements/index' %>');

View File

@ -0,0 +1,17 @@
<%= labelled_form_for @measurement, url: measurement_readouts_path(@measurement),
method: :patch, remote: true,
html: {id: 'edit-measurement-form', name: 'edit-measurement-form'} do |measurement_f| %>
<div class="box tabular">
<%= render partial: 'measurements/form', locals: {measurement_f: measurement_f} %>
</div>
<div class="tabular">
<p>
<%= submit_tag l(:button_save) %>
<%= link_to l(:button_cancel), "#",
onclick: '$(this).closest("tr").nextUntil("tr.measurement", "tr.details").show()
.addBack().first().remove(); return false;' %>
</p>
</div>
<% end %>

View File

@ -0,0 +1,9 @@
$('tr[id=measurement-<%= @measurement.id %>]').nextUntil('tr.measurement')
.remove('tr:not(.details)').hide().addBack().first().after(
'<tr>' +
'<td class="topleft symmetric"' +
'colspan="'+$('table#readouts tr:first-child td').length+'">' +
'<%= j render partial: 'readouts/edit_form' %>' +
'</td>' +
'</tr>'
);

View File

@ -0,0 +1 @@
$('#readouts').html('<%= j render partial: 'readouts/index' %>');

View File

@ -124,11 +124,12 @@ en:
other: "Created %{count} targets"
update:
success:
zero: "Targets left unchanged"
one: "Successfully updated target"
other: "Successfully updated targets"
other: "Successfully updated %{count} targets"
destroy:
success:
one: "Deleted 1 target"
one: "Deleted target"
other: "Deleted %{count} targets"
failure: "Some targets have not been deleted"
meals:
@ -158,6 +159,12 @@ en:
heading_new_measurement: 'New measurement'
index:
heading: 'Measurements'
readouts:
update:
success:
zero: "Successfully updated measurement"
one: "Successfully updated readout"
other: "Successfully updated %{count} readouts"
foods:
contextual:
link_import_foods: 'Import'

View File

@ -30,7 +30,9 @@ resources :projects, shallow: true do
resources :readouts, only: [:index]
post 'toggle_exposure', controller: :readouts
end
# TODO: nest measurements inside routines?
resources :measurements, except: [:show] do
resource :readouts, only: [:edit, :update]
member do
get 'retake'
end

View File

@ -35,7 +35,7 @@ Redmine::Plugin.register :body_tracking do
:toggle_eaten, :toggle_exposure, :adjust],
measurement_routines: [:edit],
measurements: [:new, :create, :edit, :update, :destroy, :retake],
readouts: [:toggle_exposure],
readouts: [:edit, :update, :toggle_exposure],
foods: [:new, :create, :edit, :update, :destroy, :toggle, :toggle_exposure,
:import],
sources: [:create, :destroy],