Measurement index improvements
This commit is contained in:
parent
d6b3fe3f60
commit
b6dbf369d1
@ -1,6 +1,7 @@
|
|||||||
module MeasurementsHelper
|
module MeasurementsHelper
|
||||||
def format_datetime(m)
|
def format_datetime(m)
|
||||||
m.taken_at.getlocal.strftime("%F <small>%R</small>").html_safe
|
m.taken_at.getlocal
|
||||||
|
.strftime("%F <small>%R (#{time_ago_in_words(m.taken_at)} ago)</small>").html_safe
|
||||||
end
|
end
|
||||||
|
|
||||||
def format_time(m)
|
def format_time(m)
|
||||||
|
@ -2,7 +2,7 @@ class ColumnView < ActiveRecord::Base
|
|||||||
enum domain: Quantity.domains
|
enum domain: Quantity.domains
|
||||||
|
|
||||||
belongs_to :project, required: true
|
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 :name, presence: true, uniqueness: {scope: :domain}
|
||||||
validates :domain, inclusion: {in: domains.keys}
|
validates :domain, inclusion: {in: domains.keys}
|
||||||
@ -10,9 +10,10 @@ class ColumnView < ActiveRecord::Base
|
|||||||
# TODO: enforce column_view - quantity 'domain' identity
|
# TODO: enforce column_view - quantity 'domain' identity
|
||||||
def toggle_column!(q)
|
def toggle_column!(q)
|
||||||
column = self.quantities.find(q.id)
|
column = self.quantities.find(q.id)
|
||||||
self.quantites.destroy(column)
|
self.quantities.destroy(column)
|
||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
# Cannot 'create' association, as ColumnView (parent) may not be saved yet
|
# Cannot 'create' association, as ColumnView (parent) may not be saved yet
|
||||||
self.quantities.append(q).save!
|
self.quantities.append(q)
|
||||||
|
self.save!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -69,7 +69,8 @@ class Measurement < ActiveRecord::Base
|
|||||||
return unless old_column_view
|
return unless old_column_view
|
||||||
|
|
||||||
if self.project.measurements.exists?(name: self.name_was)
|
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
|
else
|
||||||
old_column_view.update!(name: self.name)
|
old_column_view.update!(name: self.name)
|
||||||
end
|
end
|
||||||
|
@ -24,7 +24,12 @@
|
|||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<tr class="<%= row_class %>" style="display:none">
|
<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>
|
<span class="icon icon-bullet-closed"><%= format_datetime(m) %></span>
|
||||||
</td>
|
</td>
|
||||||
<% @requested_r[index].each do |q_name, value| %>
|
<% @requested_r[index].each do |q_name, value| %>
|
||||||
@ -38,7 +43,6 @@
|
|||||||
<% next unless @quantities.length > 0 %>
|
<% next unless @quantities.length > 0 %>
|
||||||
<% @extra_r[index].each_slice(@quantities.length).with_index do |values| %>
|
<% @extra_r[index].each_slice(@quantities.length).with_index do |values| %>
|
||||||
<tr class="extra <%= row_class %>" style="display:none">
|
<tr class="extra <%= row_class %>" style="display:none">
|
||||||
<td class="space"></td>
|
|
||||||
<% values.each do |q_name, value| %>
|
<% values.each do |q_name, value| %>
|
||||||
<td class="extra">
|
<td class="extra">
|
||||||
<p class="quantity"><%= q_name %></p>
|
<p class="quantity"><%= q_name %></p>
|
||||||
|
@ -9,11 +9,10 @@ table.list .quantity {text-align: left;}
|
|||||||
table.list .action,
|
table.list .action,
|
||||||
table.list .value {text-align: right;}
|
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 th,
|
||||||
table.list td.action,
|
|
||||||
table.list td.date,
|
|
||||||
table.list td.name,
|
table.list td.name,
|
||||||
table.list td.quantity,
|
table.list td.quantity,
|
||||||
table.list td.value {
|
table.list td.value {
|
||||||
|
Reference in New Issue
Block a user