|
|
|
@ -3,9 +3,6 @@ class Controller {
|
|
|
|
|
this.model = model;
|
|
|
|
|
this.view = view;
|
|
|
|
|
|
|
|
|
|
this.redrawDirTree(view);
|
|
|
|
|
//this.pullRep();
|
|
|
|
|
|
|
|
|
|
this.addListeners();
|
|
|
|
|
this.init();
|
|
|
|
|
}
|
|
|
|
@ -40,15 +37,22 @@ class Controller {
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (localStorage.getItem("pushError")) {
|
|
|
|
|
this.view.openPublish();
|
|
|
|
|
this.view.errorPublish("Máte nepublikované změny: publikujte je.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
addListeners() {
|
|
|
|
|
var cloneBtn = document.getElementsByClassName("clone")[0];
|
|
|
|
|
var purgeBtn = document.getElementsByClassName("wipe")[0];
|
|
|
|
|
var settingsBtn = document.getElementsByClassName("settingsBtn")[0];
|
|
|
|
|
var settingsClose = document.getElementsByClassName("close");
|
|
|
|
|
var closeDialog = document.getElementsByClassName("close");
|
|
|
|
|
var settingsSubmit = document.getElementById("settingsSubmit");
|
|
|
|
|
var saveBtn = document.getElementById("saveBtn");
|
|
|
|
|
var publishBtn = document.getElementsByClassName("publishBtn")[0];
|
|
|
|
|
var commitSubmit = document.getElementById("commitSubmit");
|
|
|
|
|
|
|
|
|
|
cloneBtn.addEventListener("click", this.cloneRep.bind(this));
|
|
|
|
|
purgeBtn.addEventListener("click", this.wipeFS.bind(this));
|
|
|
|
@ -56,15 +60,17 @@ class Controller {
|
|
|
|
|
"click",
|
|
|
|
|
this.view.openSettings.bind(this.view)
|
|
|
|
|
);
|
|
|
|
|
for (let i = 0; i < settingsClose.length; i++) {
|
|
|
|
|
settingsClose[i].addEventListener(
|
|
|
|
|
for (let i = 0; i < closeDialog.length; i++) {
|
|
|
|
|
closeDialog[i].addEventListener(
|
|
|
|
|
"click",
|
|
|
|
|
this.view.closeSettings.bind(this)
|
|
|
|
|
this.view.closeDialog.bind(this)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
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));
|
|
|
|
|
commitSubmit.addEventListener("click", this.publish.bind(this));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
saveButton() {
|
|
|
|
@ -102,8 +108,10 @@ class Controller {
|
|
|
|
|
this.redrawDirTree(this.view);
|
|
|
|
|
}.bind(this),
|
|
|
|
|
function (error) {
|
|
|
|
|
// zatim to teda znovu naclonuj
|
|
|
|
|
this.cloneRep();
|
|
|
|
|
console.log(error);
|
|
|
|
|
}
|
|
|
|
|
}.bind(this)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -153,10 +161,9 @@ class Controller {
|
|
|
|
|
// udělej clone
|
|
|
|
|
this.cloneRep();
|
|
|
|
|
} else {
|
|
|
|
|
// udelej jenom pull
|
|
|
|
|
this.pullRep();
|
|
|
|
|
this.redrawDirTree(this.view);
|
|
|
|
|
}
|
|
|
|
|
this.view.closeSettings();
|
|
|
|
|
this.view.closeDialog();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
loadFile(file) {
|
|
|
|
@ -172,6 +179,53 @@ class Controller {
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
publish() {
|
|
|
|
|
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í"
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
loading.style.removeProperty("display");
|
|
|
|
|
localStorage.setItem("pushError", "true");
|
|
|
|
|
}.bind(this)
|
|
|
|
|
);
|
|
|
|
|
}.bind(this),
|
|
|
|
|
function (error) {
|
|
|
|
|
console.log(error);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}.bind(this),
|
|
|
|
|
function (error) {
|
|
|
|
|
console.log(error);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
saveFile() {
|
|
|
|
|
var textArea = this.view.simplemde;
|
|
|
|
|
this.model.saveFile(this.openedFile, textArea.value());
|
|
|
|
|