Skip to content

Commit fb179e3

Browse files
committed
Fixed the bug angular-ui-tree#101
1 parent 1ff9a99 commit fb179e3

File tree

11 files changed

+51
-15
lines changed

11 files changed

+51
-15
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-ui-tree",
3-
"version": "2.0.7",
3+
"version": "2.0.8",
44
"homepage": "https://github.com/JimLiu/angular-ui-tree",
55
"authors": [
66
"Jim Liu <https://github.com/JimLiu>",

demo/dist/angular-ui-tree.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @license Angular UI Tree v2.0.7
2+
* @license Angular UI Tree v2.0.8
33
* (c) 2010-2014. https://github.com/JimLiu/angular-ui-tree
44
* License: MIT
55
*/
@@ -346,6 +346,15 @@
346346
$scope.$nodes.splice(subNode.index(), 0, subNode);
347347
};
348348

349+
$scope.reinitNodes = function() {
350+
var nodes = $scope.$nodes.splice(0);
351+
$scope.$nodes = [];
352+
for (var i = 0; i < nodes.length; i++) {
353+
var node = nodes[i];
354+
$scope.$nodes.splice(node.index(), 0, node);
355+
}
356+
};
357+
349358
$scope.accept = function(sourceNode, destIndex) {
350359
return $scope.$treeScope.$callbacks.accept(sourceNode, $scope, destIndex);
351360
};
@@ -681,9 +690,10 @@
681690
scope.$treeScope = treeCtrl.scope;
682691

683692
if (ngModel) {
684-
ngModel.$render = function() {
693+
scope.$watch(attrs.ngModel, function() {
685694
scope.$modelValue = ngModel.$modelValue;
686-
};
695+
scope.reinitNodes(); // we have to keep syncing with $nodes array
696+
}, true);
687697
}
688698

689699
scope.$watch(function() {

demo/dist/angular-ui-tree.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo/js/tree.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
scope.toggle();
1313
};
1414

15+
$scope.moveLastToTheBegginig = function () {
16+
var a = $scope.data.pop();
17+
$scope.data.splice(0,0, a);
18+
};
19+
1520
$scope.newSubItem = function(scope) {
1621
var nodeData = scope.$modelValue;
1722
nodeData.nodes.push({

demo/tree.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ <h1 class="page-header">Tree - demo</h1>
2020
<h3>Tree view
2121
<a href="" class="btn btn-default pull-right" ng-click="collapseAll()">Collapse all</a>
2222
<a href="" class="btn btn-default pull-right" ng-click="expandAll()">Expand all</a>
23+
<a href="" class="btn btn-default btn-warning pull-right" ng-click="moveLastToTheBegginig()">Move Last To The Begginig</a>
2324

2425
</h3>
2526

dist/angular-ui-tree.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @license Angular UI Tree v2.0.7
2+
* @license Angular UI Tree v2.0.8
33
* (c) 2010-2014. https://github.com/JimLiu/angular-ui-tree
44
* License: MIT
55
*/
@@ -346,6 +346,15 @@
346346
$scope.$nodes.splice(subNode.index(), 0, subNode);
347347
};
348348

349+
$scope.reinitNodes = function() {
350+
var nodes = $scope.$nodes.splice(0);
351+
$scope.$nodes = [];
352+
for (var i = 0; i < nodes.length; i++) {
353+
var node = nodes[i];
354+
$scope.$nodes.splice(node.index(), 0, node);
355+
}
356+
};
357+
349358
$scope.accept = function(sourceNode, destIndex) {
350359
return $scope.$treeScope.$callbacks.accept(sourceNode, $scope, destIndex);
351360
};
@@ -681,9 +690,10 @@
681690
scope.$treeScope = treeCtrl.scope;
682691

683692
if (ngModel) {
684-
ngModel.$render = function() {
693+
scope.$watch(attrs.ngModel, function() {
685694
scope.$modelValue = ngModel.$modelValue;
686-
};
695+
scope.reinitNodes(); // we have to keep syncing with $nodes array
696+
}, true);
687697
}
688698

689699
scope.$watch(function() {

dist/angular-ui-tree.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Angular-NestedSortable",
3-
"version": "2.0.7",
3+
"version": "2.0.8",
44
"dependencies": {
55
"grunt": "~0.4.2",
66
"grunt-contrib-jshint": "~0.8.0",

source/controllers/nodesCtrl.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@
2121
$scope.$nodes.splice(subNode.index(), 0, subNode);
2222
};
2323

24+
$scope.reinitNodes = function() {
25+
var nodes = $scope.$nodes.splice(0);
26+
$scope.$nodes = [];
27+
for (var i = 0; i < nodes.length; i++) {
28+
var node = nodes[i];
29+
$scope.$nodes.splice(node.index(), 0, node);
30+
}
31+
};
32+
2433
$scope.accept = function(sourceNode, destIndex) {
2534
return $scope.$treeScope.$callbacks.accept(sourceNode, $scope, destIndex);
2635
};

source/directives/uiTreeNodes.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@
3030
scope.$treeScope = treeCtrl.scope;
3131

3232
if (ngModel) {
33-
ngModel.$render = function() {
33+
scope.$watch(attrs.ngModel, function() {
3434
scope.$modelValue = ngModel.$modelValue;
35-
};
35+
scope.reinitNodes(); // we have to keep syncing with $nodes array
36+
}, true);
3637
}
3738

3839
scope.$watch(function() {

source/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @license Angular UI Tree v2.0.7
2+
* @license Angular UI Tree v2.0.8
33
* (c) 2010-2014. https://github.com/JimLiu/angular-ui-tree
44
* License: MIT
55
*/

0 commit comments

Comments
 (0)