Skip to content

Commit fd5345f

Browse files
committed
Modified buildTree function so that sidebar tree is updated when user deletes a folder. See joni2back#9
1 parent d257882 commit fd5345f

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/js/services/filenavigator.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
self.buildTree(path);
6767
});
6868
};
69-
69+
7070
FileNavigator.prototype.buildTree = function(path) {
7171
function recursive(parent, item, path) {
7272
var absName = path ? (path + '/' + item.model.name) : item.model.name;
@@ -90,7 +90,23 @@
9090
});
9191
}
9292

93-
!this.history.length && this.history.push({name: path, nodes: []});
93+
!this.history.length && this.history.push({name: '', nodes: []});
94+
function flatten(node, array) {
95+
array.push(node);
96+
for(var n in node.nodes) {
97+
flatten(node.nodes[n],array);
98+
}
99+
}
100+
function findNode(data, path) {
101+
return data.filter(function (n) {
102+
return n.name === path;
103+
})[0];
104+
}
105+
var flatNodes = [];
106+
flatten(this.history[0],flatNodes);
107+
var selectedNode = findNode(flatNodes, path);
108+
selectedNode.nodes = [];
109+
94110
for (var o in this.fileList) {
95111
var item = this.fileList[o];
96112
item.isFolder() && recursive(this.history[0], item, path);

0 commit comments

Comments
 (0)