youpin-api icon indicating copy to clipboard operation
youpin-api copied to clipboard

Export data to CSV/XSLX weekly

Open rapee opened this issue 7 years ago • 9 comments

Export pins as CSV or XSLX

Input:

  • Start - end date range
  • Assigned department (optional)
  • Assigned user (optional)

Output:

Tabular data with these columns:

  • Pin Detail
  • Status
  • Reported Date
  • Close Date (if any)
  • Assigned Department
  • Assigned User
  • Category (in Thai and English)
  • Tag

rapee avatar Oct 03 '17 03:10 rapee

Should it be a command line script?

p16i avatar Oct 03 '17 07:10 p16i

Seems to me like a cron job in another container might be fitting. Maybe a pure service that takes any data object (in JSON perhaps) and response with a CSV file transparently that gets run by a cron job weekly.

formatData(obj) -> csv

If no one is on this, I'd like to give it a first take.

Also, are we limited to using Javascript, provided if docker orchestrates isolated services?

jochasinga avatar Oct 09 '17 21:10 jochasinga

Actually, I have another idea. Maybe we can create a new route for this purpose. For example,

URL : ./export/pins?start_date=YYYY-MM-DD&end_date=YYYY-MM-DD&department=[all|...]&format=[json|xml|csv]

I guess they plan to use it from frontend. Meaning that, the user will select date range and the frontend will redirect to this url with parameters and return data with corresponding content-type. We might also need to check whether the user have an access to data of the department.

p16i avatar Oct 10 '17 04:10 p16i

@heytitle I see. Why weekly then? That sounded like something that's not user-facing.

jochasinga avatar Oct 10 '17 05:10 jochasinga

@jochasinga You're right, the weekly part is unnecessary. It will be handled on frontend.

I agree with @heytitle about making a new route for this.

rapee avatar Oct 10 '17 10:10 rapee

So basically the route send a GET request with relevant query params or payload to the database, retrieve the data and do the parsing to CSV or whatever format on the frontend.

jochasinga avatar Oct 10 '17 17:10 jochasinga

I think the workflow will look like this. gitscout-image-from-clipboard-1

What do you think? cc: @jochasinga @rapee @parnurzeal @supasate

p16i avatar Oct 12 '17 13:10 p16i

@heytitle you mean the api server responds with Content-Type: 'text/csv' and does the parsing in the back end while the UI returns a promise and display a download element when response is ready. Looks good.

jochasinga avatar Oct 12 '17 21:10 jochasinga

@jochasinga actually, what I meant by download dialog is the one from the browser which can be called in 2 ways to do that

  1. using download attribute of <a>. For example,
<a href="<path>/<to>/<api>?query=.." download="filename.csv">Download</a>
  1. add Content-Disposition: attachment; filename="filename.csv" header when returning the data. I've tested found that using Content-Type only would't force browser to show the save dialog. See : https://stackoverflow.com/questions/20039533/how-can-i-force-a-save-as-dialog

p16i avatar Oct 20 '17 05:10 p16i