přidání uložení změn do fs, oprava vypisování dir tree

master
David Zálešák 4 years ago
parent 8cd31d4b73
commit 6329bacff8

@ -66,6 +66,10 @@ li::before {
section {
grid-area: section;
margin: 1em 2em;
display: grid;
grid-template-columns: auto;
grid-template-rows: auto min-content;
row-gap: 2em;
}
textarea {

@ -32,7 +32,8 @@
<section>
<textarea name="" id="" cols="30" rows="10"></textarea>
<textarea name="" id="" cols="30" rows="10" disabled></textarea>
<button disabled id="saveBtn">Save</button>
</section>
<footer>

@ -10,6 +10,8 @@ class Controller {
var settingsBtn = document.getElementsByClassName("settingsBtn")[0];
var settingsClose = document.getElementsByClassName("close");
var settingsSubmit = document.getElementById("settingsSubmit");
var textArea = document.getElementsByTagName("textarea")[0];
var saveBtn = document.getElementById("saveBtn");
cloneBtn.addEventListener("click", this.cloneRep.bind(this));
purgeBtn.addEventListener("click", this.wipeFS.bind(this));
@ -18,6 +20,17 @@ class Controller {
settingsClose[i].addEventListener("click", view.closeSettings.bind(this));
}
settingsSubmit.addEventListener("click", this.saveSettings.bind(this));
textArea.addEventListener("keyup", this.saveButton.bind(this));
saveBtn.addEventListener("click", this.saveFile.bind(this));
}
saveButton() {
var textArea = document.getElementsByTagName("textarea")[0];
if (textArea.value != this.openedFileValue) {
this.view.showSaveButton(true);
} else {
this.view.showSaveButton(false);
}
}
wipeFS() {
@ -27,14 +40,13 @@ class Controller {
}
cloneRep(repurl) {
var that = this;
var loading = document.getElementsByClassName("loading")[0];
loading.style.display = "grid";
this.model.cloneRep().then(
function (value) {
loading.style.removeProperty("display");
that.redrawDirTree(that.view);
},
this.redrawDirTree(this.view);
}.bind(this),
function (error) {}
);
}
@ -63,11 +75,20 @@ class Controller {
}
loadFile(file) {
this.openedFile = file;
this.model.readFile(file).then(
function (value) {
this.openedFileValue = value;
this.view.openFile(value);
}.bind(this),
function (error) {}
);
}
saveFile() {
var textArea = document.getElementsByTagName("textarea")[0];
this.model.saveFile(this.openedFile, textArea.value)
this.openedFileValue = textArea.value;
this.saveButton()
}
}

@ -36,7 +36,13 @@ class Model {
}
async dirTree() {
let baseDir = localStorage.getItem("baseDir");
var baseDir = localStorage.getItem("baseDir");
var stat = await pfs.stat(baseDir).catch((e) => {});
if (stat == null) {
var baseDir = "/";
}
var tree = await this.dirList(baseDir);
return tree;
@ -64,10 +70,17 @@ class Model {
}
setBaseDir(baseDir) {
if (!baseDir.endsWith("/")) {
baseDir += "/";
}
localStorage.setItem("baseDir", baseDir);
}
readFile(file) {
return pfs.readFile(file, "utf8");
}
saveFile(cesta, obsah) {
pfs.writeFile(cesta, obsah, "utf8");
}
}

@ -37,6 +37,7 @@ class View {
openFile(fileread) {
let textArea = document.getElementsByTagName("textarea")[0];
textArea.disabled = false;
textArea.value = fileread;
}
@ -82,4 +83,13 @@ class View {
var settings = document.getElementsByClassName("settingsbg")[0];
settings.style.removeProperty("display");
}
showSaveButton(show) {
var saveButton = document.getElementById("saveBtn");
if(show) {
saveButton.disabled = false;
} else {
saveButton.disabled = true;
}
}
}