Compare commits

...

2 Commits

Author SHA1 Message Date
Prasoon Dwivedi c5ece45c92
Merge 99f1b9d3c4 into 8e79294413 2023-09-21 13:57:20 -06:00
Prasoon Dwivedi 99f1b9d3c4 Add feature to export group targets as CSV
A new feature has been added through which targets in a group can be
exported as CSV. For this a new button has been added to the group page
for every group. On clicking this button for a group, group targets will
be downloaded as CSV file.

This will enable an admin to download group targets from one system and
import them on other to create a group.
2021-06-15 23:16:27 +05:30
1 changed files with 40 additions and 6 deletions

View File

@ -241,7 +241,11 @@ function load() {
escapeHtml(group.name), escapeHtml(group.name),
escapeHtml(group.num_targets), escapeHtml(group.num_targets),
moment(group.modified_date).format('MMMM Do YYYY, h:mm:ss a'), moment(group.modified_date).format('MMMM Do YYYY, h:mm:ss a'),
"<div class='pull-right'><button class='btn btn-primary' data-toggle='modal' data-backdrop='static' data-target='#modal' onclick='edit(" + group.id + ")'>\ "<div class='pull-right'>\
<button class='btn btn-info' id='exportGroupButton" + group.id + "' onclick='exportGroupAsCSV(" + group.id + ',\"' + group.name +"\")'>\
<i class='fa fa-file-excel-o'></i>\
</button>\
<button class='btn btn-primary' data-toggle='modal' data-backdrop='static' data-target='#modal' onclick='edit(" + group.id + ")'>\
<i class='fa fa-pencil'></i>\ <i class='fa fa-pencil'></i>\
</button>\ </button>\
<button class='btn btn-danger' onclick='deleteGroup(" + group.id + ")'>\ <button class='btn btn-danger' onclick='deleteGroup(" + group.id + ")'>\
@ -294,3 +298,33 @@ $(document).ready(function () {
}); });
$("#csv-template").click(downloadCSVTemplate) $("#csv-template").click(downloadCSVTemplate)
}); });
// Exports group contents as a CSV file
function exportGroupAsCSV(groupId, groupName) {
var exportHTML = $("#exportGroupButton"+groupId).html()
var filename = groupName + '.csv'
var groupDetails = api.groupId.get(groupId)
if (!groupDetails) {
return
}
$("#exportGroupButton"+groupId).html('<i class="fa fa-spinner fa-spin"></i>')
var csvString = Papa.unparse(groupDetails.responseJSON.targets, {
'escapeFormulae': true
})
var csvData = new Blob([csvString], {
type: 'text/csv;charset=utf-8;'
});
if (navigator.msSaveBlob) {
navigator.msSaveBlob(csvData, filename);
} else {
var csvURL = window.URL.createObjectURL(csvData);
var dlLink = document.createElement('a');
dlLink.href = csvURL;
dlLink.setAttribute('download', filename)
document.body.appendChild(dlLink)
dlLink.click();
document.body.removeChild(dlLink)
}
$("#exportGroupButton"+groupId).html(exportHTML)
}