Implemented download list

This commit is contained in:
Martin Edenhofer 2015-10-20 14:58:04 +02:00
parent 78fc282051
commit 563789135f
5 changed files with 43 additions and 57 deletions

View file

@ -188,11 +188,12 @@ class Download extends App.Controller
reports = [] reports = []
# select first backend, if no backend is selected # select first backend, if no backend is selected
$('.js-backendSelector:checked').each( (index, element) -> @backendSelected = undefined
if $(element).hasClass('download') if @config.metric[@params.metric]
value = $(element).val() for backend in @config.metric[@params.metric].backend
reports.push value console.log('bac', backend)
) if backend.dataDownload && !@backendSelected
@backendSelected = backend.name
# get used profiles # get used profiles
profiles = [] profiles = []
@ -203,26 +204,10 @@ class Download extends App.Controller
profiles.push App.ReportProfile.find(key) profiles.push App.ReportProfile.find(key)
@html App.view('report/download_header')( @html App.view('report/download_header')(
reports: reports reports: reports
profiles: profiles profiles: profiles
metric: @config.metric[@params.metric] backendSelected: @backendSelected
) metric: @config.metric[@params.metric]
@backendSelected = ''
active = false
@el.find('.js-dataDownloadBackendSelector').each( (index, element) ->
if $(element).parent().hasClass('is-active')
active = true
)
if !active
@el.find('.js-dataDownloadBackendSelector').first().parent().addClass('is-active')
# rerender view after backend is selected
@el.find('.js-dataDownloadBackendSelector').each( (index, element) =>
if $(element).parent().hasClass('is-active')
@profileSelectedId = $(element).data('profile-id')
@backendSelected = $(element).data('backend')
) )
@tableUpdate() @tableUpdate()
@ -240,7 +225,7 @@ class Download extends App.Controller
if App.Config.get('import_mode') if App.Config.get('import_mode')
url = App.Config.get('import_otrs_endpoint') + '/index.pl?Action=AgentTicketZoom;TicketID=' url = App.Config.get('import_otrs_endpoint') + '/index.pl?Action=AgentTicketZoom;TicketID='
if _.isEmpty(tickets) if _.isEmpty(tickets)
@el.find('js-dataDownloadTable').html('') @el.find('.js-dataDownloadTable').html('')
else else
html = App.view('report/download_list')( html = App.view('report/download_list')(
tickets: tickets tickets: tickets
@ -248,7 +233,7 @@ class Download extends App.Controller
url: url url: url
download: @apiPath + '/reports/csvforset/' + name download: @apiPath + '/reports/csvforset/' + name
) )
@el.find('js-dataDownloadTable').html(html) @el.find('.js-dataDownloadTable').html(html)
@startLoading() @startLoading()
@ajax( @ajax(
@ -267,14 +252,11 @@ class Download extends App.Controller
processData: true processData: true
success: (data) => success: (data) =>
@stopLoading() @stopLoading()
App.Collection.loadAssets(data.assets)
# load ticket collection / do not save in localStorage
App.Collection.load( type: 'TicketReport', data: data.tickets, localStorage: true )
ticket_collection = [] ticket_collection = []
if data.ticket_ids
if data.tickets for record_id in data.ticket_ids
for record in data.tickets ticket = App.Ticket.fullLocal( record_id )
ticket = App.TicketReport.fullLocal( record.id )
ticket_collection.push ticket ticket_collection.push ticket
table(ticket_collection, data.count) table(ticket_collection, data.count)

View file

@ -4,7 +4,7 @@
<% for profile in @profiles: %> <% for profile in @profiles: %>
<% for backend in @metric.backend: %> <% for backend in @metric.backend: %>
<% if backend.dataDownload: %> <% if backend.dataDownload: %>
<li><a href="#" class="js-dataDownloadBackendSelector" data-toggle="tab" data-profile-id="<%= profile.id %>" data-backend="<%= backend.name %>"><%= @T(backend.display) %></a></li> <li <% if backend.name is @backendSelected: %>class="is-active active"<% end %>><a href="#" class="js-dataDownloadBackendSelector" data-toggle="tab" data-profile-id="<%= profile.id %>" data-backend="<%= backend.name %>"><%= @T(backend.display) %></a></li>
<% end %> <% end %>
<% end %> <% end %>
<% end %> <% end %>

View file

@ -1,7 +1,5 @@
<i><%- @T('%s records', @count) %></i> <i><%- @T('%s records', @count) %></i>
<a href="<%-@download%>" target="_blank" data-type="attachment" id="downloadsetascsv"> <a href="<%- @download %>" target="_blank" data-type="attachment" id="downloadsetascsv"><%- @Icon('download') %></a>
<i class="glyphicon glyphicon-download" title="<%- @Ti('Download') %>"></i>
</a>
<table class="table table-striped table-hover"> <table class="table table-striped table-hover">
<thead> <thead>
<tr> <tr>
@ -15,7 +13,7 @@
<tbody> <tbody>
<% for ticket in @tickets: %> <% for ticket in @tickets: %>
<tr> <tr>
<td><a target="_blank" href="<%= @url %><%= ticket.id %>"><%- @P(ticket, 'number') %></a></td> <td><a <% if App.Config.get('import_mode'): %>target="_blank"<% end %> href="<%= @url %><%= ticket.id %>"><%- @P(ticket, 'number') %></a></td>
<td><%- @P(ticket, 'title') %></td> <td><%- @P(ticket, 'title') %></td>
<td><%- @P(ticket, 'state') %></td> <td><%- @P(ticket, 'state') %></td>
<td><%- @P(ticket, 'group') %></td> <td><%- @P(ticket, 'group') %></td>

View file

@ -76,12 +76,18 @@ class ReportsController < ApplicationController
end end
# get data # get data
ticket_ids = []
assets = {}
Ticket.select('id').all.each {|ticket_part|
ticket = Ticket.lookup(id: ticket_part.id)
assets = ticket.assets(assets)
ticket_ids.push ticket_part.id
}
count = Ticket.count
render json: { render json: {
data: { ticket_ids: ticket_ids,
start: start, assets: assets,
stop: stop, count: count,
}
} }
end end

View file

@ -123,36 +123,36 @@ class Report
name: 'first_response_average', name: 'first_response_average',
display: 'First Response average', display: 'First Response average',
selected: true, selected: true,
dataDownload: true, dataDownload: false,
}, },
{ {
name: 'first_response_max', name: 'first_response_max',
display: 'First Response max', display: 'First Response max',
selected: true, selected: false,
dataDownload: true, dataDownload: true,
}, },
{ {
name: 'first_response_min', name: 'first_response_min',
display: 'First Response min', display: 'First Response min',
selected: true, selected: false,
dataDownload: true, dataDownload: true,
}, },
{ {
name: 'solution_time_average', name: 'solution_time_average',
display: 'Solution Time average', display: 'Solution Time average',
selected: true, selected: true,
dataDownload: true, dataDownload: false,
}, },
{ {
name: 'solution_time_max', name: 'solution_time_max',
display: 'Solution Time max', display: 'Solution Time max',
selected: true, selected: false,
dataDownload: true, dataDownload: true,
}, },
{ {
name: 'solution_time_min', name: 'solution_time_min',
display: 'Solution Time min', display: 'Solution Time min',
selected: true, selected: false,
dataDownload: true, dataDownload: true,
}, },
] ]
@ -168,43 +168,43 @@ class Report
name: 'phone_in', name: 'phone_in',
display: 'Phone (in)', display: 'Phone (in)',
selected: true, selected: true,
dataDownload: true, dataDownload: false,
}, },
{ {
name: 'phone_out', name: 'phone_out',
display: 'Phone (out)', display: 'Phone (out)',
selected: true, selected: true,
dataDownload: true, dataDownload: false,
}, },
{ {
name: 'email_in', name: 'email_in',
display: 'Email (in)', display: 'Email (in)',
selected: true, selected: true,
dataDownload: true, dataDownload: false,
}, },
{ {
name: 'email_out', name: 'email_out',
display: 'Email (out)', display: 'Email (out)',
selected: true, selected: true,
dataDownload: true, dataDownload: false,
}, },
{ {
name: 'web_in', name: 'web_in',
display: 'Web (in)', display: 'Web (in)',
selected: true, selected: true,
dataDownload: true, dataDownload: false,
}, },
{ {
name: 'twitter_in', name: 'twitter_in',
display: 'Twitter (in)', display: 'Twitter (in)',
selected: true, selected: true,
dataDownload: true, dataDownload: false,
}, },
{ {
name: 'twitter_out', name: 'twitter_out',
display: 'Twitter (out)', display: 'Twitter (out)',
selected: true, selected: true,
dataDownload: true, dataDownload: false,
}, },
] ]
config[:metric][:communication][:backend] = backend config[:metric][:communication][:backend] = backend