+
X
+
diff --git a/js/controller.js b/js/controller.js
index e1c8537..7dbde69 100644
--- a/js/controller.js
+++ b/js/controller.js
@@ -4,7 +4,45 @@ class Controller {
this.view = view;
this.redrawDirTree(view);
+ //this.pullRep();
+ this.addListeners();
+ this.init();
+ }
+
+ init() {
+ let repo = localStorage.getItem("repo");
+ let name = localStorage.getItem("name");
+ let email = localStorage.getItem("email");
+
+ if (
+ repo == null ||
+ name == null ||
+ email == null ||
+ repo == "" ||
+ name == "" ||
+ email == ""
+ ) {
+ this.view.openSettings();
+ } else {
+ this.model.getDirTree().then(
+ function (value) {
+ if (value.length == 1) {
+ //Nic nenaklonovaného, klonovat
+ this.cloneRep();
+ } else {
+ //Udělat Pull
+ this.pullRep();
+ }
+ }.bind(this),
+ function (error) {
+ console.log(error);
+ }
+ );
+ }
+ }
+
+ addListeners() {
var cloneBtn = document.getElementsByClassName("clone")[0];
var purgeBtn = document.getElementsByClassName("wipe")[0];
var settingsBtn = document.getElementsByClassName("settingsBtn")[0];
@@ -14,12 +52,18 @@ class Controller {
cloneBtn.addEventListener("click", this.cloneRep.bind(this));
purgeBtn.addEventListener("click", this.wipeFS.bind(this));
- settingsBtn.addEventListener("click", view.openSettings.bind(this));
+ settingsBtn.addEventListener(
+ "click",
+ this.view.openSettings.bind(this.view)
+ );
for (let i = 0; i < settingsClose.length; i++) {
- settingsClose[i].addEventListener("click", view.closeSettings.bind(this));
+ settingsClose[i].addEventListener(
+ "click",
+ this.view.closeSettings.bind(this)
+ );
}
settingsSubmit.addEventListener("click", this.saveSettings.bind(this));
- view.simplemde.codemirror.on("change", this.saveButton.bind(this));
+ this.view.simplemde.codemirror.on("change", this.saveButton.bind(this));
saveBtn.addEventListener("click", this.saveFile.bind(this));
}
@@ -35,7 +79,7 @@ class Controller {
this.redrawDirTree(this.view);
}
- cloneRep(repurl) {
+ cloneRep() {
var loading = document.getElementsByClassName("loading")[0];
loading.style.display = "grid";
this.model.cloneRep().then(
@@ -43,7 +87,23 @@ class Controller {
loading.style.removeProperty("display");
this.redrawDirTree(this.view);
}.bind(this),
- function (error) {}
+ function (error) {
+ console.log(error);
+ }
+ );
+ }
+
+ pullRep() {
+ var loading = document.getElementsByClassName("loading")[0];
+ loading.style.display = "grid";
+ this.model.pullRep().then(
+ function (value) {
+ loading.style.removeProperty("display");
+ this.redrawDirTree(this.view);
+ }.bind(this),
+ function (error) {
+ console.log(error);
+ }
);
}
@@ -55,7 +115,9 @@ class Controller {
view.dirTreeToggler();
this.updateFileStats();
}.bind(this),
- function (error) {}
+ function (error) {
+ console.log(error);
+ }
);
}
@@ -63,7 +125,6 @@ class Controller {
this.model.getGitStatusTree().then(
function (value) {
this.view.statDirTree(value, undefined);
- console.log(value);
}.bind(this),
function (error) {
console.log(error);
@@ -74,13 +135,28 @@ class Controller {
saveSettings() {
let repo = document.getElementById("inputRepository");
let baseDir = document.getElementById("inputBaseDir");
+ let name = document.getElementById("inputName");
+ let email = document.getElementById("inputEmail");
+ let oldRepoURL = localStorage.getItem("repo");
this.model.setRepo(repo.value);
this.model.setBaseDir(baseDir.value);
+ this.model.setName(name.value);
+ this.model.setEmail(email.value);
- this.redrawDirTree(this.view);
+ if (repo.value == "" || name.value == "" || email.value == "") {
+ this.view.openSettings();
+ return;
+ }
+
+ if (repo.value != oldRepoURL) {
+ // udělej clone
+ this.cloneRep();
+ } else {
+ // udelej jenom pull
+ this.pullRep();
+ }
this.view.closeSettings();
- console.log(repo.value);
}
loadFile(file) {
@@ -90,7 +166,9 @@ class Controller {
this.openedFileValue = value;
this.view.openFile(value);
}.bind(this),
- function (error) {}
+ function (error) {
+ console.log(error);
+ }
);
}
diff --git a/js/model.js b/js/model.js
index 59fb264..674396e 100644
--- a/js/model.js
+++ b/js/model.js
@@ -90,6 +90,19 @@ class Model {
});
}
+ async pullRep() {
+ await git.pull({
+ fs,
+ http,
+ dir,
+ fastForwardOnly: true,
+ author: {
+ name: localStorage.getItem("name"),
+ email: localStorage.getItem("email"),
+ },
+ });
+ }
+
setRepo(repoURL) {
localStorage.setItem("repo", repoURL);
}
@@ -100,6 +113,13 @@ class Model {
}
localStorage.setItem("baseDir", baseDir);
}
+ async setName(name) {
+ localStorage.setItem("name", name);
+ }
+
+ async setEmail(email) {
+ localStorage.setItem("email", email);
+ }
readFile(file) {
return pfs.readFile(file, "utf8");
diff --git a/js/view.js b/js/view.js
index 8395d19..ef86425 100644
--- a/js/view.js
+++ b/js/view.js
@@ -50,7 +50,7 @@ class View {
this.statDirTree(dirtree[i], li[skip + 1]);
skip += 2;
} else {
- if (dirtree[i] == "*modified") {
+ if (dirtree[i] != "unmodified") {
li[skip].style.backgroundColor = "red";
} else {
li[skip].style.removeProperty("background-color");
@@ -68,6 +68,11 @@ class View {
this.simplemde.value(fileread);
}
+ closeEditor() {
+ var editText = document.getElementById("editText");
+ editText.style.removeProperty("display");
+ }
+
removeDirTree() {
let mainul = document.getElementsByTagName("ul")[0];
while (mainul.firstChild) {
@@ -96,14 +101,20 @@ class View {
}
openSettings() {
+ this.closeEditor();
+
var settings = document.getElementsByClassName("settingsbg")[0];
settings.style.display = "grid";
let repo = document.getElementById("inputRepository");
let baseDir = document.getElementById("inputBaseDir");
+ let name = document.getElementById("inputName");
+ let email = document.getElementById("inputEmail");
repo.value = localStorage.getItem("repo");
baseDir.value = localStorage.getItem("baseDir");
+ name.value = localStorage.getItem("name");
+ email.value = localStorage.getItem("email");
}
closeSettings() {