End of day commit
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
class SupplierEmployeesSettings
|
||||
attr_reader :dictionary, :employee_ids, :supplier
|
||||
def initialize(supplier)
|
||||
@supplier = supplier
|
||||
@dictionary = supplier.employee_settings_storage || {}
|
||||
@employee_ids = supplier.employee_ids || []
|
||||
end
|
||||
|
||||
def for_employee(employee_id)
|
||||
employee_id = employee_id.id if employee_id.is_a?(Employee)
|
||||
if employee_ids.include? employee_id
|
||||
SupplierEmployeeSettings.new(self, employee_id, dictionary[employee_id])
|
||||
else
|
||||
SupplierEmployeeSettings::NullObject.new
|
||||
end
|
||||
end
|
||||
|
||||
def [](val)
|
||||
val = val.to_s
|
||||
if dictionary[val].is_a? SettingsPersistor
|
||||
dictionary[val]
|
||||
else
|
||||
dictionary[val] = SettingsPersistor.new(self, dictionary[val])
|
||||
end
|
||||
end
|
||||
|
||||
def persist
|
||||
supplier.employee_settings_storage = dictionary
|
||||
end
|
||||
|
||||
def method_missing(m, *args)
|
||||
dictionary.send(m, *args)
|
||||
end
|
||||
|
||||
class SettingsPersistor < Hash
|
||||
attr_reader :all_employees_settings
|
||||
def initialize(all_employees_settings, options = {})
|
||||
@all_employees_settings = all_employees_settings
|
||||
self.replace options if options.is_a? Hash
|
||||
end
|
||||
|
||||
def []=(*args)
|
||||
super
|
||||
all_employees_settings.persist
|
||||
end
|
||||
end
|
||||
|
||||
class SupplierEmployeeSettings
|
||||
delegate :as_json, :to_json, to: :settings
|
||||
DEFAULTS = {
|
||||
'manager' => false
|
||||
}
|
||||
attr_reader :id, :settings, :all_employees_settings
|
||||
class NullObject < ::NullObject
|
||||
end
|
||||
|
||||
def initialize(all_employees_settings, employee_id, settings = {})
|
||||
@all_employees_settings = all_employees_settings
|
||||
@id = employee_id
|
||||
@settings = DEFAULTS.merge(settings || {})
|
||||
end
|
||||
|
||||
def manager?
|
||||
settings['manager']
|
||||
end
|
||||
|
||||
def is_manager!
|
||||
all_employees_settings[id]['manager'] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,6 +0,0 @@
|
||||
class SupplierExtendedSectionSerializer < Qwaiter::Serializer
|
||||
root 'section'
|
||||
embed :ids, include: true
|
||||
attributes :title, :path, :width, :height
|
||||
has_many :tables, serializer: SupplierExtendedTableSerializer
|
||||
end
|
||||
@@ -1,10 +0,0 @@
|
||||
class SupplierSupplierSerializer < Qwaiter::Serializer
|
||||
self.root = :supplier
|
||||
attributes :extended_version, :open, :name, :lat, :lng, :email, :time_zone, :address, :house_number, :house_number_addition, :postal_code, :city, :country,
|
||||
:facebook_promotion_url, :iens_profile, :week_starts_on_monday, :orders_in_process_count, :orders_placed_count
|
||||
|
||||
def extended_version
|
||||
false
|
||||
end
|
||||
|
||||
end
|
||||
@@ -2,5 +2,5 @@ class SupplierTableSerializer < Qwaiter::Serializer
|
||||
self.root = :table
|
||||
embed :ids, include: true
|
||||
attributes :number, :width, :height, :position_x, :position_y, :section_id, :needs_help
|
||||
has_one :supplier, serializer: SupplierSupplierSerializer
|
||||
has_one :supplier, serializer: Suppliers::SupplierSerializer
|
||||
end
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
class Suppliers::EmployeeSerializer < Qwaiter::Serializer
|
||||
self.root = :employee
|
||||
embed :ids, include: true
|
||||
attributes :supplier_id, :name, :email
|
||||
has_many :orders
|
||||
attributes :name, :email
|
||||
end
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
class Suppliers::ExtendedSectionSerializer < Qwaiter::Serializer
|
||||
root 'section'
|
||||
embed :ids, include: true
|
||||
attributes :title, :path, :width, :height
|
||||
has_many :tables, serializer: Suppliers::ExtendedTableSerializer
|
||||
end
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
class SupplierExtendedTableSerializer < Qwaiter::Serializer
|
||||
class Suppliers::ExtendedTableSerializer < Qwaiter::Serializer
|
||||
root 'table'
|
||||
embed :ids, include: true
|
||||
attributes :number, :width, :height, :position_x, :position_y, :section_id#, :active_list_id
|
||||
@@ -0,0 +1,12 @@
|
||||
class Suppliers::SupplierSerializer < Qwaiter::Serializer
|
||||
self.root = :supplier
|
||||
embed :ids, include: true
|
||||
attributes :extended_version, :open, :name, :lat, :lng, :time_zone, :address, :house_number, :house_number_addition, :postal_code, :city, :country,
|
||||
:facebook_promotion_url, :iens_profile, :week_starts_on_monday, :orders_in_process_count, :orders_placed_count
|
||||
|
||||
def extended_version
|
||||
true
|
||||
end
|
||||
has_many :sections, serializer: Suppliers::ExtendedSectionSerializer
|
||||
has_many :product_categories
|
||||
end
|
||||
Reference in New Issue
Block a user