add some styling on tables view

This commit is contained in:
2012-09-11 10:34:54 +02:00
parent 7f8a8e9e26
commit 17b3494033
8 changed files with 79 additions and 37 deletions
+10
View File
@@ -26,6 +26,12 @@ class List
}
}|, 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);
}
}|, reduce_function: '_sum'
view :for_user_view, type: :custom, map_function: %|function(doc){
if(doc.ruby_class == 'List' && doc.user_ids && doc.user_ids.length){
doc.user_ids.forEach(function(uid){
@@ -45,6 +51,10 @@ class List
list
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.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)))
+31
View File
@@ -22,6 +22,19 @@ class Section
section
end
def occupied_tables
return @occupied_tables if @occupied_tables.present?
@active_lists = List.active_for_section(self.id)
@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)
end
def width
self.path.last.try(:first).to_f - self.path.first.try(:first).to_f
end
@@ -47,4 +60,22 @@ class Section
path_will_change!
end
end
def as_json
super.merge(width: width, height: height)
end
def for_tables_as_json
return @for_tables_as_json if @for_tables_as_json.present?
h = as_json
h[:tables] = []
for table in tables
ht = table.as_json
ht[:occupied] = occupied_tables.include?(table)
ht[:needs_help] = ht[:occupied] ? active_lists.find{|l| l.table_id == table.id}.try(:needs_help).present? : false
ht[:needs_payment] = ht[:occupied] ? active_lists.find{|l| l.table_id == table.id}.try(:needs_payment).present? : false
h[:tables] << ht
end
@for_tables_as_json = h
end
end