Zpřehlednění kódu
This commit is contained in:
@@ -62,7 +62,7 @@
|
|||||||
<label for="inputEmail">Email:</label>
|
<label for="inputEmail">Email:</label>
|
||||||
<input type="email" id="inputEmail" required>
|
<input type="email" id="inputEmail" required>
|
||||||
<button class="close">Cancel</button>
|
<button class="close">Cancel</button>
|
||||||
<button id="settingsSubmit">Submit</button>
|
<button id="settingsSubmit" type="submit">Submit</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -78,7 +78,7 @@
|
|||||||
<label for="inputPasswd">Git heslo:</label>
|
<label for="inputPasswd">Git heslo:</label>
|
||||||
<input type="password" id="inputPasswd" required>
|
<input type="password" id="inputPasswd" required>
|
||||||
<button class="close">Cancel</button>
|
<button class="close">Cancel</button>
|
||||||
<button id="commitSubmit">Publikovat</button>
|
<button id="commitSubmit" type="submit">Publikovat</button>
|
||||||
</form>
|
</form>
|
||||||
<img src="./img/loading.gif" alt="loading" class="publishLoading">
|
<img src="./img/loading.gif" alt="loading" class="publishLoading">
|
||||||
</div>
|
</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.openPublish();
|
||||||
this.view.errorPublish("Máte nepublikované změny: publikujte je.");
|
this.view.errorPublish("Máte nepublikované změny: publikujte je.");
|
||||||
}
|
}
|
||||||
@@ -73,12 +73,65 @@ class Controller {
|
|||||||
commitSubmit.addEventListener("click", this.publish.bind(this));
|
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() {
|
saveButton() {
|
||||||
var textArea = this.view.simplemde;
|
var textArea = this.view.simplemde;
|
||||||
|
|
||||||
this.view.showSaveButton(textArea.value() == this.openedFileValue);
|
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() {
|
wipeFS() {
|
||||||
this.model.wipeFS();
|
this.model.wipeFS();
|
||||||
//window.location.reload();
|
//window.location.reload();
|
||||||
@@ -115,30 +168,8 @@ class Controller {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
redrawDirTree(view) {
|
/* ================== Windows ================== */
|
||||||
this.model.getDirTree().then(
|
/* ------------------ Settings ------------------ */
|
||||||
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);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
saveSettings() {
|
saveSettings() {
|
||||||
let repo = document.getElementById("inputRepository");
|
let repo = document.getElementById("inputRepository");
|
||||||
@@ -166,18 +197,7 @@ class Controller {
|
|||||||
this.view.closeDialog();
|
this.view.closeDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
loadFile(file) {
|
/* ------------------ Publish ------------------ */
|
||||||
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");
|
let msg = document.getElementById("inputCommitMsg");
|
||||||
@@ -207,7 +227,11 @@ class Controller {
|
|||||||
console.log(error);
|
console.log(error);
|
||||||
if (error == "HttpError: HTTP Error: 401 Unauthorized") {
|
if (error == "HttpError: HTTP Error: 401 Unauthorized") {
|
||||||
this.view.errorPublish(
|
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");
|
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;
|
window.http = http;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ================== Dir Tree ================== */
|
||||||
|
|
||||||
async dirList(dir = "/") {
|
async dirList(dir = "/") {
|
||||||
let list = await pfs.readdir(dir);
|
let list = await pfs.readdir(dir);
|
||||||
|
|
||||||
@@ -71,6 +73,18 @@ class Model {
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ================== Text Area ================== */
|
||||||
|
|
||||||
|
readFile(file) {
|
||||||
|
return pfs.readFile(file, "utf8");
|
||||||
|
}
|
||||||
|
|
||||||
|
saveFile(cesta, obsah) {
|
||||||
|
pfs.writeFile(cesta, obsah, "utf8");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================== Controls ================== */
|
||||||
|
|
||||||
wipeFS() {
|
wipeFS() {
|
||||||
delete window.fs;
|
delete window.fs;
|
||||||
window.fs = new LightningFS("fs", { wipe: true });
|
window.fs = new LightningFS("fs", { wipe: true });
|
||||||
@@ -147,6 +161,9 @@ class Model {
|
|||||||
console.log(pushResult);
|
console.log(pushResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ================== Windows ================== */
|
||||||
|
/* ------------------ Settings ------------------ */
|
||||||
|
|
||||||
setRepo(repoURL) {
|
setRepo(repoURL) {
|
||||||
localStorage.setItem("repo", repoURL);
|
localStorage.setItem("repo", repoURL);
|
||||||
}
|
}
|
||||||
@@ -157,19 +174,11 @@ class Model {
|
|||||||
}
|
}
|
||||||
localStorage.setItem("baseDir", baseDir);
|
localStorage.setItem("baseDir", baseDir);
|
||||||
}
|
}
|
||||||
async setName(name) {
|
setName(name) {
|
||||||
localStorage.setItem("name", name);
|
localStorage.setItem("name", name);
|
||||||
}
|
}
|
||||||
|
|
||||||
async setEmail(email) {
|
setEmail(email) {
|
||||||
localStorage.setItem("email", 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(
|
drawDirTree(
|
||||||
dirtree,
|
dirtree,
|
||||||
ulToAdd = document.getElementsByTagName("ul")[0],
|
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() {
|
removeDirTree() {
|
||||||
let mainul = document.getElementsByTagName("ul")[0];
|
let mainul = document.getElementsByTagName("ul")[0];
|
||||||
while (mainul.firstChild) {
|
while (mainul.firstChild) {
|
||||||
@@ -100,6 +90,35 @@ class View {
|
|||||||
toggler[0].removeEventListener("click", addClass);
|
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() {
|
openSettings() {
|
||||||
this.closeEditor();
|
this.closeEditor();
|
||||||
|
|
||||||
@@ -117,13 +136,7 @@ class View {
|
|||||||
email.value = localStorage.getItem("email");
|
email.value = localStorage.getItem("email");
|
||||||
}
|
}
|
||||||
|
|
||||||
closeDialog() {
|
/* ------------------ Publish ------------------ */
|
||||||
var settings = document.getElementsByClassName("settingsbg")[0];
|
|
||||||
var publish = document.getElementsByClassName("commitWrapper")[0];
|
|
||||||
|
|
||||||
settings.style.removeProperty("display");
|
|
||||||
publish.style.removeProperty("display");
|
|
||||||
}
|
|
||||||
|
|
||||||
openPublish() {
|
openPublish() {
|
||||||
this.closeEditor();
|
this.closeEditor();
|
||||||
@@ -132,11 +145,6 @@ class View {
|
|||||||
publish.style.display = "grid";
|
publish.style.display = "grid";
|
||||||
}
|
}
|
||||||
|
|
||||||
showSaveButton(show) {
|
|
||||||
var saveButton = document.getElementById("saveBtn");
|
|
||||||
saveButton.disabled = show;
|
|
||||||
}
|
|
||||||
|
|
||||||
errorPublish(error) {
|
errorPublish(error) {
|
||||||
let errorDiv = document.getElementById("errorPublish");
|
let errorDiv = document.getElementById("errorPublish");
|
||||||
if (!error) {
|
if (!error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user