Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.

Commit 6a05d60

Browse files
authored
Merge pull request #138 from symfony-cmf/issue-135/load-nodes-before-activating
Load nodes before activating them
2 parents 98a51f9 + a9ed5d1 commit 6a05d60

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/Resources/assets/js/adapter/fancytree.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,19 @@ export class FancytreeAdapter {
110110
return requestNodeToFancytreeNode(requestNode.children[Object.keys(requestNode.children)[0]]);
111111
}
112112

113-
var key = "" + jQuery.ui.fancytree._nextNodeKey++;
113+
var refPath = requestNode.path.replace('\/', '/').replace('//', '/');
114+
var key = this.pathKeyMap[refPath] || "" + jQuery.ui.fancytree._nextNodeKey++;
114115
var fancytreeNode = {
115116
title: requestNode.label,
116117
key: key,
117118
children: [],
118119
actions: {},
119-
refPath: requestNode.path.replace('\/', '/').replace('//', '/'),
120+
refPath: refPath,
120121
type: requestNode.payload_type,
121122
unselectable: true
122123
};
123124

124-
this.pathKeyMap[fancytreeNode.refPath] = key;
125+
this.pathKeyMap[refPath] = key;
125126

126127
if (requestNode.descriptors.hasOwnProperty('icon')) {
127128
fancytreeNode.icon = requestNode.descriptors.icon;
@@ -311,7 +312,20 @@ export class FancytreeAdapter {
311312

312313
var showPath = (path) => {
313314
if (!this.pathKeyMap.hasOwnProperty(path)) {
314-
return;
315+
var parts = path.split('/');
316+
317+
while (!this.pathKeyMap.hasOwnProperty(parts.join('/')) && parts.pop());
318+
319+
if (parts.length === 0) {
320+
return;
321+
}
322+
323+
var loadedPath = parts.join('/');
324+
var pathsToLoad = path.substr(loadedPath.length + 1).split('/');
325+
326+
pathsToLoad.forEach((pathToLoad) => {
327+
this.pathKeyMap[loadedPath += '/' + pathToLoad] = "" + jQuery.ui.fancytree._nextNodeKey++;
328+
});
315329
}
316330

317331
this.tree.loadKeyPath(generateKeyPath(path), function (node, status) {

0 commit comments

Comments
 (0)