add clone functionality
This commit is contained in:
@@ -42,7 +42,6 @@
|
|||||||
<script src="js/model.js"></script>
|
<script src="js/model.js"></script>
|
||||||
<script src="js/view.js"></script>
|
<script src="js/view.js"></script>
|
||||||
<script src="js/controller.js"></script>
|
<script src="js/controller.js"></script>
|
||||||
<script type="text/javascript" src="http://livejs.com/live.js"></script>
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
@@ -7,18 +7,26 @@ class Controller {
|
|||||||
|
|
||||||
var cloneBtn = document.getElementsByClassName("clone")[0];
|
var cloneBtn = document.getElementsByClassName("clone")[0];
|
||||||
var purgeBtn = document.getElementsByClassName("purge")[0];
|
var purgeBtn = document.getElementsByClassName("purge")[0];
|
||||||
cloneBtn.addEventListener("click", function () {
|
cloneBtn.addEventListener("click", this.cloneRep.bind(this));
|
||||||
console.log("clone");
|
|
||||||
});
|
|
||||||
purgeBtn.addEventListener("click", this.purgeFS.bind(this));
|
purgeBtn.addEventListener("click", this.purgeFS.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
purgeFS() {
|
purgeFS() {
|
||||||
this.model.purgeFS();
|
this.model.purgeFS();
|
||||||
//this.drawDirTree(this.view);
|
//window.location.reload();
|
||||||
this.redrawDirTree(this.view);
|
this.redrawDirTree(this.view);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cloneRep(repurl) {
|
||||||
|
var that = this;
|
||||||
|
this.model.cloneRep().then(
|
||||||
|
function (value) {
|
||||||
|
that.redrawDirTree(that.view);
|
||||||
|
},
|
||||||
|
function (error) {}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
redrawDirTree(view) {
|
redrawDirTree(view) {
|
||||||
this.model.dirTree().then(
|
this.model.dirTree().then(
|
||||||
function (value) {
|
function (value) {
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
import http from "https://unpkg.com/isomorphic-git@beta/http/web/index.js";
|
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());
|
||||||
|
|||||||
17
js/model.js
17
js/model.js
@@ -1,11 +1,13 @@
|
|||||||
class Model {
|
class Model {
|
||||||
constructor() {
|
constructor(http) {
|
||||||
// Initialize isomorphic-git with a file system
|
// Initialize isomorphic-git with a file system
|
||||||
window.fs = new LightningFS("fs");
|
window.fs = new LightningFS("fs");
|
||||||
// I prefer using the Promisified version honestly
|
// I prefer using the Promisified version honestly
|
||||||
window.pfs = window.fs.promises;
|
window.pfs = window.fs.promises;
|
||||||
|
|
||||||
window.dir = "/test-clone";
|
window.dir = "/";
|
||||||
|
|
||||||
|
window.http = http;
|
||||||
}
|
}
|
||||||
|
|
||||||
async dirList(dir = "/") {
|
async dirList(dir = "/") {
|
||||||
@@ -36,7 +38,6 @@ class Model {
|
|||||||
async dirTree(dir = "/") {
|
async dirTree(dir = "/") {
|
||||||
var tree = await this.dirList(dir);
|
var tree = await this.dirList(dir);
|
||||||
|
|
||||||
//console.log(tree);
|
|
||||||
return tree;
|
return tree;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,4 +45,14 @@ class Model {
|
|||||||
delete window.fs;
|
delete window.fs;
|
||||||
window.fs = new LightningFS("fs", { wipe: true });
|
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",
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,8 +31,9 @@ class View {
|
|||||||
|
|
||||||
removeDirTree() {
|
removeDirTree() {
|
||||||
let mainul = document.getElementsByTagName("ul")[0];
|
let mainul = document.getElementsByTagName("ul")[0];
|
||||||
if (mainul !== undefined) {
|
while (mainul.firstChild) {
|
||||||
mainul.firstChild.remove();
|
mainul.lastChild.remove();
|
||||||
}
|
}
|
||||||
|
this.hloubka = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user