diff --git a/js/controller.js b/js/controller.js index 56fe687..ddd89cb 100644 --- a/js/controller.js +++ b/js/controller.js @@ -57,11 +57,24 @@ class Controller { 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"); @@ -89,6 +102,8 @@ class Controller { var textArea = document.getElementsByTagName("textarea")[0]; this.model.saveFile(this.openedFile, textArea.value); this.openedFileValue = textArea.value; - this.saveButton() + this.saveButton(); + + this.updateFileStats(); } } diff --git a/js/model.js b/js/model.js index 1e1a848..59fb264 100644 --- a/js/model.js +++ b/js/model.js @@ -49,6 +49,30 @@ class Model { 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() { delete window.fs; window.fs = new LightningFS("fs", { wipe: true }); diff --git a/js/view.js b/js/view.js index 63a0e5f..da1d136 100644 --- a/js/view.js +++ b/js/view.js @@ -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) {