refactor and styling change, add button logick, add i18n logic

This commit is contained in:
2012-09-17 14:28:00 +02:00
parent 17b3494033
commit 930e53e837
20 changed files with 316 additions and 55 deletions
+19 -1
View File
@@ -20,12 +20,18 @@ class List
view :by_supplier_id_and_id, key: [:supplier_id, :_id]
view :active_by_table_id, type: :custom, map_function: %|function(doc){
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_section_id_view, type: :custom, map_function: %|function(doc){
if(doc.ruby_class == 'List' && doc.state == 'active' && doc.section_id){
emit(doc.section_id, 1);
@@ -40,6 +46,10 @@ class List
}
}|, reduce_function: '_sum'
def self.active
database.view(active_by_supplier_id_view(reduce: false, include_docs: true))
end
# Create, a list given a table and a user
def self.from_table table, user
return if user.has_active_list?
@@ -51,10 +61,18 @@ class List
list
end
def self.active_for_supplier(supplier_id, options = {})
database.view(active_by_supplier_id_view(key: supplier_id, 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))
end
def self.active_for_table(table_id, options = {})
database.view(active_by_table_id_view(options.reverse_merge(key: table_id, reduce: false, include_docs: true)))
end
def self.for_user(user, options = {})
with_pagination_options(options) do |options|
database.view(for_user_view({startkey: ["#{user.id}\u9999"], endkey: [user.id], include_docs: true, reduce: false, descending: true}.merge(options)))
+3 -4
View File
@@ -33,11 +33,10 @@ class Supplier
end
def active_lists(options = {})
return @active_lists if @active_lists
@tables ||= active_tables(options)
@tables.include_relation(:lists)
@active_lists = @tables.map(&:lists).flatten.select(&:active?)
return @active_lists if @active_lists.present?
@active_lists = List.active_for_supplier(id)
@active_lists.include_relations(table: :section, orders: {product_orders: :product})
@active_lists
end
+2 -2
View File
@@ -18,11 +18,11 @@ class Table
def occupied?
return @is_occupied if instance_variable_defined?(:'@is_occupied')
@is_occupied = !self.class.database.view(List.active_by_table_id(key: id, reduce: true)).zero?
@is_occupied = !self.class.database.view(List.active_by_table_id_view(key: id, reduce: true)).zero?
end
def active_list
@active_list ||= self.class.database.view(List.active_by_table_id(key: id, include_docs: true, reduce: false, limit: 1)).try(:first)
@active_list ||= self.class.database.view(List.active_by_table_id_view(key: id, include_docs: true, reduce: false, limit: 1)).try(:first)
end
def reserved?