2021-05-06 19:35:43 +00:00
|
|
|
{{template "base" .}}
|
|
|
|
|
|
|
|
{{define "title"}}{{.Title}}{{end}}
|
|
|
|
|
|
|
|
{{define "extra_css"}}
|
|
|
|
<link href="{{.StaticURL}}/vendor/datatables/dataTables.bootstrap4.min.css" rel="stylesheet">
|
|
|
|
<link href="{{.StaticURL}}/vendor/datatables/buttons.bootstrap4.min.css" rel="stylesheet">
|
|
|
|
<link href="{{.StaticURL}}/vendor/datatables/fixedHeader.bootstrap4.min.css" rel="stylesheet">
|
|
|
|
<link href="{{.StaticURL}}/vendor/datatables/responsive.bootstrap4.min.css" rel="stylesheet">
|
2021-05-30 21:07:46 +00:00
|
|
|
<link href="{{.StaticURL}}/vendor/datatables/dataTables.checkboxes.css" rel="stylesheet">
|
|
|
|
<style>
|
|
|
|
div.dataTables_wrapper span.selected-info,
|
|
|
|
div.dataTables_wrapper span.selected-item {
|
|
|
|
margin-left: 0.5em;
|
|
|
|
}
|
|
|
|
</style>
|
2021-05-06 19:35:43 +00:00
|
|
|
{{end}}
|
|
|
|
|
|
|
|
{{define "page_body"}}
|
2021-05-27 07:40:46 +00:00
|
|
|
<div id="errorMsg" class="card mb-4 border-left-warning" style="display: none;">
|
|
|
|
<div id="errorTxt" class="card-body text-form-error"></div>
|
|
|
|
</div>
|
2021-05-06 19:35:43 +00:00
|
|
|
|
|
|
|
<div class="card shadow mb-4">
|
|
|
|
<div class="card-header py-3">
|
|
|
|
<h6 class="m-0 font-weight-bold"><a href="{{.FilesURL}}?path=%2F"><i class="fas fa-home"></i> Home</a> {{range .Paths}}{{if eq .Href ""}}/{{.DirName}}{{else}}<a href="{{.Href}}">/{{.DirName}}</a>{{end}}{{end}}</h6>
|
|
|
|
</div>
|
|
|
|
<div class="card-body">
|
|
|
|
{{if .Error}}
|
|
|
|
<div class="card mb-4 border-left-warning">
|
|
|
|
<div class="card-body text-form-error">{{.Error}}</div>
|
|
|
|
</div>
|
|
|
|
{{end}}
|
|
|
|
<div class="table-responsive">
|
|
|
|
<table class="table table-hover nowrap" id="dataTable" width="100%" cellspacing="0">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
2021-05-30 21:07:46 +00:00
|
|
|
<th></th>
|
2021-05-06 19:35:43 +00:00
|
|
|
<th>Type</th>
|
|
|
|
<th>Name</th>
|
|
|
|
<th>Size</th>
|
|
|
|
<th>Last modified</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{{end}}
|
|
|
|
|
|
|
|
{{define "extra_js"}}
|
|
|
|
<script src="{{.StaticURL}}/vendor/datatables/jquery.dataTables.min.js"></script>
|
|
|
|
<script src="{{.StaticURL}}/vendor/datatables/dataTables.bootstrap4.min.js"></script>
|
|
|
|
<script src="{{.StaticURL}}/vendor/datatables/dataTables.buttons.min.js"></script>
|
|
|
|
<script src="{{.StaticURL}}/vendor/datatables/buttons.bootstrap4.min.js"></script>
|
|
|
|
<script src="{{.StaticURL}}/vendor/datatables/dataTables.fixedHeader.min.js"></script>
|
|
|
|
<script src="{{.StaticURL}}/vendor/datatables/dataTables.responsive.min.js"></script>
|
|
|
|
<script src="{{.StaticURL}}/vendor/datatables/responsive.bootstrap4.min.js"></script>
|
2021-05-30 21:07:46 +00:00
|
|
|
<script src="{{.StaticURL}}/vendor/datatables/dataTables.checkboxes.min.js"></script>
|
2021-05-06 19:35:43 +00:00
|
|
|
<script type="text/javascript">
|
2021-05-27 07:40:46 +00:00
|
|
|
|
|
|
|
function getIconForFile(filename) {
|
2021-05-30 21:07:46 +00:00
|
|
|
var extension = filename.slice((filename.lastIndexOf(".") - 1 >>> 0) + 2).toLowerCase();
|
|
|
|
switch (extension) {
|
|
|
|
case "doc":
|
|
|
|
case "docx":
|
|
|
|
case "odt":
|
|
|
|
case "wps":
|
|
|
|
return "far fa-file-word";
|
|
|
|
case "ppt":
|
|
|
|
case "pptx":
|
|
|
|
return "far fa-file-powerpoint";
|
|
|
|
case "xls":
|
|
|
|
case "xlsx":
|
|
|
|
case "ods":
|
|
|
|
return "far fa-file-excel";
|
|
|
|
case "pdf":
|
|
|
|
return "far fa-file-pdf";
|
|
|
|
case "webm":
|
|
|
|
case "mkv":
|
|
|
|
case "flv":
|
|
|
|
case "vob":
|
|
|
|
case "ogv":
|
|
|
|
case "ogg":
|
|
|
|
case "avi":
|
|
|
|
case "ts":
|
|
|
|
case "mov":
|
|
|
|
case "wmv":
|
|
|
|
case "asf":
|
|
|
|
case "mpeg":
|
|
|
|
case "mpv":
|
|
|
|
case "3gp":
|
|
|
|
return "far fa-file-video";
|
|
|
|
case "jpeg":
|
|
|
|
case "jpg":
|
|
|
|
case "png":
|
|
|
|
case "gif":
|
|
|
|
case "webp":
|
|
|
|
case "tiff":
|
|
|
|
case "psd":
|
|
|
|
case "bmp":
|
|
|
|
case "svg":
|
|
|
|
case "jp2":
|
|
|
|
return "far fa-file-image";
|
|
|
|
case "go":
|
|
|
|
case "sh":
|
|
|
|
case "bat":
|
|
|
|
case "java":
|
|
|
|
case "php":
|
|
|
|
case "cs":
|
|
|
|
case "asp":
|
|
|
|
case "aspx":
|
|
|
|
case "css":
|
|
|
|
case "html":
|
|
|
|
case "xhtml":
|
|
|
|
case "htm":
|
|
|
|
case "js":
|
|
|
|
case "jsp":
|
|
|
|
case "py":
|
|
|
|
case "rb":
|
|
|
|
case "cgi":
|
|
|
|
case "c":
|
|
|
|
case "cpp":
|
|
|
|
case "h":
|
|
|
|
case "hpp":
|
|
|
|
case "kt":
|
|
|
|
case "ktm":
|
|
|
|
case "kts":
|
|
|
|
case "swift":
|
|
|
|
case "r":
|
|
|
|
return "far fa-file-code";
|
|
|
|
case "zip":
|
|
|
|
case "zipx":
|
|
|
|
case "rar":
|
|
|
|
case "tar":
|
|
|
|
case "gz":
|
|
|
|
case "bz2":
|
|
|
|
case "zstd":
|
|
|
|
case "zst":
|
|
|
|
case "sz":
|
|
|
|
case "lz":
|
|
|
|
case "lz4":
|
|
|
|
case "xz":
|
|
|
|
case "jar":
|
|
|
|
return "far fa-file-archive";
|
|
|
|
case "txt":
|
|
|
|
case "rtf":
|
|
|
|
case "json":
|
|
|
|
case "xml":
|
|
|
|
case "yaml":
|
|
|
|
case "toml":
|
|
|
|
case "log":
|
|
|
|
case "csv":
|
|
|
|
case "ini":
|
|
|
|
case "cfg":
|
|
|
|
return "far fa-file-alt";
|
|
|
|
default:
|
|
|
|
return "far fa-file";
|
2021-05-27 07:40:46 +00:00
|
|
|
}
|
2021-05-30 21:07:46 +00:00
|
|
|
}
|
2021-05-27 07:40:46 +00:00
|
|
|
|
2021-05-06 19:35:43 +00:00
|
|
|
$(document).ready(function () {
|
|
|
|
$.fn.dataTable.ext.buttons.refresh = {
|
|
|
|
text: '<i class="fas fa-sync-alt"></i>',
|
|
|
|
name: 'refresh',
|
|
|
|
titleAttr: "Refresh",
|
|
|
|
action: function (e, dt, node, config) {
|
|
|
|
location.reload();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-05-30 21:07:46 +00:00
|
|
|
$.fn.dataTable.ext.buttons.download = {
|
|
|
|
text: '<i class="fas fa-download"></i>',
|
|
|
|
name: 'download',
|
|
|
|
titleAttr: "Download",
|
|
|
|
action: function (e, dt, node, config) {
|
|
|
|
var filesArray = [];
|
|
|
|
var selected = dt.column(0).checkboxes.selected();
|
|
|
|
for (i = 0; i < selected.length; i++) {
|
|
|
|
filesArray.push(selected[i]);
|
|
|
|
}
|
|
|
|
var files = fixedEncodeURIComponent(JSON.stringify(filesArray));
|
|
|
|
var downloadURL = '{{.DownloadURL}}';
|
|
|
|
var currentDir = '{{.CurrentDir}}';
|
|
|
|
window.location = `${downloadURL}?path=${currentDir}&files=${files}`;
|
|
|
|
},
|
|
|
|
enabled: false
|
|
|
|
};
|
|
|
|
|
2021-05-06 19:35:43 +00:00
|
|
|
var table = $('#dataTable').DataTable({
|
2021-05-27 07:40:46 +00:00
|
|
|
"ajax": {
|
|
|
|
"url": "{{.ReadDirURL}}?path={{.CurrentDir}}",
|
|
|
|
"dataSrc": "",
|
|
|
|
"error": function ($xhr, textStatus, errorThrown) {
|
|
|
|
$(".dataTables_processing").hide();
|
|
|
|
var txt = "Failed to get directory listing";
|
|
|
|
if ($xhr) {
|
|
|
|
var json = $xhr.responseJSON;
|
|
|
|
if (json) {
|
|
|
|
txt += ": " + json.message;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$('#errorTxt').text(txt);
|
|
|
|
$('#errorMsg').show();
|
|
|
|
setTimeout(function () {
|
|
|
|
$('#errorMsg').hide();
|
|
|
|
}, 10000);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"deferRender": true,
|
|
|
|
"processing": true,
|
|
|
|
"columns": [
|
2021-05-30 21:07:46 +00:00
|
|
|
{ "data": "name" },
|
2021-05-27 07:40:46 +00:00
|
|
|
{ "data": "type" },
|
|
|
|
{
|
|
|
|
"data": "name",
|
2021-05-30 21:07:46 +00:00
|
|
|
"render": function (data, type, row) {
|
2021-05-27 07:40:46 +00:00
|
|
|
if (type === 'display') {
|
2021-05-30 21:07:46 +00:00
|
|
|
if (row["type"] == "1") {
|
2021-05-27 07:40:46 +00:00
|
|
|
return `<i class="fas fa-folder"></i> <a href="${row['url']}">${data}</a>`;
|
|
|
|
}
|
2021-05-30 21:07:46 +00:00
|
|
|
if (row["size"] == "") {
|
|
|
|
return `<i class="fas fa-external-link-alt"></i> <a href="${row['url']}">${data}</a>`;
|
|
|
|
}
|
|
|
|
var icon = getIconForFile(data);
|
|
|
|
return `<i class="${icon}"></i> <a href="${row['url']}">${data}</a>`;
|
2021-05-27 07:40:46 +00:00
|
|
|
}
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{ "data": "size" },
|
|
|
|
{ "data": "last_modified" }
|
|
|
|
],
|
2021-05-06 19:35:43 +00:00
|
|
|
"buttons": [],
|
|
|
|
"lengthChange": false,
|
|
|
|
"columnDefs": [
|
|
|
|
{
|
|
|
|
"targets": [0],
|
2021-05-30 21:07:46 +00:00
|
|
|
"checkboxes": {
|
|
|
|
"selectCallback": function (nodes, selected) {
|
|
|
|
var selectedItems = table.column(0).checkboxes.selected().length;
|
|
|
|
var selectedText = "";
|
|
|
|
if (selectedItems == 1) {
|
|
|
|
selectedText = "1 item selected";
|
|
|
|
} else if (selectedItems > 1) {
|
|
|
|
selectedText = `${selectedItems} items selected`;
|
|
|
|
}
|
|
|
|
table.button('download:name').enable(selectedItems > 0);
|
|
|
|
$('#dataTable_info').find('span').remove();
|
|
|
|
$("#dataTable_info").append('<span class="selected-info"><span class="selected-item">' + selectedText + '</span></span>');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"orderable": false,
|
|
|
|
"searchable": false
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"targets": [1],
|
2021-05-06 19:35:43 +00:00
|
|
|
"visible": false,
|
|
|
|
"searchable": false
|
|
|
|
},
|
|
|
|
{
|
2021-05-30 21:07:46 +00:00
|
|
|
"targets": [3, 4],
|
2021-05-06 19:35:43 +00:00
|
|
|
"searchable": false
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"scrollX": false,
|
|
|
|
"scrollY": false,
|
|
|
|
"responsive": true,
|
|
|
|
"language": {
|
2021-05-27 07:40:46 +00:00
|
|
|
"processing": '<i class="fas fa-spinner fa-spin fa-3x fa-fw"></i><span class="sr-only">Loading...</span>',
|
|
|
|
"loadingRecords": "",
|
2021-05-07 18:41:20 +00:00
|
|
|
"emptyTable": "No files or folders"
|
2021-05-06 19:35:43 +00:00
|
|
|
},
|
2021-05-30 21:07:46 +00:00
|
|
|
"initComplete": function (settings, json) {
|
|
|
|
table.button().add(0, 'refresh');
|
|
|
|
table.button().add(0, 'pageLength');
|
|
|
|
table.button().add(0, 'download');
|
2021-05-27 07:40:46 +00:00
|
|
|
table.buttons().container().appendTo('#dataTable_wrapper .col-md-6:eq(0)');
|
|
|
|
},
|
2021-05-30 21:07:46 +00:00
|
|
|
"orderFixed": [1, 'asc'],
|
|
|
|
"order": [[2, 'asc']]
|
2021-05-06 19:35:43 +00:00
|
|
|
});
|
|
|
|
|
2021-05-30 21:07:46 +00:00
|
|
|
new $.fn.dataTable.FixedHeader(table);
|
2021-05-27 07:40:46 +00:00
|
|
|
$.fn.dataTable.ext.errMode = 'none';
|
2021-05-06 19:35:43 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
{{end}}
|