Zpřehlednění kódu
This commit is contained in:
@@ -62,7 +62,7 @@
|
||||
<label for="inputEmail">Email:</label>
|
||||
<input type="email" id="inputEmail" required>
|
||||
<button class="close">Cancel</button>
|
||||
<button id="settingsSubmit">Submit</button>
|
||||
<button id="settingsSubmit" type="submit">Submit</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
@@ -78,7 +78,7 @@
|
||||
<label for="inputPasswd">Git heslo:</label>
|
||||
<input type="password" id="inputPasswd" required>
|
||||
<button class="close">Cancel</button>
|
||||
<button id="commitSubmit">Publikovat</button>
|
||||
<button id="commitSubmit" type="submit">Publikovat</button>
|
||||
</form>
|
||||
<img src="./img/loading.gif" alt="loading" class="publishLoading">
|
||||
</div>
|
||||
|
||||
109
js/controller.js
109
js/controller.js
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
29
js/model.js
29
js/model.js
@@ -10,6 +10,8 @@ class Model {
|
||||
window.http = http;
|
||||
}
|
||||
|
||||
/* ================== Dir Tree ================== */
|
||||
|
||||
async dirList(dir = "/") {
|
||||
let list = await pfs.readdir(dir);
|
||||
|
||||
@@ -71,6 +73,18 @@ class Model {
|
||||
return list;
|
||||
}
|
||||
|
||||
/* ================== Text Area ================== */
|
||||
|
||||
readFile(file) {
|
||||
return pfs.readFile(file, "utf8");
|
||||
}
|
||||
|
||||
saveFile(cesta, obsah) {
|
||||
pfs.writeFile(cesta, obsah, "utf8");
|
||||
}
|
||||
|
||||
/* ================== Controls ================== */
|
||||
|
||||
wipeFS() {
|
||||
delete window.fs;
|
||||
window.fs = new LightningFS("fs", { wipe: true });
|
||||
@@ -147,6 +161,9 @@ class Model {
|
||||
console.log(pushResult);
|
||||
}
|
||||
|
||||
/* ================== Windows ================== */
|
||||
/* ------------------ Settings ------------------ */
|
||||
|
||||
setRepo(repoURL) {
|
||||
localStorage.setItem("repo", repoURL);
|
||||
}
|
||||
@@ -157,19 +174,11 @@ class Model {
|
||||
}
|
||||
localStorage.setItem("baseDir", baseDir);
|
||||
}
|
||||
async setName(name) {
|
||||
setName(name) {
|
||||
localStorage.setItem("name", name);
|
||||
}
|
||||
|
||||
async setEmail(email) {
|
||||
setEmail(email) {
|
||||
localStorage.setItem("email", email);
|
||||
}
|
||||
|
||||
readFile(file) {
|
||||
return pfs.readFile(file, "utf8");
|
||||
}
|
||||
|
||||
saveFile(cesta, obsah) {
|
||||
pfs.writeFile(cesta, obsah, "utf8");
|
||||
}
|
||||
}
|
||||
|
||||
56
js/view.js
56
js/view.js
@@ -6,6 +6,8 @@ class View {
|
||||
});
|
||||
}
|
||||
|
||||
/* ================== Dir Tree ================== */
|
||||
|
||||
drawDirTree(
|
||||
dirtree,
|
||||
ulToAdd = document.getElementsByTagName("ul")[0],
|
||||
@@ -61,18 +63,6 @@ class View {
|
||||
}
|
||||
}
|
||||
|
||||
openFile(fileread) {
|
||||
var editText = document.getElementById("editText");
|
||||
editText.style.display = "grid";
|
||||
|
||||
this.simplemde.value(fileread);
|
||||
}
|
||||
|
||||
closeEditor() {
|
||||
var editText = document.getElementById("editText");
|
||||
editText.style.removeProperty("display");
|
||||
}
|
||||
|
||||
removeDirTree() {
|
||||
let mainul = document.getElementsByTagName("ul")[0];
|
||||
while (mainul.firstChild) {
|
||||
@@ -100,6 +90,35 @@ class View {
|
||||
toggler[0].removeEventListener("click", addClass);
|
||||
}
|
||||
|
||||
/* ================== Text Area ================== */
|
||||
|
||||
openFile(fileread) {
|
||||
var editText = document.getElementById("editText");
|
||||
editText.style.display = "grid";
|
||||
|
||||
this.simplemde.value(fileread);
|
||||
}
|
||||
|
||||
closeEditor() {
|
||||
var editText = document.getElementById("editText");
|
||||
editText.style.removeProperty("display");
|
||||
}
|
||||
|
||||
showSaveButton(show) {
|
||||
var saveButton = document.getElementById("saveBtn");
|
||||
saveButton.disabled = show;
|
||||
}
|
||||
|
||||
/* ================== Windows ================== */
|
||||
closeDialog() {
|
||||
var settings = document.getElementsByClassName("settingsbg")[0];
|
||||
var publish = document.getElementsByClassName("commitWrapper")[0];
|
||||
|
||||
settings.style.removeProperty("display");
|
||||
publish.style.removeProperty("display");
|
||||
}
|
||||
/* ------------------ Settings ------------------ */
|
||||
|
||||
openSettings() {
|
||||
this.closeEditor();
|
||||
|
||||
@@ -117,13 +136,7 @@ class View {
|
||||
email.value = localStorage.getItem("email");
|
||||
}
|
||||
|
||||
closeDialog() {
|
||||
var settings = document.getElementsByClassName("settingsbg")[0];
|
||||
var publish = document.getElementsByClassName("commitWrapper")[0];
|
||||
|
||||
settings.style.removeProperty("display");
|
||||
publish.style.removeProperty("display");
|
||||
}
|
||||
/* ------------------ Publish ------------------ */
|
||||
|
||||
openPublish() {
|
||||
this.closeEditor();
|
||||
@@ -132,11 +145,6 @@ class View {
|
||||
publish.style.display = "grid";
|
||||
}
|
||||
|
||||
showSaveButton(show) {
|
||||
var saveButton = document.getElementById("saveBtn");
|
||||
saveButton.disabled = show;
|
||||
}
|
||||
|
||||
errorPublish(error) {
|
||||
let errorDiv = document.getElementById("errorPublish");
|
||||
if (!error) {
|
||||
|
||||
Reference in New Issue
Block a user