From b9a5de081e41841b3d75bb93e3371a08d819b5ab Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Thu, 29 Oct 2015 03:33:36 +0100 Subject: [PATCH] Next features for mini reporting. --- .../app/controllers/report.js.coffee | 85 +- .../app/views/report/download_header.jst.eco | 2 +- .../app/views/report/download_list.jst.eco | 2 +- .../javascripts/app/views/report/main.jst.eco | 12 +- .../app/views/report/sidebar.jst.eco | 2 +- app/controllers/reports_controller.rb | 225 +++--- app/models/report.rb | 106 ++- lib/report/base.rb | 389 +++++++++ lib/report/ticket_first_solution.rb | 118 +++ lib/report/ticket_generic_time.rb | 131 +++ lib/report/ticket_moved.rb | 165 ++++ lib/report/ticket_reopened.rb | 124 +++ lib/search_index_backend.rb | 167 ++-- test/integration/report_test.rb | 747 ++++++++++++++++++ 14 files changed, 2042 insertions(+), 233 deletions(-) create mode 100644 lib/report/base.rb create mode 100644 lib/report/ticket_first_solution.rb create mode 100644 lib/report/ticket_generic_time.rb create mode 100644 lib/report/ticket_moved.rb create mode 100644 lib/report/ticket_reopened.rb create mode 100644 test/integration/report_test.rb diff --git a/app/assets/javascripts/app/controllers/report.js.coffee b/app/assets/javascripts/app/controllers/report.js.coffee index dca5b6eff..315b26121 100644 --- a/app/assets/javascripts/app/controllers/report.js.coffee +++ b/app/assets/javascripts/app/controllers/report.js.coffee @@ -87,8 +87,6 @@ class Graph extends App.ControllerContent constructor: -> super - return - # rerender view @bind 'ui:report:rerender', => @render() @@ -98,7 +96,14 @@ class Graph extends App.ControllerContent render: => update = (data) => - @draw(data.data) + + # show only selected lines + dataNew = {} + for key, value of data.data + if @params.backendSelected[key] is true + dataNew[key] = value + + @draw(dataNew) t = new Date @el.find('#download-chart').html(t.toString()) new Download( @@ -109,19 +114,20 @@ class Graph extends App.ControllerContent ) url = @apiPath + '/reports/generate' - interval = 60000 + interval = 5 * 60000 if @params.timeRange is 'year' - interval = 30000 + interval = 5 * 60000 if @params.timeRange is 'month' - interval = 20000 + interval = 60000 if @params.timeRange is 'week' - interval = 20000 + interval = 40000 if @params.timeRange is 'day' interval = 20000 if @params.timeRange is 'realtime' interval = 10000 @ajax( + id: 'report_graph' type: 'POST' url: url data: JSON.stringify( @@ -137,7 +143,7 @@ class Graph extends App.ControllerContent processData: true success: (data) => update(data) - @delay( @render, interval, 'report-update', 'page' ) + @delay(@render, interval, 'report-update', 'page') ) draw: (data) => @@ -162,10 +168,22 @@ class Graph extends App.ControllerContent dataPlot = [] for key, value of data + realname = key + if @config.metric[@params.metric] + for backend in @config.metric[@params.metric].backend + if backend.name is key + realname = backend.display + content = [] + count = 0 + for i in xaxis + content.push [count, value[count]] + count += 1 + dataPlot.push { - data: value - label: key + data: content + label: App.i18n.translateInline(realname) } + # plot $.plot( $('#placeholder'), dataPlot, { yaxis: { min: 0 }, @@ -190,12 +208,10 @@ class Download extends App.Controller reports = [] # select first backend, if no backend is selected - @backendSelected = undefined if @config.metric[@params.metric] for backend in @config.metric[@params.metric].backend - console.log('bac', backend) - if backend.dataDownload && !@backendSelected - @backendSelected = backend.name + if backend.dataDownload && !@params.downloadBackendSelected + @params.downloadBackendSelected = backend.name # get used profiles profiles = [] @@ -206,10 +222,10 @@ class Download extends App.Controller profiles.push App.ReportProfile.find(key) @html App.view('report/download_header')( - reports: reports - profiles: profiles - backendSelected: @backendSelected - metric: @config.metric[@params.metric] + reports: reports + profiles: profiles + downloadBackendSelected: @params.downloadBackendSelected + metric: @config.metric[@params.metric] ) @tableUpdate() @@ -219,8 +235,8 @@ class Download extends App.Controller e.preventDefault() @el.find('.js-dataDownloadBackendSelector').parent().removeClass('active') $(e.target).parent().addClass('active') - @profileSelectedId = $(e.target).data('profile-id') - @backendSelected = $(e.target).data('backend') + @profileSelectedId = $(e.target).data('profile-id') + @params.downloadBackendSelected = $(e.target).data('backend') table = (tickets, count) => url = '#ticket/zoom/' @@ -239,17 +255,19 @@ class Download extends App.Controller @startLoading() @ajax( + id: 'report_download' type: 'POST' url: @apiPath + '/reports/sets' data: JSON.stringify( - metric: @params.metric - year: @params.year - month: @params.month - week: @params.week - day: @params.day - timeRange: @params.timeRange - profile_id: @profileSelectedId - backend: @backendSelected + metric: @params.metric + year: @params.year + month: @params.month + week: @params.week + day: @params.day + timeRange: @params.timeRange + profiles: @params.profileSelected + backends: @params.backendSelected + downloadBackendSelected: @params.downloadBackendSelected ) processData: true success: (data) => @@ -433,7 +451,7 @@ class Sidebar extends App.Controller events: 'click .js-profileSelector': 'selectProfile' 'click .js-backendSelector': 'selectBackend' - 'click .panel-heading': 'selectMetric' + 'click .panel-heading': 'selectMetric' constructor: -> super @@ -459,11 +477,10 @@ class Sidebar extends App.Controller selectProfile: (e) => profile_id = $(e.target).val() - active = $(e.target).prop('checked') - if active - @params.profileSelected[profile_id] = true - else - delete @params.profileSelected[profile_id] + console.log('llll', profile_id) + for key, value of @params.profileSelected + delete @params.profileSelected[key] + @params.profileSelected[profile_id] = true App.Event.trigger( 'ui:report:rerender' ) selectBackend: (e) => diff --git a/app/assets/javascripts/app/views/report/download_header.jst.eco b/app/assets/javascripts/app/views/report/download_header.jst.eco index 03e04c277..d51e1a3f4 100644 --- a/app/assets/javascripts/app/views/report/download_header.jst.eco +++ b/app/assets/javascripts/app/views/report/download_header.jst.eco @@ -4,7 +4,7 @@ <% for profile in @profiles: %> <% for backend in @metric.backend: %> <% if backend.dataDownload: %> -
  • class="is-active active"<% end %>><%= @T(backend.display) %>
  • +
  • class="is-active active"<% end %>><%= @T(backend.display) %>
  • <% end %> <% end %> <% end %> diff --git a/app/assets/javascripts/app/views/report/download_list.jst.eco b/app/assets/javascripts/app/views/report/download_list.jst.eco index ef18cdebc..8efda3496 100644 --- a/app/assets/javascripts/app/views/report/download_list.jst.eco +++ b/app/assets/javascripts/app/views/report/download_list.jst.eco @@ -1,5 +1,5 @@ <%- @T('%s records', @count) %> - <%- @Icon('download') %> + <%- @Icon('download') %> diff --git a/app/assets/javascripts/app/views/report/main.jst.eco b/app/assets/javascripts/app/views/report/main.jst.eco index 87778862e..4adf5fd60 100644 --- a/app/assets/javascripts/app/views/report/main.jst.eco +++ b/app/assets/javascripts/app/views/report/main.jst.eco @@ -1,6 +1,6 @@
    -