FEATURE: export dashboard reports to csv file
This commit is contained in:
parent
b12ace5f9d
commit
b4a724e80a
|
@ -1,3 +1,6 @@
|
|||
import { exportEntity } from 'discourse/lib/export-csv';
|
||||
import { outputExportResult } from 'discourse/lib/export-result';
|
||||
|
||||
export default Ember.Controller.extend({
|
||||
viewMode: 'table',
|
||||
viewingTable: Em.computed.equal('viewMode', 'table'),
|
||||
|
@ -30,6 +33,15 @@ export default Ember.Controller.extend({
|
|||
|
||||
viewAsBarChart() {
|
||||
this.set('viewMode', 'barChart');
|
||||
},
|
||||
|
||||
exportCsv() {
|
||||
exportEntity('report', {
|
||||
name: this.get("model.type"),
|
||||
start_date: this.get('startDate'),
|
||||
end_date: this.get('endDate'),
|
||||
category_id: this.get('categoryId') == 'all' ? undefined : this.get('categoryId')
|
||||
}).then(outputExportResult);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
{{i18n 'admin.dashboard.reports.end_date'}} {{input type="date" value=endDate}}
|
||||
{{combo-box valueAttribute="value" content=categoryOptions value=categoryId}}
|
||||
{{d-button action="refreshReport" class="btn-primary" label="admin.dashboard.reports.refresh_report" icon="refresh"}}
|
||||
{{d-button action="exportCsv" label="admin.export_csv.button_text"}}
|
||||
</div>
|
||||
|
||||
<div class='view-options'>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
function exportEntityByType(type, entity) {
|
||||
function exportEntityByType(type, entity, args) {
|
||||
return Discourse.ajax("/export_csv/export_entity.json", {
|
||||
method: 'POST',
|
||||
data: {entity_type: type, entity}
|
||||
data: {entity_type: type, entity, args}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,6 @@ export function exportUserArchive() {
|
|||
}
|
||||
|
||||
|
||||
export function exportEntity(entity) {
|
||||
return exportEntityByType('admin', entity);
|
||||
export function exportEntity(entity, args) {
|
||||
return exportEntityByType('admin', entity, args);
|
||||
}
|
||||
|
|
|
@ -3,11 +3,8 @@ class ExportCsvController < ApplicationController
|
|||
skip_before_filter :preload_json, :check_xhr, only: [:show]
|
||||
|
||||
def export_entity
|
||||
params.require(:entity)
|
||||
params.require(:entity_type)
|
||||
guardian.ensure_can_export_entity!(params[:entity_type])
|
||||
|
||||
Jobs.enqueue(:export_csv_file, entity: params[:entity], user_id: current_user.id)
|
||||
guardian.ensure_can_export_entity!(export_params[:entity_type])
|
||||
Jobs.enqueue(:export_csv_file, entity: export_params[:entity], user_id: current_user.id, args: export_params[:args])
|
||||
render json: success_json
|
||||
end
|
||||
|
||||
|
@ -27,4 +24,13 @@ class ExportCsvController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def export_params
|
||||
@_export_params ||= begin
|
||||
params.require(:entity)
|
||||
params.require(:entity_type)
|
||||
params.permit(:entity, :entity_type, args: [:name, :start_date, :end_date, :category_id])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -15,12 +15,14 @@ module Jobs
|
|||
HEADER_ATTRS_FOR['screened_email'] = ['email','action','match_count','last_match_at','created_at','ip_address']
|
||||
HEADER_ATTRS_FOR['screened_ip'] = ['ip_address','action','match_count','last_match_at','created_at']
|
||||
HEADER_ATTRS_FOR['screened_url'] = ['domain','action','match_count','last_match_at','created_at']
|
||||
HEADER_ATTRS_FOR['report'] = ['date', 'value']
|
||||
|
||||
sidekiq_options retry: false
|
||||
attr_accessor :current_user
|
||||
|
||||
def execute(args)
|
||||
@entity = args[:entity]
|
||||
@extra = HashWithIndifferentAccess.new(args[:args]) if args[:args]
|
||||
@file_name = @entity
|
||||
@current_user = User.find_by(id: args[:user_id])
|
||||
|
||||
|
@ -93,6 +95,16 @@ module Jobs
|
|||
end
|
||||
end
|
||||
|
||||
def report_export
|
||||
@extra[:start_date] = @extra[:start_date].to_date if @extra[:start_date].is_a?(String)
|
||||
@extra[:end_date] = @extra[:end_date].to_date if @extra[:end_date].is_a?(String)
|
||||
@extra[:category_id] = @extra[:category_id].to_i if @extra[:category_id]
|
||||
r = Report.find(@extra[:name], @extra)
|
||||
r.data.map do |row|
|
||||
[row[:x].to_s(:db), row[:y].to_s(:db)]
|
||||
end
|
||||
end
|
||||
|
||||
def get_header
|
||||
|
||||
case @entity
|
||||
|
|
Loading…
Reference in New Issue