|
|
@ -3,8 +3,12 @@ class Controller {
|
|
|
|
this.model = model;
|
|
|
|
this.model = model;
|
|
|
|
this.view = view;
|
|
|
|
this.view = view;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
model.getDirTree().then(
|
|
|
|
|
|
|
|
function () {
|
|
|
|
this.addListeners();
|
|
|
|
this.addListeners();
|
|
|
|
this.init();
|
|
|
|
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) {
|
|
|
|
|
|
|
|
if (value.length == 1) {
|
|
|
|
|
|
|
|
//Nic nenaklonovaného, klonovat
|
|
|
|
//Nic nenaklonovaného, klonovat
|
|
|
|
this.cloneRep();
|
|
|
|
this.cloneRep();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
//Udělat Pull
|
|
|
|
//Udělat Pull
|
|
|
|
this.pullRep();
|
|
|
|
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);
|
|
|
|
|
|
|
|
view.dirTreeToggler();
|
|
|
|
|
|
|
|
this.updateFileStats();
|
|
|
|
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,12 +222,20 @@ 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");
|
|
|
|
|
|
|
|
let loading = document.getElementsByClassName("publishLoading")[0];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 == "") {
|
|
|
|
if (msg.value == "" || gitUser.value == "" || gitPass.gitPass == "") {
|
|
|
|
|
|
|
|
this.view.errorPublish("Vyplňte potřebné údaje.");
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let loading = document.getElementsByClassName("publishLoading")[0];
|
|
|
|
|
|
|
|
loading.style.display = "block";
|
|
|
|
loading.style.display = "block";
|
|
|
|
|
|
|
|
|
|
|
|
this.model.gitAddAll().then(
|
|
|
|
this.model.gitAddAll().then(
|
|
|
@ -216,37 +243,21 @@ class Controller {
|
|
|
|
this.model.gitCommit(msg.value).then(
|
|
|
|
this.model.gitCommit(msg.value).then(
|
|
|
|
function (value) {
|
|
|
|
function (value) {
|
|
|
|
this.updateFileStats();
|
|
|
|
this.updateFileStats();
|
|
|
|
this.model.gitPush(gitUser.value, gitPass.value).then(
|
|
|
|
this.gitPush(gitUser.value, gitPass.value);
|
|
|
|
function (value) {
|
|
|
|
|
|
|
|
localStorage.setItem("pushError", "false");
|
|
|
|
|
|
|
|
loading.style.removeProperty("display");
|
|
|
|
|
|
|
|
this.view.closeDialog();
|
|
|
|
|
|
|
|
this.view.errorPublish();
|
|
|
|
|
|
|
|
}.bind(this),
|
|
|
|
}.bind(this),
|
|
|
|
function (error) {
|
|
|
|
function (error) {
|
|
|
|
console.log(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),
|
|
|
|
}.bind(this),
|
|
|
|
function (error) {
|
|
|
|
function (error) {
|
|
|
|
console.log(error);
|
|
|
|
console.log(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}.bind(this),
|
|
|
|
|
|
|
|
function (error) {
|
|
|
|
|
|
|
|
console.log(error);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
openPublish() {
|
|
|
|
|
|
|
|
this.view.openPublish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|