Skip to content

Commit

Permalink
WebClient: add CSV export for users, groups, folders, admins, roles
Browse files Browse the repository at this point in the history
Signed-off-by: Nicola Murino <[email protected]>
  • Loading branch information
drakkan committed Oct 5, 2024
1 parent 18bf0c6 commit 8cf8a77
Show file tree
Hide file tree
Showing 7 changed files with 721 additions and 1 deletion.
3 changes: 3 additions & 0 deletions static/vendor/file-saver/FileSaver.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions static/vendor/papaparse/papaparse.min.js

Large diffs are not rendered by default.

109 changes: 109 additions & 0 deletions templates/webadmin/admins.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ <h3 data-i18n="admin.view_manage" class="card-title section-title">View and mana
<i class="ki-solid ki-magnifier fs-1 position-absolute ms-6"></i>
<input name="search" data-i18n="[placeholder]general.search" type="text" data-table-filter="search"
class="form-control rounded-1 w-250px ps-15 me-5" placeholder="Search" />
<button id="export_button" type="button" class="btn btn-light-primary ms-3" data-table-filter="export">
<span data-i18n="general.export" class="indicator-label">
Export
</span>
<span data-i18n="general.wait" class="indicator-progress">
Please wait...
<span class="spinner-border spinner-border-sm align-middle ms-2"></span>
</span>
</button>
</div>

<div class="d-flex justify-content-end my-2" data-table-toolbar="base">
Expand Down Expand Up @@ -112,6 +121,8 @@ <h3 data-i18n="admin.view_manage" class="card-title section-title">View and mana
{{- end}}
{{- define "extra_js"}}
<script {{- if .CSPNonce}} nonce="{{.CSPNonce}}"{{- end}} src="{{.StaticURL}}/assets/plugins/custom/datatables/datatables.bundle.js"></script>
<script {{- if .CSPNonce}} nonce="{{.CSPNonce}}"{{- end}} src="{{.StaticURL}}/vendor/papaparse/papaparse.min.js"></script>
<script {{- if .CSPNonce}} nonce="{{.CSPNonce}}"{{- end}} src="{{.StaticURL}}/vendor/file-saver/FileSaver.min.js"></script>
<script type="text/javascript" {{- if .CSPNonce}} nonce="{{.CSPNonce}}"{{- end}}>
function deleteAction(username) {
ModalAlert.fire({
Expand Down Expand Up @@ -453,6 +464,104 @@ <h3 data-i18n="admin.view_manage" class="card-title section-title">View and mana
handleColVisibilityCheckbox($('#checkColRole'), 4);
handleColVisibilityCheckbox($('#checkCol2FA'), 5);
handleColVisibilityCheckbox($('#checkColDesc'), 6);

const exportButton = $(document.querySelector('[data-table-filter="export"]'));
exportButton.on('click', function(e){
e.preventDefault();
this.blur();
this.setAttribute('data-kt-indicator', 'on');
this.disabled = true;

let data = [];
dt.rows({ search: 'applied' }).every(function (rowIdx, tableLoop, rowLoop){
let line = {};
let rowData = dt.row(rowIdx).data();
let filters = rowData["filters"];

line["Username"] = rowData["username"];
let status = "Inactive";
if (rowData["status"] == 1){
status = "Active";
}
line["Status"] = status;
line["Permissions"] = rowData["permissions"].join(", ");

if (rowData["created_at"]) {
line["Created At"] = moment(rowData["created_at"]).format("YYYY-MM-DD HH:mm");
} else {
line["Created At"] = "";
}
if (rowData["updated_at"]) {
line["Updated At"] = moment(rowData["updated_at"]).format("YYYY-MM-DD HH:mm");
} else {
line["Updated At"] = "";
}
if (rowData["last_login"]) {
line["Last Login"] = moment(rowData["last_login"]).format("YYYY-MM-DD HH:mm");
} else {
line["Last Login"] = "";
}
if (rowData["email"]){
line["Email"] = rowData["email"];
} else {
line["Email"] = "";
}
let totpConfig = filters["totp_config"];
if (totpConfig && totpConfig["enabled"]){
line["Two-factor auth"] = "Enabled";
} else {
line["Two-factor auth"] = "Disabled";
}
if (filters["allow_list"]){
line["Allow List"] = filters["allow_list"].join(", ");
} else {
line["Allow List"] = "";
}
let groups = [];
let rowGroups = rowData["groups"];
if (rowGroups){
for (i = 0; i < rowGroups.length; i++ ){
groups.push(rowGroups[i].name);
}
}
line["Groups"] = groups.join(", ");
if (rowData["role"]){
line["Role"] = rowData["role"];
} else {
line["Role"] = "";
}
if (rowData["description"]){
line["Description"] = rowData["description"];
} else {
line["Description"] = "";
}
if (rowData["additional_info"]){
line["Additional info"] = rowData["additional_info"];
} else {
line["Additional info"] = "";
}

data.push(line);
});

let csv = Papa.unparse(data, {
quotes: false,
quoteChar: '"',
escapeChar: '"',
delimiter: ",",
header: true,
newline: "\r\n",
skipEmptyLines: false,
columns: null,
escapeFormulae: true
});
let blob = new Blob([csv], {type: "text/csv"});
let ts = moment().format("YYYY_MM_DD_HH_mm_ss");
saveAs(blob, `admins_${ts}.csv`);

this.removeAttribute('data-kt-indicator');
this.disabled = false;
});
}

function handleRowActions() {
Expand Down
88 changes: 88 additions & 0 deletions templates/webadmin/folders.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ <h3 data-i18n="virtual_folders.view_manage" class="card-title section-title">Vie
<i class="ki-solid ki-magnifier fs-1 position-absolute ms-6"></i>
<input name="search" data-i18n="[placeholder]general.search" type="text" data-table-filter="search"
class="form-control rounded-1 w-250px ps-15 me-5" placeholder="Search" />
<button id="export_button" type="button" class="btn btn-light-primary ms-3" data-table-filter="export">
<span data-i18n="general.export" class="indicator-label">
Export
</span>
<span data-i18n="general.wait" class="indicator-progress">
Please wait...
<span class="spinner-border spinner-border-sm align-middle ms-2"></span>
</span>
</button>
</div>

<div class="d-flex justify-content-end my-2" data-table-toolbar="base">
Expand Down Expand Up @@ -97,6 +106,8 @@ <h3 data-i18n="virtual_folders.view_manage" class="card-title section-title">Vie
{{- end}}
{{- define "extra_js"}}
<script {{- if .CSPNonce}} nonce="{{.CSPNonce}}"{{- end}} src="{{.StaticURL}}/assets/plugins/custom/datatables/datatables.bundle.js"></script>
<script {{- if .CSPNonce}} nonce="{{.CSPNonce}}"{{- end}} src="{{.StaticURL}}/vendor/papaparse/papaparse.min.js"></script>
<script {{- if .CSPNonce}} nonce="{{.CSPNonce}}"{{- end}} src="{{.StaticURL}}/vendor/file-saver/FileSaver.min.js"></script>
<script type="text/javascript" {{- if .CSPNonce}} nonce="{{.CSPNonce}}"{{- end}}>
function deleteAction(name) {
ModalAlert.fire({
Expand Down Expand Up @@ -375,6 +386,83 @@ <h3 data-i18n="virtual_folders.view_manage" class="card-title section-title">Vie
handleColVisibilityCheckbox($('#checkColQuota'), 2);
handleColVisibilityCheckbox($('#checkColAssociations'), 3);
handleColVisibilityCheckbox($('#checkColDesc'), 4);

const exportButton = $(document.querySelector('[data-table-filter="export"]'));
exportButton.on('click', function(e){
e.preventDefault();
this.blur();
this.setAttribute('data-kt-indicator', 'on');
this.disabled = true;

let data = [];
dt.rows({ search: 'applied' }).every(function (rowIdx, tableLoop, rowLoop){
let line = {};
let rowData = dt.row(rowIdx).data();

line["Name"] = rowData["name"];
let fsProvider = "Local storage";
if (rowData["mapped_path"]){
fsProvider+=": "+rowData["mapped_path"];
}
switch (rowData["filesystem"]["provider"]){
case 1:
fsProvider = "S3 Compatible";
break;
case 2:
fsProvider = "Google Cloud Storage";
break;
case 3:
fsProvider = "Azure Blob";
break;
case 4:
fsProvider = "Local storage encrypted: "+rowData["home_dir"];
break;
case 5:
fsProvider = "SFTP";
break;
case 6:
fsProvider = "HTTP";
break;
}
line["Filesystem"] = fsProvider;

if (rowData["users"]){
line["Users"] = rowData["users"].join(", ");
} else {
line["Users"] = "";
}
if (rowData["groups"]){
line["Groups"] = rowData["groups"].join(", ");
} else {
line["Groups"] = "";
}
if (rowData["description"]){
line["Description"] = rowData["description"];
} else {
line["Description"] = "";
}

data.push(line);
});

let csv = Papa.unparse(data, {
quotes: false,
quoteChar: '"',
escapeChar: '"',
delimiter: ",",
header: true,
newline: "\r\n",
skipEmptyLines: false,
columns: null,
escapeFormulae: true
});
let blob = new Blob([csv], {type: "text/csv"});
let ts = moment().format("YYYY_MM_DD_HH_mm_ss");
saveAs(blob, `folders_${ts}.csv`);

this.removeAttribute('data-kt-indicator');
this.disabled = false;
});
}

function handleRowActions() {
Expand Down
Loading

0 comments on commit 8cf8a77

Please sign in to comment.