Added ticket zoom previous/next pagination.

This commit is contained in:
Martin Edenhofer 2012-07-20 13:23:09 +02:00
parent bd1689ca06
commit 88aa1a1b6c
5 changed files with 149 additions and 95 deletions

View file

@ -1,8 +1,20 @@
<div class="page-header">
<div class="row">
<div class="span12">
<div class="span10">
<h1><%= @ticket.title %> <small><%= @ticket.number %></small></h1>
</div>
<div class="span2">
<% if window.Config['LastOverview']: %>
<div class="pagination">
<span class="count"><%= Config['LastOverviewPosition'] %>/<%= Config['LastOverviewTotal'] %></span>
<% base_url ="#ticket/view/#{Config['LastOverview']}/#{Config['LastOverviewPosition']}/" %>
<ul>
<li class="<% if Config['LastOverviewPosition'] <= 1: %>disabled<% end %>"><a href="<%- base_url %>previous" title="<%- T('previous Ticket in Overview') %>">«</a></li>
<li class="<% if Config['LastOverviewPosition'] is Config['LastOverviewTotal']: %>disabled<% end %>"><a href="<%- base_url %>next" title="<%- T('next Ticket in Overview') %>">»</a></li>
</ul>
</div>
<% end %>
</div>
</div>
<div class="row">
<div class="span12">

View file

@ -13,8 +13,10 @@
</tr>
</thead>
<tbody>
<% position = 0 %>
<% for object in @objects: %>
<tr class="item" data-id="<%= object.id %>">
<% position++ %>
<tr class="item" data-id="<%= object.id %>" data-position="<%= position %>" >
<% if @checkbox: %>
<td>
<input type="checkbox" value="<%= object.id %>" name="bulk"/>

View file

@ -44,6 +44,13 @@ body {
line-height: 26px;
}
.pagination .count {
padding: 6px 6px;
float: left;
color: #999;
}
/* replace music icon with attachment */
.icon-attachment {
background-position: -24px 0;

View file

@ -4,95 +4,29 @@ class TicketOverviewsController < ApplicationController
# GET /tickets
def show
#sleep 2
# build up attributes hash
overview_selected = nil
overview_selected_raw = nil
overviews = Overview.all
overviews.each { |overview|
# for cleanup reasons, remove me later!
overview.condition.each { |item, value |
if item == 'owner_id' && overview.condition[item] != 1
overview.condition[item] = 'current_user.id'
end
}
# remember selected view
if params[:view] && params[:view] == overview.meta[:url]
overview_selected = overview
overview_selected_raw = Marshal.load( Marshal.dump(overview.attributes) )
end
# replace 'current_user.id' with current_user.id
overview.condition.each { |item, value |
if value == 'current_user.id'
overview.condition[item] = current_user.id
end
}
}
# sortby
# prio
# state
# group
# customer
# order
# asc
# desc
# groupby
# prio
# state
# group
# customer
# all = attributes[:myopenassigned]
# all.merge( { :group_id => groups } )
# @tickets = Ticket.where(:group_id => groups, attributes[:myopenassigned] ).limit(params[:limit])
# get only tickets with permissions
group_ids = Group.select( 'groups.id' ).joins(:users).
where( 'groups_users.user_id = ?', [current_user.id] ).
where( 'groups.active = ?', true ).
map( &:id )
# overview meta for navbar
if !overview_selected
# loop each overview
result = []
overviews.each { |overview|
# get count
count = Ticket.where( :group_id => group_ids ).where( overview.condition ).count()
# get meta info
all = overview.meta
# push to result data
result.push all.merge( { :count => count } )
}
# get navbar overview data
if !params[:view]
result = Ticket.overview(
:current_user_id => current_user.id,
)
render :json => result
return
end
# get tickets for overview
params[:start_page] ||= 1
tickets = Ticket.where( :group_id => group_ids ).
where( overview_selected.condition ).
order( overview_selected[:order][:by].to_s + ' ' + overview_selected[:order][:direction].to_s ).
limit( overview_selected.view[ params[:view_mode].to_sym ][:per_page] ).
offset( overview_selected.view[ params[:view_mode].to_sym ][:per_page].to_i * ( params[:start_page].to_i - 1 ) )
tickets_count = Ticket.where( :group_id => group_ids ).
where( overview_selected.condition ).
count()
# get real overview data
overview = Ticket.overview(
:view => params[:view],
:view_mode => params[:view_mode],
:current_user_id => current_user.id,
:start_page => params[:start_page],
)
# get related users
users = {}
tickets.each {|ticket|
tickets = []
overview[:tickets].each {|ticket|
tickets.push ticket.attributes
if !users[ ticket.owner_id ]
users[ ticket.owner_id ] = user_data_full( ticket.owner_id )
end
@ -116,14 +50,14 @@ class TicketOverviewsController < ApplicationController
# return result
render :json => {
:overview => overview_selected_raw,
:overview => overview[:overview],
:tickets => tickets,
:tickets_count => tickets_count,
:tickets_count => overview[:tickets_count],
:users => users,
:bulk => {
:owner_id => {
:id => bulk_owner_ids,
}
},
},
}
end

View file

@ -123,6 +123,105 @@ class Ticket < ActiveRecord::Base
return subject
end
# Ticket.overview(
# :view => 'some_view_url',
# :current_user_id => 123,
# )
def self.overview (data)
# build up attributes hash
overview_selected = nil
overview_selected_raw = nil
overviews = Overview.all
overviews.each { |overview|
# for cleanup reasons, remove me later!
overview.condition.each { |item, value |
if item == 'owner_id' && overview.condition[item] != 1
overview.condition[item] = 'current_user.id'
end
}
# remember selected view
if data[:view] && data[:view] == overview.meta[:url]
overview_selected = overview
overview_selected_raw = Marshal.load( Marshal.dump(overview.attributes) )
end
# replace 'current_user.id' with current_user.id
overview.condition.each { |item, value |
if value == 'current_user.id'
overview.condition[item] = data[:current_user_id]
end
}
}
# sortby
# prio
# state
# group
# customer
# order
# asc
# desc
# groupby
# prio
# state
# group
# customer
# all = attributes[:myopenassigned]
# all.merge( { :group_id => groups } )
# @tickets = Ticket.where(:group_id => groups, attributes[:myopenassigned] ).limit(params[:limit])
# get only tickets with permissions
group_ids = Group.select( 'groups.id' ).joins(:users).
where( 'groups_users.user_id = ?', [ data[:current_user_id] ] ).
where( 'groups.active = ?', true ).
map( &:id )
# overview meta for navbar
if !overview_selected
# loop each overview
result = []
overviews.each { |overview|
# get count
count = Ticket.where( :group_id => group_ids ).where( overview.condition ).count()
# get meta info
all = overview.meta
# push to result data
result.push all.merge( { :count => count } )
}
return result
end
# get tickets for overview
data[:start_page] ||= 1
tickets = Ticket.where( :group_id => group_ids ).
where( overview_selected.condition ).
order( overview_selected[:order][:by].to_s + ' ' + overview_selected[:order][:direction].to_s ).
limit( overview_selected.view[ data[:view_mode].to_sym ][:per_page] ).
offset( overview_selected.view[ data[:view_mode].to_sym ][:per_page].to_i * ( data[:start_page].to_i - 1 ) )
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
private
def number_generate
Ticket.new.number_adapter = Setting.get('ticket_number')