1
0

Added setting taken_at in measurement form

Changed action toggle -> retake
This commit is contained in:
cryptogopher 2019-12-01 01:08:09 +01:00
parent fc2db76a3e
commit 54040a2764
10 changed files with 48 additions and 20 deletions

View File

@ -2,7 +2,7 @@ class MeasurementsController < ApplicationController
menu_item :body_trackers
before_action :find_project_by_project_id, only: [:index, :create]
before_action :find_measurement, only: [:destroy, :toggle]
before_action :find_measurement, only: [:destroy, :retake]
before_action :authorize
def index
@ -31,11 +31,10 @@ class MeasurementsController < ApplicationController
flash[:notice] = 'Deleted measurement'
end
prepare_measurements
render :toggle
render :index
end
def toggle
@measurement.toggle_hidden!
def retake
prepare_measurements
end

View File

@ -16,14 +16,30 @@ class Measurement < ActiveRecord::Base
end
validates :name, presence: true
validates :taken_at, presence: true
after_initialize do
if new_record?
self.hidden = false if self.hidden.nil?
self.taken_at = Time.now
end
end
def toggle_hidden!
self.toggle!(:hidden)
end
def taken_at_date
self.taken_at
end
def taken_at_date=(value)
self.taken_at = Time.parse(value, self.taken_at)
end
def taken_at_time
self.taken_at
end
def taken_at_time=(value)
self.taken_at = Time.parse(value, self.taken_at)
end
end

View File

@ -4,11 +4,16 @@
<p><%= f.select :source_id, source_options,
{required: false, include_blank: t('.null_source')} %></p>
<p><%= f.text_field :name, size: 40, required: true %></p>
<p>
<%= f.date_field :taken_at_date, required: true %>
<%= f.time_field :taken_at_time, value: @measurement.taken_at.strftime("%H:%M"),
required: true, label: '' %>
</p>
<% @measurement.readouts.each_with_index do |r, index| %>
<%= f.fields_for 'readouts_attributes', r, index: '' do |ff| %>
<p class="readout">
<%= ff.select :quantity_id, quantity_options,
{include_blank: true, label: (index > 0 ? '' : :field_readouts)} %>
{include_blank: true, required: true, label: (index > 0 ? '' : :field_readouts)} %>
<%= ff.number_field :value, {size: 8, step: :any, label: ''} %>
<%= ff.select :unit_id, unit_options, {label: ''} %>
<%= ff.check_box :_destroy, {style: "display:none", label: ''} %>

View File

@ -3,6 +3,7 @@
<thead>
<tr>
<th><%= l(:field_name) %></th>
<th><%= l(:field_taken_at_date) %></th>
<th><%= l(:field_source) %></th>
<th style="width:10%"><%= l(:field_action) %></th>
</tr>
@ -11,18 +12,14 @@
<% @measurements.each do |m| %>
<% next if m.new_record? %>
<tr id="measurement-<%= m.id %>" class="measurement <%= 'hidden' if m.hidden %>">
<td class="name">
<%= link_to '', toggle_measurement_path(m), {
remote: true,
method: :post,
class: "icon icon-eye"
} %>
<%= m.name %>
</td>
<td class="source">
<%= m.source.name if m.source.present? %>
</td>
<td class="name"><%= m.name %></td>
<td class="date"><%= m.taken_at.strftime("%F %R") %></td>
<td class="source"><%= m.source.name if m.source.present? %></td>
<td class="action">
<%= link_to l(:button_retake), retake_measurement_path(m), {
remote: true,
class: "icon icon-reload"
} %>
<%= delete_link measurement_path(m), {remote: true, data: {}} %>
</td>
</tr>

View File

@ -0,0 +1,3 @@
$('div[id^=flash_]').remove();
$('#content').prepend('<%= escape_javascript(render_flash_messages) %>');
$('#measurements').html('<%= escape_javascript(render partial: 'measurements/index') %>');

View File

@ -10,7 +10,7 @@
<th><%= l(:field_domain) %></th>
<th><%= l(:field_description) %></th>
<th><%= l(:field_formula) %></th>
<th><%= l(:field_action) %></th>
<th style="width:10%"><%= l(:field_action) %></th>
</tr>
</thead>
<tbody>

View File

@ -28,3 +28,9 @@ fieldset#filters table.filter td {padding-left: 8px;}
.icon-eye { background-image: url(../images/eye.png); }
.icon-bullet-open { background-image: url(../../../images/bullet_toggle_minus.png); }
.icon-bullet-closed { background-image: url(../../../images/bullet_toggle_plus.png); }
input[type=number] {-moz-appearance:textfield;}
input[type=date], input[type=time], input[type=number] {
border:1px solid #9EB1C2;
padding: 3px;
}

View File

@ -2,11 +2,12 @@
en:
body_trackers_menu_caption: 'Body trackers'
field_readouts: 'Readouts'
field_taken_at_date: 'Taken at'
field_order: 'Order'
field_action: 'Action'
field_reference: 'Reference'
field_group: 'Group'
field_source: 'Data source'
field_source: 'Source'
field_source_ident: 'Source identifier'
field_nutrients: 'Nutrients:'
field_domain: 'Domain'
@ -15,6 +16,7 @@ en:
field_primary: 'Primary'
field_shortname: 'Short name'
button_primary: 'Primary'
button_retake: 'Retake'
activerecord:
errors:
models:

View File

@ -6,7 +6,7 @@ resources :projects, shallow: true do
collection do
post 'defaults'
resources :measurements, only: [:index, :create, :destroy] do
post 'toggle', on: :member
get 'retake', on: :member
end
resources :ingredients, only: [:index, :create, :destroy] do
post 'toggle', on: :member

View File

@ -24,7 +24,7 @@ Redmine::Plugin.register :body_tracking do
}, read: true
permission :manage_common, {
body_trackers: [:defaults],
measurements: [:create, :destroy, :toggle],
measurements: [:create, :destroy, :retake],
ingredients: [:create, :destroy, :toggle, :import, :toggle_nutrient_column],
sources: [:create, :destroy],
quantities: [:create, :edit, :update, :destroy, :toggle, :move],