summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--help/app/controllers/tickets_controller.rb12
-rw-r--r--help/app/models/ticket.rb2
-rw-r--r--help/app/views/tickets/index.html.haml4
3 files changed, 16 insertions, 2 deletions
diff --git a/help/app/controllers/tickets_controller.rb b/help/app/controllers/tickets_controller.rb
index 4c7415b..4684a40 100644
--- a/help/app/controllers/tickets_controller.rb
+++ b/help/app/controllers/tickets_controller.rb
@@ -41,6 +41,7 @@ class TicketsController < ApplicationController
@ticket = Ticket.find(params[:id])
@ticket.attributes = params[:ticket]
+ # what if there is an update and no new comment? Confirm that there is a new comment to update posted_by. will @tickets.comments_changed? work?
@ticket.comments.last.posted_by = (current_user ? current_user.id : nil) #protecting posted_by isn't working, so this should protect it.
if @ticket.save
@@ -56,7 +57,16 @@ class TicketsController < ApplicationController
def index
# @tickets = Ticket.by_title #not actually what we will want
- respond_with(@tickets = Ticket.all) #we'll want only tickets that this user can access
+ #we'll want only tickets that this user can access
+ # @tickets = Ticket.by_is_open.key(params[:status])
+ if params[:status] == 'open'
+ @tickets = Ticket.by_is_open.key(true)
+ elsif params[:status] == 'closed'
+ @tickets = Ticket.by_is_open.key(false)
+ else
+ @tickets = Ticket.all
+ end
+ respond_with(@tickets)
end
private
diff --git a/help/app/models/ticket.rb b/help/app/models/ticket.rb
index f38fed2..0407012 100644
--- a/help/app/models/ticket.rb
+++ b/help/app/models/ticket.rb
@@ -37,6 +37,7 @@ class Ticket < CouchRest::Model::Base
design do
view :by_title
+ view :by_is_open
end
validates :title, :presence => true
@@ -80,6 +81,7 @@ class Ticket < CouchRest::Model::Base
comment = TicketComment.new(attributes.values.first) #TicketComment.new(attributes)
#comment.posted_by = User.current.id if User.current #we want to avoid User.current, and current_user won't work here. instead will set in tickets_controller
+ # what about: comment.posted_by = self.updated_by (will need to add ticket.updated_by)
comment.posted_at = Time.now
comments << comment
diff --git a/help/app/views/tickets/index.html.haml b/help/app/views/tickets/index.html.haml
index 6db2140..1f46433 100644
--- a/help/app/views/tickets/index.html.haml
+++ b/help/app/views/tickets/index.html.haml
@@ -3,7 +3,9 @@ Create a
= link_to "new ticket", new_ticket_path
= # below shouldn't be unless logged in
%h2 Tickets
-= # want to have selection option to see tickets, that are open, closed or all
+= form_tag (tickets_path, :method => :get) do # want to redo as ajax, and make sure it displays the selected option
+ = select_tag :status, options_for_select(["open", "closed", "all"])
+ = submit_tag "filter"
- @tickets.each do |ticket|
%p
= link_to ticket.title, ticket