add open file

master
David Zálešák 4 years ago
parent edfc98e08e
commit e9b2231581

@ -20,7 +20,6 @@ ul {
ul:nth-child(1) { ul:nth-child(1) {
padding: 1em 1em; padding: 1em 1em;
position: absolute;
} }
li:hover { li:hover {
@ -66,6 +65,13 @@ li::before {
} }
section { section {
grid-area: section; grid-area: section;
margin: 1em 2em;
}
textarea {
width: 100%;
height: 100%;
resize: none;
} }
aside { aside {
@ -97,6 +103,7 @@ sub {
height: 100%; height: 100%;
justify-items: center; justify-items: center;
align-items: center; align-items: center;
top: 0;
} }
.settingsBtn { .settingsBtn {

@ -20,9 +20,11 @@
<button class="settingsBtn">Settings</button> <button class="settingsBtn">Settings</button>
</nav> </nav>
<aside> <aside>
<ul> <div>
<ul>
</ul> </ul>
</div>
<div class="loading"> <div class="loading">
<img src="img/loading.gif" alt="loading"> <img src="img/loading.gif" alt="loading">
</div> </div>
@ -30,7 +32,7 @@
<section> <section>
lolo <textarea name="" id="" cols="30" rows="10"></textarea>
</section> </section>
<footer> <footer>

@ -43,9 +43,9 @@ class Controller {
this.model.dirTree().then( this.model.dirTree().then(
function (value) { function (value) {
view.removeDirTree(); view.removeDirTree();
view.drawDirTree(value); view.drawDirTree(value, undefined, this);
view.dirTreeToggler(); view.dirTreeToggler();
}, }.bind(this),
function (error) {} function (error) {}
); );
} }
@ -61,4 +61,13 @@ class Controller {
this.view.closeSettings(); this.view.closeSettings();
console.log(repo.value); console.log(repo.value);
} }
loadFile(file) {
this.model.readFile(file).then(
function (value) {
this.view.openFile(value);
}.bind(this),
function (error) {}
);
}
} }

@ -66,4 +66,8 @@ class Model {
setBaseDir(baseDir) { setBaseDir(baseDir) {
localStorage.setItem("baseDir", baseDir); localStorage.setItem("baseDir", baseDir);
} }
readFile(file) {
return pfs.readFile(file, "utf8");
}
} }

@ -1,7 +1,11 @@
class View { class View {
constructor() {} constructor() {}
drawDirTree(dirtree, ulToAdd = document.getElementsByTagName("ul")[0]) { drawDirTree(
dirtree,
ulToAdd = document.getElementsByTagName("ul")[0],
parrentObj
) {
var dirtreeul = document.getElementsByTagName("ul"); var dirtreeul = document.getElementsByTagName("ul");
var tag = document.createElement("li"); var tag = document.createElement("li");
var text = document.createTextNode(dirtree[0]); var text = document.createTextNode(dirtree[0]);
@ -16,17 +20,25 @@ class View {
tag.parentElement.appendChild(newul); tag.parentElement.appendChild(newul);
for (let i = 1; i < dirtree.length; i++) { for (let i = 1; i < dirtree.length; i++) {
if (Array.isArray(dirtree[i])) { if (Array.isArray(dirtree[i])) {
this.drawDirTree(dirtree[i], newul); this.drawDirTree(dirtree[i], newul, parrentObj);
} else { } else {
var tag = document.createElement("li"); var tag = document.createElement("li");
var text = document.createTextNode(dirtree[i]); var text = document.createTextNode(dirtree[i]);
tag.appendChild(text); tag.appendChild(text);
newul.appendChild(tag); newul.appendChild(tag);
var _this = this;
tag.addEventListener("click", function () {
parrentObj.loadFile(dirtree[0] + dirtree[i]);
});
} }
} }
} }
} }
openFile(fileread) {
let textArea = document.getElementsByTagName("textarea")[0];
}
removeDirTree() { removeDirTree() {
let mainul = document.getElementsByTagName("ul")[0]; let mainul = document.getElementsByTagName("ul")[0];
while (mainul.firstChild) { while (mainul.firstChild) {
@ -61,7 +73,7 @@ class View {
let repo = document.getElementById("inputRepository"); let repo = document.getElementById("inputRepository");
let baseDir = document.getElementById("inputBaseDir"); let baseDir = document.getElementById("inputBaseDir");
repo.value = localStorage.getItem("repo") repo.value = localStorage.getItem("repo");
baseDir.value = localStorage.getItem("baseDir"); baseDir.value = localStorage.getItem("baseDir");
} }