before switch to ubuntu commit since apple has issues

This commit is contained in:
2015-08-13 12:54:02 +02:00
parent 6b764fcd39
commit 919474b54c
17 changed files with 81 additions and 41 deletions
+21 -18
View File
@@ -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