diff --git a/js/controller.js b/js/controller.js index 343eb1e..56fe687 100644 --- a/js/controller.js +++ b/js/controller.js @@ -52,7 +52,7 @@ class Controller { } redrawDirTree(view) { - this.model.dirTree().then( + this.model.getDirTree().then( function (value) { view.removeDirTree(); view.drawDirTree(value, undefined, this); @@ -87,7 +87,7 @@ class Controller { saveFile() { var textArea = document.getElementsByTagName("textarea")[0]; - this.model.saveFile(this.openedFile, textArea.value) + this.model.saveFile(this.openedFile, textArea.value); this.openedFileValue = textArea.value; this.saveButton() } diff --git a/js/model.js b/js/model.js index cdc58b1..1e1a848 100644 --- a/js/model.js +++ b/js/model.js @@ -25,23 +25,24 @@ class Model { let dirtree = [dir]; for (let i = 0; i < list.length; i++) { - dirtree[i + 1] = list[i]; - let itemStat = await pfs.stat(dirtree[0] + dirtree[i + 1]); + let itemStat = await pfs.stat(dir + list[i]); if (itemStat.isDirectory()) { - dirtree[i + 1] = await this.dirList(dirtree[0] + dirtree[i + 1] + "/"); + dirtree[i + 1] = await this.dirList(dir + list[i] + "/"); + } else { + dirtree[i + 1] = list[i]; } } return dirtree; } - async dirTree() { + async getDirTree() { var baseDir = localStorage.getItem("baseDir"); var stat = await pfs.stat(baseDir).catch((e) => {}); if (stat == null) { - var baseDir = "/"; + var baseDir = dir; } var tree = await this.dirList(baseDir); diff --git a/js/view.js b/js/view.js index a827508..63a0e5f 100644 --- a/js/view.js +++ b/js/view.js @@ -13,27 +13,26 @@ class View { tag.classList.add("caret"); ulToAdd.appendChild(tag); - if (dirtree.length > 1) { - var newul = document.createElement("ul"); - newul.classList.add("nested"); + var newul = document.createElement("ul"); + newul.classList.add("nested"); - tag.parentElement.appendChild(newul); - for (let i = 1; i < dirtree.length; i++) { - if (Array.isArray(dirtree[i])) { - this.drawDirTree(dirtree[i], newul, parrentObj); - } else { - var tag = document.createElement("li"); - var text = document.createTextNode(dirtree[i]); - tag.appendChild(text); - newul.appendChild(tag); - var _this = this; - tag.addEventListener("click", function () { - parrentObj.loadFile(dirtree[0] + dirtree[i]); - }); - } + tag.parentElement.appendChild(newul); + for (let i = 1; i < dirtree.length; i++) { + if (Array.isArray(dirtree[i])) { + this.drawDirTree(dirtree[i], newul, parrentObj); + } else { + var tag = document.createElement("li"); + var text = document.createTextNode(dirtree[i]); + tag.appendChild(text); + newul.appendChild(tag); + var _this = this; + tag.addEventListener("click", function () { + parrentObj.loadFile(dirtree[0] + dirtree[i]); + }); } } } + } openFile(fileread) { let textArea = document.getElementsByTagName("textarea")[0]; @@ -86,7 +85,7 @@ class View { showSaveButton(show) { var saveButton = document.getElementById("saveBtn"); - if(show) { + if (show) { saveButton.disabled = false; } else { saveButton.disabled = true;