add wipe fs

master
David Zálešák 4 years ago
parent 2e91df6260
commit 62cb680181

@ -23,7 +23,7 @@ ul:nth-child(1) {
} }
li:hover { li:hover {
background-color: blue; background-color: blue;
} }
li::before { li::before {

@ -11,7 +11,7 @@
</head> </head>
<body> <body>
<div class="container"> <div class="container">
<nav> <nav>
@ -30,11 +30,11 @@
</section> </section>
<footer> <footer>
CoMato © 2020 David Zálešák <br><sub>Seminární práce do předmětu tvorba www aplikací</sub> CoMato © 2020 David Zálešák <br><sub>Seminární práce do předmětu tvorba www aplikací</sub>
</footer> </footer>
</div> </div>

@ -3,20 +3,29 @@ class Controller {
this.model = model; this.model = model;
this.view = view; this.view = view;
this.redrawDirTree(view);
// Initialize isomorphic-git with a file system var cloneBtn = document.getElementsByClassName("clone")[0];
window.fs = new LightningFS("fs"); var purgeBtn = document.getElementsByClassName("purge")[0];
// I prefer using the Promisified version honestly cloneBtn.addEventListener("click", function () {
window.pfs = window.fs.promises; console.log("clone");
});
purgeBtn.addEventListener("click", this.purgeFS.bind(this));
}
window.dir = "/test-clone"; purgeFS() {
this.model.purgeFS();
//this.drawDirTree(this.view);
this.redrawDirTree(this.view);
}
redrawDirTree(view) {
this.model.dirTree().then( this.model.dirTree().then(
function (value) { function (value) {
view.showDirTree(value); view.removeDirTree();
view.drawDirTree(value);
}, },
function (error) {} function (error) {}
); );
} }
} }

@ -1,26 +1,32 @@
class Model { class Model {
constructor() {} constructor() {
// Initialize isomorphic-git with a file system
window.fs = new LightningFS("fs");
// I prefer using the Promisified version honestly
window.pfs = window.fs.promises;
window.dir = "/test-clone";
}
async dirList(dir = "/") { async dirList(dir = "/") {
let list = await pfs.readdir(dir); let list = await pfs.readdir(dir);
for (let u = 0; u < list.length; u++) { for (let u = 0; u < list.length; u++) {
let re = /^\..*$/; let re = /^\..*$/;
if (re.test(list[u])) { if (re.test(list[u])) {
list.splice(u, 1) list.splice(u, 1);
u-- u--;
} }
} }
let dirtree = [dir]; let dirtree = [dir];
for (let i = 0; i < list.length; i++) { for (let i = 0; i < list.length; i++) {
dirtree[i + 1] = list[i]; dirtree[i + 1] = list[i];
let itemStat = await pfs.stat(dirtree[0] + dirtree[i+1]); let itemStat = await pfs.stat(dirtree[0] + dirtree[i + 1]);
if (itemStat.isDirectory()) { if (itemStat.isDirectory()) {
dirtree[i+1] = await this.dirList(dirtree[0] + dirtree[i+1] + "/"); dirtree[i + 1] = await this.dirList(dirtree[0] + dirtree[i + 1] + "/");
} }
} }
@ -30,7 +36,12 @@ class Model {
async dirTree(dir = "/") { async dirTree(dir = "/") {
var tree = await this.dirList(dir); var tree = await this.dirList(dir);
console.log(tree); //console.log(tree);
return tree; return tree;
} }
purgeFS() {
delete window.fs;
window.fs = new LightningFS("fs", { wipe: true });
}
} }

@ -1,10 +1,9 @@
class View { class View {
constructor() { constructor() {}
}
hloubka = 1; hloubka = 1;
showDirTree(dirtree) { drawDirTree(dirtree) {
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]);
@ -18,16 +17,22 @@ class View {
tag.parentElement.append(newul); tag.parentElement.append(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.showDirTree(dirtree[i]); this.drawDirTree(dirtree[i]);
} 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);
} }
} }
this.hloubka++; this.hloubka++;
} }
} }
removeDirTree() {
let mainul = document.getElementsByTagName("ul")[0];
if (mainul !== undefined) {
mainul.firstChild.remove();
}
}
} }