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.rb81
-rw-r--r--help/app/views/tickets/_comment.html.haml3
-rw-r--r--help/app/views/tickets/_new_comment.html.haml2
-rw-r--r--help/app/views/tickets/new.html.haml2
-rw-r--r--help/app/views/tickets/show.html.haml2
-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
14 files changed, 109 insertions, 117 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 fa056b4..a27a9d4 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
@@ -132,7 +55,7 @@ class Ticket < CouchRest::Model::Base
# html5 has built-in validation which isn't ideal, as it says 'please enter an email address' for invalid email addresses, which implies an email address is required, and it is not.
- validates :email, :format => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/, :if => :email #email address is optional
+ validates :email, :allow_blank => true, :format => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/
#TODO:
#def set_created_by
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/help/app/views/tickets/_new_comment.html.haml b/help/app/views/tickets/_new_comment.html.haml
index 7307dad..31d134f 100644
--- a/help/app/views/tickets/_new_comment.html.haml
+++ b/help/app/views/tickets/_new_comment.html.haml
@@ -1,2 +1,2 @@
= f.simple_fields_for :comments, @comment do |c|
- = c.input :body, :label => 'Comment', :as => :text, :input_html => {:class => "span12", :rows=>4}
+ = c.input :body, :label => 'Comment', :as => :text, :input_html => {:class => "span9", :rows=>4}
diff --git a/help/app/views/tickets/new.html.haml b/help/app/views/tickets/new.html.haml
index 750b990..ee7adb2 100644
--- a/help/app/views/tickets/new.html.haml
+++ b/help/app/views/tickets/new.html.haml
@@ -1,6 +1,6 @@
.span12
%h2=t :new_ticket
- = simple_form_for(@ticket, :html => {:novalidate => true}) do |f| #turn off html5 validations to test
+ = simple_form_for @ticket, :validate => true, :html => {:class => 'form-horizontal'} do |f|
= f.input :title
= f.input :email if !current_user #hmm--might authenticated users want to submit an alternate email?
= render :partial => 'new_comment', :locals => {:f => f}
diff --git a/help/app/views/tickets/show.html.haml b/help/app/views/tickets/show.html.haml
index 3f00b35..a69048b 100644
--- a/help/app/views/tickets/show.html.haml
+++ b/help/app/views/tickets/show.html.haml
@@ -8,7 +8,7 @@
= render(:partial => "comment", :collection => @ticket.comments)
= #render @ticket.comments should work if view is in /app/views/comments/_comment
- = simple_form_for(@ticket, :html => {:novalidate => true}) do |f| #turn off html5 validations to test
+ = simple_form_for @ticket, :html => {:class => 'form-horizontal'} do |f| # don't need validations so long as this is so simple
= render :partial => 'new_comment', :locals => {:f => f}
.span10.offset3
= f.button :submit, @post_reply_str, :class => 'btn-primary'
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