From 59c2625cd111b61082e5013955f984a20e3d78f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Z=C3=A1le=C5=A1=C3=A1k?= Date: Sat, 19 Dec 2020 19:53:31 +0100 Subject: [PATCH] Initial commit, vypis adresarove struktury --- README.md | 0 css/style.css | 0 index.php | 23 ++++++++++++++ js/controller.js | 22 ++++++++++++++ js/main.js | 25 +++++++++++++++ js/model.js | 36 ++++++++++++++++++++++ js/view.js | 79 ++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 185 insertions(+) create mode 100644 README.md create mode 100644 css/style.css create mode 100644 index.php create mode 100644 js/controller.js create mode 100644 js/main.js create mode 100644 js/model.js create mode 100644 js/view.js diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/css/style.css b/css/style.css new file mode 100644 index 0000000..e69de29 diff --git a/index.php b/index.php new file mode 100644 index 0000000..a6d0267 --- /dev/null +++ b/index.php @@ -0,0 +1,23 @@ + + + + + + + Správa obsahu webu + + + + + + + + + + + + + + \ No newline at end of file diff --git a/js/controller.js b/js/controller.js new file mode 100644 index 0000000..7e71962 --- /dev/null +++ b/js/controller.js @@ -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) {} + ); + } + +} diff --git a/js/main.js b/js/main.js new file mode 100644 index 0000000..f8619c6 --- /dev/null +++ b/js/main.js @@ -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()); diff --git a/js/model.js b/js/model.js new file mode 100644 index 0000000..8057167 --- /dev/null +++ b/js/model.js @@ -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; + } +} diff --git a/js/view.js b/js/view.js new file mode 100644 index 0000000..f268310 --- /dev/null +++ b/js/view.js @@ -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); + } + } + + + }*/ + } +}