Implement traversal of folders

This commit is contained in:
2019-05-22 20:22:59 +05:30
parent 90c950d822
commit e9cd71b770
3 changed files with 76 additions and 51 deletions

View File

@@ -5,7 +5,7 @@ let currDir = {'loc':'','contents':null};
function doUpdate(ele){
console.log(ele.attr('data-choice'));
if(ele.hasClass('file-isDir')){
currDir.loc = currDir.loc+ "/"+ ele.attr('data-choice');
currDir.loc = ele.attr('data-choice');
populateContents();
}
//$()
@@ -13,15 +13,24 @@ function doUpdate(ele){
}
function updateContents(contents){
//console.log(contents)
console.log(contents)
// Change top header contents
$('#files-location').html(currDir.loc)
if(contents===null) $('#files-table').append(`<tr><td>null</td><td class="file-handlers"></td></tr>`)
// if empty, return null, this shouldnt execute if the server is responding properly but ok
if(contents===null) {
$('#files-table').append(`<tr><td>null</td><td class="file-handlers"></td></tr>`)
}
else
{
$('#files-table').empty();
contents.contents.forEach(element => {
$('#files-table').append(`<tr class="files-row"><td onclick="doUpdate($(this))" class="file-name ${(element.type?'file-isDir':'file-isFile')}" data-choice="${element.name}">${element.name}</td><td class="file-handlers"></td></tr>`)
$('#files-table').append(`<tr class="files-row"><td onclick="doUpdate($(this))" class="file-name ${(element.isDir?'file-isDir':'file-isFile')}" data-choice="${element.path}">${element.name}</td><td class="file-handlers"></td></tr>`)
});
if(contents.back!=null){
$('#files-table').prepend(`<tr class="files-row"><td onclick="doUpdate($(this))" class="file-name file-isDir file-isBack" data-choice="${contents.back}">..</td><td class="file-handlers"></td></tr>`)
}
}
}