Make section table view work request and event based

This commit is contained in:
2013-03-10 12:48:03 +01:00
parent cc13797f5a
commit 5eac918255
11 changed files with 164 additions and 38 deletions
+16
View File
@@ -11,6 +11,7 @@ class Table
has_many :lists
attr_protected :supplier_id
attr_accessor :active_list_id
validates :supplier_id, presence: true
#validates :list_id, presence: true
@@ -45,6 +46,21 @@ class Table
@is_occupied = !self.class.database.view(List.active_by_table_id_view(key: id, reduce: true)).zero?
end
def self.enrich_active_list_id(tables)
if tables.is_a?(Array)
lists = List.active_for_table(tables.map(&:id))
for table in tables
table.active_list_id = lists.find{|l| l.table_id == table.id}.try(:id)
end
tables
else
table = tables
list = List.active_for_table(table).first
table.active_list_id = list.id if list.present?
table
end
end
def active_list
@active_list ||= self.class.database.view(List.active_by_table_id_view(key: id, include_docs: true, reduce: false, limit: 1)).try(:first)
end