From d9d67bd60d3fdfa4106977de9e5aba11f659fc79 Mon Sep 17 00:00:00 2001 From: jessib Date: Wed, 21 Nov 2012 16:21:24 -0800 Subject: Playing around with pagination, and ways to filter/order ticket results. --- help/app/models/ticket.rb | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'help/app/models') diff --git a/help/app/models/ticket.rb b/help/app/models/ticket.rb index 3b66fe4..e8b004f 100644 --- a/help/app/models/ticket.rb +++ b/help/app/models/ticket.rb @@ -36,10 +36,32 @@ class Ticket < CouchRest::Model::Base #named_scope :open, :conditions => {:is_open => true} #?? design do - view :by_title + #TODO--clean this all up view :by_is_open view :by_created_by + + view :by_updated_at # + + view :by_title, #test + :map => + "function(doc) { + emit(doc._id, doc); + }" view :by_is_open_and_created_by + view :by_updated_at_and_is_open, + :map => + "function(doc) { + if (doc['type'] == 'Ticket' && doc.is_open == true) { + emit(doc.updated_at, doc); + } + }" + view :by_updated_at_and_is_closed, + :map => + "function(doc) { + if (doc['type'] == 'Ticket' && doc.is_open == false) { + emit(doc.updated_at, doc); + } + }" end @@ -87,8 +109,11 @@ class Ticket < CouchRest::Model::Base commenters = [] self.comments.each do |comment| if comment.posted_by - user = User.find(comment.posted_by) - commenters << user.login if user and !commenters.include?(user.login) + if user = User.find(comment.posted_by) + commenters << user.login if user and !commenters.include?(user.login) + else + commenters << 'unknown user' if !commenters.include?('unknown user') #todo don't hardcode string 'unknown user' + end else commenters << 'unauthenticated user' if !commenters.include?('unauthenticated user') #todo don't hardcode string 'unauthenticated user' end -- cgit v1.2.3