Zpřehlednění kódu

This commit is contained in:
2021-01-07 23:26:13 +01:00
parent 35138ec30b
commit f1d269d762
4 changed files with 115 additions and 83 deletions

View File

@@ -38,7 +38,7 @@ class Controller {
);
}
if (localStorage.getItem("pushError")) {
if (localStorage.getItem("pushError") != "false") {
this.view.openPublish();
this.view.errorPublish("Máte nepublikované změny: publikujte je.");
}
@@ -73,12 +73,65 @@ class Controller {
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);
}
);
}
updateFileStats() {
this.model.getGitStatusTree().then(
function (value) {
this.view.statDirTree(value, undefined);
}.bind(this),
function (error) {
console.log(error);
}
);
}
/* ================== Text Area ================== */
saveButton() {
var textArea = this.view.simplemde;
this.view.showSaveButton(textArea.value() == this.openedFileValue);
}
loadFile(file) {
this.openedFile = file;
this.model.readFile(file).then(
function (value) {
this.openedFileValue = value;
this.view.openFile(value);
}.bind(this),
function (error) {
console.log(error);
}
);
}
saveFile() {
var textArea = this.view.simplemde;
this.model.saveFile(this.openedFile, textArea.value());
this.openedFileValue = textArea.value();
this.saveButton();
this.updateFileStats();
}
/* ================== Controls ================== */
wipeFS() {
this.model.wipeFS();
//window.location.reload();
@@ -115,30 +168,8 @@ class Controller {
);
}
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);
}
);
}
updateFileStats() {
this.model.getGitStatusTree().then(
function (value) {
this.view.statDirTree(value, undefined);
}.bind(this),
function (error) {
console.log(error);
}
);
}
/* ================== Windows ================== */
/* ------------------ Settings ------------------ */
saveSettings() {
let repo = document.getElementById("inputRepository");
@@ -166,18 +197,7 @@ class Controller {
this.view.closeDialog();
}
loadFile(file) {
this.openedFile = file;
this.model.readFile(file).then(
function (value) {
this.openedFileValue = value;
this.view.openFile(value);
}.bind(this),
function (error) {
console.log(error);
}
);
}
/* ------------------ Publish ------------------ */
publish() {
let msg = document.getElementById("inputCommitMsg");
@@ -207,7 +227,11 @@ class Controller {
console.log(error);
if (error == "HttpError: HTTP Error: 401 Unauthorized") {
this.view.errorPublish(
"Změny nebyly publikovány: Chyba přihlášení"
"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");
@@ -225,13 +249,4 @@ class Controller {
}
);
}
saveFile() {
var textArea = this.view.simplemde;
this.model.saveFile(this.openedFile, textArea.value());
this.openedFileValue = textArea.value();
this.saveButton();
this.updateFileStats();
}
}