summaryrefslogtreecommitdiff
path: root/help/app
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
parent80cd2489d87a523663d92776de55fa7fda2ecb99 (diff)
Playing around with pagination, and ways to filter/order ticket results.
Diffstat (limited to 'help/app')
-rw-r--r--help/app/controllers/tickets_controller.rb31
-rw-r--r--help/app/models/ticket.rb31
-rw-r--r--help/app/views/tickets/index.html.haml41
-rw-r--r--help/app/views/tickets/show.html.haml2
4 files changed, 76 insertions, 29 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
diff --git a/help/app/models/ticket.rb b/help/app/models/ticket.rb
index 3b66fe4..e8b004f 100644
--- a/help/app/models/ticket.rb
+++ b/help/app/models/ticket.rb
@@ -36,10 +36,32 @@ class Ticket < CouchRest::Model::Base
#named_scope :open, :conditions => {:is_open => true} #??
design do
- view :by_title
+ #TODO--clean this all up
view :by_is_open
view :by_created_by
+
+ view :by_updated_at #
+
+ view :by_title, #test
+ :map =>
+ "function(doc) {
+ emit(doc._id, doc);
+ }"
view :by_is_open_and_created_by
+ view :by_updated_at_and_is_open,
+ :map =>
+ "function(doc) {
+ if (doc['type'] == 'Ticket' && doc.is_open == true) {
+ emit(doc.updated_at, doc);
+ }
+ }"
+ view :by_updated_at_and_is_closed,
+ :map =>
+ "function(doc) {
+ if (doc['type'] == 'Ticket' && doc.is_open == false) {
+ emit(doc.updated_at, doc);
+ }
+ }"
end
@@ -87,8 +109,11 @@ class Ticket < CouchRest::Model::Base
commenters = []
self.comments.each do |comment|
if comment.posted_by
- user = User.find(comment.posted_by)
- commenters << user.login if user and !commenters.include?(user.login)
+ if user = User.find(comment.posted_by)
+ commenters << user.login if user and !commenters.include?(user.login)
+ else
+ commenters << 'unknown user' if !commenters.include?('unknown user') #todo don't hardcode string 'unknown user'
+ end
else
commenters << 'unauthenticated user' if !commenters.include?('unauthenticated user') #todo don't hardcode string 'unauthenticated user'
end
diff --git a/help/app/views/tickets/index.html.haml b/help/app/views/tickets/index.html.haml
index 0bb9c1d..b8ec6cc 100644
--- a/help/app/views/tickets/index.html.haml
+++ b/help/app/views/tickets/index.html.haml
@@ -14,21 +14,34 @@ Create a
%li{:class => ("active" if params[:admin_status] != 'mine')}
= link_to 'all tickets', {:admin_status => 'all', :open_status => params[:open_status]}
.span10
- %ul.nav.nav-tabs
- %li{:class => ("active" if params[:open_status] != 'closed' and params[:open_status] != 'all')}
- = link_to 'open issues', {:open_status => 'open', :admin_status => params[:admin_status]}
- %li{:class => ("active" if params[:open_status] == 'closed')}
- = link_to 'closed issues', {:open_status => 'closed', :admin_status => params[:admin_status]}
- = #%a{:href => "#"} closed issue
- %li{:class => ("active" if params[:open_status] == 'all')}
- = link_to 'open & closed issues', {:open_status => 'all', :admin_status => params[:admin_status]}
-
- - @tickets.each do |ticket|
- %p
- = link_to ticket.title, ticket
- comments by:
- = ticket.commenters
+ .table-bordered
+ = # TODO not sure if want table, but playing around with layout here.
+ %ul.nav.nav-tabs
+ %li{:class => ("active" if params[:open_status] != 'closed' and params[:open_status] != 'all')}
+ = link_to 'open issues', {:open_status => 'open', :admin_status => params[:admin_status]}
+ %li{:class => ("active" if params[:open_status] == 'closed')}
+ = link_to 'closed issues', {:open_status => 'closed', :admin_status => params[:admin_status]}
+ = #%a{:href => "#"} closed issue
+ %li{:class => ("active" if params[:open_status] == 'all')}
+ = link_to 'open & closed issues', {:open_status => 'all', :admin_status => params[:admin_status]}
+ %ul.nav.nav-pills
+ = #TODO-pull-right isn't working as i want, but want this to the right of tabs within the same div/table
+ %li
+ = link_to 'created at'
+ %li{:class=> ("active" if true)}
+ = link_to 'updated at'
+ .table-bordered
+ - @tickets.each do |ticket|
+ %p
+ = link_to ticket.title, ticket
+ created:
+ = ticket.created_at.to_s(:short)
+ updated:
+ = ticket.updated_at.to_s(:short)
+ comments by:
+ = ticket.commenters
+ = paginate @tickets
%div{"data-pjax-container" => ""}
/ PJAX updates will go here
diff --git a/help/app/views/tickets/show.html.haml b/help/app/views/tickets/show.html.haml
index 9b12f34..d9f594b 100644
--- a/help/app/views/tickets/show.html.haml
+++ b/help/app/views/tickets/show.html.haml
@@ -1,5 +1,3 @@
-%h1 tickets show (just as space for firefox)
-%h1 tickets show (just as space for firefox)
%h2= @ticket.title
- if @ticket.email
email: