Also support user export as csv

This commit is contained in:
Johannes Zellner
2022-01-22 09:28:41 +01:00
parent 0af47bba54
commit 36b0d4e1bc
2 changed files with 18 additions and 4 deletions

View File

@@ -184,14 +184,20 @@ angular.module('Application').controller('UsersController', ['$scope', '$locatio
}
};
$scope.userExport = function () {
// supported types are 'json' and 'csv'
$scope.userExport = function (type) {
Client.getUsers(function (error, result) {
if (error) {
Client.error('Failed to list users. Full error in the webinspector.');
return console.error('Failed to list users.', error);
}
var file = new Blob([ JSON.stringify(result, null, 2) ], { type: 'application/json' });
var content = '';
if (type === 'json') content = JSON.stringify(result, null, 2);
else if (type === 'csv') content = result.map(function (user) { return `${user.id},${user.username},${user.email},${user.displayName}`; }).join('\n');
else return;
var file = new Blob([ content ], { type: 'application/json' });
var a = document.createElement('a');
a.href = URL.createObjectURL(file);
a.download = 'users.json';