Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
Co-authored-by Drenmi <drenmi@gmail.com>
  • Loading branch information
Lhcfl committed Aug 27, 2024
1 parent e7fa81a commit 73467e5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
8 changes: 5 additions & 3 deletions app/controllers/discourse_data_explorer/query_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,14 @@ def run

render json: { success: false, errors: [err_msg] }, status: 422
else
filename =
content_disposition =
"attachment; filename=#{query.slug}@#{Slug.for(Discourse.current_hostname, "discourse")}-#{Date.today}.dcqresult"

respond_to do |format|
format.json do
response.headers["Content-Disposition"] = "#{filename}.json" if params[:download]
response.headers["Content-Disposition"] = "#{content_disposition}.json" if params[
:download
]

render json:
ResultFormatConverter.convert(
Expand All @@ -195,7 +197,7 @@ def run
)
end
format.csv do
response.headers["Content-Disposition"] = "#{filename}.csv"
response.headers["Content-Disposition"] = "#{content_disposition}.csv"

render plain: ResultFormatConverter.convert(:csv, result)
end
Expand Down
8 changes: 4 additions & 4 deletions lib/report_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def self.generate(query_id, query_params, recipients, opts = {})
return [] if opts[:skip_empty] && result[:pg_result].values.empty?
table = ResultToMarkdown.convert(result[:pg_result])

build_report_pms(query, table, recipients, opts: { attach_csv: opts[:attach_csv], result: })
build_report_pms(query, table, recipients, attach_csv:, result:)
end

private
Expand All @@ -40,14 +40,14 @@ def self.params_to_hash(query_params)
params_hash
end

def self.build_report_pms(query, table = "", targets = [], opts: {})
def self.build_report_pms(query, table = "", targets = [], attach_csv: false, result: nil)
pms = []
upload =
if opts[:attach_csv]
if attach_csv
tmp_filename =
"#{query.slug}@#{Slug.for(Discourse.current_hostname, "discourse")}-#{Date.today}.dcqresult.csv"
tmp = Tempfile.new(tmp_filename)
tmp.write(ResultFormatConverter.convert(:csv, opts[:result]))
tmp.write(ResultFormatConverter.convert(:csv, result))
tmp.rewind
UploadCreator.new(tmp, tmp_filename, type: "csv_export").create_for(
Discourse.system_user.id,
Expand Down

0 comments on commit 73467e5

Please sign in to comment.