1
0

Measurement index improvements

This commit is contained in:
cryptogopher 2019-12-21 18:01:46 +01:00
parent d6b3fe3f60
commit b6dbf369d1
5 changed files with 16 additions and 10 deletions

View File

@ -1,6 +1,7 @@
module MeasurementsHelper
def format_datetime(m)
m.taken_at.getlocal.strftime("%F <small>%R</small>").html_safe
m.taken_at.getlocal
.strftime("%F <small>%R&emsp;(#{time_ago_in_words(m.taken_at)} ago)</small>").html_safe
end
def format_time(m)

View File

@ -2,7 +2,7 @@ class ColumnView < ActiveRecord::Base
enum domain: Quantity.domains
belongs_to :project, required: true
has_and_belongs_to_many :quantities
has_and_belongs_to_many :quantities, -> { order "lft" }
validates :name, presence: true, uniqueness: {scope: :domain}
validates :domain, inclusion: {in: domains.keys}
@ -10,9 +10,10 @@ class ColumnView < ActiveRecord::Base
# TODO: enforce column_view - quantity 'domain' identity
def toggle_column!(q)
column = self.quantities.find(q.id)
self.quantites.destroy(column)
self.quantities.destroy(column)
rescue ActiveRecord::RecordNotFound
# Cannot 'create' association, as ColumnView (parent) may not be saved yet
self.quantities.append(q).save!
self.quantities.append(q)
self.save!
end
end

View File

@ -69,7 +69,8 @@ class Measurement < ActiveRecord::Base
return unless old_column_view
if self.project.measurements.exists?(name: self.name_was)
self.column_view.quantities.append(old_column_view.quantities).save!
self.column_view.quantities.append(old_column_view.quantities)
self.save!
else
old_column_view.update!(name: self.name)
end

View File

@ -24,7 +24,12 @@
</tr>
<tr class="<%= row_class %>" style="display:none">
<td class="date" style="cursor: pointer;" onclick="$(this).closest('tr').prev('tr.primary').toggle(); $(this).closest('tr').prev('tr.primary').nextUntil('tr.primary', 'tr').toggle(); return false;">
<% if @quantities.length > 0
rows = (@extra_r[index].length - 1) / @quantities.length + 2
else
rows = 1
end %>
<td rowspan="<%= rows %>" class="date" style="cursor: pointer;" onclick="$(this).closest('tr').prev('tr.primary').toggle(); $(this).closest('tr').prev('tr.primary').nextUntil('tr.primary', 'tr').toggle(); return false;">
<span class="icon icon-bullet-closed"><%= format_datetime(m) %></span>
</td>
<% @requested_r[index].each do |q_name, value| %>
@ -38,7 +43,6 @@
<% next unless @quantities.length > 0 %>
<% @extra_r[index].each_slice(@quantities.length).with_index do |values| %>
<tr class="extra <%= row_class %>" style="display:none">
<td class="space"></td>
<% values.each do |q_name, value| %>
<td class="extra">
<p class="quantity"><%= q_name %></p>

View File

@ -9,11 +9,10 @@ table.list .quantity {text-align: left;}
table.list .action,
table.list .value {text-align: right;}
table.list .space {border-top: none; border-bottom: none;}
table.list td.action,
table.list td.date {white-space: nowrap;}
table.list th,
table.list td.action,
table.list td.date,
table.list td.name,
table.list td.quantity,
table.list td.value {