34630f6557
* add timestamp to attribution * create usage stat component * updates stat text boxes * remove flex-header css * remove comment * add empty state if no data * update monthly serializer * remove empty state - unnecessary * change tab to 'history' * add usage stats to history view * change css styling for upcased grey subtitle * correctly exports namespace and auth data * close modal on download * test making a service? * fix monthly attrs * update csv content format * remove component and make downloadCsv a service * update function name * wip//add warning labels, fixing up current and history tabs * wip//clean up serializer fix with real data * fix link styling: * add conditionals for no data, add warning for 1.9 counting changes * naming comment * fix tooltip formatting * fix number format and consolidate actions * remove outdated test * add revokeObjectURL and rename variable * fix errors and empty state views when no activity data at all * fix end time error * fix comment * return truncating to serializer * PR review cleanup * return new object
26 lines
941 B
JavaScript
26 lines
941 B
JavaScript
import Service from '@ember/service';
|
|
|
|
// SAMPLE CSV FORMAT ('content' argument)
|
|
// Must be a string with each row \n separated and each column comma separated
|
|
// 'Namespace path,Authentication method,Total clients,Entity clients,Non-entity clients\n
|
|
// namespacelonglonglong4/,,191,171,20\n
|
|
// namespacelonglonglong4/,auth/method/uMGBU,35,20,15\n'
|
|
|
|
export default class DownloadCsvService extends Service {
|
|
download(filename, content) {
|
|
let formattedFilename = filename?.replace(/\s+/g, '-') || 'vault-data.csv';
|
|
let { document, URL } = window;
|
|
let downloadElement = document.createElement('a');
|
|
downloadElement.download = formattedFilename;
|
|
downloadElement.href = URL.createObjectURL(
|
|
new Blob([content], {
|
|
type: 'text/csv',
|
|
})
|
|
);
|
|
document.body.appendChild(downloadElement);
|
|
downloadElement.click();
|
|
URL.revokeObjectURL(downloadElement.href);
|
|
downloadElement.remove();
|
|
}
|
|
}
|