From 77352b3c1040ae17d1835136e78cddbbff77bbf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Z=C3=A1le=C5=A1=C3=A1k?= Date: Sun, 20 Dec 2020 16:03:47 +0100 Subject: [PATCH] add clone functionality --- index.php | 1 - js/controller.js | 16 ++++++++++++---- js/main.js | 2 +- js/model.js | 17 ++++++++++++++--- js/view.js | 5 +++-- 5 files changed, 30 insertions(+), 11 deletions(-) diff --git a/index.php b/index.php index bc5569b..3420692 100644 --- a/index.php +++ b/index.php @@ -42,7 +42,6 @@ - \ No newline at end of file diff --git a/js/controller.js b/js/controller.js index 2fc0133..5d193da 100644 --- a/js/controller.js +++ b/js/controller.js @@ -7,18 +7,26 @@ class Controller { var cloneBtn = document.getElementsByClassName("clone")[0]; var purgeBtn = document.getElementsByClassName("purge")[0]; - cloneBtn.addEventListener("click", function () { - console.log("clone"); - }); + cloneBtn.addEventListener("click", this.cloneRep.bind(this)); purgeBtn.addEventListener("click", this.purgeFS.bind(this)); } purgeFS() { this.model.purgeFS(); - //this.drawDirTree(this.view); + //window.location.reload(); this.redrawDirTree(this.view); } + cloneRep(repurl) { + var that = this; + this.model.cloneRep().then( + function (value) { + that.redrawDirTree(that.view); + }, + function (error) {} + ); + } + redrawDirTree(view) { this.model.dirTree().then( function (value) { diff --git a/js/main.js b/js/main.js index e42cecc..b215c12 100644 --- a/js/main.js +++ b/js/main.js @@ -1,3 +1,3 @@ import http from "https://unpkg.com/isomorphic-git@beta/http/web/index.js"; -const app = new Controller(new Model(), new View()); +const app = new Controller(new Model(http), new View()); diff --git a/js/model.js b/js/model.js index eebe089..5a6f2d9 100644 --- a/js/model.js +++ b/js/model.js @@ -1,11 +1,13 @@ class Model { - constructor() { + constructor(http) { // 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"; + window.dir = "/"; + + window.http = http; } async dirList(dir = "/") { @@ -36,7 +38,6 @@ class Model { async dirTree(dir = "/") { var tree = await this.dirList(dir); - //console.log(tree); return tree; } @@ -44,4 +45,14 @@ class Model { delete window.fs; window.fs = new LightningFS("fs", { wipe: true }); } + + async cloneRep() { + await git.clone({ + fs, + http, + dir, + url: "https://git.microlab.space/microlab/website.git", + corsProxy: "https://cors.isomorphic-git.org", + }); + } } diff --git a/js/view.js b/js/view.js index 167ac06..efcd778 100644 --- a/js/view.js +++ b/js/view.js @@ -31,8 +31,9 @@ class View { removeDirTree() { let mainul = document.getElementsByTagName("ul")[0]; - if (mainul !== undefined) { - mainul.firstChild.remove(); + while (mainul.firstChild) { + mainul.lastChild.remove(); } + this.hloubka = 1; } }