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) => zoom: (e) =>
e.preventDefault() e.preventDefault()
id = $(e.target).parents('[data-id]').data('id') id = $(e.target).parents('[data-id]').data('id')
@log 'goto zoom!' position = $(e.target).parents('[data-position]').data('position')
@navigate 'ticket/zoom/' + id
Config['LastOverview'] = @view
Config['LastOverviewPosition'] = position
Config['LastOverviewTotal'] = @tickets_count
@log 'goto zoom!', id, position
@navigate 'ticket/zoom/' + id + '/nav/true'
settings: (e) => settings: (e) =>
e.preventDefault() e.preventDefault()

View file

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

View file

@ -185,6 +185,7 @@ class Index extends App.Controller
articles: @articles, articles: @articles,
form_ticket: form_ticket, form_ticket: form_ticket,
form_article: form_article, form_article: form_article,
nav: @nav,
) )
@el.find('textarea').elastic() @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'] = Index
Config.Routes['ticket/zoom/:ticket_id/nav/:nav'] = Index
Config.Routes['ticket/zoom/:ticket_id/:article_id'] = Index Config.Routes['ticket/zoom/:ticket_id/:article_id'] = Index

View file

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

View file

@ -15,6 +15,26 @@ class TicketOverviewsController < ApplicationController
end end
# get real overview data # 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( overview = Ticket.overview(
:view => params[:view], :view => params[:view],
:view_mode => params[:view_mode], :view_mode => params[:view_mode],

View file

@ -202,6 +202,25 @@ class Ticket < ActiveRecord::Base
return result return result
end 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 # get tickets for overview
data[:start_page] ||= 1 data[:start_page] ||= 1
tickets = Ticket.where( :group_id => group_ids ). tickets = Ticket.where( :group_id => group_ids ).