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