@@ -28,7 +28,7 @@ export class NodeTreeComponent implements OnInit {
2828 }
2929
3030 hasLeaf ( ) : boolean {
31- return ( ( this . node . childs != null ) && ( this . node . childs . length > 0 ) ) ;
31+ return ( ( this . node . children != null ) && ( this . node . children . length > 0 ) ) ;
3232 }
3333
3434 hasParent ( ) : boolean {
@@ -55,6 +55,9 @@ export class NodeTreeComponent implements OnInit {
5555 this . node . firstNode = this . firstNode ;
5656 this . node . lastNode = this . lastNode ;
5757 console . log ( "el node " + this . node . name + " te lastNode " + this . node . lastNode ) ;
58+ if ( this . node . children == null ) {
59+ this . node . children = [ ] ;
60+ }
5861 if ( this . node . ancestors == null ) {
5962 this . node . ancestors = [ ] ;
6063 }
@@ -82,16 +85,16 @@ export class NodeTreeComponent implements OnInit {
8285 }
8386
8487 if ( parentTree != null ) {
85- const nodeIndex = parentTree . childs . indexOf ( this . node ) ;
88+ const nodeIndex = parentTree . children . indexOf ( this . node ) ;
8689 const siblingIndex = nodeIndex - 1 ;
87- const siblingNode = parentTree . childs [ siblingIndex ] ;
90+ const siblingNode = parentTree . children [ siblingIndex ] ;
8891
8992 console . log ( 'nodeIndex:' + nodeIndex ) ;
9093 console . log ( 'siblingIndex:' + siblingIndex ) ;
9194 console . log ( 'this.node.ancestors.length:' + this . node . ancestors . length ) ;
9295
93- parentTree . childs [ siblingIndex ] = this . node ;
94- parentTree . childs [ nodeIndex ] = siblingNode ;
96+ parentTree . children [ siblingIndex ] = this . node ;
97+ parentTree . children [ nodeIndex ] = siblingNode ;
9598
9699 this . reloadFirstAndLastNode ( parentTree , parentTree . firstNode , parentTree . lastNode ) ;
97100 }
@@ -107,16 +110,16 @@ export class NodeTreeComponent implements OnInit {
107110 }
108111
109112 if ( parentTree != null ) {
110- const nodeIndex = parentTree . childs . indexOf ( this . node ) ;
113+ const nodeIndex = parentTree . children . indexOf ( this . node ) ;
111114 const siblingIndex = nodeIndex + 1 ;
112- const siblingNode = parentTree . childs [ siblingIndex ] ;
115+ const siblingNode = parentTree . children [ siblingIndex ] ;
113116
114117 console . log ( 'nodeIndex:' + nodeIndex ) ;
115118 console . log ( 'siblingIndex:' + siblingIndex ) ;
116- console . log ( 'parentTree.childs .length:' + parentTree . childs . length ) ;
119+ console . log ( 'parentTree.children .length:' + parentTree . children . length ) ;
117120
118- parentTree . childs [ siblingIndex ] = this . node ;
119- parentTree . childs [ nodeIndex ] = siblingNode ;
121+ parentTree . children [ siblingIndex ] = this . node ;
122+ parentTree . children [ nodeIndex ] = siblingNode ;
120123
121124 this . reloadFirstAndLastNode ( parentTree , parentTree . firstNode , parentTree . lastNode ) ;
122125 }
@@ -138,24 +141,24 @@ export class NodeTreeComponent implements OnInit {
138141
139142 if ( parentTree != null && grandParentTree != null ) {
140143
141- let ancestorsSecondLevel : Node [ ] = grandParentTree . childs ;
142- let childsSecondLevel : Node [ ] = [ ] ;
144+ let ancestorsSecondLevel : Node [ ] = grandParentTree . children ;
145+ let childrenSecondLevel : Node [ ] = [ ] ;
143146 for ( let ancestor of ancestorsSecondLevel ) {
144- childsSecondLevel . push ( ancestor ) ;
147+ childrenSecondLevel . push ( ancestor ) ;
145148 if ( ancestor === parentTree ) {
146- childsSecondLevel . push ( this . node ) ;
149+ childrenSecondLevel . push ( this . node ) ;
147150 }
148151 }
149- grandParentTree . childs = childsSecondLevel ;
152+ grandParentTree . children = childrenSecondLevel ;
150153
151- let ancestorsFirstLevel : Node [ ] = parentTree . childs ;
152- let childsFirstLevel : Node [ ] = [ ] ;
154+ let ancestorsFirstLevel : Node [ ] = parentTree . children ;
155+ let childrenFirstLevel : Node [ ] = [ ] ;
153156 for ( let ancestor of ancestorsFirstLevel ) {
154157 if ( ! ( ancestor === this . node ) ) {
155- childsFirstLevel . push ( ancestor ) ;
158+ childrenFirstLevel . push ( ancestor ) ;
156159 }
157160 }
158- parentTree . childs = childsFirstLevel ;
161+ parentTree . children = childrenFirstLevel ;
159162
160163 let ancestors : Node [ ] = [ ] ;
161164 for ( let ancestor of this . node . ancestors ) {
@@ -165,6 +168,8 @@ export class NodeTreeComponent implements OnInit {
165168 }
166169 this . node . ancestors = ancestors ;
167170
171+ this . removeParentMovedInChildren ( this . node , parentTree ) ;
172+
168173 this . reloadFirstAndLastNode ( grandParentTree , grandParentTree . firstNode , grandParentTree . lastNode ) ;
169174 }
170175 }
@@ -173,12 +178,27 @@ export class NodeTreeComponent implements OnInit {
173178 let i = 0 ;
174179 node . firstNode = firstNode ;
175180 node . lastNode = lastNode ;
176- if ( node . childs != null && node . childs . length > 0 ) {
177- for ( let child of node . childs ) {
178- this . reloadFirstAndLastNode ( child , i === 0 , i === node . childs . length - 1 ) ;
181+ if ( node . children != null && node . children . length > 0 ) {
182+ for ( let child of node . children ) {
183+ this . reloadFirstAndLastNode ( child , i === 0 , i === node . children . length - 1 ) ;
179184 i ++ ;
180185 }
181186 }
182187 }
183188
189+ removeParentMovedInChildren ( node : Node , parent : Node ) {
190+ for ( let child of node . children ) {
191+ let ancestors : Node [ ] = [ ] ;
192+ for ( let ancestorChild of child . ancestors ) {
193+ if ( ! ( ancestorChild === parent ) ) {
194+ ancestors . push ( ancestorChild ) ;
195+ }
196+ }
197+ child . ancestors = ancestors ;
198+ if ( child . children . length > 0 ) {
199+ this . removeParentMovedInChildren ( child , parent ) ;
200+ }
201+ }
202+ }
203+
184204}
0 commit comments