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 { section {
grid-area: section; grid-area: section;
margin: 1em 2em; margin: 1em 2em;
display: grid;
grid-template-columns: auto;
grid-template-rows: auto min-content;
row-gap: 2em;
} }
textarea { textarea {

@ -32,7 +32,8 @@
<section> <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> </section>
<footer> <footer>

@ -10,6 +10,8 @@ class Controller {
var settingsBtn = document.getElementsByClassName("settingsBtn")[0]; var settingsBtn = document.getElementsByClassName("settingsBtn")[0];
var settingsClose = document.getElementsByClassName("close"); var settingsClose = document.getElementsByClassName("close");
var settingsSubmit = document.getElementById("settingsSubmit"); var settingsSubmit = document.getElementById("settingsSubmit");
var textArea = document.getElementsByTagName("textarea")[0];
var saveBtn = document.getElementById("saveBtn");
cloneBtn.addEventListener("click", this.cloneRep.bind(this)); cloneBtn.addEventListener("click", this.cloneRep.bind(this));
purgeBtn.addEventListener("click", this.wipeFS.bind(this)); purgeBtn.addEventListener("click", this.wipeFS.bind(this));
@ -18,6 +20,17 @@ class Controller {
settingsClose[i].addEventListener("click", view.closeSettings.bind(this)); settingsClose[i].addEventListener("click", view.closeSettings.bind(this));
} }
settingsSubmit.addEventListener("click", this.saveSettings.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() { wipeFS() {
@ -27,14 +40,13 @@ class Controller {
} }
cloneRep(repurl) { cloneRep(repurl) {
var that = this;
var loading = document.getElementsByClassName("loading")[0]; var loading = document.getElementsByClassName("loading")[0];
loading.style.display = "grid"; loading.style.display = "grid";
this.model.cloneRep().then( this.model.cloneRep().then(
function (value) { function (value) {
loading.style.removeProperty("display"); loading.style.removeProperty("display");
that.redrawDirTree(that.view); this.redrawDirTree(this.view);
}, }.bind(this),
function (error) {} function (error) {}
); );
} }
@ -63,11 +75,20 @@ class Controller {
} }
loadFile(file) { loadFile(file) {
this.openedFile = file;
this.model.readFile(file).then( this.model.readFile(file).then(
function (value) { function (value) {
this.openedFileValue = value;
this.view.openFile(value); this.view.openFile(value);
}.bind(this), }.bind(this),
function (error) {} 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() { 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); var tree = await this.dirList(baseDir);
return tree; return tree;
@ -64,10 +70,17 @@ class Model {
} }
setBaseDir(baseDir) { setBaseDir(baseDir) {
if (!baseDir.endsWith("/")) {
baseDir += "/";
}
localStorage.setItem("baseDir", baseDir); localStorage.setItem("baseDir", baseDir);
} }
readFile(file) { readFile(file) {
return pfs.readFile(file, "utf8"); return pfs.readFile(file, "utf8");
} }
saveFile(cesta, obsah) {
pfs.writeFile(cesta, obsah, "utf8");
}
} }

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