before switch to ubuntu commit since apple has issues
This commit is contained in:
+21
-18
@@ -29,17 +29,22 @@ class List
|
||||
view :by_supplier_id_and_id, key: [:supplier_id, :_id]
|
||||
view :for_supplier_view, key: [:supplier_id, :created_at]
|
||||
|
||||
view :active_by_table_id_view, type: :custom, map_function: %|function(doc){
|
||||
view :active_view, type: :custom, map_function: %|function(doc){
|
||||
if(doc.ruby_class == 'List' && doc.state == 'active'){
|
||||
emit(doc.table_id, 1);
|
||||
emit([doc.supplier_id, doc.table_id], 1);
|
||||
}
|
||||
}|, reduce_function: '_sum'
|
||||
#view :active_by_table_id_view, type: :custom, map_function: %|function(doc){
|
||||
#if(doc.ruby_class == 'List' && doc.state == 'active'){
|
||||
#emit(doc.table_id, 1);
|
||||
#}
|
||||
#}|, reduce_function: '_sum'
|
||||
|
||||
view :active_by_supplier_id_view, type: :custom, map_function: %|function(doc){
|
||||
if(doc.ruby_class == 'List' && doc.state == 'active'){
|
||||
emit(doc.supplier_id, 1);
|
||||
}
|
||||
}|, reduce_function: '_sum'
|
||||
#view :active_by_supplier_id_view, type: :custom, map_function: %|function(doc){
|
||||
#if(doc.ruby_class == 'List' && doc.state == 'active'){
|
||||
#emit(doc.supplier_id, 1);
|
||||
#}
|
||||
#}|, reduce_function: '_sum'
|
||||
|
||||
view :active_by_section_id_view, type: :custom, map_function: %|function(doc){
|
||||
if(doc.ruby_class == 'List' && doc.state == 'active' && doc.section_id){
|
||||
@@ -70,7 +75,7 @@ class List
|
||||
}|, reduce_function: '_sum'
|
||||
|
||||
def self.active
|
||||
database.view(active_by_supplier_id_view(reduce: false, include_docs: true))
|
||||
database.view(active_view(reduce: false, include_docs: true))
|
||||
end
|
||||
|
||||
# Create, a list given a table and a user
|
||||
@@ -107,13 +112,12 @@ class List
|
||||
end
|
||||
end
|
||||
|
||||
def self.active_for_supplier(supplier_id, options = {})
|
||||
supplier_id = supplier_id.id if supplier_id.is_a?(Supplier)
|
||||
database.view(active_by_supplier_id_view(key: supplier_id, reduce: false, include_docs: true))
|
||||
def self.active_for_supplier(supplier, options = {})
|
||||
database.view(active_view(startkey: [supplier.id], endkey: ["#{supplier.id}\u9999"], reduce: false, include_docs: true))
|
||||
end
|
||||
|
||||
def self.active_for_section(section_id, options = {})
|
||||
database.view(active_by_section_id_view(key: section_id, reduce: false, include_docs: true))
|
||||
def self.active_for_section(section, options = {})
|
||||
database.view(active_by_section_id_view(key: section.id, reduce: false, include_docs: true))
|
||||
end
|
||||
|
||||
# Return all currently active orders for a given section
|
||||
@@ -121,12 +125,11 @@ class List
|
||||
database.view(active_for_supplier_and_section_view(key: [supplier.id, section_id], reduce: false, include_docs: true))
|
||||
end
|
||||
|
||||
def self.active_for_table(table_id, options = {})
|
||||
if table_id.is_a?(Array)
|
||||
database.view(active_by_table_id_view(options.reverse_merge(keys: table_id, reduce: false, include_docs: true)))
|
||||
def self.active_for_table(table_or_tables, options = {})
|
||||
if table_or_tables.is_a?(Array)
|
||||
database.view(active_view(options.reverse_merge(keys: table_or_tables.map{|t| [t.supplier_id, t.id]}, reduce: false, include_docs: true)))
|
||||
else
|
||||
table_id = table_id.id if table_id.is_a?(SimplyStored::Couch)
|
||||
database.view(active_by_table_id_view(options.reverse_merge(key: table_id, reduce: false, include_docs: true)))
|
||||
database.view(active_view(options.reverse_merge(key: [table_or_tables.supplier_id, table_or_tables.id], reduce: false, include_docs: true)))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -20,14 +20,14 @@ class Section
|
||||
|
||||
def occupied_tables
|
||||
return @occupied_tables if @occupied_tables.present?
|
||||
@active_lists = List.active_for_section(self.id)
|
||||
@active_lists = List.active_for_section(self)
|
||||
@active_lists.include_relation(:table)
|
||||
@occupied_tables = @active_lists.map(&:table)
|
||||
end
|
||||
|
||||
def active_lists
|
||||
return @active_lists if @active_lists.present?
|
||||
@active_lists = List.active_for_section(self.id)
|
||||
@active_lists = List.active_for_section(self)
|
||||
end
|
||||
|
||||
def active_orders
|
||||
|
||||
@@ -99,9 +99,10 @@ class Supplier
|
||||
@active_orders
|
||||
end
|
||||
|
||||
# Tody, simplify to List.active_for_supplier(self)
|
||||
def active_lists(options = {})
|
||||
return @active_lists if @active_lists
|
||||
@active_lists = options[:section_id].present? ? List.active_for_supplier_and_section(self, options[:section_id]) : List.active_for_supplier(id)
|
||||
@active_lists = options[:section_id].present? ? List.active_for_supplier_and_section(self, options[:section_id]) : List.active_for_supplier(self)
|
||||
@active_lists.include_relations(table: :section, orders: {product_orders: :product})
|
||||
@active_lists
|
||||
end
|
||||
|
||||
+3
-3
@@ -51,14 +51,14 @@ class Table
|
||||
|
||||
def occupied?
|
||||
return @is_occupied if instance_variable_defined?(:'@is_occupied')
|
||||
@is_occupied = !self.class.database.view(List.active_by_table_id_view(key: id, reduce: true)).zero?
|
||||
@is_occupied = !self.class.database.view(List.active_view(key: [supplier_id, id], reduce: true)).zero?
|
||||
end
|
||||
alias occupied occupied?
|
||||
def occupied=(val) end
|
||||
|
||||
def self.enrich_active_list_id(tables)
|
||||
if tables.is_a?(Array)
|
||||
lists = List.active_for_table(tables.map(&:id))
|
||||
lists = List.active_for_table(tables)
|
||||
for table in tables
|
||||
if list = lists.find{|l| l.table_id == table.id}
|
||||
table.active_list_id = list.id
|
||||
@@ -79,7 +79,7 @@ class Table
|
||||
def active_list
|
||||
# nil memoizing
|
||||
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)
|
||||
self.active_list = self.class.database.view(List.active_view(key: [supplier_id, id], include_docs: true, reduce: false, limit: 1)).try(:first)
|
||||
end
|
||||
|
||||
def active_list=(val)
|
||||
|
||||
Reference in New Issue
Block a user