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="page-header">
<div class="row"> <div class="row">
<div class="span12"> <div class="span10">
<h1><%= @ticket.title %> <small><%= @ticket.number %></small></h1> <h1><%= @ticket.title %> <small><%= @ticket.number %></small></h1>
</div> </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>
<div class="row"> <div class="row">
<div class="span12"> <div class="span12">

View file

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

View file

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

View file

@ -4,103 +4,37 @@ class TicketOverviewsController < ApplicationController
# GET /tickets # GET /tickets
def show def show
#sleep 2 #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 render :json => result
return return
end end
# get tickets for overview # get real overview data
params[:start_page] ||= 1 overview = Ticket.overview(
tickets = Ticket.where( :group_id => group_ids ). :view => params[:view],
where( overview_selected.condition ). :view_mode => params[:view_mode],
order( overview_selected[:order][:by].to_s + ' ' + overview_selected[:order][:direction].to_s ). :current_user_id => current_user.id,
limit( overview_selected.view[ params[:view_mode].to_sym ][:per_page] ). :start_page => params[:start_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 related users # get related users
users = {} users = {}
tickets.each {|ticket| tickets = []
if !users[ticket.owner_id] overview[:tickets].each {|ticket|
users[ticket.owner_id] = user_data_full(ticket.owner_id) tickets.push ticket.attributes
if !users[ ticket.owner_id ]
users[ ticket.owner_id ] = user_data_full( ticket.owner_id )
end end
if !users[ticket.customer_id] if !users[ ticket.customer_id ]
users[ticket.customer_id] = user_data_full(ticket.customer_id) users[ ticket.customer_id ] = user_data_full( ticket.customer_id )
end end
if !users[ticket.created_by_id] if !users[ ticket.created_by_id ]
users[ticket.created_by_id] = user_data_full(ticket.created_by_id) users[ ticket.created_by_id ] = user_data_full( ticket.created_by_id )
end end
} }
@ -109,21 +43,21 @@ class TicketOverviewsController < ApplicationController
bulk_owner_ids = [] bulk_owner_ids = []
bulk_owners.each { |user| bulk_owners.each { |user|
bulk_owner_ids.push user.id bulk_owner_ids.push user.id
if !users[user.id] if !users[ user.id ]
users[user.id] = user_data_full(user.id) users[ user.id ] = user_data_full( user.id )
end end
} }
# return result # return result
render :json => { render :json => {
:overview => overview_selected_raw, :overview => overview[:overview],
:tickets => tickets, :tickets => tickets,
:tickets_count => tickets_count, :tickets_count => overview[:tickets_count],
:users => users, :users => users,
:bulk => { :bulk => {
:owner_id => { :owner_id => {
:id => bulk_owner_ids, :id => bulk_owner_ids,
} },
}, },
} }
end end

View file

@ -123,6 +123,105 @@ class Ticket < ActiveRecord::Base
return subject return subject
end 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 private
def number_generate def number_generate
Ticket.new.number_adapter = Setting.get('ticket_number') Ticket.new.number_adapter = Setting.get('ticket_number')