From f1488f847a9e6897fa5e657c3b28dcd058a5f588 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Z=C3=A1le=C5=A1=C3=A1k?= Date: Sat, 9 Jan 2021 11:38:15 +0100 Subject: [PATCH] ulozeni dirtree do promene --- css/style.css | 5 +- favicon.ico | 0 js/controller.js | 171 +++++++++++++++++++++++++---------------------- js/model.js | 20 ++++-- js/view.js | 10 ++- 5 files changed, 118 insertions(+), 88 deletions(-) create mode 100644 favicon.ico diff --git a/css/style.css b/css/style.css index ab89188..9c3a88f 100644 --- a/css/style.css +++ b/css/style.css @@ -53,6 +53,10 @@ aside li::before { margin-right: 6px; } +.caret:hover::before { + color: white; +} + .container { display: grid; grid-template-columns: max-content auto; @@ -145,7 +149,6 @@ sub { .settings, .commit { background-color: white; - width: 30vw; padding: 1.5em; border: 5px solid #c3c3c3; z-index: 10; diff --git a/favicon.ico b/favicon.ico new file mode 100644 index 0000000..e69de29 diff --git a/js/controller.js b/js/controller.js index 11d0d1a..d8021ff 100644 --- a/js/controller.js +++ b/js/controller.js @@ -3,8 +3,12 @@ class Controller { this.model = model; this.view = view; - this.addListeners(); - this.init(); + model.getDirTree().then( + function () { + this.addListeners(); + this.init(); + }.bind(this) + ); } init() { @@ -22,23 +26,16 @@ class Controller { ) { this.view.openSettings(); } else { - this.model.getDirTree().then( - function (value) { - if (value.length == 1) { - //Nic nenaklonovaného, klonovat - this.cloneRep(); - } else { - //Udělat Pull - this.pullRep(); - } - }.bind(this), - function (error) { - console.log(error); - } - ); + if (this.model.dirTree.length == 1) { + //Nic nenaklonovaného, klonovat + this.cloneRep(); + } else { + //Udělat Pull + this.pullRep(); + } } - if (localStorage.getItem("pushError") != "false") { + if (localStorage.getItem("pushError") == "true") { this.view.openPublish(); this.view.errorPublish("Máte nepublikované změny: publikujte je."); } @@ -69,24 +66,17 @@ class Controller { settingsSubmit.addEventListener("click", this.saveSettings.bind(this)); this.view.simplemde.codemirror.on("change", this.saveButton.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)); } /* ================== 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); - } - ); + redrawDirTree() { + this.view.removeDirTree(); + this.view.drawDirTree(this.model.dirTree, undefined, this); + this.view.dirTreeToggler(); + this.updateFileStats(); } updateFileStats() { @@ -133,9 +123,9 @@ class Controller { /* ================== Controls ================== */ wipeFS() { - this.model.wipeFS(); - //window.location.reload(); - this.redrawDirTree(this.view); + this.model.wipeFS().then(function () { + this.redrawDirTree(); + }.bind(this)); } cloneRep() { @@ -143,8 +133,10 @@ class Controller { loading.style.display = "grid"; this.model.cloneRep().then( function (value) { + this.redrawDirTree(); loading.style.removeProperty("display"); - this.redrawDirTree(this.view); + localStorage.setItem("pushError", "false"); + this.view.errorPublish(); }.bind(this), function (error) { console.log(error); @@ -158,7 +150,7 @@ class Controller { this.model.pullRep().then( function (value) { loading.style.removeProperty("display"); - this.redrawDirTree(this.view); + this.redrawDirTree(); }.bind(this), function (error) { // 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 ================== */ /* ------------------ Settings ------------------ */ @@ -179,7 +196,11 @@ class Controller { let oldRepoURL = localStorage.getItem("repo"); 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.setEmail(email.value); @@ -191,8 +212,6 @@ class Controller { if (repo.value != oldRepoURL) { // udělej clone this.cloneRep(); - } else { - this.redrawDirTree(this.view); } this.view.closeDialog(); } @@ -203,50 +222,42 @@ class Controller { let msg = document.getElementById("inputCommitMsg"); let gitUser = document.getElementById("inputUser"); let gitPass = document.getElementById("inputPasswd"); - - if (msg.value == "" || gitUser.value == "" || gitPass.gitPass == "") { - return; - } - let loading = document.getElementsByClassName("publishLoading")[0]; - loading.style.display = "block"; - this.model.gitAddAll().then( - function (value) { - this.model.gitCommit(msg.value).then( - function (value) { - this.updateFileStats(); - this.model.gitPush(gitUser.value, gitPass.value).then( - function (value) { - localStorage.setItem("pushError", "false"); - loading.style.removeProperty("display"); - this.view.closeDialog(); - this.view.errorPublish(); - }.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." - ); - } - loading.style.removeProperty("display"); - localStorage.setItem("pushError", "true"); - }.bind(this) - ); - }.bind(this), - function (error) { - console.log(error); - } - ); - }.bind(this), - function (error) { - console.log(error); + 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 == "") { + this.view.errorPublish("Vyplňte potřebné údaje."); + return; + } + loading.style.display = "block"; + + this.model.gitAddAll().then( + function (value) { + this.model.gitCommit(msg.value).then( + function (value) { + this.updateFileStats(); + this.gitPush(gitUser.value, gitPass.value); + }.bind(this), + function (error) { + console.log(error); + } + ); + }.bind(this), + function (error) { + console.log(error); + } + ); + } + } + + openPublish() { + this.view.openPublish(); } } diff --git a/js/model.js b/js/model.js index 12b6591..1a9f36b 100644 --- a/js/model.js +++ b/js/model.js @@ -47,7 +47,7 @@ class Model { var baseDir = dir; } var tree = await this.dirList(baseDir); - + this.dirTree = tree; return tree; } @@ -85,9 +85,10 @@ class Model { /* ================== Controls ================== */ - wipeFS() { + async wipeFS() { delete window.fs; window.fs = new LightningFS("fs", { wipe: true }); + await this.getDirTree(); } async cloneRep() { @@ -100,6 +101,8 @@ class Model { url: localStorage.getItem("repo"), corsProxy: "https://cors.isomorphic-git.org", }); + + await this.getDirTree(); } async pullRep() { @@ -113,13 +116,14 @@ class Model { email: localStorage.getItem("email"), }, }); + await this.getDirTree(); } async gitAddAll(dirTree) { if (!dirTree) { 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])) { await this.gitAddAll(dirTree[i]); } else { @@ -130,7 +134,12 @@ class Model { }); console.log(dirTree[0].substring(1) + dirTree[i]); } - } + } */ + await git.add({ + fs, + dir, + filepath: ".", + }); } async gitCommit(msg) { @@ -168,11 +177,12 @@ class Model { localStorage.setItem("repo", repoURL); } - setBaseDir(baseDir) { + async setBaseDir(baseDir) { if (!baseDir.endsWith("/")) { baseDir += "/"; } localStorage.setItem("baseDir", baseDir); + await this.getDirTree(); } setName(name) { localStorage.setItem("name", name); diff --git a/js/view.js b/js/view.js index 6ad9ff2..8dcba88 100644 --- a/js/view.js +++ b/js/view.js @@ -53,9 +53,11 @@ class View { skip += 2; } else { if (dirtree[i] != "unmodified") { - li[skip].style.backgroundColor = "red"; + li[skip].style.backgroundColor = "#008080"; + li[skip].style.color = "white"; } else { li[skip].style.removeProperty("background-color"); + li[skip].style.removeProperty("color"); } skip += 1; @@ -138,11 +140,15 @@ class View { /* ------------------ Publish ------------------ */ - openPublish() { + openPublish(changedFiles) { + this.closeDialog(); this.closeEditor(); var publish = document.getElementsByClassName("commitWrapper")[0]; publish.style.display = "grid"; + + let gitMsg = document.getElementById("inputCommitMsg"); + gitMsg.disabled = localStorage.getItem("pushError") == "true"; } errorPublish(error) {