FEATURE: Export all types of reports (#8748)
There is a single stacked_chart which was not exportable
This commit is contained in:
parent
8883cca373
commit
0a27086764
|
@ -22,11 +22,6 @@ const Report = EmberObject.extend({
|
|||
percent: false,
|
||||
higher_is_better: true,
|
||||
|
||||
@discourseComputed("modes")
|
||||
isTable(modes) {
|
||||
return modes.some(mode => mode === "table");
|
||||
},
|
||||
|
||||
@discourseComputed("type", "start_date", "end_date")
|
||||
reportUrl(type, start_date, end_date) {
|
||||
start_date = moment
|
||||
|
|
|
@ -160,17 +160,15 @@
|
|||
</div>
|
||||
{{/each}}
|
||||
|
||||
{{#if model.isTable}}
|
||||
<div class="control">
|
||||
<div class="input">
|
||||
{{d-button
|
||||
class="btn-default export-csv-btn"
|
||||
action=(action "exportCsv")
|
||||
label="admin.export_csv.button_text"
|
||||
icon="download"}}
|
||||
</div>
|
||||
<div class="control">
|
||||
<div class="input">
|
||||
{{d-button
|
||||
class="btn-default export-csv-btn"
|
||||
action=(action "exportCsv")
|
||||
label="admin.export_csv.button_text"
|
||||
icon="download"}}
|
||||
</div>
|
||||
{{/if}}
|
||||
</div>
|
||||
|
||||
{{#if showRefresh}}
|
||||
<div class="control">
|
||||
|
|
|
@ -198,8 +198,25 @@ module Jobs
|
|||
end
|
||||
end
|
||||
|
||||
if report.modes == [:stacked_chart]
|
||||
header = [:x]
|
||||
data = {}
|
||||
|
||||
report.data.map do |series|
|
||||
header << series[:label]
|
||||
series[:data].each do |datapoint|
|
||||
data[datapoint[:x]] ||= { x: datapoint[:x] }
|
||||
data[datapoint[:x]][series[:label]] = datapoint[:y]
|
||||
end
|
||||
end
|
||||
|
||||
data = data.values
|
||||
else
|
||||
data = report.data
|
||||
end
|
||||
|
||||
yield header.map { |k| titles[k] || k }
|
||||
report.data.each { |row| yield row.values_at(*header).map(&:to_s) }
|
||||
data.each { |row| yield row.values_at(*header).map(&:to_s) }
|
||||
end
|
||||
|
||||
def get_header
|
||||
|
|
|
@ -89,6 +89,28 @@ describe Jobs::ExportCsvFile do
|
|||
expect(report.second).to contain_exactly(user.username, "Earth", "2010-01-01 00:00:00 UTC")
|
||||
end
|
||||
|
||||
it 'works with stacked_chart reports' do
|
||||
ApplicationRequest.create!(date: '2010-01-01', req_type: 'page_view_logged_in', count: 1)
|
||||
ApplicationRequest.create!(date: '2010-01-02', req_type: 'page_view_logged_in', count: 2)
|
||||
ApplicationRequest.create!(date: '2010-01-03', req_type: 'page_view_logged_in', count: 3)
|
||||
|
||||
ApplicationRequest.create!(date: '2010-01-01', req_type: 'page_view_anon', count: 4)
|
||||
ApplicationRequest.create!(date: '2010-01-02', req_type: 'page_view_anon', count: 5)
|
||||
ApplicationRequest.create!(date: '2010-01-03', req_type: 'page_view_anon', count: 6)
|
||||
|
||||
ApplicationRequest.create!(date: '2010-01-01', req_type: 'page_view_crawler', count: 7)
|
||||
ApplicationRequest.create!(date: '2010-01-02', req_type: 'page_view_crawler', count: 8)
|
||||
ApplicationRequest.create!(date: '2010-01-03', req_type: 'page_view_crawler', count: 9)
|
||||
|
||||
exporter.instance_variable_get(:@extra)['name'] = 'consolidated_page_views'
|
||||
report = exporter.report_export.to_a
|
||||
|
||||
expect(report[0]).to contain_exactly("Day", "Logged in users", "Anonymous users", "Crawlers")
|
||||
expect(report[1]).to contain_exactly("2010-01-01", "1", "4", "7")
|
||||
expect(report[2]).to contain_exactly("2010-01-02", "2", "5", "8")
|
||||
expect(report[3]).to contain_exactly("2010-01-03", "3", "6", "9")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
let(:user_list_header) {
|
||||
|
|
Loading…
Reference in New Issue