Improved overview pagination in ticket zoom.

This commit is contained in:
Martin Edenhofer 2012-07-20 15:47:04 +02:00
parent 1206009d84
commit e6f4bd021f
6 changed files with 65 additions and 16 deletions

View file

@ -105,8 +105,14 @@ class App.DashboardTicket extends App.Controller
zoom: (e) =>
e.preventDefault()
id = $(e.target).parents('[data-id]').data('id')
@log 'goto zoom!'
@navigate 'ticket/zoom/' + id
position = $(e.target).parents('[data-position]').data('position')
Config['LastOverview'] = @view
Config['LastOverviewPosition'] = position
Config['LastOverviewTotal'] = @tickets_count
@log 'goto zoom!', id, position
@navigate 'ticket/zoom/' + id + '/nav/true'
settings: (e) =>
e.preventDefault()

View file

@ -29,9 +29,6 @@ class Index extends App.Controller
# set controller to active
Config['ActiveController'] = '#ticket_overview_' + @view
# set last overview
Config['LastOverview'] = @view
# refresh list ever 40 sec.
@interval( @fetch, 400000, 'ticket_overview_' + @view )
@ -285,10 +282,13 @@ class Index extends App.Controller
e.preventDefault()
id = $(e.target).parents('[data-id]').data('id')
position = $(e.target).parents('[data-position]').data('position')
# set last overview
Config['LastOverview'] = @view
Config['LastOverviewPosition'] = position
Config['LastOverviewTotal'] = @tickets_count
@navigate 'ticket/zoom/' + id
@navigate 'ticket/zoom/' + id + '/nav/true'
settings: (e) =>
e.preventDefault()
@ -441,7 +441,7 @@ class Router extends App.Controller
super
# set new key
@key = '#ticket/view/' + @view
@key = '#ticket/view/array/' + @view
# get data
if window.LastRefresh[ @key ]
@ -453,9 +453,8 @@ class Router extends App.Controller
type: 'GET',
url: '/ticket_overviews',
data: {
view: @view,
view_mode: 's',
start_page: 1,
view: @view,
array: true,
}
processData: true,
success: @load
@ -464,6 +463,9 @@ class Router extends App.Controller
load: (data) =>
@tickets = data.tickets
@tickets_count = data.tickets_count
window.LastRefresh[ @key ] = {}
window.LastRefresh[ @key ]['tickets_count'] = @tickets_count
window.LastRefresh[ @key ]['tickets'] = @tickets
@redirect()
redirect: =>
@ -475,15 +477,15 @@ class Router extends App.Controller
if @direction == 'next'
if @tickets[ @position ] && @tickets[ @position ]
Config['LastOverviewPosition']++
@navigate 'ticket/zoom/' + @tickets[ @position ].id
@navigate 'ticket/zoom/' + @tickets[ @position ].id + '/nav/true'
else
@navigate 'ticket/zoom/' + @tickets[ @position - 1 ].id
@navigate 'ticket/zoom/' + @tickets[ @position - 1 ].id + '/nav/true'
else
if @tickets[ @position - 2 ] && @tickets[ @position - 2 ].id
if @tickets[ @position - 2 ] && @tickets[ @position - 2 ].id + '/nav/true'
Config['LastOverviewPosition']--
@navigate 'ticket/zoom/' + @tickets[ @position - 2 ].id
@navigate 'ticket/zoom/' + @tickets[ @position - 2 ].id + '/nav/true'
else
@navigate 'ticket/zoom/' + @tickets[ @position - 1 ].id
@navigate 'ticket/zoom/' + @tickets[ @position - 1 ].id + '/nav/true'
Config.Routes['ticket/view/:view/:position/:direction'] = Router
Config.Routes['ticket/view/:view'] = Index

View file

@ -185,6 +185,7 @@ class Index extends App.Controller
articles: @articles,
form_ticket: form_ticket,
form_article: form_article,
nav: @nav,
)
@el.find('textarea').elastic()
@ -398,4 +399,5 @@ class Index extends App.Controller
Config.Routes['ticket/zoom/:ticket_id'] = Index
Config.Routes['ticket/zoom/:ticket_id/nav/:nav'] = Index
Config.Routes['ticket/zoom/:ticket_id/:article_id'] = Index

View file

@ -4,7 +4,7 @@
<h1><%= @ticket.title %> <small><%= @ticket.number %></small></h1>
</div>
<div class="span2">
<% if window.Config['LastOverview']: %>
<% if window.Config['LastOverview'] && @nav: %>
<div class="pagination">
<span class="count"><%= Config['LastOverviewPosition'] %>/<%= Config['LastOverviewTotal'] %></span>
<% base_url ="#ticket/view/#{Config['LastOverview']}/#{Config['LastOverviewPosition']}/" %>

View file

@ -15,6 +15,26 @@ class TicketOverviewsController < ApplicationController
end
# get real overview data
if params[:array]
overview = Ticket.overview(
:view => params[:view],
:current_user_id => current_user.id,
:array => true,
)
tickets = []
overview[:tickets].each {|ticket|
data = { :id => ticket.id }
tickets.push data
}
# return result
render :json => {
:overview => overview[:overview],
:tickets => tickets,
:tickets_count => overview[:tickets_count],
}
return
end
overview = Ticket.overview(
:view => params[:view],
:view_mode => params[:view_mode],

View file

@ -202,6 +202,25 @@ class Ticket < ActiveRecord::Base
return result
end
# get result list
if data[:array]
tickets = Ticket.select( 'id' ).
where( :group_id => group_ids ).
where( overview_selected.condition ).
order( overview_selected[:order][:by].to_s + ' ' + overview_selected[:order][:direction].to_s ).
limit( 4_000 )
tickets_count = Ticket.where( :group_id => group_ids ).
where( overview_selected.condition ).
count()
return {
:tickets => tickets,
:tickets_count => tickets_count,
:overview => overview_selected_raw,
}
end
# get tickets for overview
data[:start_page] ||= 1
tickets = Ticket.where( :group_id => group_ids ).