summaryrefslogtreecommitdiff
path: root/help/app/models
diff options
context:
space:
mode:
authorjessib <jessib@leap.se>2012-11-21 16:21:24 -0800
committerjessib <jessib@leap.se>2012-11-21 16:21:24 -0800
commitd9d67bd60d3fdfa4106977de9e5aba11f659fc79 (patch)
tree48bee70467d25cbaf92d9780e5f533e99fa8f4a4 /help/app/models
parent80cd2489d87a523663d92776de55fa7fda2ecb99 (diff)
Playing around with pagination, and ways to filter/order ticket results.
Diffstat (limited to 'help/app/models')
-rw-r--r--help/app/models/ticket.rb31
1 files changed, 28 insertions, 3 deletions
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