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 @staticmethod
def generate_tree(folder, output=""): def generate_tree(folder, output=""):
for raw_filename in os.listdir(folder): for raw_filename in os.listdir(folder):
print(raw_filename)
filename = html.escape(raw_filename) filename = html.escape(raw_filename)
print(filename)
rel = os.path.join(folder, raw_filename) rel = os.path.join(folder, raw_filename)
if os.path.isdir(rel): if os.path.isdir(rel):
output += \ output += \
"""<li class="tree-item" data-path="{}"> """<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">"""\ \n<ul class="tree-nested">"""\
.format(os.path.join(folder, filename), os.path.join(folder, filename), filename, filename) .format(os.path.join(folder, filename), os.path.join(folder, filename), filename, filename)
output += helper.generate_tree(rel) output += helper.generate_tree(rel)
output += '</ul>\n</li>' output += '</ul>\n</li>'
else: else:
console.debug('os.path.isdir(rel): "{}", rel: "{}"'.format(os.path.isdir(rel), rel))
output += """<li output += """<li
class="tree-item tree-ctx-item tree-file" class="tree-item tree-ctx-item tree-file"
data-path="{}" data-path="{}"
data-name="{}" 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 return output
@staticmethod @staticmethod

View File

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

View File

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