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 {
background-color: blue;
background-color: blue;
}
li::before {

@ -11,7 +11,7 @@
</head>
<body>
<div class="container">
<nav>
@ -30,11 +30,11 @@
</section>
<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>
</div>

@ -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,26 +1,32 @@
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);
for (let u = 0; u < list.length; u++) {
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++) {
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()) {
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 = "/") {
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]);
}else{
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();
}
}
}