|
|
@@ -1,43 +1,3 @@ |
|
|
|
// utilities |
|
|
|
// generate downloadable csv |
|
|
|
const download = (options={}) => { |
|
|
|
options.filename = options.filename || 'file' |
|
|
|
|
|
|
|
if (options.type == 'csv') { |
|
|
|
let headers = Object.keys(options.data[0]) |
|
|
|
|
|
|
|
let body = options.data.map(row => headers.map(key => row[key]).join(',')).join('\n') |
|
|
|
|
|
|
|
options.data = '\ufeff' + headers.join(',') + '\n' + body |
|
|
|
options.type = 'text/csv' |
|
|
|
} else if (options.type == 'json') { |
|
|
|
} |
|
|
|
|
|
|
|
let blob = new Blob([options.data], {type: options.type}) |
|
|
|
let url = URL.createObjectURL(blob) |
|
|
|
|
|
|
|
if (options.timestamp) |
|
|
|
options.filename = options.filename + (new Date()).toLocaleTimeString(undefined, { |
|
|
|
year: "numeric", |
|
|
|
month: "2-digit", |
|
|
|
day: "2-digit", |
|
|
|
hour: "2-digit", |
|
|
|
minute: "2-digit", |
|
|
|
second: "2-digit", |
|
|
|
hour12: false |
|
|
|
}) |
|
|
|
|
|
|
|
let anchor = document.createElement('a') |
|
|
|
anchor.href = url |
|
|
|
anchor.target = '_blank' |
|
|
|
anchor.download = `${options.filename}.csv` |
|
|
|
|
|
|
|
anchor.click() |
|
|
|
|
|
|
|
URL.revokeObjectURL(url) |
|
|
|
anchor.remove() |
|
|
|
} |
|
|
|
|
|
|
|
// authentication model |
|
|
|
const _make_auth = api_root => { |
|
|
|
|
|
|
|