ulozeni dirtree do promene

master
David Zálešák 4 years ago
parent f1d269d762
commit f1488f847a

@ -53,6 +53,10 @@ aside li::before {
margin-right: 6px; margin-right: 6px;
} }
.caret:hover::before {
color: white;
}
.container { .container {
display: grid; display: grid;
grid-template-columns: max-content auto; grid-template-columns: max-content auto;
@ -145,7 +149,6 @@ sub {
.settings, .settings,
.commit { .commit {
background-color: white; background-color: white;
width: 30vw;
padding: 1.5em; padding: 1.5em;
border: 5px solid #c3c3c3; border: 5px solid #c3c3c3;
z-index: 10; z-index: 10;

@ -3,8 +3,12 @@ class Controller {
this.model = model; this.model = model;
this.view = view; this.view = view;
model.getDirTree().then(
function () {
this.addListeners(); this.addListeners();
this.init(); this.init();
}.bind(this)
);
} }
init() { init() {
@ -22,23 +26,16 @@ class Controller {
) { ) {
this.view.openSettings(); this.view.openSettings();
} else { } else {
this.model.getDirTree().then( if (this.model.dirTree.length == 1) {
function (value) {
if (value.length == 1) {
//Nic nenaklonovaného, klonovat //Nic nenaklonovaného, klonovat
this.cloneRep(); this.cloneRep();
} else { } else {
//Udělat Pull //Udělat Pull
this.pullRep(); this.pullRep();
} }
}.bind(this),
function (error) {
console.log(error);
}
);
} }
if (localStorage.getItem("pushError") != "false") { if (localStorage.getItem("pushError") == "true") {
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.");
} }
@ -69,24 +66,17 @@ class Controller {
settingsSubmit.addEventListener("click", this.saveSettings.bind(this)); settingsSubmit.addEventListener("click", this.saveSettings.bind(this));
this.view.simplemde.codemirror.on("change", this.saveButton.bind(this)); this.view.simplemde.codemirror.on("change", this.saveButton.bind(this));
saveBtn.addEventListener("click", this.saveFile.bind(this)); saveBtn.addEventListener("click", this.saveFile.bind(this));
publishBtn.addEventListener("click", this.view.openPublish.bind(this.view)); publishBtn.addEventListener("click", this.openPublish.bind(this));
commitSubmit.addEventListener("click", this.publish.bind(this)); commitSubmit.addEventListener("click", this.publish.bind(this));
} }
/* ================== Dir Tree ================== */ /* ================== Dir Tree ================== */
redrawDirTree(view) { redrawDirTree() {
this.model.getDirTree().then( this.view.removeDirTree();
function (value) { this.view.drawDirTree(this.model.dirTree, undefined, this);
view.removeDirTree(); this.view.dirTreeToggler();
view.drawDirTree(value, undefined, this);
view.dirTreeToggler();
this.updateFileStats(); this.updateFileStats();
}.bind(this),
function (error) {
console.log(error);
}
);
} }
updateFileStats() { updateFileStats() {
@ -133,9 +123,9 @@ class Controller {
/* ================== Controls ================== */ /* ================== Controls ================== */
wipeFS() { wipeFS() {
this.model.wipeFS(); this.model.wipeFS().then(function () {
//window.location.reload(); this.redrawDirTree();
this.redrawDirTree(this.view); }.bind(this));
} }
cloneRep() { cloneRep() {
@ -143,8 +133,10 @@ class Controller {
loading.style.display = "grid"; loading.style.display = "grid";
this.model.cloneRep().then( this.model.cloneRep().then(
function (value) { function (value) {
this.redrawDirTree();
loading.style.removeProperty("display"); loading.style.removeProperty("display");
this.redrawDirTree(this.view); localStorage.setItem("pushError", "false");
this.view.errorPublish();
}.bind(this), }.bind(this),
function (error) { function (error) {
console.log(error); console.log(error);
@ -158,7 +150,7 @@ class Controller {
this.model.pullRep().then( this.model.pullRep().then(
function (value) { function (value) {
loading.style.removeProperty("display"); loading.style.removeProperty("display");
this.redrawDirTree(this.view); this.redrawDirTree();
}.bind(this), }.bind(this),
function (error) { function (error) {
// zatim to teda znovu naclonuj // zatim to teda znovu naclonuj
@ -168,6 +160,31 @@ class Controller {
); );
} }
gitPush(gitUser, gitPass) {
let loading = document.getElementsByClassName("publishLoading")[0];
this.model.gitPush(gitUser, gitPass).then(
function (value) {
localStorage.setItem("pushError", "false");
this.view.closeDialog();
this.view.errorPublish();
loading.style.removeProperty("display");
}.bind(this),
function (error) {
console.log(error);
if (error == "HttpError: HTTP Error: 401 Unauthorized") {
this.view.errorPublish("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."
);
}
localStorage.setItem("pushError", "true");
loading.style.removeProperty("display");
}.bind(this)
);
}
/* ================== Windows ================== */ /* ================== Windows ================== */
/* ------------------ Settings ------------------ */ /* ------------------ Settings ------------------ */
@ -179,7 +196,11 @@ class Controller {
let oldRepoURL = localStorage.getItem("repo"); let oldRepoURL = localStorage.getItem("repo");
this.model.setRepo(repo.value); this.model.setRepo(repo.value);
this.model.setBaseDir(baseDir.value); this.model.setBaseDir(baseDir.value).then(
function() {
this.redrawDirTree();
}.bind(this)
);
this.model.setName(name.value); this.model.setName(name.value);
this.model.setEmail(email.value); this.model.setEmail(email.value);
@ -191,8 +212,6 @@ class Controller {
if (repo.value != oldRepoURL) { if (repo.value != oldRepoURL) {
// udělej clone // udělej clone
this.cloneRep(); this.cloneRep();
} else {
this.redrawDirTree(this.view);
} }
this.view.closeDialog(); this.view.closeDialog();
} }
@ -203,12 +222,20 @@ class Controller {
let msg = document.getElementById("inputCommitMsg"); let msg = document.getElementById("inputCommitMsg");
let gitUser = document.getElementById("inputUser"); let gitUser = document.getElementById("inputUser");
let gitPass = document.getElementById("inputPasswd"); let gitPass = document.getElementById("inputPasswd");
let loading = document.getElementsByClassName("publishLoading")[0];
if (localStorage.getItem("pushError") == "true") {
if (gitUser.value == "" || gitPass.gitPass == "") {
this.view.errorPublish("Vyplňte potřebné údaje.");
return;
}
loading.style.display = "block";
this.gitPush(gitUser.value, gitPass.value);
} else {
if (msg.value == "" || gitUser.value == "" || gitPass.gitPass == "") { if (msg.value == "" || gitUser.value == "" || gitPass.gitPass == "") {
this.view.errorPublish("Vyplňte potřebné údaje.");
return; return;
} }
let loading = document.getElementsByClassName("publishLoading")[0];
loading.style.display = "block"; loading.style.display = "block";
this.model.gitAddAll().then( this.model.gitAddAll().then(
@ -216,37 +243,21 @@ class Controller {
this.model.gitCommit(msg.value).then( this.model.gitCommit(msg.value).then(
function (value) { function (value) {
this.updateFileStats(); this.updateFileStats();
this.model.gitPush(gitUser.value, gitPass.value).then( this.gitPush(gitUser.value, gitPass.value);
function (value) {
localStorage.setItem("pushError", "false");
loading.style.removeProperty("display");
this.view.closeDialog();
this.view.errorPublish();
}.bind(this), }.bind(this),
function (error) { function (error) {
console.log(error); console.log(error);
if (error == "HttpError: HTTP Error: 401 Unauthorized") {
this.view.errorPublish(
"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");
localStorage.setItem("pushError", "true");
}.bind(this)
); );
}.bind(this), }.bind(this),
function (error) { function (error) {
console.log(error); console.log(error);
} }
); );
}.bind(this),
function (error) {
console.log(error);
} }
); }
openPublish() {
this.view.openPublish();
} }
} }

@ -47,7 +47,7 @@ class Model {
var baseDir = dir; var baseDir = dir;
} }
var tree = await this.dirList(baseDir); var tree = await this.dirList(baseDir);
this.dirTree = tree;
return tree; return tree;
} }
@ -85,9 +85,10 @@ class Model {
/* ================== Controls ================== */ /* ================== Controls ================== */
wipeFS() { async wipeFS() {
delete window.fs; delete window.fs;
window.fs = new LightningFS("fs", { wipe: true }); window.fs = new LightningFS("fs", { wipe: true });
await this.getDirTree();
} }
async cloneRep() { async cloneRep() {
@ -100,6 +101,8 @@ class Model {
url: localStorage.getItem("repo"), url: localStorage.getItem("repo"),
corsProxy: "https://cors.isomorphic-git.org", corsProxy: "https://cors.isomorphic-git.org",
}); });
await this.getDirTree();
} }
async pullRep() { async pullRep() {
@ -113,13 +116,14 @@ class Model {
email: localStorage.getItem("email"), email: localStorage.getItem("email"),
}, },
}); });
await this.getDirTree();
} }
async gitAddAll(dirTree) { async gitAddAll(dirTree) {
if (!dirTree) { if (!dirTree) {
dirTree = await this.getDirTree(); dirTree = await this.getDirTree();
} }
for (let i = 1; i < dirTree.length; i++) { /* for (let i = 1; i < dirTree.length; i++) {
if (Array.isArray(dirTree[i])) { if (Array.isArray(dirTree[i])) {
await this.gitAddAll(dirTree[i]); await this.gitAddAll(dirTree[i]);
} else { } else {
@ -130,7 +134,12 @@ class Model {
}); });
console.log(dirTree[0].substring(1) + dirTree[i]); console.log(dirTree[0].substring(1) + dirTree[i]);
} }
} } */
await git.add({
fs,
dir,
filepath: ".",
});
} }
async gitCommit(msg) { async gitCommit(msg) {
@ -168,11 +177,12 @@ class Model {
localStorage.setItem("repo", repoURL); localStorage.setItem("repo", repoURL);
} }
setBaseDir(baseDir) { async setBaseDir(baseDir) {
if (!baseDir.endsWith("/")) { if (!baseDir.endsWith("/")) {
baseDir += "/"; baseDir += "/";
} }
localStorage.setItem("baseDir", baseDir); localStorage.setItem("baseDir", baseDir);
await this.getDirTree();
} }
setName(name) { setName(name) {
localStorage.setItem("name", name); localStorage.setItem("name", name);

@ -53,9 +53,11 @@ class View {
skip += 2; skip += 2;
} else { } else {
if (dirtree[i] != "unmodified") { if (dirtree[i] != "unmodified") {
li[skip].style.backgroundColor = "red"; li[skip].style.backgroundColor = "#008080";
li[skip].style.color = "white";
} else { } else {
li[skip].style.removeProperty("background-color"); li[skip].style.removeProperty("background-color");
li[skip].style.removeProperty("color");
} }
skip += 1; skip += 1;
@ -138,11 +140,15 @@ class View {
/* ------------------ Publish ------------------ */ /* ------------------ Publish ------------------ */
openPublish() { openPublish(changedFiles) {
this.closeDialog();
this.closeEditor(); this.closeEditor();
var publish = document.getElementsByClassName("commitWrapper")[0]; var publish = document.getElementsByClassName("commitWrapper")[0];
publish.style.display = "grid"; publish.style.display = "grid";
let gitMsg = document.getElementById("inputCommitMsg");
gitMsg.disabled = localStorage.getItem("pushError") == "true";
} }
errorPublish(error) { errorPublish(error) {