2021-01-15 12:13:06 +00:00
{% extends ../base.html %}
{% block meta %}
<!-- <meta http - equiv="refresh" content="60"> -->
{% end %}
2021-03-26 13:57:50 +00:00
{% block title %}Crafty Controller - {{ translate('serverDetails', 'serverDetails') }}{% end %}
2021-01-15 12:13:06 +00:00
{% block content %}
< div class = "content-wrapper" >
<!-- Page Title Header Starts -->
< div class = "row page-title-header" >
< div class = "col-12" >
< div class = "page-header" >
< h4 class = "page-title" >
2021-03-26 13:57:50 +00:00
{{ translate('serverDetails', 'serverDetails') }} - {{ data['server_stats']['server_id']['server_name'] }}
2021-01-15 12:13:06 +00:00
< br / >
2021-03-22 04:02:18 +00:00
< small > UUID: {{ data['server_stats']['server_id']['server_uuid'] }}< / small >
2021-01-15 12:13:06 +00:00
< / h4 >
< / div >
< / div >
< / div >
<!-- Page Title Header Ends -->
{% include "parts/details_stats.html %}
< div class = "row" >
< div class = "col-sm-12 grid-margin" >
< div class = "card" >
< div class = "card-body pt-0" >
2021-08-21 08:44:03 +00:00
{% include "parts/server_controls_list.html %}
2021-01-15 12:13:06 +00:00
< div class = "row" >
< div class = "col-md-6 col-sm-12" >
< noscript >
2021-03-26 13:57:50 +00:00
{{ translate('serverFiles', 'noscript') }}
2021-01-15 12:13:06 +00:00
< / noscript >
2021-01-17 17:20:28 +00:00
< div id = "files-tree-nav" class = "overlay" >
<!-- Button to close the overlay navigation -->
<!-- Overlay content -->
< div id = "files-tree-nav-content" class = "overlay-content" >
2021-03-26 13:57:50 +00:00
< a onclick = "createFileE(event)" href = "javascript:void(0)" id = "createFile" href = "#" > {{ translate('serverFiles', 'createFile') }}< / a >
< a onclick = "createDirE(event)" href = "javascript:void(0)" id = "createDir" href = "#" > {{ translate('serverFiles', 'createDir') }}< / a >
< a onclick = "renameItemE(event)" href = "javascript:void(0)" id = "renameItem" href = "#" > {{ translate('serverFiles', 'rename') }}< / a >
< a onclick = "deleteFileE(event)" href = "javascript:void(0)" id = "deleteFile" href = "#" > {{ translate('serverFiles', 'delete') }}< / a >
< a onclick = "deleteDirE(event)" href = "javascript:void(0)" id = "deleteDir" href = "#" > {{ translate('serverFiles', 'delete') }}< / a >
2021-08-24 00:24:40 +00:00
< a onclick = "uploadFilesE(event)" href = "javascript:void(0)" id = "upload" href = "#" > {{ translate('serverFiles', 'upload') }}< / a >
< a onclick = "unzipFilesE(event)" href = "javascript:void(0)" id = "unzip" href = "#" > {{ translate('serverFiles', 'unzip') }}< / a >
< a href = "javascript:void(0)" class = "closebtn" style = "color: red;" onclick = "document.getElementById('files-tree-nav').style.display = 'none';" > {{ translate('serverFiles', 'close') }}< / a >
2021-01-17 17:20:28 +00:00
< / div >
< / div >
< style >
/* The Overlay (background) */
.overlay {
2021-08-20 17:46:01 +00:00
display: none;
flex-direction: column;
background-color: #fff;
border-radius: 10px;
box-shadow: 0 10px 20px rgb(64 64 64 / 5%);
padding: 10px 0;
z-index: 10000;
overflow: scroll;
2021-01-17 17:20:28 +00:00
}
2021-08-20 19:18:55 +00:00
.overlay::-webkit-scrollbar {
display: none;
}
/* Hide scrollbar for IE, Edge and Firefox */
.overlay {
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none; /* Firefox */
2021-01-17 17:20:28 +00:00
}
/* Position the content inside the overlay */
.overlay-content {
2021-08-20 17:46:01 +00:00
display: flex;
flex-direction: column;
background-color: #fff;
border-radius: 10px;
box-shadow: 0 10px 20px rgb(64 64 64 / 5%);
padding: 10px 0;
2021-01-17 17:20:28 +00:00
}
/* The navigation links inside the overlay */
.overlay a {
2021-08-20 17:46:01 +00:00
font: inherit;
border: 0;
padding: 10px 30px 10px 15px;
width: 100%;
display: flex;
align-items: center;
position: relative;
text-decoration: unset;
color: #000;
font-weight: 500;
transition: 0.5s linear;
-webkit-transition: 0.5s linear;
-moz-transition: 0.5s linear;
-ms-transition: 0.5s linear;
-o-transition: 0.5s linear;
2021-01-17 17:20:28 +00:00
}
/* When you mouse over the navigation links, change their color */
.overlay a:hover, .overlay a:focus {
2021-08-20 17:46:01 +00:00
background:#f1f3f7;
color: #4b00ff;
2021-01-17 17:20:28 +00:00
}
/* Position the close button (top right corner) */
2021-08-20 17:46:01 +00:00
.overlay .closebtn .closebtn:hover {
background-color: red;
color: red;
z-index: 10000;
2021-01-17 17:20:28 +00:00
}
/* When the height of the screen is less than 450 pixels, change the font-size of the links and position the close button again, so they don't overlap */
@media screen and (max-height: 450px) {
.overlay a {font-size: 20px}
.overlay .closebtn {
font-size: 40px;
top: 15px;
right: 35px;
}
}
< / style >
2021-01-15 12:13:06 +00:00
< ul class = "tree-view" >
< li >
2021-01-22 22:46:33 +00:00
< div class = "tree-caret tree-ctx-item files-tree-title" >
< i class = "far fa-folder" > < / i >
< i class = "far fa-folder-open" > < / i >
2021-03-26 13:57:50 +00:00
{{ translate('serverFiles', 'files') }}
2021-01-22 22:46:33 +00:00
< / div >
2021-01-15 12:13:06 +00:00
< ul class = "tree-nested" id = "files-tree" >
2021-03-26 13:57:50 +00:00
< li > {{ translate('serverFiles', 'error') }}< / li >
2021-01-15 12:13:06 +00:00
< / ul >
< / li >
< / ul >
< / div >
< style >
/* Remove default bullets */
2021-01-22 22:46:33 +00:00
.tree-view,
.tree-nested {
2021-01-15 12:13:06 +00:00
list-style-type: none;
margin: 0;
padding: 0;
2021-01-22 22:46:33 +00:00
margin-left: 10px;
2021-01-15 12:13:06 +00:00
}
2021-08-12 14:54:52 +00:00
/* Style the items */
.tree-item,
.files-tree-title {
2021-01-15 12:13:06 +00:00
cursor: pointer;
user-select: none; /* Prevent text selection */
}
/* Create the caret/arrow with a unicode, and style it */
2021-01-22 22:46:33 +00:00
.tree-caret .fa-folder {
2021-01-15 12:13:06 +00:00
display: inline-block;
2021-01-22 22:46:33 +00:00
}
.tree-caret .fa-folder-open {
display: none;
2021-01-15 12:13:06 +00:00
}
/* Rotate the caret/arrow icon when clicked on (using JavaScript) */
2021-01-22 22:46:33 +00:00
.tree-caret-down .fa-folder {
display: none;
}
.tree-caret-down .fa-folder-open {
display: inline-block;
2021-01-15 12:13:06 +00:00
}
/* Hide the nested list */
.tree-nested {
display: none;
}
< / style >
< div class = "col-md-6 col-sm-12" >
2021-05-27 18:39:46 +00:00
< h2 id = "fileError" > < / h2 >
2021-03-26 13:57:50 +00:00
< div id = "editorParent" >
{{ translate('serverFiles', 'editingFile') }} < span id = "editingFile" > < / span >
< div id = "editor" onresize = "editor.resize()" style = "resize: both;width: 100%;" > file_contents< / div >
< br / >
< / div >
{{ translate('serverFiles', 'keybindings') }}:
2021-01-22 22:12:52 +00:00
< div class = "btn-group" role = "group" >
2021-03-26 13:57:50 +00:00
< button onclick = "setKeyboard(event.target)" class = "btn btn-primary" data-handler-name = "null" > {{ translate('serverFiles', 'default') }}< / button >
2021-01-22 22:12:52 +00:00
< button onclick = "setKeyboard(event.target)" class = "btn btn-secondary" data-handler-name = "ace/keyboard/vim" > Vim< / button >
< button onclick = "setKeyboard(event.target)" class = "btn btn-secondary" data-handler-name = "ace/keyboard/emacs" > Emacs< / button >
< button onclick = "setKeyboard(event.target)" class = "btn btn-secondary" data-handler-name = "ace/keyboard/sublime" > Sublime< / button >
< / div >
2021-01-15 12:13:06 +00:00
< h3 id = "file_warn" > < / h3 >
2021-08-21 23:41:25 +00:00
< button class = "btn btn-success" onclick = "save()" > < i class = "fas fa-save" > < / i > {{ translate('serverFiles', 'save') }}< / button >
2021-01-15 12:13:06 +00:00
< / div >
< / div >
< / div >
< / div >
< / div >
< / div >
< / div >
<!-- content - wrapper ends -->
{% end %}
{% block js %}
< script src = "/static/assets/vendors/ace-builds/src-min/ace.js" type = "text/javascript" charset = "utf-8" > < / script >
< script >
2021-01-15 19:59:58 +00:00
//used to get cookies from browser - this is part of tornados xsrf protection - it's for extra security
function getCookie(name) {
var r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
return r ? r[1] : undefined;
}
2021-01-15 12:13:06 +00:00
let editor = ace.edit('editor');
editor.setTheme('ace/theme/dracula');
2021-01-15 19:59:58 +00:00
editor.session.setUseSoftTabs(true);
2021-01-15 12:13:06 +00:00
2021-01-20 21:10:25 +00:00
// mouseup = css resize end
document.addEventListener("mouseup", function(e){
editor.resize();
});
2021-01-15 12:13:06 +00:00
let extensionChanges = [
{
regex: /^js$/,
replaceWith: 'ace/mode/javascript'
},
{
regex: /^py$/,
replaceWith: 'ace/mode/python'
},
{
regex: /^html$/,
replaceWith: 'ace/mode/html'
},
{
regex: /^yml$/,
replaceWith: 'ace/mode/yaml'
},
{
regex: /^yaml$/,
replaceWith: 'ace/mode/yaml'
},
{
regex: /^txt$/,
replaceWith: 'ace/mode/text'
},
{
regex: /^json$/,
replaceWith: 'ace/mode/json'
},
{
regex: /^java$/,
replaceWith: 'ace/mode/java'
},
{
regex: /^cpp$/,
replaceWith: 'ace/mode/c_cpp'
},
2021-03-26 13:57:50 +00:00
{
regex: /^c$/,
replaceWith: 'ace/mode/c_cpp'
},
2021-01-15 12:13:06 +00:00
{
regex: /^css$/,
replaceWith: 'ace/mode/css'
},
{
regex: /^scss$/,
replaceWith: 'ace/mode/scss'
},
{
regex: /^sass$/,
replaceWith: 'ace/mode/sass'
},
{
regex: /^lua$/,
replaceWith: 'ace/mode/lua'
},
{
regex: /^php$/,
replaceWith: 'ace/mode/php'
},
{
regex: /^ps1$/,
replaceWith: 'ace/mode/powershell'
},
{
regex: /^svg$/,
replaceWith: 'ace/mode/svg'
},
{
regex: /^sh$/,
replaceWith: 'ace/mode/sh'
},
{
regex: /^xml$/,
replaceWith: 'ace/mode/xml'
},
{
regex: /^ts$/,
replaceWith: 'ace/mode/typescript'
2021-03-26 13:57:50 +00:00
},
{
regex: /^properties$/,
replaceWith: 'ace/mode/properties'
},
2021-08-22 20:31:49 +00:00
{
regex: /^log$/,
replaceWith: 'ace/mode/txt'
},
2021-01-15 12:13:06 +00:00
];
2021-01-15 19:59:58 +00:00
var filePath = '';
function clickOnFile(event) {
filePath = event.target.getAttribute('data-path');
$.ajax({
type: 'GET',
2021-03-22 04:02:18 +00:00
url: '/ajax/get_file?id={{ data['server_stats']['server_id']['server_id'] }}& file_path=' + encodeURIComponent(filePath),
2021-01-15 19:59:58 +00:00
dataType: 'text',
success: function (data) {
console.log('Got File Contents From Server');
2021-03-26 13:57:50 +00:00
json = JSON.parse(data)
if (json.error) {
2021-05-27 18:39:46 +00:00
$('#editorParent').toggle(false) // hide
$('#fileError').toggle(true) // show
$('#fileError').text("{{ translate('serverFiles', 'fileReadError') }}: " + json.error) // show error
2021-03-26 13:57:50 +00:00
editor.blur()
} else {
2021-05-27 18:39:46 +00:00
$('#editorParent').toggle(true) // show
$('#fileError').toggle(false) // hide
2021-03-26 13:57:50 +00:00
setFileName(event.target.innerText);
editor.session.setValue(json.content);
}
2021-01-15 19:59:58 +00:00
},
});
}
2021-01-15 12:13:06 +00:00
function setFileName(name) {
let fileName = name || 'default.txt';
document.getElementById('editingFile').innerText = fileName;
if (fileName.match('.')) {
// The pop method removes and returns the last element.
setMode(fileName
.split('.')
.pop()
.replace('ace/mode/', ''));
} else {
setMode('txt');
document
.querySelector('#file_warn')
2021-03-26 13:57:50 +00:00
.innerText = "{% raw translate('serverFiles', 'unsupportedLanguage') %}";
2021-01-15 12:13:06 +00:00
}
}
setFileName();
2021-05-27 18:39:46 +00:00
$('#editorParent').toggle(false) // show
$('#fileError').toggle(false) // hide
2021-03-26 13:57:50 +00:00
editor.blur()
2021-01-15 12:13:06 +00:00
function setMode (extension) {
// if the extension matches with the RegEx it will return the replaceWith
// property. else it will return the one it has. defaults to the extension.
// this runs for each element in extensionChanges.
let aceMode = extensionChanges.reduce((output, element) => {
return extension.match(element.regex)
? element.replaceWith
: output;
}, extension);
if (!aceMode.startsWith('ace/mode/')) {
document
.querySelector('#file_warn')
2021-03-26 13:57:50 +00:00
.innerText = "{% raw translate('serverFiles', 'unsupportedLanguage') %}";
2021-01-15 12:13:06 +00:00
} else {
document
.querySelector('#file_warn')
.innerText = '';
console.log(aceMode || 'ace/mode/text');
editor.session.setMode(aceMode || 'ace/mode/text');
}
}
function save() {
let text = editor.session.getValue();
2021-01-15 19:59:58 +00:00
var token = getCookie("_xsrf")
$.ajax({
2021-01-17 17:20:28 +00:00
type: "PUT",
2021-01-15 19:59:58 +00:00
headers: {'X-XSRFToken': token},
2021-03-22 04:02:18 +00:00
url: '/ajax/save_file?id={{ data['server_stats']['server_id']['server_id'] }}',
2021-01-15 19:59:58 +00:00
data: {
file_contents: text,
file_path: filePath
},
success: function(data){
console.log("got response:");
console.log(data);
},
});
2021-01-15 12:13:06 +00:00
}
2021-01-17 17:20:28 +00:00
function createFile(parent, name, callback) {
var token = getCookie("_xsrf")
$.ajax({
type: "POST",
headers: {'X-XSRFToken': token},
2021-03-22 04:02:18 +00:00
url: '/ajax/create_file?id={{ data['server_stats']['server_id']['server_id'] }}',
2021-01-17 17:20:28 +00:00
data: {
file_parent: parent,
file_name: name
},
success: function(data){
console.log("got response:");
console.log(data);
callback();
},
});
}
function createDir(parent, name, callback) {
var token = getCookie("_xsrf")
$.ajax({
type: "POST",
headers: {'X-XSRFToken': token},
2021-03-22 04:02:18 +00:00
url: '/ajax/create_dir?id={{ data['server_stats']['server_id']['server_id'] }}',
2021-01-17 17:20:28 +00:00
data: {
dir_parent: parent,
dir_name: name
},
success: function(data){
console.log("got response:");
console.log(data);
callback();
},
});
}
function renameItem(path, name, callback) {
var token = getCookie("_xsrf")
$.ajax({
type: "PUT",
headers: {'X-XSRFToken': token},
2021-03-22 04:02:18 +00:00
url: '/ajax/rename_item?id={{ data['server_stats']['server_id']['server_id'] }}',
2021-01-17 17:20:28 +00:00
data: {
item_path: path,
new_item_name: name
},
success: function(data){
console.log("got response:");
console.log(data);
callback();
},
});
}
function deleteFile(path, callback) {
console.log('Deleting: ' + path)
var token = getCookie("_xsrf")
$.ajax({
type: "DELETE",
headers: {'X-XSRFToken': token},
2021-03-22 04:02:18 +00:00
url: '/ajax/del_file?id={{ data['server_stats']['server_id']['server_id'] }}',
2021-01-17 17:20:28 +00:00
data: {
file_path: path
},
success: function(data){
console.log("got response:");
console.log(data);
callback();
},
});
}
function deleteDir(path, callback) {
var token = getCookie("_xsrf")
$.ajax({
type: "DELETE",
headers: {'X-XSRFToken': token},
2021-03-22 04:02:18 +00:00
url: '/ajax/del_dir?id={{ data['server_stats']['server_id']['server_id'] }}',
2021-01-17 17:20:28 +00:00
data: {
dir_path: path
},
success: function(data){
console.log("got response:");
console.log(data);
callback();
},
});
}
2021-08-19 20:50:18 +00:00
function unZip(path, callback) {
var token = getCookie("_xsrf")
$.ajax({
type: "POST",
headers: {'X-XSRFToken': token},
url: '/ajax/unzip_file?id={{ data['server_stats']['server_id']['server_id'] }}',
data: {
path: path
},
});
2021-08-20 03:50:24 +00:00
window.location.href = "/panel/server_detail?id={{ data['server_stats']['server_id']['server_id'] }}& subpage=files"
2021-08-19 20:50:18 +00:00
}
2021-08-22 20:31:49 +00:00
2021-08-23 22:22:35 +00:00
function sendFile(file, path, server_id, left, onProgress){
2021-08-22 20:31:49 +00:00
var xmlHttpRequest = new XMLHttpRequest();
var token = getCookie("_xsrf")
var fileName = file.name
var target = '/upload?server_id=' + server_id
var mimeType = file.type
xmlHttpRequest.open('POST', target, true);
xmlHttpRequest.setRequestHeader('X-Content-Type', mimeType);
xmlHttpRequest.setRequestHeader('X-XSRFToken', token);
xmlHttpRequest.setRequestHeader('X-Content-Disposition', 'attachment; filename="' + fileName + '"');
xmlHttpRequest.setRequestHeader('X-Path', path);
2021-08-23 22:22:35 +00:00
xmlHttpRequest.setRequestHeader('X-Files-Left', left);
2021-08-22 20:31:49 +00:00
xmlHttpRequest.setRequestHeader('X-FileName', fileName);
xmlHttpRequest.setRequestHeader('X-ServerId', "{{ data['server_stats']['server_id']['server_id'] }}");
xmlHttpRequest.upload.addEventListener('progress', (event) =>
onProgress(Math.floor(event.loaded / event.total * 100)), false);
xmlHttpRequest.addEventListener('load', (event) => {
if (event.target.responseText == 'success') {
console.log('Upload for file', file.name, 'was successful!')
}
else {
alert('Upload failed with response: ' + event.target.responseText);
doUpload = false;
}
}, false);
xmlHttpRequest.addEventListener('error', (e) => {
console.error('Error while uploading file', file.name + '.', 'Event:', e)
}, false);
xmlHttpRequest.send(file);
}
var uploadWaitDialog;
var doUpload = true;
function uploadFilesE(event){
2021-08-19 20:50:18 +00:00
path = event.target.parentElement.getAttribute('data-path');
2021-08-20 03:36:25 +00:00
console.log("PATH: " + path);
2021-08-22 20:31:49 +00:00
$(function () {
server_id = {{ data['server_stats']['server_id']['server_id'] }};
var uploadHtml = "< div > " +
'< form id = "upload_file" enctype = "multipart/form-data" > '+"< label class = 'upload-area' style = 'width:100%;text-align:center;' for = 'files' > " +
"< input id = 'files' name = 'files' type = 'file' style = 'display:none;' multiple = 'true' > " +
"< i class = 'fa fa-cloud-upload fa-3x' > < / i > " +
"< br / > " +
2021-08-24 00:24:40 +00:00
"{{translate('serverFiles', 'clickUpload')}}" +
2021-08-22 20:31:49 +00:00
"< / label > < / form > " +
"< br / > " +
"< ul style = 'margin-left:5px !important;' id = 'fileList' > < / ul > " +
"< / div > < div class = 'clearfix' > < / div > ";
bootbox.dialog({
message: uploadHtml,
2021-08-24 00:24:40 +00:00
title: "{{ translate('serverFiles', 'uploadTitle')}}"+path,
2021-08-22 20:31:49 +00:00
buttons: {
success: {
2021-08-24 00:24:40 +00:00
label: "{{ translate('serverFiles', 'upload') }}",
2021-08-22 20:31:49 +00:00
className: "btn-default",
callback: async function () {
2021-08-23 21:52:55 +00:00
var height = files.files.length*50;
var waitMessage = '< p class = "text-center mb-0" > '+
'< i class = "fa fa-spin fa-cog" > < / i > '+
2021-08-24 00:24:40 +00:00
"{{ translate('serverFiles', 'waitUpload') }}"+'< br > '+
'< strong > '+"{{ translate('serverFiles', 'stayHere') }}"+'< / strong > '+
2021-08-23 21:52:55 +00:00
'< / p > '+
'< div class = "progress" id = "upload-progress-bar-parent" style = "height:'+height +'px; width:100%; display: block;" > '+
'< / div > '
2021-08-22 20:31:49 +00:00
files = document.getElementById("files");
uploadWaitDialog = bootbox.dialog({
2021-08-23 21:52:55 +00:00
message: waitMessage,
2021-08-22 20:31:49 +00:00
closeButton: false
});
let nFiles = files.files.length;
for(i=0; i < files.files.length ; i + + ) {
if (!doUpload) {
doUpload = true;
hideUploadBox();
break;
}
2021-08-23 21:52:55 +00:00
console.log(files.files[i].name);
2021-08-22 20:31:49 +00:00
const progressHtml = `
2021-08-23 21:52:55 +00:00
< div style = "width: 100%; min-width: 100%;" >
${files.files[i].name}:
< br > < div
2021-08-22 20:31:49 +00:00
id="upload-progress-bar-${i + 1}"
class="progress-bar progress-bar-striped progress-bar-animated"
role="progressbar"
2021-08-23 21:52:55 +00:00
style="width: 100%; height: 10px;"
2021-08-22 20:31:49 +00:00
aria-valuenow="0"
aria-valuemin="0"
aria-valuemax="100"
>< / div >
2021-08-23 21:52:55 +00:00
< / div > < br >
2021-08-22 20:31:49 +00:00
`;
$('#upload-progress-bar-parent').append(progressHtml);
2021-08-23 22:22:35 +00:00
console.log(files.files.length)
sendFile(files.files[i], path, server_id, files.files.length - i - 1, (progress) => {
2021-08-22 20:31:49 +00:00
$(`#upload-progress-bar-${i + 1}`).attr('aria-valuenow', progress)
$(`#upload-progress-bar-${i + 1}`).css('width', progress + '%')
});
2021-08-22 14:42:06 +00:00
}
2021-08-22 20:31:49 +00:00
hideUploadBox();
//$('#upload_file').submit(); //.trigger('submit');
}
}
}
2021-08-19 20:50:18 +00:00
});
2021-08-22 20:31:49 +00:00
2021-08-20 03:36:25 +00:00
var fileList = document.getElementById("files");
2021-08-19 20:50:18 +00:00
fileList.addEventListener("change", function (e) {
var list = "";
for (var i = 0; i < this.files.length ; i + + ) {
2021-08-20 03:36:25 +00:00
list += "< li class = 'col-xs-12 file-list' > " + this.files[i].name + "< / li > "
2021-08-19 20:50:18 +00:00
}
2021-08-20 03:36:25 +00:00
document.getElementById("fileList").innerHTML = list;
2021-08-19 20:50:18 +00:00
}, false);
2021-08-20 03:36:25 +00:00
});
}
2021-01-17 17:20:28 +00:00
function getTreeView() {
$.ajax({
type: "GET",
2021-03-22 04:02:18 +00:00
url: '/ajax/get_tree?id={{ data['server_stats']['server_id']['server_id'] }}',
2021-01-17 17:20:28 +00:00
dataType: 'text',
success: function(data){
console.log("got response:");
console.log(data);
dataArr = data.split('\n');
serverDir = dataArr.shift(); // Remove & return first element (server directory)
text = dataArr.join('\n');
document.getElementById('files-tree').innerHTML = text;
document.getElementsByClassName('files-tree-title')[0].setAttribute('data-path', serverDir);
document.getElementsByClassName('files-tree-title')[0].setAttribute('data-name', 'Files');
setTimeout(function () {setTreeViewContext()}, 1000);
var toggler = document.getElementsByClassName("tree-caret");
var i;
for (i = 0; i < toggler.length ; i + + ) {
if (toggler[i].classList.contains('files-tree-title')) continue;
toggler[i].addEventListener("click", function caretListener() {
this.parentElement.querySelector(".tree-nested").classList.toggle("d-block");
this.classList.toggle("tree-caret-down");
});
}
},
});
}
function setTreeViewContext() {
var treeItems = document.getElementsByClassName('tree-ctx-item');
for (var i = 0; i < treeItems.length ; i + + ) {
var treeItem = treeItems[i];
treeItem.addEventListener('contextmenu', function contextListener(event) {
event.preventDefault();
var ctxmenuPath = event.target.getAttribute('data-path');
var ctxmenuName = event.target.getAttribute('data-name');
if (!ctxmenuPath) {
console.log({ 'event.target': event.target, ctxmenuPath });
return;
}
$('#renameItem').show();
var isDir = event.target.classList.contains('tree-folder');
$('#createFile').toggle(isDir);
$('#createDir').toggle(isDir);
$('#deleteDir').toggle(isDir);
2021-08-19 20:50:18 +00:00
$('#upload').toggle(isDir);
2021-01-17 17:20:28 +00:00
var isFile = event.target.classList.contains('tree-file');
$('#deleteFile').toggle(isFile);
console.log({ 'event.target': event.target, isDir, isFile });
if(event.target.classList.contains('files-tree-title')) {
$('#createFile').show();
$('#createDir').show();
$('#renameItem').hide();
$('#deleteDir').hide();
$('#deleteFile').hide();
2021-08-19 20:50:18 +00:00
$('#upload').show();
2021-01-17 17:20:28 +00:00
}
2021-08-20 17:46:01 +00:00
if(event.target.textContent.endsWith('.zip')){
$('#unzip').show();
console.log(event.target.textContent)
}else{
$('#unzip').hide();}
2021-08-20 18:58:52 +00:00
var clientX = event.clientX;
var clientY = event.clientY;
2021-01-17 17:20:28 +00:00
document.getElementById('files-tree-nav-content')
.setAttribute('data-path', ctxmenuPath);
document.getElementById('files-tree-nav-content')
.setAttribute('data-name', ctxmenuName);
2021-08-20 17:46:01 +00:00
document.getElementById("files-tree-nav").style.display = "flex";
document.getElementById("files-tree-nav").style.position = "fixed";
2021-08-20 18:58:52 +00:00
domRect = document.getElementById("files-tree-nav").getBoundingClientRect();
sum = (clientY+domRect['height']) - window.innerHeight
if(domRect['height']+clientY > window.innerHeight){
clientY = clientY - sum
}
document.getElementById("files-tree-nav").style.top = clientY + 'px';
document.getElementById("files-tree-nav").style.left = clientX + 'px';
console.log(domRect)
console.log(window.innerHeight)
2021-01-17 17:20:28 +00:00
})
}
}
2021-08-20 18:58:52 +00:00
document.addEventListener('click', function(e){
let inside = (e.target.closest('#files-tree-nav'));
2021-08-22 20:31:49 +00:00
let contextMenu = document.getElementById('files-tree-nav');
2021-08-20 18:58:52 +00:00
if(!inside){
2021-08-22 20:31:49 +00:00
contextMenu.setAttribute('style', 'display:none');
}else{
2021-08-20 18:58:52 +00:00
contextMenu.setAttribute('style', 'display:none');
}
});
2021-08-22 20:31:49 +00:00
if (webSocket) {
webSocket.on('close_upload_box', function (close_upload_box) {
hideUploadBox();
});
}
function hideUploadBox(){
if (!uploadWaitDialog) return;
uploadWaitDialog.modal('hide');
getTreeView();
}
2021-01-17 17:20:28 +00:00
function createFileE(event) {
2021-03-26 13:57:50 +00:00
bootbox.prompt("{% raw translate('serverFiles', 'createFileQuestion') %}", function(result) {
2021-01-17 17:20:28 +00:00
path = event.target.parentElement.getAttribute('data-path');
name = event.target.parentElement.getAttribute('data-name');
if (!result) return;
createFile(path, result, function () {
getTreeView()
2021-08-20 17:46:01 +00:00
document.getElementById('files-tree-nav').style.display = 'none';
2021-01-17 17:20:28 +00:00
});
})
}
function createDirE(event) {
2021-03-26 13:57:50 +00:00
bootbox.prompt("{% raw translate('serverFiles', 'createDirQuestion') %}", function(result) {
2021-01-17 17:20:28 +00:00
path = event.target.parentElement.getAttribute('data-path');
name = event.target.parentElement.getAttribute('data-name');
if (!result) return;
createDir(path, result, function () {
getTreeView()
2021-08-20 17:46:01 +00:00
document.getElementById('files-tree-nav').style.display = 'none';
2021-01-17 17:20:28 +00:00
});
})
}
function renameItemE(event) {
2021-03-26 13:57:50 +00:00
bootbox.prompt("{% raw translate('serverFiles', 'renameItemQuestion') %}", function(result) {
2021-01-17 17:20:28 +00:00
path = event.target.parentElement.getAttribute('data-path');
name = event.target.parentElement.getAttribute('data-name');
if (!result) return;
renameItem(path, result, function () {
getTreeView()
2021-08-20 17:46:01 +00:00
document.getElementById('files-tree-nav').style.display = 'none';
2021-01-17 17:20:28 +00:00
});
})
}
2021-08-19 20:50:18 +00:00
function unzipFilesE(event) {
path = event.target.parentElement.getAttribute('data-path');
unZip(path)
}
2021-01-17 17:20:28 +00:00
function deleteFileE(event) {
path = event.target.parentElement.getAttribute('data-path');
name = event.target.parentElement.getAttribute('data-name');
bootbox.confirm({
size: "",
2021-03-26 13:57:50 +00:00
title: "{% raw translate('serverFiles', 'deleteItemQuestion') %}",
2021-01-17 17:20:28 +00:00
closeButton: false,
2021-03-26 13:57:50 +00:00
message: "{% raw translate('serverFiles', 'deleteItemQuestionMessage') %}",
2021-01-17 17:20:28 +00:00
buttons: {
confirm: {
2021-03-26 13:57:50 +00:00
label: "{{ translate('serverFiles', 'yesDelete') }}",
2021-01-17 17:20:28 +00:00
className: 'btn-danger'
},
cancel: {
2021-03-26 13:57:50 +00:00
label: "{{ translate('serverFiles', 'noDelete') }}",
2021-01-17 17:20:28 +00:00
className: 'btn-link'
}
},
callback: function(result) {
if (!result) return;
deleteFile(path, function () {
getTreeView()
2021-08-20 17:46:01 +00:00
document.getElementById('files-tree-nav').style.display = 'none';
2021-01-17 17:20:28 +00:00
});
}
});
}
function deleteDirE(event) {
path = event.target.parentElement.getAttribute('data-path');
name = event.target.parentElement.getAttribute('data-name');
bootbox.confirm({
size: "",
2021-03-26 13:57:50 +00:00
title: "{% raw translate('serverFiles', 'deleteItemQuestion') %}",
2021-01-17 17:20:28 +00:00
closeButton: false,
2021-03-26 13:57:50 +00:00
message: "{% raw translate('serverFiles', 'deleteItemQuestionMessage') %}",
2021-01-17 17:20:28 +00:00
buttons: {
confirm: {
2021-03-26 13:57:50 +00:00
label: "{{ translate('serverFiles', 'yesDelete') }}",
2021-01-17 17:20:28 +00:00
className: 'btn-danger'
},
cancel: {
2021-03-26 13:57:50 +00:00
label: "{{ translate('serverFiles', 'noDelete') }}",
2021-01-17 17:20:28 +00:00
className: 'btn-link'
}
},
callback: function(result) {
if (!result) return;
deleteDir(path, function () {
getTreeView()
2021-08-20 17:46:01 +00:00
document.getElementById('files-tree-nav').style.display = 'none';
2021-01-17 17:20:28 +00:00
});
}
});
}
document.getElementsByClassName('files-tree-title')[0].addEventListener("click", function caretListener() {
this.parentElement.querySelector(".tree-nested").classList.toggle("d-block");
this.classList.toggle("tree-caret-down");
});
getTreeView();
setTreeViewContext();
2021-01-22 22:12:52 +00:00
function setKeyboard(target) {
var handlerName = target.getAttribute('data-handler-name');
if (handlerName == 'null') handlerName = null;
editor.setKeyboardHandler(handlerName);
var nodes = target.parentNode.querySelectorAll("[data-handler-name]");
for (var i = 0; i < nodes.length ; i + + ) {
nodes[i].classList.remove('btn-primary');
nodes[i].classList.add('btn-secondary');
}
target.classList.remove('btn-secondary');
target.classList.add('btn-primary');
}
2021-01-15 12:13:06 +00:00
< / script >
{% end %}