diff options
author | Azul <azul@leap.se> | 2012-11-27 12:37:18 +0100 |
---|---|---|
committer | Azul <azul@leap.se> | 2012-11-27 12:58:23 +0100 |
commit | ebf5dddc39f09bac6640084edbaaefa9c9d48477 (patch) | |
tree | a5b31470f97c32eded6601a5389fe3a1b28b30d0 /help/app/controllers | |
parent | bc432bb9b266524fd97cfb8030987c6a3e8f126e (diff) |
moved ticket fetching logic from controller to model
Diffstat (limited to 'help/app/controllers')
-rw-r--r-- | help/app/controllers/tickets_controller.rb | 43 |
1 files changed, 2 insertions, 41 deletions
diff --git a/help/app/controllers/tickets_controller.rb b/help/app/controllers/tickets_controller.rb index 3ce3a8a..2e55c36 100644 --- a/help/app/controllers/tickets_controller.rb +++ b/help/app/controllers/tickets_controller.rb @@ -82,37 +82,13 @@ class TicketsController < ApplicationController def index #TODO: we will need pagination - if admin? - if params[:admin_status] == 'mine' - @tickets = tickets_by_admin(current_user.id) #returns Array so pagination does not work - elsif params[:open_status] == 'open' - @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_updated_at_and_is_closed - # @tickets = Ticket.by_is_open.key(false) #returns CouchRest::Model::Designs::View - else - # @tickets = Ticket.all #returns CouchRest::Model::Designs::View - @tickets = Ticket.by_updated_at - end + @tickets = Ticket.for_admin(current_user, params) else - #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]) - elsif params[:open_status] == 'closed' - @tickets = Ticket.by_is_open_and_created_by.key([false, current_user.id]) - else - @tickets = Ticket.by_created_by(:key => current_user.id) - end + @tickets = Ticket.for_user(current_user, params) end - - # 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 @@ -132,21 +108,6 @@ class TicketsController < ApplicationController access_denied unless ticket_access? end - 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| - ticket.comments.each do |comment| - if comment.posted_by == id and (params[:open_status] != 'open' or ticket.is_open) and (params[:open_status] != 'closed' or !ticket.is_open) #limit based on whether the ticket is open if open_status is set to open or closed - admin_tickets << ticket - break - end - end - end - # 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 @post_reply_str = 'Post reply' #t :post_reply |