ulozeni dirtree do promene
This commit is contained in:
171
js/controller.js
171
js/controller.js
@@ -3,8 +3,12 @@ class Controller {
|
||||
this.model = model;
|
||||
this.view = view;
|
||||
|
||||
this.addListeners();
|
||||
this.init();
|
||||
model.getDirTree().then(
|
||||
function () {
|
||||
this.addListeners();
|
||||
this.init();
|
||||
}.bind(this)
|
||||
);
|
||||
}
|
||||
|
||||
init() {
|
||||
@@ -22,23 +26,16 @@ class Controller {
|
||||
) {
|
||||
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);
|
||||
}
|
||||
);
|
||||
if (this.model.dirTree.length == 1) {
|
||||
//Nic nenaklonovaného, klonovat
|
||||
this.cloneRep();
|
||||
} else {
|
||||
//Udělat Pull
|
||||
this.pullRep();
|
||||
}
|
||||
}
|
||||
|
||||
if (localStorage.getItem("pushError") != "false") {
|
||||
if (localStorage.getItem("pushError") == "true") {
|
||||
this.view.openPublish();
|
||||
this.view.errorPublish("Máte nepublikované změny: publikujte je.");
|
||||
}
|
||||
@@ -69,24 +66,17 @@ class Controller {
|
||||
settingsSubmit.addEventListener("click", this.saveSettings.bind(this));
|
||||
this.view.simplemde.codemirror.on("change", this.saveButton.bind(this));
|
||||
saveBtn.addEventListener("click", this.saveFile.bind(this));
|
||||
publishBtn.addEventListener("click", this.view.openPublish.bind(this.view));
|
||||
publishBtn.addEventListener("click", this.openPublish.bind(this));
|
||||
commitSubmit.addEventListener("click", this.publish.bind(this));
|
||||
}
|
||||
|
||||
/* ================== Dir Tree ================== */
|
||||
|
||||
redrawDirTree(view) {
|
||||
this.model.getDirTree().then(
|
||||
function (value) {
|
||||
view.removeDirTree();
|
||||
view.drawDirTree(value, undefined, this);
|
||||
view.dirTreeToggler();
|
||||
this.updateFileStats();
|
||||
}.bind(this),
|
||||
function (error) {
|
||||
console.log(error);
|
||||
}
|
||||
);
|
||||
redrawDirTree() {
|
||||
this.view.removeDirTree();
|
||||
this.view.drawDirTree(this.model.dirTree, undefined, this);
|
||||
this.view.dirTreeToggler();
|
||||
this.updateFileStats();
|
||||
}
|
||||
|
||||
updateFileStats() {
|
||||
@@ -133,9 +123,9 @@ class Controller {
|
||||
/* ================== Controls ================== */
|
||||
|
||||
wipeFS() {
|
||||
this.model.wipeFS();
|
||||
//window.location.reload();
|
||||
this.redrawDirTree(this.view);
|
||||
this.model.wipeFS().then(function () {
|
||||
this.redrawDirTree();
|
||||
}.bind(this));
|
||||
}
|
||||
|
||||
cloneRep() {
|
||||
@@ -143,8 +133,10 @@ class Controller {
|
||||
loading.style.display = "grid";
|
||||
this.model.cloneRep().then(
|
||||
function (value) {
|
||||
this.redrawDirTree();
|
||||
loading.style.removeProperty("display");
|
||||
this.redrawDirTree(this.view);
|
||||
localStorage.setItem("pushError", "false");
|
||||
this.view.errorPublish();
|
||||
}.bind(this),
|
||||
function (error) {
|
||||
console.log(error);
|
||||
@@ -158,7 +150,7 @@ class Controller {
|
||||
this.model.pullRep().then(
|
||||
function (value) {
|
||||
loading.style.removeProperty("display");
|
||||
this.redrawDirTree(this.view);
|
||||
this.redrawDirTree();
|
||||
}.bind(this),
|
||||
function (error) {
|
||||
// zatim to teda znovu naclonuj
|
||||
@@ -168,6 +160,31 @@ class Controller {
|
||||
);
|
||||
}
|
||||
|
||||
gitPush(gitUser, gitPass) {
|
||||
let loading = document.getElementsByClassName("publishLoading")[0];
|
||||
|
||||
this.model.gitPush(gitUser, gitPass).then(
|
||||
function (value) {
|
||||
localStorage.setItem("pushError", "false");
|
||||
this.view.closeDialog();
|
||||
this.view.errorPublish();
|
||||
loading.style.removeProperty("display");
|
||||
}.bind(this),
|
||||
function (error) {
|
||||
console.log(error);
|
||||
if (error == "HttpError: HTTP Error: 401 Unauthorized") {
|
||||
this.view.errorPublish("Změny nebyly publikovány: Chyba přihlášení.");
|
||||
} else if (error == "HttpError: HTTP Error: 403 Forbidden") {
|
||||
this.view.errorPublish(
|
||||
"Změny nebyly publikovány: Nemáte práva publikovat do tohoto repozitáře."
|
||||
);
|
||||
}
|
||||
localStorage.setItem("pushError", "true");
|
||||
loading.style.removeProperty("display");
|
||||
}.bind(this)
|
||||
);
|
||||
}
|
||||
|
||||
/* ================== Windows ================== */
|
||||
/* ------------------ Settings ------------------ */
|
||||
|
||||
@@ -179,7 +196,11 @@ class Controller {
|
||||
|
||||
let oldRepoURL = localStorage.getItem("repo");
|
||||
this.model.setRepo(repo.value);
|
||||
this.model.setBaseDir(baseDir.value);
|
||||
this.model.setBaseDir(baseDir.value).then(
|
||||
function() {
|
||||
this.redrawDirTree();
|
||||
}.bind(this)
|
||||
);
|
||||
this.model.setName(name.value);
|
||||
this.model.setEmail(email.value);
|
||||
|
||||
@@ -191,8 +212,6 @@ class Controller {
|
||||
if (repo.value != oldRepoURL) {
|
||||
// udělej clone
|
||||
this.cloneRep();
|
||||
} else {
|
||||
this.redrawDirTree(this.view);
|
||||
}
|
||||
this.view.closeDialog();
|
||||
}
|
||||
@@ -203,50 +222,42 @@ class Controller {
|
||||
let msg = document.getElementById("inputCommitMsg");
|
||||
let gitUser = document.getElementById("inputUser");
|
||||
let gitPass = document.getElementById("inputPasswd");
|
||||
|
||||
if (msg.value == "" || gitUser.value == "" || gitPass.gitPass == "") {
|
||||
return;
|
||||
}
|
||||
|
||||
let loading = document.getElementsByClassName("publishLoading")[0];
|
||||
loading.style.display = "block";
|
||||
|
||||
this.model.gitAddAll().then(
|
||||
function (value) {
|
||||
this.model.gitCommit(msg.value).then(
|
||||
function (value) {
|
||||
this.updateFileStats();
|
||||
this.model.gitPush(gitUser.value, gitPass.value).then(
|
||||
function (value) {
|
||||
localStorage.setItem("pushError", "false");
|
||||
loading.style.removeProperty("display");
|
||||
this.view.closeDialog();
|
||||
this.view.errorPublish();
|
||||
}.bind(this),
|
||||
function (error) {
|
||||
console.log(error);
|
||||
if (error == "HttpError: HTTP Error: 401 Unauthorized") {
|
||||
this.view.errorPublish(
|
||||
"Změny nebyly publikovány: Chyba přihlášení."
|
||||
);
|
||||
} else if (error == "HttpError: HTTP Error: 403 Forbidden") {
|
||||
this.view.errorPublish(
|
||||
"Změny nebyly publikovány: Nemáte práva publikovat do tohoto repozitáře."
|
||||
);
|
||||
}
|
||||
loading.style.removeProperty("display");
|
||||
localStorage.setItem("pushError", "true");
|
||||
}.bind(this)
|
||||
);
|
||||
}.bind(this),
|
||||
function (error) {
|
||||
console.log(error);
|
||||
}
|
||||
);
|
||||
}.bind(this),
|
||||
function (error) {
|
||||
console.log(error);
|
||||
if (localStorage.getItem("pushError") == "true") {
|
||||
if (gitUser.value == "" || gitPass.gitPass == "") {
|
||||
this.view.errorPublish("Vyplňte potřebné údaje.");
|
||||
return;
|
||||
}
|
||||
);
|
||||
loading.style.display = "block";
|
||||
this.gitPush(gitUser.value, gitPass.value);
|
||||
} else {
|
||||
if (msg.value == "" || gitUser.value == "" || gitPass.gitPass == "") {
|
||||
this.view.errorPublish("Vyplňte potřebné údaje.");
|
||||
return;
|
||||
}
|
||||
loading.style.display = "block";
|
||||
|
||||
this.model.gitAddAll().then(
|
||||
function (value) {
|
||||
this.model.gitCommit(msg.value).then(
|
||||
function (value) {
|
||||
this.updateFileStats();
|
||||
this.gitPush(gitUser.value, gitPass.value);
|
||||
}.bind(this),
|
||||
function (error) {
|
||||
console.log(error);
|
||||
}
|
||||
);
|
||||
}.bind(this),
|
||||
function (error) {
|
||||
console.log(error);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
openPublish() {
|
||||
this.view.openPublish();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user