summaryrefslogtreecommitdiff
path: root/help/app
diff options
context:
space:
mode:
Diffstat (limited to 'help/app')
-rw-r--r--help/app/controllers/tickets_controller.rb41
-rw-r--r--help/app/models/ticket.rb15
-rw-r--r--help/app/models/ticket_comment.rb12
-rw-r--r--help/app/views/tickets/_comment.html.haml10
-rw-r--r--help/app/views/tickets/_new_comment.html.haml2
-rw-r--r--help/app/views/tickets/index.html.haml5
-rw-r--r--help/app/views/tickets/new.html.haml14
-rw-r--r--help/app/views/tickets/show.html.haml10
8 files changed, 101 insertions, 8 deletions
diff --git a/help/app/controllers/tickets_controller.rb b/help/app/controllers/tickets_controller.rb
new file mode 100644
index 0000000..9383d7e
--- /dev/null
+++ b/help/app/controllers/tickets_controller.rb
@@ -0,0 +1,41 @@
+class TicketsController < ApplicationController
+
+ def new
+ @ticket = Ticket.new
+ end
+
+ def create
+ # @ticket = Ticket.new :posted_by => current_user
+ @ticket = Ticket.new :created_by => User.current_test.id
+ @ticket.attributes = params[:ticket]
+
+ add_comment
+ redirect_to @ticket
+ end
+
+ def show
+ @ticket = Ticket.find(params[:id])
+ end
+
+ def update
+ @ticket = Ticket.find(params[:id])
+ add_comment
+ redirect_to @ticket
+ end
+
+ def index
+ @tickets = Ticket.by_title #not actually what we will want
+ end
+
+ private
+
+ def add_comment
+ comment = TicketComment.new(params[:comment])
+ #comment.posted_by = current_user #could be nil
+ comment.posted_by = User.current_test.id #could be nil
+ comment.posted_at = Time.now # TODO: it seems strange to have this here, and not in model.
+ @ticket.comments << comment
+ @ticket.save
+ end
+
+end
diff --git a/help/app/models/ticket.rb b/help/app/models/ticket.rb
index 784d7ef..355ae02 100644
--- a/help/app/models/ticket.rb
+++ b/help/app/models/ticket.rb
@@ -29,7 +29,8 @@ class Ticket < CouchRest::Model::Base
timestamps!
- before_validation :set_created_by, :set_code, :on => :create
+ #before_validation :set_created_by, :set_code, :set_email, :on => :create
+ before_validation :set_code, :set_email, :on => :create
design do
view :by_title
@@ -38,9 +39,10 @@ class Ticket < CouchRest::Model::Base
validates :email, :format => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/, :if => :email #email address is optional
- def set_created_by
- self.created_by = User.current if User.current
- end
+ #TODO:
+ #def set_created_by
+ # self.created_by = User.current if User.current
+ #end
def is_creator_validated?
!!created_by
@@ -51,6 +53,11 @@ class Ticket < CouchRest::Model::Base
self.code = SecureRandom.hex(8) if !is_creator_validated?
end
+
+ def set_email
+ #self.email = current users email if is_creator_validated?
+ end
+
def close
self.is_open = false
save
diff --git a/help/app/models/ticket_comment.rb b/help/app/models/ticket_comment.rb
index 652133a..6b6b4db 100644
--- a/help/app/models/ticket_comment.rb
+++ b/help/app/models/ticket_comment.rb
@@ -2,13 +2,13 @@ class TicketComment
include CouchRest::Model::Embeddable
#belongs_to :ticket #is this best way to do it? will want to access all of a tickets comments, so maybe this isn't the way?
- property :posted_by, Integer, :protected => true# maybe this should be current_user if that is set, meaning the user is logged in #String # user??
+ property :posted_by, Integer#, :protected => true# maybe this should be current_user if that is set, meaning the user is logged in #String # user??
# if the current user is not set, then we could just say the comment comes from an 'unauthenticated user', which would be somebody with the secret URL
- property :posted_at, Time, :protected => true
+ property :posted_at, Time#, :protected => true
#property :posted_verified, TrueClass, :protected => true #should be true if current_user is set when the comment is created
property :body, String
- before_validation :set_time#, :set_posted_by
+ #before_validation :set_time#, :set_posted_by
#design do
# view :by_posted_at
@@ -18,10 +18,14 @@ class TicketComment
def is_comment_validated?
!!posted_by
end
-
+
+=begin
+ #TODO.
+ #this is resetting all comments associated with the ticket:
def set_time
self.posted_at = Time.now
end
+=end
=begin
def set_posted_by
diff --git a/help/app/views/tickets/_comment.html.haml b/help/app/views/tickets/_comment.html.haml
new file mode 100644
index 0000000..77e29b8
--- /dev/null
+++ b/help/app/views/tickets/_comment.html.haml
@@ -0,0 +1,10 @@
+%div
+ - if User.find(comment.posted_by)
+ Posted by
+ = User.find(comment.posted_by).login
+ %p
+ Posted at
+ = comment.posted_at
+ %p
+ = comment.body
+ %p \ No newline at end of file
diff --git a/help/app/views/tickets/_new_comment.html.haml b/help/app/views/tickets/_new_comment.html.haml
new file mode 100644
index 0000000..bf88da6
--- /dev/null
+++ b/help/app/views/tickets/_new_comment.html.haml
@@ -0,0 +1,2 @@
+= simple_fields_for :comment do |c|
+ = c.input :body, :label => 'Comment', :as => :text
diff --git a/help/app/views/tickets/index.html.haml b/help/app/views/tickets/index.html.haml
new file mode 100644
index 0000000..55bfa79
--- /dev/null
+++ b/help/app/views/tickets/index.html.haml
@@ -0,0 +1,5 @@
+%h2 Tickets
+- @tickets.each do |ticket|
+ %p
+ = link_to ticket.title, ticket
+= #render(:partial => "ticket", :collection => @tickets) \ No newline at end of file
diff --git a/help/app/views/tickets/new.html.haml b/help/app/views/tickets/new.html.haml
new file mode 100644
index 0000000..fd1bcd4
--- /dev/null
+++ b/help/app/views/tickets/new.html.haml
@@ -0,0 +1,14 @@
+%h2=t :new_ticket
+= simple_form_for @ticket do |f|
+ = f.input :title
+ = #f.input :email #if there is no current_user
+ = f.input :email if !User.current_test
+ = #simple_fields_for :comment do |c|
+ = #c.input :body, :label => 'Comment', :as => :text
+ = #f.input :comment
+ = render :partial => 'new_comment'
+ = # regarding_user if not logged in
+ = # email if not logged in
+ = #f.button :submit, :value => t(:submit), :class => 'btn-primary'
+ = f.button :submit
+ = link_to t(:cancel), root_url, :class => :btn
diff --git a/help/app/views/tickets/show.html.haml b/help/app/views/tickets/show.html.haml
new file mode 100644
index 0000000..a37f5c8
--- /dev/null
+++ b/help/app/views/tickets/show.html.haml
@@ -0,0 +1,10 @@
+%h2= @ticket.title
+is open?
+= @ticket.is_open
+code:
+= @ticket.code
+= render(:partial => "comment", :collection => @ticket.comments)
+
+= simple_form_for @ticket do |f|
+ = render :partial => 'new_comment'
+ = f.button :submit \ No newline at end of file