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
+10 -3
View File
@@ -70,6 +70,7 @@ class List
list.save
user.active_list_id = list.id
user.save
# list_added is depricated, now handled by list_update
#list.broadcast_supplier list.supplier_id, 'list_added', list.with_info_as_json
list
end
@@ -96,7 +97,12 @@ class List
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)))
if table_id.is_a?(Array)
database.view(active_by_table_id_view(options.reverse_merge(keys: table_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)))
end
end
def self.for_user(user, options = {})
@@ -158,13 +164,14 @@ class List
def move_to_table! to_table
UserTableMove.create list: self, from_table_id: table_id, to_table: to_table
from_table = self.table_id.try(:dup)
self.table = to_table
self.section_id = to_table.section_id
if save
for user_id in user_ids
broadcast_user user_id, 'list_changed_table', list_id: id, table: to_table, section_title: to_table.section.try(:title)
broadcast_user user_id, 'list_changed_table', list_id: id, table: to_table, section_title: to_table.section.try(:title), from_table_id: from_table
end
broadcast_supplier supplier_id, 'list_changed_table', list_id: id, table: to_table, section_title: to_table.section.try(:title)
broadcast_supplier supplier_id, 'list_changed_table', list_id: id, table: to_table, section_title: to_table.section.try(:title), from_table_id: from_table
end
end