add wipe fs

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

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

@ -1,5 +1,12 @@
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 = "/") {
let list = await pfs.readdir(dir);
@ -8,12 +15,11 @@ class Model {
let re = /^\..*$/;
if (re.test(list[u])) {
list.splice(u, 1)
u--
list.splice(u, 1);
u--;
}
}
let dirtree = [dir];
for (let i = 0; i < list.length; i++) {
@ -30,7 +36,12 @@ class Model {
async dirTree(dir = "/") {
var tree = await this.dirList(dir);
console.log(tree);
//console.log(tree);
return tree;
}
purgeFS() {
delete window.fs;
window.fs = new LightningFS("fs", { wipe: true });
}
}

@ -1,10 +1,9 @@
class View {
constructor() {
}
constructor() {}
hloubka = 1;
showDirTree(dirtree) {
drawDirTree(dirtree) {
var dirtreeul = document.getElementsByTagName("ul");
var tag = document.createElement("li");
var text = document.createTextNode(dirtree[0]);
@ -18,16 +17,22 @@ class View {
tag.parentElement.append(newul);
for (let i = 1; i < dirtree.length; i++) {
if (Array.isArray(dirtree[i])) {
this.showDirTree(dirtree[i]);
this.drawDirTree(dirtree[i]);
} else {
var tag = document.createElement("li");
var text = document.createTextNode(dirtree[i]);
tag.appendChild(text)
newul.appendChild(tag)
tag.appendChild(text);
newul.appendChild(tag);
}
}
this.hloubka++;
}
}
removeDirTree() {
let mainul = document.getElementsByTagName("ul")[0];
if (mainul !== undefined) {
mainul.firstChild.remove();
}
}
}