upgrade pat3
This commit is contained in:
+16
-8
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user