pridan pull pri initu aplikace, pridano nastaveni, uprava interakce

master
David Zálešák 4 years ago
parent 3b6cbc143f
commit dcfaef47a6

@ -22,18 +22,18 @@ ul:nth-child(1) {
padding: 1em 1em;
}
li:hover {
aside li:hover {
background-color: rgb(0, 0, 130);
color: white;
}
li {
aside li {
cursor: pointer;
user-select: none;
white-space: nowrap;
}
li::before {
aside li::before {
content: "";
color: black;
display: inline-block;
@ -117,7 +117,8 @@ sub {
float: right;
}
.settingsbg {
.settingsbg,
.commitWrapper {
position: absolute;
background-color: rgba(0, 0, 0, 0.75);
width: 100%;
@ -128,10 +129,10 @@ sub {
z-index: 5;
}
.settings {
.settings,
.commit {
background-color: white;
width: 30vw;
height: 30vh;
padding: 1.5em;
border: 5px solid #c3c3c3;
z-index: 10;

@ -24,6 +24,7 @@
<nav>
<button class="clone">Clone</button>
<button class="wipe">Wipe FS</button>
<button class="publishBtn">Publikovat (Commit & Push)</button>
<button class="settingsBtn">Settings</button>
</nav>
<aside>
@ -53,9 +54,24 @@
<div id="settingsClose" class="close">X</div>
<form action="javascript:void(0);">
<label for="inputRepository">Git repository:</label>
<input type="text" id="inputRepository">
<input type="text" id="inputRepository" required>
<label for="inputBaseDir">Base directory:</label>
<input type="text" id="inputBaseDir">
<label for="inputName">Name:</label>
<input type="text" id="inputName" required>
<label for="inputEmail">Email:</label>
<input type="email" id="inputEmail" required>
<button id="settingsSubmit">Submit</button>
<button id="settingsCancel" class="close">Cancel</button>
</form>
</div>
</div>
<div class="commitWrapper">
<div class="commit">
<div id="settingsClose" class="close">X</div>
<form action="javascript:void(0);">
<label for="inputCommitMsg">Poznámka k úpravám:</label>
<input type="text" id="inputCommitMsg">
<button id="settingsSubmit">Submit</button>
<button id="settingsCancel" class="close">Cancel</button>
</form>

@ -4,7 +4,45 @@ class Controller {
this.view = view;
this.redrawDirTree(view);
//this.pullRep();
this.addListeners();
this.init();
}
init() {
let repo = localStorage.getItem("repo");
let name = localStorage.getItem("name");
let email = localStorage.getItem("email");
if (
repo == null ||
name == null ||
email == null ||
repo == "" ||
name == "" ||
email == ""
) {
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);
}
);
}
}
addListeners() {
var cloneBtn = document.getElementsByClassName("clone")[0];
var purgeBtn = document.getElementsByClassName("wipe")[0];
var settingsBtn = document.getElementsByClassName("settingsBtn")[0];
@ -14,12 +52,18 @@ class Controller {
cloneBtn.addEventListener("click", this.cloneRep.bind(this));
purgeBtn.addEventListener("click", this.wipeFS.bind(this));
settingsBtn.addEventListener("click", view.openSettings.bind(this));
settingsBtn.addEventListener(
"click",
this.view.openSettings.bind(this.view)
);
for (let i = 0; i < settingsClose.length; i++) {
settingsClose[i].addEventListener("click", view.closeSettings.bind(this));
settingsClose[i].addEventListener(
"click",
this.view.closeSettings.bind(this)
);
}
settingsSubmit.addEventListener("click", this.saveSettings.bind(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));
}
@ -35,7 +79,7 @@ class Controller {
this.redrawDirTree(this.view);
}
cloneRep(repurl) {
cloneRep() {
var loading = document.getElementsByClassName("loading")[0];
loading.style.display = "grid";
this.model.cloneRep().then(
@ -43,7 +87,23 @@ class Controller {
loading.style.removeProperty("display");
this.redrawDirTree(this.view);
}.bind(this),
function (error) {}
function (error) {
console.log(error);
}
);
}
pullRep() {
var loading = document.getElementsByClassName("loading")[0];
loading.style.display = "grid";
this.model.pullRep().then(
function (value) {
loading.style.removeProperty("display");
this.redrawDirTree(this.view);
}.bind(this),
function (error) {
console.log(error);
}
);
}
@ -55,7 +115,9 @@ class Controller {
view.dirTreeToggler();
this.updateFileStats();
}.bind(this),
function (error) {}
function (error) {
console.log(error);
}
);
}
@ -63,7 +125,6 @@ class Controller {
this.model.getGitStatusTree().then(
function (value) {
this.view.statDirTree(value, undefined);
console.log(value);
}.bind(this),
function (error) {
console.log(error);
@ -74,13 +135,28 @@ class Controller {
saveSettings() {
let repo = document.getElementById("inputRepository");
let baseDir = document.getElementById("inputBaseDir");
let name = document.getElementById("inputName");
let email = document.getElementById("inputEmail");
let oldRepoURL = localStorage.getItem("repo");
this.model.setRepo(repo.value);
this.model.setBaseDir(baseDir.value);
this.model.setName(name.value);
this.model.setEmail(email.value);
this.redrawDirTree(this.view);
if (repo.value == "" || name.value == "" || email.value == "") {
this.view.openSettings();
return;
}
if (repo.value != oldRepoURL) {
// udělej clone
this.cloneRep();
} else {
// udelej jenom pull
this.pullRep();
}
this.view.closeSettings();
console.log(repo.value);
}
loadFile(file) {
@ -90,7 +166,9 @@ class Controller {
this.openedFileValue = value;
this.view.openFile(value);
}.bind(this),
function (error) {}
function (error) {
console.log(error);
}
);
}

@ -90,6 +90,19 @@ class Model {
});
}
async pullRep() {
await git.pull({
fs,
http,
dir,
fastForwardOnly: true,
author: {
name: localStorage.getItem("name"),
email: localStorage.getItem("email"),
},
});
}
setRepo(repoURL) {
localStorage.setItem("repo", repoURL);
}
@ -100,6 +113,13 @@ class Model {
}
localStorage.setItem("baseDir", baseDir);
}
async setName(name) {
localStorage.setItem("name", name);
}
async setEmail(email) {
localStorage.setItem("email", email);
}
readFile(file) {
return pfs.readFile(file, "utf8");

@ -50,7 +50,7 @@ class View {
this.statDirTree(dirtree[i], li[skip + 1]);
skip += 2;
} else {
if (dirtree[i] == "*modified") {
if (dirtree[i] != "unmodified") {
li[skip].style.backgroundColor = "red";
} else {
li[skip].style.removeProperty("background-color");
@ -68,6 +68,11 @@ class View {
this.simplemde.value(fileread);
}
closeEditor() {
var editText = document.getElementById("editText");
editText.style.removeProperty("display");
}
removeDirTree() {
let mainul = document.getElementsByTagName("ul")[0];
while (mainul.firstChild) {
@ -96,14 +101,20 @@ class View {
}
openSettings() {
this.closeEditor();
var settings = document.getElementsByClassName("settingsbg")[0];
settings.style.display = "grid";
let repo = document.getElementById("inputRepository");
let baseDir = document.getElementById("inputBaseDir");
let name = document.getElementById("inputName");
let email = document.getElementById("inputEmail");
repo.value = localStorage.getItem("repo");
baseDir.value = localStorage.getItem("baseDir");
name.value = localStorage.getItem("name");
email.value = localStorage.getItem("email");
}
closeSettings() {