Improved merge feature.

This commit is contained in:
Martin Edenhofer 2012-10-18 21:23:05 +02:00
parent 507eae63bb
commit 1d805d13db
9 changed files with 154 additions and 24 deletions

View file

@ -1,5 +1,5 @@
class App.Controller extends Spine.Controller class App.Controller extends Spine.Controller
# add @title methode to set title # add @title methode to set title
title: (name) -> title: (name) ->
# $('html head title').html( Config.product_name + ' - ' + App.i18n.translateInline(name) ) # $('html head title').html( Config.product_name + ' - ' + App.i18n.translateInline(name) )

View file

@ -14,6 +14,8 @@ class App.ControllerTable extends App.Controller
overview: ['host', 'user', 'adapter', 'active'], overview: ['host', 'user', 'adapter', 'active'],
model: App.Channel, model: App.Channel,
objects: data, objects: data,
checkbox: false,
radio: false,
) )
new App.ControllerTable( new App.ControllerTable(
@ -34,6 +36,8 @@ class App.ControllerTable extends App.Controller
], ],
model: App.Ticket, model: App.Ticket,
objects: tickets, objects: tickets,
checkbox: false,
radio: false,
) )
### ###
@ -43,6 +47,7 @@ class App.ControllerTable extends App.Controller
attributes = data.attributes || data.model.configure_attributes || {} attributes = data.attributes || data.model.configure_attributes || {}
header = data.header header = data.header
# check if table is empty
if _.isEmpty(data.objects) if _.isEmpty(data.objects)
table = '' table = ''
table = '-none-' table = '-none-'
@ -111,11 +116,8 @@ class App.ControllerTable extends App.Controller
overview: dataTypesForCols, overview: dataTypesForCols,
objects: data.objects, objects: data.objects,
checkbox: data.checkbox, checkbox: data.checkbox,
radio: data.radio,
) )
# @log 'ttt', $(table).find('span')
# $(table).find('span').bind('click', ->
# console.log('----------click---------')
# )
# convert to jquery object # convert to jquery object
table = $(table) table = $(table)

View file

@ -1,10 +1,99 @@
class App.TicketMerge extends App.ControllerModal class App.TicketMerge extends App.ControllerModal
constructor: -> constructor: ->
super super
@render() @fetch()
fetch: ->
# merge tickets
App.Com.ajax(
id: 'ticket_merge_list',
type: 'GET',
url: '/api/ticket_merge_list/' + @ticket_id,
data: {
# view: @view
}
processData: true,
success: (data, status, xhr) =>
if data.customer
App.Collection.load( type: 'Ticket', data: data.customer.tickets )
App.Collection.load( type: 'User', data: data.customer.users )
if data.recent
App.Collection.load( type: 'Ticket', data: data.recent.tickets )
App.Collection.load( type: 'User', data: data.recent.users )
@render( data )
)
render: (data) ->
render: ->
@html App.view('agent_ticket_merge')() @html App.view('agent_ticket_merge')()
list = []
for t in data.customer.tickets
ticketItem = App.Collection.find( 'Ticket', t.id )
list.push ticketItem
new App.ControllerTable(
el: @el.find('#ticket-merge-customer-tickets'),
overview_extended: [
{ name: 'number', link: true },
{ name: 'title', link: true },
# { name: 'customer', class: 'user-data', data: { id: true } },
{ name: 'ticket_state', translate: true },
# { name: 'ticket_priority', translate: true },
{ name: 'group' },
# { name: 'owner', class: 'user-data', data: { id: true } },
{ name: 'created_at', callback: @humanTime },
# { name: 'last_contact', callback: @frontendTime },
# { name: 'last_contact_agent', callback: @frontendTime },
# { name: 'last_contact_customer', callback: @frontendTime },
# { name: 'first_response', callback: @frontendTime },
# { name: 'close_time', callback: @frontendTime },
],
model: App.Ticket,
objects: list,
radio: true,
)
list = []
for t in data.recent.tickets
ticketItem = App.Collection.find( 'Ticket', t.id )
list.push ticketItem
new App.ControllerTable(
el: @el.find('#ticket-merge-recent-tickets'),
overview_extended: [
{ name: 'number', link: true },
{ name: 'title', link: true },
# { name: 'customer', class: 'user-data', data: { id: true } },
{ name: 'ticket_state', translate: true },
# { name: 'ticket_priority', translate: true },
{ name: 'group' },
# { name: 'owner', class: 'user-data', data: { id: true } },
{ name: 'created_at', callback: @humanTime },
# { name: 'last_contact', callback: @frontendTime },
# { name: 'last_contact_agent', callback: @frontendTime },
# { name: 'last_contact_customer', callback: @frontendTime },
# { name: 'first_response', callback: @frontendTime },
# { name: 'close_time', callback: @frontendTime },
],
model: App.Ticket,
objects: list,
radio: true,
)
@el.delegate('[name="master_ticket_number"]', 'focus', (e) ->
$(e.target).parents().find('[name="radio"]').attr( 'checked', false )
)
@el.delegate('[name="radio"]', 'click', (e) ->
if $(e.target).attr('checked')
ticket_id = $(e.target).val()
ticket = App.Collection.find( 'Ticket', ticket_id )
$(e.target).parents().find('[name="master_ticket_number"]').val( ticket.number )
)
@modalShow() @modalShow()
submit: (e) => submit: (e) =>

View file

@ -4,19 +4,14 @@
<h3><%- @T( 'Merge' ) %></h3> <h3><%- @T( 'Merge' ) %></h3>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<div class="table_history"></div>
<h4><%- @T( 'Merge to Ticket#' ) %></h4> <h4><%- @T( 'Merge to Ticket#' ) %></h4>
<input type="text" name="master_ticket_number" value=""/> <input type="text" name="master_ticket_number" value=""/>
<hr>
<h4><%- @T( 'Recent Customer Tickets' ) %></h4> <h4><%- @T( 'Recent Customer Tickets' ) %></h4>
<div id="ticket-merge-customer-tickets"></div> <div id="ticket-merge-customer-tickets"></div>
<!-- <hr>
<ul> <h4><%- @T( 'Recent Views Tickets' ) %></h4>
<li>Ticket#</li> <div id="ticket-merge-recent-tickets"></div>
<li>Recent Views Tickets</li>
<li>Recent Customer Tickets</li>
</ul>
-->
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button type="submit" class="btn btn-primary"><%- @T( 'Submit' ) %></button> <button type="submit" class="btn btn-primary"><%- @T( 'Submit' ) %></button>

View file

@ -4,6 +4,9 @@
<% if @checkbox: %> <% if @checkbox: %>
<th style="width: 10px"><input type="checkbox" value="" name="bulk_all"/></th> <th style="width: 10px"><input type="checkbox" value="" name="bulk_all"/></th>
<% end %> <% end %>
<% if @radio: %>
<th style="width: 10px"></th>
<% end %>
<% for row in @header: %> <% for row in @header: %>
<th <% if row.style: %>style="<%= row.style %>"<% end %>><%- @T( row.display ) %></th> <th <% if row.style: %>style="<%= row.style %>"<% end %>><%- @T( row.display ) %></th>
<% end %> <% end %>
@ -18,9 +21,10 @@
<% position++ %> <% position++ %>
<tr class="item <% if object.active is false: %>not-active<% end %>" data-id="<%= object.id %>" data-position="<%= position %>" > <tr class="item <% if object.active is false: %>not-active<% end %>" data-id="<%= object.id %>" data-position="<%= position %>" >
<% if @checkbox: %> <% if @checkbox: %>
<td> <td><input type="checkbox" value="<%= object.id %>" name="bulk"/></td>
<input type="checkbox" value="<%= object.id %>" name="bulk"/> <% end %>
</td> <% if @radio: %>
<td><input type="radio" value="<%= object.id %>" name="radio"/></td>
<% end %> <% end %>
<% for row in @overview: %> <% for row in @overview: %>
<% displayName = @P( object[row.name], row ) %> <% displayName = @P( object[row.name], row ) %>

View file

@ -17,7 +17,7 @@ curl http://localhost/api/recent_viewed.json -v -u #{login}:#{password} -H "Cont
=end =end
def recent_viewed def recent_viewed
recent_viewed = History.recent_viewed_fulldata(current_user) recent_viewed = History.recent_viewed_fulldata( current_user, 10 )
# return result # return result
render :json => recent_viewed render :json => recent_viewed

View file

@ -185,6 +185,45 @@ class TicketsController < ApplicationController
} }
end end
# GET /ticket_merge_list/1
def ticket_merge_list
# get closed/open states
ticket_states = Ticket::State.where(
:ticket_state_type_id => Ticket::StateType.where( :name => ['new','open', 'pending reminder', 'pending action', 'closed'] )
)
ticket = Ticket.find( params[:ticket_id] )
ticket_list = Ticket.where( :customer_id => ticket.customer_id, :ticket_state_id => ticket_states ).limit(6)
# get related users
users = {}
tickets = []
ticket_list.each {|ticket|
data = Ticket.full_data(ticket.id)
tickets.push data
if !users[ data['owner_id'] ]
users[ data['owner_id'] ] = User.user_data_full( data['owner_id'] )
end
if !users[ data['customer_id'] ]
users[ data['customer_id'] ] = User.user_data_full( data['customer_id'] )
end
if !users[ data['created_by_id'] ]
users[ data['created_by_id'] ] = User.user_data_full( data['created_by_id'] )
end
}
recent_viewed = History.recent_viewed_fulldata( current_user, 6 )
# return result
render :json => {
:customer => {
:tickets => tickets,
:users => users,
},
:recent => recent_viewed
}
end
# GET /ticket_merge/1/1 # GET /ticket_merge/1/1
def ticket_merge def ticket_merge

View file

@ -188,14 +188,14 @@ class History < ActiveRecord::Base
} }
end end
def self.recent_viewed(user) def self.recent_viewed( user, limit = 10 )
# g = Group.where( :active => true ).joins(:users).where( 'users.id' => user.id ) # g = Group.where( :active => true ).joins(:users).where( 'users.id' => user.id )
stream = History.select("distinct(o_id), created_by_id, history_type_id, history_object_id, created_at"). stream = History.select("distinct(o_id), created_by_id, history_type_id, history_object_id, created_at").
where( :history_object_id => History::Object.where( :name => 'Ticket').first.id ). where( :history_object_id => History::Object.where( :name => 'Ticket').first.id ).
where( :history_type_id => History::Type.where( :name => ['viewed'] ) ). where( :history_type_id => History::Type.where( :name => ['viewed'] ) ).
where( :created_by_id => user.id ). where( :created_by_id => user.id ).
order('created_at DESC, id ASC'). order('created_at DESC, id ASC').
limit(10) limit(limit)
datas = [] datas = []
stream.each do |item| stream.each do |item|
data = item.attributes data = item.attributes
@ -209,8 +209,8 @@ class History < ActiveRecord::Base
return datas return datas
end end
def self.recent_viewed_fulldata(user) def self.recent_viewed_fulldata( user, limit )
recent_viewed = History.recent_viewed(user) recent_viewed = History.recent_viewed( user, limit )
# get related users # get related users
users = {} users = {}

View file

@ -10,6 +10,7 @@ module ExtraRoutes
map.match '/api/ticket_full/:id', :to => 'tickets#ticket_full', :via => :get map.match '/api/ticket_full/:id', :to => 'tickets#ticket_full', :via => :get
map.match '/api/ticket_history/:id', :to => 'tickets#ticket_history', :via => :get map.match '/api/ticket_history/:id', :to => 'tickets#ticket_history', :via => :get
map.match '/api/ticket_customer', :to => 'tickets#ticket_customer', :via => :get map.match '/api/ticket_customer', :to => 'tickets#ticket_customer', :via => :get
map.match '/api/ticket_merge_list/:ticket_id', :to => 'tickets#ticket_merge_list', :via => :get
map.match '/api/ticket_merge/:slave_ticket_id/:master_ticket_number', :to => 'tickets#ticket_merge' map.match '/api/ticket_merge/:slave_ticket_id/:master_ticket_number', :to => 'tickets#ticket_merge'
# ticket overviews # ticket overviews