summaryrefslogtreecommitdiff
path: root/help/app/controllers
diff options
context:
space:
mode:
authorjessib <jessib@leap.se>2012-11-21 16:21:24 -0800
committerjessib <jessib@leap.se>2012-11-21 16:21:24 -0800
commitd9d67bd60d3fdfa4106977de9e5aba11f659fc79 (patch)
tree48bee70467d25cbaf92d9780e5f533e99fa8f4a4 /help/app/controllers
parent80cd2489d87a523663d92776de55fa7fda2ecb99 (diff)
Playing around with pagination, and ways to filter/order ticket results.
Diffstat (limited to 'help/app/controllers')
-rw-r--r--help/app/controllers/tickets_controller.rb31
1 files changed, 21 insertions, 10 deletions
diff --git a/help/app/controllers/tickets_controller.rb b/help/app/controllers/tickets_controller.rb
index 2f26d24..04cf1a9 100644
--- a/help/app/controllers/tickets_controller.rb
+++ b/help/app/controllers/tickets_controller.rb
@@ -83,29 +83,38 @@ class TicketsController < ApplicationController
if admin?
if params[:admin_status] == 'mine'
- @tickets = tickets_by_admin(current_user.id)
+ @tickets = tickets_by_admin(current_user.id) #returns Array so pagination does not work
elsif params[:open_status] == 'open'
- @tickets = Ticket.by_is_open.key(true)
+ @tickets = Ticket.by_updated_at_and_is_open
+ # @tickets = Ticket.by_is_open.key(true) #returns CouchRest::Model::Designs::View
elsif params[:open_status] == 'closed'
- @tickets = Ticket.by_is_open.key(false)
+ @tickets = Ticket.by_updated_at_and_is_closed
+ # @tickets = Ticket.by_is_open.key(false) #returns CouchRest::Model::Designs::View
else
- @tickets = Ticket.all
+ # @tickets = Ticket.all #returns CouchRest::Model::Designs::View
+ @tickets = Ticket.by_updated_at
end
elsif logged_in?
#TODO---if, when logged in, user accessed unauthenticated ticket, then seems okay to list it in their list of tickets. Thus, include all tickets that the user has posted to, not just those that they created.
if params[:open_status] == 'open'
- @tickets = Ticket.by_is_open_and_created_by.key([true, current_user.id]).all
+ @tickets = Ticket.by_is_open_and_created_by.key([true, current_user.id])
elsif params[:open_status] == 'closed'
- @tickets = Ticket.by_is_open_and_created_by.key([false, current_user.id]).all
+ @tickets = Ticket.by_is_open_and_created_by.key([false, current_user.id])
else
- @tickets = Ticket.by_created_by.key(current_user.id).all
+ @tickets = Ticket.by_created_by(:key => current_user.id)
end
else
access_denied
return
end
- respond_with(@tickets)
+ # todo. presumably quite inefficent. sorts by updated_at increasing. would also make it an array, so pagination wouldn't work
+ # @tickets = @tickets.sort{|x,y| x.updated_at <=> y.updated_at}
+
+ #below works if @tickets is a CouchRest::Model::Designs::View, but not if it is an Array
+ @tickets = @tickets.page(params[:page]).per(10) #TEST
+
+ #respond_with(@tickets)
end
def destroy
@@ -124,7 +133,7 @@ class TicketsController < ApplicationController
access_denied unless ticket_access?
end
- def tickets_by_admin(id=current_user.id)
+ def tickets_by_admin(id=current_user.id) #returns Array which doesn't work for pagination, as it is now.
admin_tickets = []
tickets = Ticket.all
tickets.each do |ticket|
@@ -135,7 +144,9 @@ class TicketsController < ApplicationController
end
end
end
- admin_tickets
+ # TODO. is this inefficent?:
+ # this sorts by updated at increasing:
+ admin_tickets.sort{|x,y| x.updated_at <=> y.updated_at}
end
def set_strings