Merge branch 'file_manager_polishing' into 'dev'

File manager polishing

See merge request crafty-controller/crafty-commander!22
This commit is contained in:
Phillip Tarrant 2021-02-21 17:14:43 +00:00
commit 96dbaf3583
3 changed files with 87 additions and 52 deletions

View File

@ -490,26 +490,27 @@ class Helpers:
@staticmethod
def generate_tree(folder, output=""):
for raw_filename in os.listdir(folder):
print(raw_filename)
filename = html.escape(raw_filename)
print(filename)
rel = os.path.join(folder, raw_filename)
if os.path.isdir(rel):
output += \
"""<li class="tree-item" data-path="{}">
\n<div data-path="{}" data-name="{}" class="tree-caret tree-ctx-item tree-folder">{}</div>
\n<div data-path="{}" data-name="{}" class="tree-caret tree-ctx-item tree-folder">
<i class="far fa-folder"></i>
<i class="far fa-folder-open"></i>
{}
</div>
\n<ul class="tree-nested">"""\
.format(os.path.join(folder, filename), os.path.join(folder, filename), filename, filename)
output += helper.generate_tree(rel)
output += '</ul>\n</li>'
else:
console.debug('os.path.isdir(rel): "{}", rel: "{}"'.format(os.path.isdir(rel), rel))
output += """<li
class="tree-item tree-ctx-item tree-file"
data-path="{}"
data-name="{}"
onclick="clickOnFile(event)">{}</li>""".format(os.path.join(folder, filename), filename, filename)
onclick="clickOnFile(event)"><span style="margin-right: 6px;"><i class="far fa-file"></i></span>{}</li>""".format(os.path.join(folder, filename), filename, filename)
return output
@staticmethod

View File

@ -57,7 +57,7 @@ class AjaxHandler(BaseHandler):
self.redirect("/panel/error?error=Server ID Not Found")
if server_data['log_path']:
logger.warning("Server ID not found in server_log ajax call")
logger.warning("Server ID not found in server_log ajax call ({})".format(server_id))
if full_log:
log_lines = helper.get_setting('max_log_lines')
@ -94,21 +94,20 @@ class AjaxHandler(BaseHandler):
# does this server id exist?
if not db_helper.server_id_exists(server_id):
logger.warning("Server ID not found in get_file ajax call")
console.warning("Server ID not found in get_file ajax call")
logger.warning("Server ID not found in get_file ajax call ({})".format(server_id))
console.warning("Server ID not found in get_file ajax call ({})".format(server_id))
return False
if not helper.in_path(db_helper.get_server_data_by_id(server_id)['path'], file_path)\
or not helper.check_file_exists(os.path.abspath(file_path)):
logger.warning("Invalid path in get_file ajax call")
console.warning("Invalid path in get_file ajax call")
logger.warning("Invalid path in get_file ajax call ({})".format(file_path))
console.warning("Invalid path in get_file ajax call ({})".format(file_path))
return False
file = open(file_path)
file_contents = file.read()
file.close()
console.debug("Send file contents")
self.write(file_contents)
self.finish()
@ -124,8 +123,8 @@ class AjaxHandler(BaseHandler):
# does this server id exist?
if not db_helper.server_id_exists(server_id):
logger.warning("Server ID not found in get_file ajax call")
console.warning("Server ID not found in get_file ajax call")
logger.warning("Server ID not found in get_file ajax call ({})".format(server_id))
console.warning("Server ID not found in get_file ajax call ({})".format(server_id))
return False
self.write(db_helper.get_server_data_by_id(server_id)['path'] + '\n' +
@ -172,14 +171,14 @@ class AjaxHandler(BaseHandler):
# does this server id exist?
if not db_helper.server_id_exists(server_id):
logger.warning("Server ID not found in create_file ajax call")
console.warning("Server ID not found in create_file ajax call")
logger.warning("Server ID not found in create_file ajax call ({})".format(server_id))
console.warning("Server ID not found in create_file ajax call ({})".format(server_id))
return False
if not helper.in_path(db_helper.get_server_data_by_id(server_id)['path'], file_path) \
or helper.check_file_exists(os.path.abspath(file_path)):
logger.warning("Invalid path in create_file ajax call")
console.warning("Invalid path in create_file ajax call")
logger.warning("Invalid path in create_file ajax call ({})".format(file_path))
console.warning("Invalid path in create_file ajax call ({})".format(file_path))
return False
# Create the file by opening it
@ -202,14 +201,14 @@ class AjaxHandler(BaseHandler):
# does this server id exist?
if not db_helper.server_id_exists(server_id):
logger.warning("Server ID not found in create_dir ajax call")
console.warning("Server ID not found in create_dir ajax call")
logger.warning("Server ID not found in create_dir ajax call ({})".format(server_id))
console.warning("Server ID not found in create_dir ajax call ({})".format(server_id))
return False
if not helper.in_path(db_helper.get_server_data_by_id(server_id)['path'], dir_path) \
or helper.check_path_exists(os.path.abspath(dir_path)):
logger.warning("Invalid path in create_dir ajax call")
console.warning("Invalid path in create_dir ajax call")
logger.warning("Invalid path in create_dir ajax call ({})".format(dir_path))
console.warning("Invalid path in create_dir ajax call ({})".format(dir_path))
return False
# Create the directory
@ -231,14 +230,14 @@ class AjaxHandler(BaseHandler):
# does this server id exist?
if not db_helper.server_id_exists(server_id):
logger.warning("Server ID not found in del_file ajax call")
console.warning("Server ID not found in del_file ajax call")
logger.warning("Server ID not found in del_file ajax call ({})".format(server_id))
console.warning("Server ID not found in del_file ajax call ({})".format(server_id))
return False
if not helper.in_path(db_helper.get_server_data_by_id(server_id)['path'], file_path) \
or not helper.check_file_exists(os.path.abspath(file_path)):
logger.warning("Invalid path in del_file ajax call")
console.warning("Invalid path in del_file ajax call")
logger.warning("Invalid path in del_file ajax call ({})".format(file_path))
console.warning("Invalid path in del_file ajax call ({})".format(file_path))
return False
# Delete the file
@ -258,14 +257,14 @@ class AjaxHandler(BaseHandler):
# does this server id exist?
if not db_helper.server_id_exists(server_id):
logger.warning("Server ID not found in del_file ajax call")
console.warning("Server ID not found in del_file ajax call")
logger.warning("Server ID not found in del_file ajax call ({})".format(server_id))
console.warning("Server ID not found in del_file ajax call ({})".format(server_id))
return False
if not helper.in_path(db_helper.get_server_data_by_id(server_id)['path'], dir_path) \
or not helper.check_path_exists(os.path.abspath(dir_path)):
logger.warning("Invalid path in del_file ajax call")
console.warning("Invalid path in del_file ajax call")
logger.warning("Invalid path in del_file ajax call ({})".format(dir_path))
console.warning("Invalid path in del_file ajax call ({})".format(dir_path))
return False
# Delete the file
@ -291,14 +290,14 @@ class AjaxHandler(BaseHandler):
# does this server id exist?
if not db_helper.server_id_exists(server_id):
logger.warning("Server ID not found in save_file ajax call")
console.warning("Server ID not found in save_file ajax call")
logger.warning("Server ID not found in save_file ajax call ({})".format(server_id))
console.warning("Server ID not found in save_file ajax call ({})".format(server_id))
return False
if not helper.in_path(db_helper.get_server_data_by_id(server_id)['path'], file_path)\
or not helper.check_file_exists(os.path.abspath(file_path)):
logger.warning("Invalid path in save_file ajax call")
console.warning("Invalid path in save_file ajax call")
logger.warning("Invalid path in save_file ajax call ({})".format(file_path))
console.warning("Invalid path in save_file ajax call ({})".format(file_path))
return False
# Open the file in write mode and store the content in file_object
@ -312,35 +311,35 @@ class AjaxHandler(BaseHandler):
print(server_id)
if server_id is None:
logger.warning("Server ID not found in rename_item ajax call")
console.warning("Server ID not found in rename_item ajax call")
logger.warning("Server ID not found in rename_item ajax call ({})".format(server_id))
console.warning("Server ID not found in rename_item ajax call ({})".format(server_id))
return False
else:
server_id = bleach.clean(server_id)
# does this server id exist?
if not db_helper.server_id_exists(server_id):
logger.warning("Server ID not found in rename_item ajax call (1)")
console.warning("Server ID not found in rename_item ajax call (1)")
logger.warning("Server ID not found in rename_item ajax call ({})".format(server_id))
console.warning("Server ID not found in rename_item ajax call ({})".format(server_id))
return False
if item_path is None or new_item_name is None:
logger.warning("Invalid path in rename_item ajax call (2)")
console.warning("Invalid path in rename_item ajax call (2)")
logger.warning("Invalid path in rename_item ajax call")
console.warning("Invalid path in rename_item ajax call")
return False
if not helper.in_path(db_helper.get_server_data_by_id(server_id)['path'], item_path) \
or not helper.check_path_exists(os.path.abspath(item_path)):
logger.warning("Invalid path in rename_item ajax call (3)")
console.warning("Invalid path in rename_item ajax call (3)")
logger.warning("Invalid path in rename_item ajax call ({})".format(server_id))
console.warning("Invalid path in rename_item ajax call ({})".format(server_id))
return False
new_item_path = os.path.join(os.path.split(item_path)[0], new_item_name)
if not helper.in_path(db_helper.get_server_data_by_id(server_id)['path'], new_item_path) \
or helper.check_path_exists(os.path.abspath(new_item_path)):
logger.warning("Invalid path 2 in rename_item ajax call")
console.warning("Invalid path 2 in rename_item ajax call")
logger.warning("Invalid path 2 in rename_item ajax call ({})".format(server_id))
console.warning("Invalid path 2 in rename_item ajax call ({})".format(server_id))
return False
# RENAME

View File

@ -140,7 +140,11 @@
</style>
<ul class="tree-view">
<li>
<div class="tree-caret tree-ctx-item files-tree-title">Files</div>
<div class="tree-caret tree-ctx-item files-tree-title">
<i class="far fa-folder"></i>
<i class="far fa-folder-open"></i>
Files
</div>
<ul class="tree-nested" id="files-tree">
<li>Error while getting files</li>
@ -150,10 +154,12 @@
</div>
<style>
/* Remove default bullets */
.tree-view {
.tree-view,
.tree-nested {
list-style-type: none;
margin: 0;
padding: 0;
margin-left: 10px;
}
/* Style the caret/arrow */
@ -163,16 +169,19 @@
}
/* Create the caret/arrow with a unicode, and style it */
.tree-caret::before {
content: "\25B6";
color: white;
.tree-caret .fa-folder {
display: inline-block;
margin-right: 6px;
}
.tree-caret .fa-folder-open {
display: none;
}
/* Rotate the caret/arrow icon when clicked on (using JavaScript) */
.tree-caret-down::before {
transform: rotate(90deg);
.tree-caret-down .fa-folder {
display: none;
}
.tree-caret-down .fa-folder-open {
display: inline-block;
}
/* Hide the nested list */
@ -182,7 +191,13 @@
</style>
<div class="col-md-6 col-sm-12">
Editing file <span id="editingFile"></span>
<div id="editor">file_contents</div>
<div id="editor" style="resize: both;">file_contents</div>
<div class="btn-group" role="group">
<button onclick="setKeyboard(event.target)" class="btn btn-primary" data-handler-name="null">Default</button>
<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>
<h3 id="file_warn"></h3>
<button class="btn btn-success" onclick="save()">Save</button>
</div>
@ -217,6 +232,11 @@
editor.setTheme('ace/theme/dracula');
editor.session.setUseSoftTabs(true);
// mouseup = css resize end
document.addEventListener("mouseup", function(e){
editor.resize();
});
let extensionChanges = [
{
regex: /^js$/,
@ -652,6 +672,21 @@
getTreeView();
setTreeViewContext();
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');
}
</script>
{% end %}