|
|
@ -3,8 +3,12 @@ class Controller {
|
|
|
|
this.model = model;
|
|
|
|
this.model = model;
|
|
|
|
this.view = view;
|
|
|
|
this.view = view;
|
|
|
|
|
|
|
|
|
|
|
|
this.addListeners();
|
|
|
|
model.getDirTree().then(
|
|
|
|
this.init();
|
|
|
|
function () {
|
|
|
|
|
|
|
|
this.addListeners();
|
|
|
|
|
|
|
|
this.init();
|
|
|
|
|
|
|
|
}.bind(this)
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
init() {
|
|
|
|
init() {
|
|
|
@ -22,23 +26,16 @@ class Controller {
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
this.view.openSettings();
|
|
|
|
this.view.openSettings();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
this.model.getDirTree().then(
|
|
|
|
if (this.model.dirTree.length == 1) {
|
|
|
|
function (value) {
|
|
|
|
//Nic nenaklonovaného, klonovat
|
|
|
|
if (value.length == 1) {
|
|
|
|
this.cloneRep();
|
|
|
|
//Nic nenaklonovaného, klonovat
|
|
|
|
} else {
|
|
|
|
this.cloneRep();
|
|
|
|
//Udělat Pull
|
|
|
|
} else {
|
|
|
|
this.pullRep();
|
|
|
|
//Udělat Pull
|
|
|
|
}
|
|
|
|
this.pullRep();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}.bind(this),
|
|
|
|
|
|
|
|
function (error) {
|
|
|
|
|
|
|
|
console.log(error);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (localStorage.getItem("pushError") != "false") {
|
|
|
|
if (localStorage.getItem("pushError") == "true") {
|
|
|
|
this.view.openPublish();
|
|
|
|
this.view.openPublish();
|
|
|
|
this.view.errorPublish("Máte nepublikované změny: publikujte je.");
|
|
|
|
this.view.errorPublish("Máte nepublikované změny: publikujte je.");
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -69,24 +66,17 @@ class Controller {
|
|
|
|
settingsSubmit.addEventListener("click", this.saveSettings.bind(this));
|
|
|
|
settingsSubmit.addEventListener("click", this.saveSettings.bind(this));
|
|
|
|
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));
|
|
|
|
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));
|
|
|
|
commitSubmit.addEventListener("click", this.publish.bind(this));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ================== Dir Tree ================== */
|
|
|
|
/* ================== Dir Tree ================== */
|
|
|
|
|
|
|
|
|
|
|
|
redrawDirTree(view) {
|
|
|
|
redrawDirTree() {
|
|
|
|
this.model.getDirTree().then(
|
|
|
|
this.view.removeDirTree();
|
|
|
|
function (value) {
|
|
|
|
this.view.drawDirTree(this.model.dirTree, undefined, this);
|
|
|
|
view.removeDirTree();
|
|
|
|
this.view.dirTreeToggler();
|
|
|
|
view.drawDirTree(value, undefined, this);
|
|
|
|
this.updateFileStats();
|
|
|
|
view.dirTreeToggler();
|
|
|
|
|
|
|
|
this.updateFileStats();
|
|
|
|
|
|
|
|
}.bind(this),
|
|
|
|
|
|
|
|
function (error) {
|
|
|
|
|
|
|
|
console.log(error);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
updateFileStats() {
|
|
|
|
updateFileStats() {
|
|
|
@ -133,9 +123,9 @@ class Controller {
|
|
|
|
/* ================== Controls ================== */
|
|
|
|
/* ================== Controls ================== */
|
|
|
|
|
|
|
|
|
|
|
|
wipeFS() {
|
|
|
|
wipeFS() {
|
|
|
|
this.model.wipeFS();
|
|
|
|
this.model.wipeFS().then(function () {
|
|
|
|
//window.location.reload();
|
|
|
|
this.redrawDirTree();
|
|
|
|
this.redrawDirTree(this.view);
|
|
|
|
}.bind(this));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cloneRep() {
|
|
|
|
cloneRep() {
|
|
|
@ -143,8 +133,10 @@ class Controller {
|
|
|
|
loading.style.display = "grid";
|
|
|
|
loading.style.display = "grid";
|
|
|
|
this.model.cloneRep().then(
|
|
|
|
this.model.cloneRep().then(
|
|
|
|
function (value) {
|
|
|
|
function (value) {
|
|
|
|
|
|
|
|
this.redrawDirTree();
|
|
|
|
loading.style.removeProperty("display");
|
|
|
|
loading.style.removeProperty("display");
|
|
|
|
this.redrawDirTree(this.view);
|
|
|
|
localStorage.setItem("pushError", "false");
|
|
|
|
|
|
|
|
this.view.errorPublish();
|
|
|
|
}.bind(this),
|
|
|
|
}.bind(this),
|
|
|
|
function (error) {
|
|
|
|
function (error) {
|
|
|
|
console.log(error);
|
|
|
|
console.log(error);
|
|
|
@ -158,7 +150,7 @@ class Controller {
|
|
|
|
this.model.pullRep().then(
|
|
|
|
this.model.pullRep().then(
|
|
|
|
function (value) {
|
|
|
|
function (value) {
|
|
|
|
loading.style.removeProperty("display");
|
|
|
|
loading.style.removeProperty("display");
|
|
|
|
this.redrawDirTree(this.view);
|
|
|
|
this.redrawDirTree();
|
|
|
|
}.bind(this),
|
|
|
|
}.bind(this),
|
|
|
|
function (error) {
|
|
|
|
function (error) {
|
|
|
|
// zatim to teda znovu naclonuj
|
|
|
|
// 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 ================== */
|
|
|
|
/* ================== Windows ================== */
|
|
|
|
/* ------------------ Settings ------------------ */
|
|
|
|
/* ------------------ Settings ------------------ */
|
|
|
|
|
|
|
|
|
|
|
@ -179,7 +196,11 @@ class Controller {
|
|
|
|
|
|
|
|
|
|
|
|
let oldRepoURL = localStorage.getItem("repo");
|
|
|
|
let oldRepoURL = localStorage.getItem("repo");
|
|
|
|
this.model.setRepo(repo.value);
|
|
|
|
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.setName(name.value);
|
|
|
|
this.model.setEmail(email.value);
|
|
|
|
this.model.setEmail(email.value);
|
|
|
|
|
|
|
|
|
|
|
@ -191,8 +212,6 @@ class Controller {
|
|
|
|
if (repo.value != oldRepoURL) {
|
|
|
|
if (repo.value != oldRepoURL) {
|
|
|
|
// udělej clone
|
|
|
|
// udělej clone
|
|
|
|
this.cloneRep();
|
|
|
|
this.cloneRep();
|
|
|
|
} else {
|
|
|
|
|
|
|
|
this.redrawDirTree(this.view);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.view.closeDialog();
|
|
|
|
this.view.closeDialog();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -203,50 +222,42 @@ class Controller {
|
|
|
|
let msg = document.getElementById("inputCommitMsg");
|
|
|
|
let msg = document.getElementById("inputCommitMsg");
|
|
|
|
let gitUser = document.getElementById("inputUser");
|
|
|
|
let gitUser = document.getElementById("inputUser");
|
|
|
|
let gitPass = document.getElementById("inputPasswd");
|
|
|
|
let gitPass = document.getElementById("inputPasswd");
|
|
|
|
|
|
|
|
|
|
|
|
if (msg.value == "" || gitUser.value == "" || gitPass.gitPass == "") {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let loading = document.getElementsByClassName("publishLoading")[0];
|
|
|
|
let loading = document.getElementsByClassName("publishLoading")[0];
|
|
|
|
loading.style.display = "block";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.model.gitAddAll().then(
|
|
|
|
if (localStorage.getItem("pushError") == "true") {
|
|
|
|
function (value) {
|
|
|
|
if (gitUser.value == "" || gitPass.gitPass == "") {
|
|
|
|
this.model.gitCommit(msg.value).then(
|
|
|
|
this.view.errorPublish("Vyplňte potřebné údaje.");
|
|
|
|
function (value) {
|
|
|
|
return;
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|