Small improvements.
This commit is contained in:
parent
289e2da392
commit
26c1a03e77
4 changed files with 101 additions and 20 deletions
|
@ -245,15 +245,19 @@ class Download extends App.Controller
|
||||||
if _.isEmpty(tickets)
|
if _.isEmpty(tickets)
|
||||||
@el.find('.js-dataDownloadTable').html('')
|
@el.find('.js-dataDownloadTable').html('')
|
||||||
else
|
else
|
||||||
|
profile_id = 0
|
||||||
|
for key, value of @params.profileSelected
|
||||||
|
if value
|
||||||
|
profile_id = key
|
||||||
|
downloadUrl = "#{@apiPath}/reports/sets?sheet=true;metric=#{@params.metric};year=#{@params.year};month=#{@params.month};week=#{@params.week};day=#{@params.day};timeRange=#{@params.timeRange};profile_id=#{profile_id};downloadBackendSelected=#{@params.downloadBackendSelected}"
|
||||||
html = App.view('report/download_list')(
|
html = App.view('report/download_list')(
|
||||||
tickets: tickets
|
tickets: tickets
|
||||||
count: count
|
count: count
|
||||||
url: url
|
url: url
|
||||||
download: @apiPath + '/reports/csvforset/' + name
|
download: downloadUrl
|
||||||
)
|
)
|
||||||
@el.find('.js-dataDownloadTable').html(html)
|
@el.find('.js-dataDownloadTable').html(html)
|
||||||
|
|
||||||
@startLoading()
|
|
||||||
@ajax(
|
@ajax(
|
||||||
id: 'report_download'
|
id: 'report_download'
|
||||||
type: 'POST'
|
type: 'POST'
|
||||||
|
@ -271,7 +275,6 @@ class Download extends App.Controller
|
||||||
)
|
)
|
||||||
processData: true
|
processData: true
|
||||||
success: (data) =>
|
success: (data) =>
|
||||||
@stopLoading()
|
|
||||||
App.Collection.loadAssets(data.assets)
|
App.Collection.loadAssets(data.assets)
|
||||||
ticket_collection = []
|
ticket_collection = []
|
||||||
if data.ticket_ids
|
if data.ticket_ids
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
|
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
|
||||||
|
|
||||||
|
require 'tempfile'
|
||||||
|
|
||||||
class ReportsController < ApplicationController
|
class ReportsController < ApplicationController
|
||||||
before_action :authentication_check
|
before_action :authentication_check
|
||||||
|
|
||||||
# GET /api/reports/config
|
# GET /api/reports/config
|
||||||
def config
|
def reporting_config
|
||||||
return if deny_if_not_role('Report')
|
return if deny_if_not_role('Report')
|
||||||
render json: {
|
render json: {
|
||||||
config: Report.config,
|
config: Report.config,
|
||||||
|
@ -89,22 +91,38 @@ class ReportsController < ApplicationController
|
||||||
selector: backend[:condition],
|
selector: backend[:condition],
|
||||||
params: backend[:params],
|
params: backend[:params],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# generate sheet
|
||||||
|
next if !params[:sheet]
|
||||||
|
content = sheet(get_params[:profile], backend[:display], result)
|
||||||
|
send_data(
|
||||||
|
content,
|
||||||
|
filename: "tickets-#{get_params[:profile].name}-#{backend[:display]}.xls",
|
||||||
|
type: 'application/vnd.ms-excel',
|
||||||
|
disposition: 'attachment'
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
return if params[:sheet]
|
||||||
|
|
||||||
render json: result
|
render json: result
|
||||||
end
|
end
|
||||||
|
|
||||||
def params_all
|
def params_all
|
||||||
profile = nil
|
profile = nil
|
||||||
if !params[:profiles]
|
if !params[:profiles] && !params[:profile_id]
|
||||||
render json: {
|
render json: {
|
||||||
error: 'No such profiles param',
|
error: 'No such profiles param',
|
||||||
}, status: :unprocessable_entity
|
}, status: :unprocessable_entity
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
params[:profiles].each {|profile_id, active|
|
if params[:profile_id]
|
||||||
next if !active
|
profile = Report::Profile.find(params[:profile_id])
|
||||||
profile = Report::Profile.find(profile_id)
|
else
|
||||||
}
|
params[:profiles].each {|profile_id, active|
|
||||||
|
next if !active
|
||||||
|
profile = Report::Profile.find(profile_id)
|
||||||
|
}
|
||||||
|
end
|
||||||
if !profile
|
if !profile
|
||||||
render json: {
|
render json: {
|
||||||
error: 'No such active profile',
|
error: 'No such active profile',
|
||||||
|
@ -112,14 +130,14 @@ class ReportsController < ApplicationController
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
config = Report.config
|
local_config = Report.config
|
||||||
if !config || !config[:metric] || !config[:metric][params[:metric].to_sym]
|
if !local_config || !local_config[:metric] || !local_config[:metric][params[:metric].to_sym]
|
||||||
render json: {
|
render json: {
|
||||||
error: "No such metric #{params[:metric]}"
|
error: "No such metric #{params[:metric]}"
|
||||||
}, status: :unprocessable_entity
|
}, status: :unprocessable_entity
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
metric = config[:metric][params[:metric].to_sym]
|
metric = local_config[:metric][params[:metric].to_sym]
|
||||||
|
|
||||||
#{"metric"=>"count", "year"=>2015, "month"=>10, "week"=>43, "day"=>20, "timeSlot"=>"year", "report"=>{"metric"=>"count", "year"=>2015, "month"=>10, "week"=>43, "day"=>20, "timeSlot"=>"year"}}
|
#{"metric"=>"count", "year"=>2015, "month"=>10, "week"=>43, "day"=>20, "timeSlot"=>"year", "report"=>{"metric"=>"count", "year"=>2015, "month"=>10, "week"=>43, "day"=>20, "timeSlot"=>"year"}}
|
||||||
if params[:timeRange] == 'realtime'
|
if params[:timeRange] == 'realtime'
|
||||||
|
@ -147,11 +165,71 @@ class ReportsController < ApplicationController
|
||||||
{
|
{
|
||||||
profile: profile,
|
profile: profile,
|
||||||
metric: metric,
|
metric: metric,
|
||||||
config: config,
|
config: local_config,
|
||||||
start: start,
|
start: start,
|
||||||
stop: stop,
|
stop: stop,
|
||||||
range: range,
|
range: range,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def sheet(profile, title, result)
|
||||||
|
|
||||||
|
# Create a new Excel workbook
|
||||||
|
temp_file = Tempfile.new('time_tracking.xls')
|
||||||
|
workbook = WriteExcel.new(temp_file)
|
||||||
|
|
||||||
|
# Add a worksheet
|
||||||
|
worksheet = workbook.add_worksheet
|
||||||
|
worksheet.set_column(0, 0, 10)
|
||||||
|
worksheet.set_column(1, 1, 34)
|
||||||
|
worksheet.set_column(2, 2, 10)
|
||||||
|
worksheet.set_column(3, 3, 10)
|
||||||
|
worksheet.set_column(4, 7, 20)
|
||||||
|
|
||||||
|
# Add and define a format
|
||||||
|
format = workbook.add_format # Add a format
|
||||||
|
format.set_bold
|
||||||
|
format.set_size(14)
|
||||||
|
format.set_color('black')
|
||||||
|
worksheet.set_row(0, 0, 6)
|
||||||
|
|
||||||
|
# Write a formatted and unformatted string, row and column notation.
|
||||||
|
worksheet.write(0, 0, "Tickets: #{profile.name} (#{title})", format)
|
||||||
|
|
||||||
|
format_header = workbook.add_format # Add a format
|
||||||
|
format_header.set_italic
|
||||||
|
format_header.set_bg_color('gray')
|
||||||
|
format_header.set_color('white')
|
||||||
|
worksheet.write(2, 0, '#', format_header )
|
||||||
|
worksheet.write(2, 1, 'Title', format_header )
|
||||||
|
worksheet.write(2, 2, 'State', format_header )
|
||||||
|
worksheet.write(2, 3, 'Priority', format_header )
|
||||||
|
worksheet.write(2, 4, 'Customer', format_header )
|
||||||
|
worksheet.write(2, 5, 'Created at', format_header )
|
||||||
|
worksheet.write(2, 6, 'Updated at', format_header )
|
||||||
|
worksheet.write(2, 7, 'Closed at', format_header )
|
||||||
|
|
||||||
|
row = 2
|
||||||
|
result[:ticket_ids].each {|ticket_id|
|
||||||
|
ticket = Ticket.lookup(id: ticket_id)
|
||||||
|
row += 1
|
||||||
|
worksheet.write(row, 0, ticket.number )
|
||||||
|
worksheet.write(row, 1, ticket.title)
|
||||||
|
worksheet.write(row, 2, ticket.state.name)
|
||||||
|
worksheet.write(row, 3, ticket.priority.name)
|
||||||
|
worksheet.write(row, 4, ticket.customer.fullname)
|
||||||
|
worksheet.write(row, 5, ticket.created_at)
|
||||||
|
worksheet.write(row, 6, ticket.updated_at)
|
||||||
|
worksheet.write(row, 7, ticket.close_time)
|
||||||
|
}
|
||||||
|
|
||||||
|
workbook.close
|
||||||
|
|
||||||
|
# read file again
|
||||||
|
file = File.new(temp_file, 'r')
|
||||||
|
contents = file.read
|
||||||
|
file.close
|
||||||
|
contents
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,9 +2,9 @@ Zammad::Application.routes.draw do
|
||||||
api_path = Rails.configuration.api_path
|
api_path = Rails.configuration.api_path
|
||||||
|
|
||||||
# reports
|
# reports
|
||||||
match api_path + '/reports/config', to: 'reports#config', via: :get
|
match api_path + '/reports/config', to: 'reports#reporting_config', via: :get
|
||||||
match api_path + '/reports/generate', to: 'reports#generate', via: :post
|
match api_path + '/reports/generate', to: 'reports#generate', via: :post
|
||||||
match api_path + '/reports/sets', to: 'reports#sets', via: :post
|
match api_path + '/reports/sets', to: 'reports#sets', via: [:post, :get]
|
||||||
|
|
||||||
# report_profiles
|
# report_profiles
|
||||||
match api_path + '/report_profiles', to: 'report_profiles#index', via: :get
|
match api_path + '/report_profiles', to: 'report_profiles#index', via: :get
|
||||||
|
|
|
@ -24,7 +24,7 @@ class ReportTest < ActiveSupport::TestCase
|
||||||
# drop/create indexes
|
# drop/create indexes
|
||||||
#Rake::Task["searchindex:drop"].execute
|
#Rake::Task["searchindex:drop"].execute
|
||||||
#Rake::Task["searchindex:create"].execute
|
#Rake::Task["searchindex:create"].execute
|
||||||
#system('rake searchindex:rebuild')
|
system('rake searchindex:rebuild')
|
||||||
|
|
||||||
Group.create_if_not_exists(
|
Group.create_if_not_exists(
|
||||||
name: 'Report Test',
|
name: 'Report Test',
|
||||||
|
|
Loading…
Reference in a new issue