From 4696151eef9b2525760dbe7fe12cd217a07863d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Z=C3=A1le=C5=A1=C3=A1k?= Date: Sat, 9 Jan 2021 14:19:35 +0100 Subject: [PATCH] ulozeni gitDirStatTree do promene --- js/controller.js | 24 ++++++++++++------------ js/model.js | 34 ++++++++++++++++++++-------------- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/js/controller.js b/js/controller.js index d8021ff..8c60701 100644 --- a/js/controller.js +++ b/js/controller.js @@ -80,14 +80,7 @@ class Controller { } updateFileStats() { - this.model.getGitStatusTree().then( - function (value) { - this.view.statDirTree(value, undefined); - }.bind(this), - function (error) { - console.log(error); - } - ); + this.view.statDirTree(this.model.gitDirTreeStat, undefined); } /* ================== Text Area ================== */ @@ -113,16 +106,23 @@ class Controller { saveFile() { var textArea = this.view.simplemde; - this.model.saveFile(this.openedFile, textArea.value()); - this.openedFileValue = textArea.value(); - this.saveButton(); + this.model.saveFile(this.openedFile, textArea.value()).then( + function() { + this.openedFileValue = textArea.value(); + this.view.closeEditor(); + this.saveButton(); - this.updateFileStats(); + this.updateFileStats(); + }.bind(this) + ); + } /* ================== Controls ================== */ wipeFS() { + this.view.closeEditor(); + this.model.wipeFS().then(function () { this.redrawDirTree(); }.bind(this)); diff --git a/js/model.js b/js/model.js index 1a9f36b..daa163c 100644 --- a/js/model.js +++ b/js/model.js @@ -48,29 +48,33 @@ class Model { } var tree = await this.dirList(baseDir); this.dirTree = tree; - return tree; + + await this.getGitStatusTree(); } async getGitStatusTree() { - var dirtree = await this.getDirTree(); - var tree = await this.dirGitStatus(dirtree); - - return tree; + this.gitDirTreeStat = await this.dirGitStatus(this.dirTree); } async dirGitStatus(list) { - for (let i = 1; i < list.length; i++) { + let statList = []; + for (let i = 0; i < list.length; i++) { if (Array.isArray(list[i])) { - await this.dirGitStatus(list[i]); + statList[i] = await this.dirGitStatus(list[i]); } else { - list[i] = await git.status({ - fs, - dir, - filepath: list[0].substring(1) + list[i], - }); + if (i == 0) { + statList[i] = list[0]; + } else { + statList[i] = await git.status({ + fs, + dir, + filepath: list[0].substring(1) + list[i], + }); + } } } - return list; + + return statList; } /* ================== Text Area ================== */ @@ -79,8 +83,10 @@ class Model { return pfs.readFile(file, "utf8"); } - saveFile(cesta, obsah) { + async saveFile(cesta, obsah) { pfs.writeFile(cesta, obsah, "utf8"); + + await this.getGitStatusTree(); } /* ================== Controls ================== */