Skip to content

Commit fdfe911

Browse files
committed
Prevents child node scope with no children to be counted in depth.
1 parent 1066ac2 commit fdfe911

File tree

2 files changed

+192
-1
lines changed

2 files changed

+192
-1
lines changed

source/controllers/nodeCtrl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
for (i = 0; i < nodes.length; i++) {
122122
childNodes = nodes[i].$childNodesScope;
123123

124-
if (childNodes) {
124+
if (childNodes && childNodes.childNodesCount() > 0) {
125125
count = 1;
126126
countSubDepth(childNodes);
127127
}

tests/treeNodeCtrl.spec.js

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
describe('treeCtrl', function () {
2+
3+
var scope, $compile, attrs;
4+
var element;
5+
6+
beforeEach(module('ui.tree'));
7+
8+
beforeEach(inject(function ($rootScope, _$controller_, _$compile_) {
9+
scope = $rootScope;
10+
$controller = _$controller_;
11+
$compile = _$compile_;
12+
13+
// TODO: move test element + data to a generic module so we can reuse it for other tests
14+
element = angular.element('<div ui-tree="options">' +
15+
'<ol ui-tree-nodes ng-model="list">' +
16+
'<li ng-repeat="item in list" ui-tree-node="">' +
17+
'<div ui-tree-handle>' +
18+
'{{item.title}}' +
19+
'</div>' +
20+
'<ol ui-tree-nodes="" ng-model="item.items">' +
21+
'<li ng-repeat="subItem in item.items" ui-tree-node="">' +
22+
'<div ui-tree-handle>' +
23+
'{{subItem.title}}' +
24+
'</div>' +
25+
'<ol ui-tree-nodes="" ng-model="subItem.items">' +
26+
'<li ng-repeat="subItem1 in subItem.items" ui-tree-node="">' +
27+
'<div ui-tree-handle>' +
28+
'{{subItem.title}}' +
29+
'</div>' +
30+
'<ol ui-tree-nodes="" ng-model="subItem1.items">' +
31+
'<li ng-repeat="subItem2 in subItem1.items" ui-tree-node="">' +
32+
'<div ui-tree-handle>' +
33+
'{{subItem1.title}}' +
34+
'</div>' +
35+
'</li>' +
36+
'</ol>' +
37+
'</li>' +
38+
'</ol>' +
39+
'</li>' +
40+
'</ol>' +
41+
'</li>' +
42+
'</ol>' +
43+
'</div>');
44+
45+
46+
scope.list = [
47+
{
48+
"id": 1,
49+
"title": "item1",
50+
"items": []
51+
},
52+
{
53+
"id": 2,
54+
"title": "item2",
55+
"items": [
56+
{
57+
"id": 21,
58+
"title": "item2.1",
59+
"items": [
60+
{
61+
"id": 211,
62+
"title": "item2.1.1",
63+
"items": []
64+
},
65+
{
66+
"id": 212,
67+
"title": "item2.1.2",
68+
"items": []
69+
},
70+
{
71+
"id": 213,
72+
"title": "item2.1.3",
73+
"items": []
74+
}
75+
]
76+
},
77+
{
78+
"id": 22,
79+
"title": "item2.2",
80+
"items": []
81+
},
82+
{
83+
"id": 23,
84+
"title": "item2.3",
85+
"items": [
86+
{
87+
"id": 231,
88+
"title": "item2.3.1",
89+
"items": []
90+
},
91+
{
92+
"id": 232,
93+
"title": "item2.3.2",
94+
"items": []
95+
},
96+
{
97+
"id": 233,
98+
"title": "item2.3.3",
99+
"items": []
100+
}
101+
]
102+
},
103+
{
104+
"id": 24,
105+
"title": "item2.4",
106+
"items": [
107+
{
108+
"id": 241,
109+
"title": "item2.4.1",
110+
"items": []
111+
},
112+
{
113+
"id": 242,
114+
"title": "item2.4.2",
115+
"items": []
116+
},
117+
{
118+
"id": 243,
119+
"title": "item2.4.3",
120+
"items": []
121+
},
122+
{
123+
"id": 244,
124+
"title": "item2.4.4",
125+
"items": []
126+
}
127+
]
128+
}
129+
]
130+
},
131+
{
132+
"id": 3,
133+
"title": "item3",
134+
"items": [
135+
{
136+
"id": 31,
137+
"title": "item3.1",
138+
"items": []
139+
},
140+
{
141+
"id": 32,
142+
"title": "item3.2",
143+
"items": []
144+
},
145+
{
146+
"id": 33,
147+
"title": "item3.3",
148+
"items": [
149+
{
150+
"id": 331,
151+
"title": "item3.3.1",
152+
"items": []
153+
},
154+
{
155+
"id": 332,
156+
"title": "item3.3.2",
157+
"items": []
158+
},
159+
{
160+
"id": 333,
161+
"title": "item3.3.3",
162+
"items": []
163+
}
164+
]
165+
}
166+
]
167+
},
168+
{
169+
"id": 4,
170+
"title": "item4",
171+
"items": []
172+
}
173+
];
174+
}));
175+
176+
function createTree() {
177+
$compile(element)(scope);
178+
scope.$digest();
179+
return element;
180+
}
181+
182+
it('should not include in depth calculation child node scopes with no children', function () {
183+
tree = createTree();
184+
localScope = angular.element(tree.children('ol').first()).scope();
185+
186+
expect(localScope.childNodes()[1].maxSubDepth()).toEqual(1)
187+
188+
});
189+
});
190+
191+

0 commit comments

Comments
 (0)