You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

110 lines
3.1 KiB
JavaScript

class Controller {
constructor(model, view) {
this.model = model;
this.view = view;
this.redrawDirTree(view);
var cloneBtn = document.getElementsByClassName("clone")[0];
var purgeBtn = document.getElementsByClassName("wipe")[0];
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));
settingsBtn.addEventListener("click", view.openSettings.bind(this));
for (let i = 0; i < settingsClose.length; i++) {
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() {
this.model.wipeFS();
//window.location.reload();
this.redrawDirTree(this.view);
}
cloneRep(repurl) {
var loading = document.getElementsByClassName("loading")[0];
loading.style.display = "grid";
this.model.cloneRep().then(
function (value) {
loading.style.removeProperty("display");
this.redrawDirTree(this.view);
}.bind(this),
function (error) {}
);
}
redrawDirTree(view) {
this.model.getDirTree().then(
function (value) {
view.removeDirTree();
view.drawDirTree(value, undefined, this);
view.dirTreeToggler();
this.updateFileStats();
}.bind(this),
function (error) {}
);
}
updateFileStats() {
this.model.getGitStatusTree().then(
function (value) {
this.view.statDirTree(value, undefined);
console.log(value);
}.bind(this),
function (error) {
console.log(error);
}
);
}
saveSettings() {
let repo = document.getElementById("inputRepository");
let baseDir = document.getElementById("inputBaseDir");
this.model.setRepo(repo.value);
this.model.setBaseDir(baseDir.value);
this.redrawDirTree(this.view);
this.view.closeSettings();
console.log(repo.value);
}
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();
this.updateFileStats();
}
}