upgrade pat3

This commit is contained in:
2013-12-21 16:46:07 +01:00
parent b4c4a15e60
commit c6f790eccd
12 changed files with 124 additions and 80 deletions
+16 -8
View File
@@ -4,7 +4,7 @@ class Section
include ActiveModel::SerializerSupport
property :title
property :path, type: Array, default: [[0.0, 0.0], [20.0, 30.0]] # default width 20m height 30m
property :path, type: Array, default: [[0.0, 0.0], [20.0, 0.0], [20.0, 30.0], [0.0, 30.0]] # default width 20m height 30m
belongs_to :supplier
has_many :tables
@@ -34,20 +34,25 @@ class Section
@active_orders ||= Order.active_for_supplier_and_section(supplier_id, id)
end
def width
self.path.last.try(:first).to_f - self.path.first.try(:first).to_f
x_coords = path.map(&:first)
x_coords.max - x_coords.min
end
def height
self.path.last.try(:last).to_f - self.path.first.try(:last).to_f
def height
y_coords = path.map(&:last)
y_coords.max - y_coords.min
end
def width=(val)
val = val.to_f
self.path[0] ||= [0.0, 0.0]
self.path[1] ||= [0.0, 0.0]
unless path[1][0] == val
self.path[2] ||= [0.0, 0.0]
self.path[3] ||= [0.0, 0.0]
unless path[1][0] == val && path[2][0] == val
self.path[1][0] = val
self.path[2][0] = val
path_will_change!
end
end
@@ -56,8 +61,11 @@ class Section
val = val.to_f
self.path[0] ||= [0.0, 0.0]
self.path[1] ||= [0.0, 0.0]
unless path[1][1] == val
self.path[1][1] = val
self.path[2] ||= [0.0, 0.0]
self.path[3] ||= [0.0, 0.0]
unless path[2][1] == val && path[3][1] == val
self.path[2][1] = val
self.path[3][1] = val
path_will_change!
end
end
+10 -5
View File
@@ -56,21 +56,26 @@ class Table
if tables.is_a?(Array)
lists = List.active_for_table(tables.map(&:id))
for table in tables
table.active_list_id = lists.find{|l| l.table_id == table.id}.try(:id)
if list = lists.find{|l| l.table_id == table.id}
table.active_list_id = list.id
table.active_list = list
end
end
tables
else
table = tables
list = List.active_for_table(table).first
table.active_list_id = list.id if list.present?
if list = List.active_for_table(table).first
table.active_list_id = list.id
table.active_list = list
end
table
end
end
def active_list
# nil memoizing
return @active_list if @active_list_is_set
@active_list ||= self.class.database.view(List.active_by_table_id_view(key: id, include_docs: true, reduce: false, limit: 1)).try(:first)
return @active_list if @active_list || @active_list_is_set
self.active_list = self.class.database.view(List.active_by_table_id_view(key: id, include_docs: true, reduce: false, limit: 1)).try(:first)
end
def active_list=(val)