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>