Initial commit, vypis adresarove struktury
commit
59c2625cd1
@ -0,0 +1,23 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Správa obsahu webu</title>
|
||||
<link rel="stylesheet" href="css/style.css">
|
||||
<script src="https://unpkg.com/@isomorphic-git/lightning-fs"></script>
|
||||
<script src="https://unpkg.com/isomorphic-git@beta"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<ul id="dirtree-0">
|
||||
|
||||
</ul>
|
||||
<script src="js/main.js" type="module"></script>
|
||||
<script src="js/model.js"></script>
|
||||
<script src="js/view.js"></script>
|
||||
<script src="js/controller.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
@ -0,0 +1,22 @@
|
||||
class Controller {
|
||||
constructor(model, view) {
|
||||
this.model = model;
|
||||
this.view = 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;
|
||||
|
||||
window.dir = "/test-clone";
|
||||
|
||||
this.model.dirTree().then(
|
||||
function (value) {
|
||||
view.showDirTree(value);
|
||||
},
|
||||
function (error) {}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
import http from "https://unpkg.com/isomorphic-git@beta/http/web/index.js";
|
||||
|
||||
/*
|
||||
async function fsListDir(){
|
||||
|
||||
let dirlist = await pfs.readdir("/test-clone");
|
||||
|
||||
document.getElementsByTagName("body")[0].innerHTML = dirlist;
|
||||
}
|
||||
|
||||
async function gitStatus(){
|
||||
document.getElementsByTagName("body")[0].innerHTML = await git.status({
|
||||
fs,
|
||||
dir,
|
||||
filepath: "karma.conf.js",
|
||||
});
|
||||
}
|
||||
|
||||
fsListDir()
|
||||
|
||||
gitStatus();
|
||||
|
||||
*/
|
||||
|
||||
const app = new Controller(new Model(), new View());
|
@ -0,0 +1,36 @@
|
||||
class Model {
|
||||
constructor() {}
|
||||
|
||||
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--
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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]);
|
||||
if (itemStat.isDirectory()) {
|
||||
dirtree[i+1] = await this.dirList(dirtree[0] + dirtree[i+1] + "/");
|
||||
}
|
||||
}
|
||||
|
||||
return dirtree;
|
||||
}
|
||||
|
||||
async dirTree(dir = "/") {
|
||||
var tree = await this.dirList(dir);
|
||||
|
||||
console.log(tree);
|
||||
return tree;
|
||||
}
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
class View {
|
||||
constructor() {
|
||||
document.body.style.backgroundColor = "olive";
|
||||
}
|
||||
|
||||
hloubka = 1;
|
||||
|
||||
showfiles(dir) {
|
||||
console.log(dir)
|
||||
}
|
||||
|
||||
showDirTree(dirtree) {
|
||||
var dirtreeul = document.getElementsByTagName("ul");
|
||||
var tag = document.createElement("li");
|
||||
var text = document.createTextNode(dirtree[0]);
|
||||
tag.appendChild(text);
|
||||
tag.style.fontWeight = "bold";
|
||||
|
||||
dirtreeul[dirtreeul.length - this.hloubka].appendChild(tag);
|
||||
if (dirtree.length > 1) {
|
||||
var newul = document.createElement("ul");
|
||||
|
||||
tag.parentElement.append(newul);
|
||||
for (let i = 1; i < dirtree.length; i++) {
|
||||
if (Array.isArray(dirtree[i])) {
|
||||
this.showDirTree(dirtree[i]);
|
||||
|
||||
}else{
|
||||
var tag = document.createElement("li");
|
||||
var text = document.createTextNode(dirtree[i]);
|
||||
tag.appendChild(text)
|
||||
newul.appendChild(tag)
|
||||
}
|
||||
}
|
||||
this.hloubka++;
|
||||
}
|
||||
|
||||
/*if(dirtree.length > 1) {
|
||||
var tag = document.createElement("li");
|
||||
var text = document.createTextNode(dirtree[0]);
|
||||
tag.appendChild(text);
|
||||
tag.style.fontWeight = "bold"
|
||||
mainul.appendChild(tag);
|
||||
var newul = document.createElement("ul");
|
||||
tag.parentElement.append(newul);
|
||||
for (let i = 1; i < dirtree.length; i++) {
|
||||
var tag = document.createElement("li");
|
||||
var text = document.createTextNode(dirtree[i]);
|
||||
tag.appendChild(text);
|
||||
newul.appendChild(tag);
|
||||
}
|
||||
}else{
|
||||
var tag = document.createElement("li");
|
||||
var text = document.createTextNode(dirtree[0]);
|
||||
tag.appendChild(text);
|
||||
mainul.appendChild(tag);
|
||||
}*/
|
||||
|
||||
/*for (let i = 1; i < dirtree.length; i++) {
|
||||
var tag = document.createElement("li");
|
||||
var text = document.createTextNode(dirtree[i][0]);
|
||||
tag.appendChild(text);
|
||||
mainul.appendChild(tag);
|
||||
if(dirtree[i].length > 1) {
|
||||
//this.showDir(dirtree[i])
|
||||
var newul = document.createElement("ul")
|
||||
tag.parentElement.append(newul)
|
||||
for (let i = 1; i < dirtree.length; i++) {
|
||||
var tag = document.createElement("li");
|
||||
var text = document.createTextNode(dirtree[i]);
|
||||
tag.appendChild(text);
|
||||
newul.appendChild(tag);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}*/
|
||||
}
|
||||
}
|
Reference in New Issue