oznaceni polozek v dirtree podle git statusu

master
David Zálešák 4 years ago
parent 9f31a4f171
commit dd73924bbf

@ -57,11 +57,24 @@ class Controller {
view.removeDirTree(); view.removeDirTree();
view.drawDirTree(value, undefined, this); view.drawDirTree(value, undefined, this);
view.dirTreeToggler(); view.dirTreeToggler();
this.updateFileStats();
}.bind(this), }.bind(this),
function (error) {} 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() { saveSettings() {
let repo = document.getElementById("inputRepository"); let repo = document.getElementById("inputRepository");
let baseDir = document.getElementById("inputBaseDir"); let baseDir = document.getElementById("inputBaseDir");
@ -89,6 +102,8 @@ class Controller {
var textArea = document.getElementsByTagName("textarea")[0]; var textArea = document.getElementsByTagName("textarea")[0];
this.model.saveFile(this.openedFile, textArea.value); this.model.saveFile(this.openedFile, textArea.value);
this.openedFileValue = textArea.value; this.openedFileValue = textArea.value;
this.saveButton() this.saveButton();
this.updateFileStats();
} }
} }

@ -49,6 +49,30 @@ class Model {
return tree; return tree;
} }
async getGitStatusTree() {
var dirtree = await this.getDirTree();
var tree = await this.dirGitStatus(dirtree);
return tree;
}
async dirGitStatus(list) {
let dirlist = [list[0]];
for (let i = 1; i < list.length; i++) {
if (Array.isArray(list[i])) {
await this.dirGitStatus(list[i]);
} else {
list[i] = await git.status({
fs,
dir,
filepath: list[0].substring(1) + list[i],
});
}
}
return list;
}
wipeFS() { wipeFS() {
delete window.fs; delete window.fs;
window.fs = new LightningFS("fs", { wipe: true }); window.fs = new LightningFS("fs", { wipe: true });

@ -32,6 +32,28 @@ class View {
} }
} }
} }
statDirTree(
dirtree,
ulToAdd = document.getElementsByTagName("ul")[0].children[1]
) {
var li = ulToAdd.children;
var skip = 0;
for (let i = 1; i < dirtree.length; i++) {
if (Array.isArray(dirtree[i])) {
this.statDirTree(dirtree[i], li[skip + 1]);
skip += 2;
} else {
if (dirtree[i] == "*modified") {
li[skip].style.backgroundColor = "red";
} else {
li[skip].style.removeProperty("background-color");
}
skip += 1;
}
}
} }
openFile(fileread) { openFile(fileread) {