diff options
Diffstat (limited to 'help/app')
-rw-r--r-- | help/app/controllers/tickets_controller.rb | 52 | ||||
-rw-r--r-- | help/app/models/ticket.rb | 32 | ||||
-rw-r--r-- | help/app/models/ticket_comment.rb | 14 | ||||
-rw-r--r-- | help/app/views/tickets/_comment.html.haml | 10 | ||||
-rw-r--r-- | help/app/views/tickets/_new_comment.html.haml | 2 | ||||
-rw-r--r-- | help/app/views/tickets/index.html.haml | 8 | ||||
-rw-r--r-- | help/app/views/tickets/new.html.haml | 16 | ||||
-rw-r--r-- | help/app/views/tickets/show.html.haml | 11 |
8 files changed, 135 insertions, 10 deletions
diff --git a/help/app/controllers/tickets_controller.rb b/help/app/controllers/tickets_controller.rb new file mode 100644 index 0000000..be07309 --- /dev/null +++ b/help/app/controllers/tickets_controller.rb @@ -0,0 +1,52 @@ +class TicketsController < ApplicationController + + respond_to :html #, :json + + def new + @ticket = Ticket.new + @ticket.comments.build + end + + def create + @ticket = Ticket.new #:created_by => User.current_test.id + @ticket.attributes = params[:ticket]#.except(:comments) + @ticket.created_by = User.current_test.id if User.current_test + #instead of calling add_comment, we are using comment_attributes= from the Ticket model + + if @ticket.save + respond_with(@ticket) + else + respond_with(@ticket, :location => new_ticket_path ) + end + + end + + def show + @ticket = Ticket.find(params[:id]) + # build ticket comments? + end + + def update + @ticket = Ticket.find(params[:id]) + add_comment #or should we use ticket attributes? + @ticket.save + redirect_to @ticket #difft behavior on failure? + end + + def index + # @tickets = Ticket.by_title #not actually what we will want + respond_with(@tickets = Ticket.all) + end + + private + + # not using now when creating tickets, we are using comment_attributes= from the Ticket model + #not yet sure about updating tickets + def add_comment + comment = TicketComment.new(params[:comment]) + comment.posted_by = User.current_test.id if User.current_test #could be nil + comment.posted_at = Time.now # TODO: it seems strange to have this here, and not in model + @ticket.comments << comment + end + +end diff --git a/help/app/models/ticket.rb b/help/app/models/ticket.rb index 784d7ef..e829a5f 100644 --- a/help/app/models/ticket.rb +++ b/help/app/models/ticket.rb @@ -15,8 +15,8 @@ class Ticket < CouchRest::Model::Base =end #belongs_to :user #from leap_web_users. doesn't necessarily belong to a user though - property :created_by, Integer #nil unless user was authenticated for ticket creation, #THIS should not be changed after being set - property :regarding_user, Integer # form cannot be submitted if they type in a username w/out corresponding ID. this field can be nil. for authenticated ticket creation by non-admins, should this just automatically be set to be same as created_by? or maybe we don't use this field unless created_by is nil? + property :created_by, String#Integer #nil unless user was authenticated for ticket creation, #THIS should not be changed after being set + property :regarding_user, String#Integer # form cannot be submitted if they type in a username w/out corresponding ID. this field can be nil. for authenticated ticket creation by non-admins, should this just automatically be set to be same as created_by? or maybe we don't use this field unless created_by is nil? #also, both created_by and regarding_user could be nil---say user forgets username, or has general question property :title, String property :email, String #verify @@ -29,18 +29,24 @@ 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 end + validates :title, :presence => true + validates :comments, :presence => true #do we want it like this? + + # 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 - 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 +57,12 @@ class Ticket < CouchRest::Model::Base self.code = SecureRandom.hex(8) if !is_creator_validated? end + + def set_email + self.email = nil if self.email == "" + #self.email = current users email if is_creator_validated? + end + def close self.is_open = false save @@ -61,6 +73,14 @@ class Ticket < CouchRest::Model::Base save end + def comments_attributes=(attributes) + comment = TicketComment.new(attributes.values.first) #TicketComment.new(attributes) + comment.posted_by = User.current_test.id if User.current_test + comment.posted_at = Time.now + comments << comment + + end + =begin def validate if email_address and not email_address.strip =~ RFC822::EmailAddress diff --git a/help/app/models/ticket_comment.rb b/help/app/models/ticket_comment.rb index 652133a..9026bc1 100644 --- a/help/app/models/ticket_comment.rb +++ b/help/app/models/ticket_comment.rb @@ -2,13 +2,15 @@ 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 + + validates :body, :presence => true + #before_validation :set_time#, :set_posted_by #design do # view :by_posted_at @@ -18,10 +20,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..d2e0ea0 --- /dev/null +++ b/help/app/views/tickets/index.html.haml @@ -0,0 +1,8 @@ +%h2 Tickets +- @tickets.each do |ticket| + %p + = link_to ticket.title, ticket +%p +Create a += link_to "new ticket", new_ticket_path += #render(:partial => "ticket", :collection => @tickets) diff --git a/help/app/views/tickets/new.html.haml b/help/app/views/tickets/new.html.haml new file mode 100644 index 0000000..0a6b25b --- /dev/null +++ b/help/app/views/tickets/new.html.haml @@ -0,0 +1,16 @@ +%h2=t :new_ticket += simple_form_for (@ticket, :html => {:novalidate => true}) do |f| #turn off html5 validations to test + = #@ticket.errors.messages + = f.input :title + = #f.input :email #if there is no current_user + = f.input :email if !User.current_test #hmm--might authenticated users want to submit an alternate email? + + = f.simple_fields_for :comments do |c| + = c.input :body, :label => 'Comment', :as => :text + + = #render :partial => 'new_comment' #what we were using + = # 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..1e1fab3 --- /dev/null +++ b/help/app/views/tickets/show.html.haml @@ -0,0 +1,11 @@ +%h2= @ticket.title +is open? += @ticket.is_open +code: += @ticket.code += render(:partial => "comment", :collection => @ticket.comments) + += simple_form_for (@ticket, :html => {:novalidate => true}) do |f| #turn off html5 validations to test + = render :partial => 'new_comment' + = f.button :submit + = link_to t(:cancel), root_url, :class => :btn
\ No newline at end of file |