summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/lib/extensions/couchrest.rb27
-rw-r--r--help/app/designs/ticket/by_includes_post_by.js13
-rw-r--r--help/app/designs/ticket/by_includes_post_by_and_created_at.js12
-rw-r--r--help/app/designs/ticket/by_includes_post_by_and_is_open_and_created_at.js12
-rw-r--r--help/app/designs/ticket/by_includes_post_by_and_is_open_and_updated_at.js12
-rw-r--r--help/app/designs/ticket/by_includes_post_by_and_updated_at.js12
-rw-r--r--help/app/models/ticket.rb79
-rw-r--r--help/app/views/tickets/_comment.html.haml3
-rw-r--r--users/app/designs/user/by_email_alias.js8
-rw-r--r--users/app/designs/user/by_email_or_alias.js11
-rw-r--r--users/app/models/user.rb29
11 files changed, 105 insertions, 113 deletions
diff --git a/core/lib/extensions/couchrest.rb b/core/lib/extensions/couchrest.rb
index a8da23b..5938df4 100644
--- a/core/lib/extensions/couchrest.rb
+++ b/core/lib/extensions/couchrest.rb
@@ -1,8 +1,23 @@
-class CouchRest::Model::Designs::View
-
- # so we can called Ticket.method.descending or Ticket.method.ascending
- def ascending
- self
- end
+module CouchRest::Model::Designs
+
+ class View
+
+ # so we can called Ticket.method.descending or Ticket.method.ascending
+ def ascending
+ self
+ end
+ end
+
+ class DesignMapper
+ def load_views(dir)
+ Dir.glob("#{dir}/*.js") do |js|
+ name = File.basename(js, '.js')
+ file = File.open(js, 'r')
+ view name.to_sym,
+ :map => file.read,
+ :reduce => "function(key, values, rereduce) { return sum(values); }"
+ end
+ end
+ end
end
diff --git a/help/app/designs/ticket/by_includes_post_by.js b/help/app/designs/ticket/by_includes_post_by.js
new file mode 100644
index 0000000..2eeac89
--- /dev/null
+++ b/help/app/designs/ticket/by_includes_post_by.js
@@ -0,0 +1,13 @@
+// TODO: This view is only used in tests--should we keep it?
+function(doc) {
+ var arr = {}
+ if (doc['type'] == 'Ticket' && doc.comments) {
+ doc.comments.forEach(function(comment){
+ if (comment.posted_by && !arr[comment.posted_by]) {
+ //don't add duplicates
+ arr[comment.posted_by] = true;
+ emit(comment.posted_by, 1);
+ }
+ });
+ }
+}
diff --git a/help/app/designs/ticket/by_includes_post_by_and_created_at.js b/help/app/designs/ticket/by_includes_post_by_and_created_at.js
new file mode 100644
index 0000000..72169b0
--- /dev/null
+++ b/help/app/designs/ticket/by_includes_post_by_and_created_at.js
@@ -0,0 +1,12 @@
+function(doc) {
+ var arr = {}
+ if (doc['type'] == 'Ticket' && doc.comments) {
+ doc.comments.forEach(function(comment){
+ if (comment.posted_by && !arr[comment.posted_by]) {
+ //don't add duplicates
+ arr[comment.posted_by] = true;
+ emit([comment.posted_by, doc.created_at], 1);
+ }
+ });
+ }
+}
diff --git a/help/app/designs/ticket/by_includes_post_by_and_is_open_and_created_at.js b/help/app/designs/ticket/by_includes_post_by_and_is_open_and_created_at.js
new file mode 100644
index 0000000..33dfe0b
--- /dev/null
+++ b/help/app/designs/ticket/by_includes_post_by_and_is_open_and_created_at.js
@@ -0,0 +1,12 @@
+function(doc) {
+ var arr = {}
+ if (doc['type'] == 'Ticket' && doc.comments) {
+ doc.comments.forEach(function(comment){
+ if (comment.posted_by && !arr[comment.posted_by]) {
+ //don't add duplicates
+ arr[comment.posted_by] = true;
+ emit([comment.posted_by, doc.is_open, doc.created_at], 1);
+ }
+ });
+ }
+}
diff --git a/help/app/designs/ticket/by_includes_post_by_and_is_open_and_updated_at.js b/help/app/designs/ticket/by_includes_post_by_and_is_open_and_updated_at.js
new file mode 100644
index 0000000..3bd2a74
--- /dev/null
+++ b/help/app/designs/ticket/by_includes_post_by_and_is_open_and_updated_at.js
@@ -0,0 +1,12 @@
+function(doc) {
+ var arr = {}
+ if (doc['type'] == 'Ticket' && doc.comments) {
+ doc.comments.forEach(function(comment){
+ if (comment.posted_by && !arr[comment.posted_by]) {
+ //don't add duplicates
+ arr[comment.posted_by] = true;
+ emit([comment.posted_by, doc.is_open, doc.updated_at], 1);
+ }
+ });
+ }
+}
diff --git a/help/app/designs/ticket/by_includes_post_by_and_updated_at.js b/help/app/designs/ticket/by_includes_post_by_and_updated_at.js
new file mode 100644
index 0000000..2b4304f
--- /dev/null
+++ b/help/app/designs/ticket/by_includes_post_by_and_updated_at.js
@@ -0,0 +1,12 @@
+function(doc) {
+ var arr = {}
+ if (doc['type'] == 'Ticket' && doc.comments) {
+ doc.comments.forEach(function(comment){
+ if (comment.posted_by && !arr[comment.posted_by]) {
+ //don't add duplicates
+ arr[comment.posted_by] = true;
+ emit([comment.posted_by, doc.updated_at], 1);
+ }
+ });
+ }
+}
diff --git a/help/app/models/ticket.rb b/help/app/models/ticket.rb
index 0399b4e..ef7b2d6 100644
--- a/help/app/models/ticket.rb
+++ b/help/app/models/ticket.rb
@@ -47,84 +47,7 @@ class Ticket < CouchRest::Model::Base
view :by_is_open_and_created_at
view :by_is_open_and_updated_at
-
- #TODO: This view is only used in tests--should we keep it?
- view :by_includes_post_by,
- :map =>
- "function(doc) {
- var arr = {}
- if (doc['type'] == 'Ticket' && doc.comments) {
- doc.comments.forEach(function(comment){
- if (comment.posted_by && !arr[comment.posted_by]) {
- //don't add duplicates
- arr[comment.posted_by] = true;
- emit(comment.posted_by, 1);
- }
- });
- }
- }", :reduce => "function(k,v,r) { return sum(v); }"
-
- view :by_includes_post_by_and_is_open_and_updated_at,
- :map =>
- "function(doc) {
- var arr = {}
- if (doc['type'] == 'Ticket' && doc.comments) {
- doc.comments.forEach(function(comment){
- if (comment.posted_by && !arr[comment.posted_by]) {
- //don't add duplicates
- arr[comment.posted_by] = true;
- emit([comment.posted_by, doc.is_open, doc.updated_at], 1);
- }
- });
- }
- }", :reduce => "function(k,v,r) { return sum(v); }"
-
- view :by_includes_post_by_and_is_open_and_created_at,
- :map =>
- "function(doc) {
- var arr = {}
- if (doc['type'] == 'Ticket' && doc.comments) {
- doc.comments.forEach(function(comment){
- if (comment.posted_by && !arr[comment.posted_by]) {
- //don't add duplicates
- arr[comment.posted_by] = true;
- emit([comment.posted_by, doc.is_open, doc.created_at], 1);
- }
- });
- }
- }", :reduce => "function(k,v,r) { return sum(v); }"
-
- view :by_includes_post_by_and_updated_at,
- :map =>
- "function(doc) {
- var arr = {}
- if (doc['type'] == 'Ticket' && doc.comments) {
- doc.comments.forEach(function(comment){
- if (comment.posted_by && !arr[comment.posted_by]) {
- //don't add duplicates
- arr[comment.posted_by] = true;
- emit([comment.posted_by, doc.updated_at], 1);
- }
- });
- }
- }", :reduce => "function(k,v,r) { return sum(v); }"
-
-
- view :by_includes_post_by_and_created_at,
- :map =>
- "function(doc) {
- var arr = {}
- if (doc['type'] == 'Ticket' && doc.comments) {
- doc.comments.forEach(function(comment){
- if (comment.posted_by && !arr[comment.posted_by]) {
- //don't add duplicates
- arr[comment.posted_by] = true;
- emit([comment.posted_by, doc.created_at], 1);
- }
- });
- }
- }", :reduce => "function(k,v,r) { return sum(v); }"
-
+ load_views(Rails.root.join('help', 'app', 'designs', 'ticket'))
end
validates :title, :presence => true
diff --git a/help/app/views/tickets/_comment.html.haml b/help/app/views/tickets/_comment.html.haml
index 26794dc..1d8ee41 100644
--- a/help/app/views/tickets/_comment.html.haml
+++ b/help/app/views/tickets/_comment.html.haml
@@ -6,7 +6,8 @@
= 'Posted by' + (commenter.is_admin? ? ' admin' : '') + ':'
= commenter.login
- else
- Unauthenticated post
+ %b
+ Unauthenticated post
.pull-right
%b
Posted at:
diff --git a/users/app/designs/user/by_email_alias.js b/users/app/designs/user/by_email_alias.js
new file mode 100644
index 0000000..51eb976
--- /dev/null
+++ b/users/app/designs/user/by_email_alias.js
@@ -0,0 +1,8 @@
+function(doc) {
+ if (doc.type != 'User') {
+ return;
+ }
+ doc.email_aliases.forEach(function(alias){
+ emit(alias.email, doc);
+ });
+}
diff --git a/users/app/designs/user/by_email_or_alias.js b/users/app/designs/user/by_email_or_alias.js
new file mode 100644
index 0000000..2f1e569
--- /dev/null
+++ b/users/app/designs/user/by_email_or_alias.js
@@ -0,0 +1,11 @@
+function(doc) {
+ if (doc.type != 'User') {
+ return;
+ }
+ if (doc.email) {
+ emit(doc.email, doc);
+ }
+ doc.email_aliases.forEach(function(alias){
+ emit(alias.email, doc);
+ });
+}
diff --git a/users/app/models/user.rb b/users/app/models/user.rb
index 2a8a57b..1798ea4 100644
--- a/users/app/models/user.rb
+++ b/users/app/models/user.rb
@@ -46,37 +46,10 @@ class User < CouchRest::Model::Base
timestamps!
design do
+ load_views(Rails.root.join('users', 'app', 'designs', 'user'))
view :by_login
view :by_created_at
view :by_email
-
- view :by_email_alias,
- :map => <<-EOJS
- function(doc) {
- if (doc.type != 'User') {
- return;
- }
- doc.email_aliases.forEach(function(alias){
- emit(alias.email, doc);
- });
- }
- EOJS
-
- view :by_email_or_alias,
- :map => <<-EOJS
- function(doc) {
- if (doc.type != 'User') {
- return;
- }
- if (doc.email) {
- emit(doc.email, doc);
- }
- doc.email_aliases.forEach(function(alias){
- emit(alias.email, doc);
- });
- }
- EOJS
-
end
class << self