From dd73924bbf3d344fa0a9669de1912395b4b55216 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Z=C3=A1le=C5=A1=C3=A1k?= Date: Tue, 29 Dec 2020 01:53:11 +0100 Subject: [PATCH] oznaceni polozek v dirtree podle git statusu --- js/controller.js | 17 ++++++++++++++++- js/model.js | 24 ++++++++++++++++++++++++ js/view.js | 22 ++++++++++++++++++++++ 3 files changed, 62 insertions(+), 1 deletion(-) 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) {