1
0

Added measurement index view

Changed locales names from heading_ to link_ where appropriate
This commit is contained in:
cryptogopher 2019-11-16 14:44:45 +01:00
parent b7b0f7634e
commit eb379c7835
8 changed files with 124 additions and 11 deletions

View File

@ -1,6 +1,6 @@
<% if User.current.allowed_to?(:manage_common, @project) %>
<%= link_to t(".heading_import_ingredients"), '#', :class => 'icon icon-multiple',
<%= link_to t(".link_import_ingredients"), '#', :class => 'icon icon-multiple',
:onclick => '$("#import-ingredients").show(); $("#filename").focus(); return false;' %>
<%= link_to t(".heading_new_ingredient"), '#', :class => 'icon icon-add',
<%= link_to t(".link_new_ingredient"), '#', :class => 'icon icon-add',
:onclick => '$("#add-ingredient").show(); $("#ingredient_name").focus(); return false;' %>
<% end %>

View File

@ -0,0 +1,59 @@
<div id="add-measurement" <%= 'style=display:none;' if @measurement.errors.empty? %>>
<h2><%= t ".heading_new_measurement" %></h2>
<%= labelled_form_for @measurement,
:url => project_measurements_path(@project),
:html => {:id => 'measurement-form'} do |f| %>
<%= error_messages_for @measurement %>
<div class="box tabular">
<p><%= f.text_field :name, size: 40, required: true %></p>
<p><%= f.select :source_id, source_options, required: false, include_blank: true %></p>
<% @measurements.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)} %>
<%= ff.select :unit_id, unit_options, {label: ''} %>
<%= ff.check_box :_destroy, {style: "display:none", label: ''} %>
<%= link_to t(".button_delete_readout"), '#',
:class => 'icon icon-del',
:style => (@measurement.readouts.length > 1 ? "" : "display:none"),
:onclick => "deleteReadout(); return false;" %>
</p>
<% end %>
<% end %>
<p>
<%= link_to t(".button_add_readout"), '#', :class => 'icon icon-add',
:onclick => 'addReadout(); return false;' %>
</p>
</div>
<%= submit_tag l(:button_create) %>
<%= link_to l(:button_cancel), "#", :onclick => '$("#add-measurement").hide()' %>
<% end %>
<hr>
</div>
<%= javascript_tag do %>
function addReadout() {
var row = $('p.readout:visible:last');
var new_row = row.clone().insertAfter(row);
new_row.find('select[id$=_quantity_id]').val('');
new_row.find('select[id$=_unit_id]').val(row.find('select[id$=_unit_id]').val());
new_row.find('label:first').text('');
if ($('p.readout:visible').length > 1) {
$('p.readout a.icon-del').show();
}
}
function deleteReadout() {
var row = $(event.target).closest('p.readout');
row.find('[id$=_destroy]').val(1);
// FIXME: should only hide() row if record already saved (to send _destroy to backend)
row.remove();
$('p.readout:visible:first label:first').text('<%= t "field_readouts" %>');
if ($('p.readout:visible').length <= 1) {
$('p.readout a.icon-del').hide();
}
}
<% end %>

View File

@ -0,0 +1,34 @@
<% if @measurements.any? { |m| m.persisted? } %>
<table class="list">
<thead>
<tr>
<th><%= l(:field_name) %></th>
<th><%= l(:field_source) %></th>
<th style="width:10%"><%= l(:field_action) %></th>
</tr>
</thead>
<tbody>
<% @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="action">
<%= delete_link measurement_path(m), {remote: true, data: {}} %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% else %>
<p class="nodata"><%= l(:label_no_data) %></p>
<% end %>

View File

@ -1 +1,17 @@
<h2>MeasurementsController#index</h2>
<% content_for :sidebar do %>
<%= render :partial => 'body_trackers/sidebar' %>
<% end %>
<div class="contextual">
<% if User.current.allowed_to?(:manage_common, @project) %>
<%= link_to t(".link_new_measurement"), '#', :class => 'icon icon-add',
:onclick => '$("#add-measurement").show(); $("#measurement_name").focus(); return false;' %>
<% end %>
</div>
<%= render :partial => 'measurements/form' %>
<h2><%= t ".heading" %></h2>
<div id='measurements'>
<%= render :partial => 'measurements/list' %>
</div>

View File

@ -4,7 +4,7 @@
<div class="contextual">
<% if User.current.allowed_to?(:manage_common, @project) %>
<%= link_to t(".heading_new_quantity"), '#', :class => 'icon icon-add',
<%= link_to t(".link_new_quantity"), '#', :class => 'icon icon-add',
:onclick => '$("#add-quantity").show(); $("#quantity_name").focus(); return false;' %>
<% end %>
</div>

View File

@ -4,7 +4,7 @@
<div class="contextual">
<% if User.current.allowed_to?(:manage_common, @project) %>
<%= link_to t(".heading_new_source"), '#', :class => 'icon icon-add',
<%= link_to t(".link_new_source"), '#', :class => 'icon icon-add',
:onclick => '$("#add-source").show(); $("#source_name").focus(); return false;' %>
<% end %>
</div>

View File

@ -4,7 +4,7 @@
<div class="contextual">
<% if User.current.allowed_to?(:manage_common, @project) %>
<%= link_to t(".heading_new_unit"), '#', :class => 'icon icon-add',
<%= link_to t(".link_new_unit"), '#', :class => 'icon icon-add',
:onclick => '$("#add-unit").show(); $("#unit_shortname").focus(); return false;' %>
<% end %>
</div>

View File

@ -1,6 +1,7 @@
# English strings go here for Rails i18n
en:
body_trackers_menu_caption: 'Body trackers'
field_readouts: 'Readouts'
field_order: 'Order'
field_action: 'Action'
field_reference: 'Reference'
@ -51,11 +52,14 @@ en:
confirm_defaults: 'This will load default quantities and units. Continue?'
measurements:
form:
heading_new_measurement: 'New measurement'
index:
heading: 'Measurements'
link_new_measurement: 'New measurement'
ingredients:
contextual:
heading_import_ingredients: 'Import'
heading_new_ingredient: 'New ingredient'
link_import_ingredients: 'Import'
link_new_ingredient: 'New ingredient'
import:
heading_import_ingredients: 'Import'
label_import_select_csv_file: 'Select CSV file'
@ -84,11 +88,11 @@ en:
sources:
index:
heading: 'Data sources'
heading_new_source: 'New source'
link_new_source: 'New source'
quantities:
index:
heading: 'Quantities'
heading_new_quantity: 'New quantity'
link_new_quantity: 'New quantity'
form:
domains:
measurement: 'measurement'
@ -100,4 +104,4 @@ en:
units:
index:
heading: 'Units'
heading_new_unit: 'New unit'
link_new_unit: 'New unit'