1
- import { Component , Inject , NgZone , Input } from '@angular/core' ;
2
- import { NgIf , NgFor , NgStyle } from '@angular/common' ;
1
+ import { Component , Inject , NgZone , Input , SimpleChange } from '@angular/core' ;
2
+ import { NgIf , NgFor } from '@angular/common' ;
3
3
import * as Rx from 'rxjs' ;
4
4
import { ComponentDataStore }
5
5
from '../../stores/component-data/component-data-store' ;
@@ -10,7 +10,7 @@ import {UserActionType}
10
10
@Component ( {
11
11
selector : 'bt-node-item' ,
12
12
templateUrl : 'src/frontend/components/node-item/node-item.html' ,
13
- directives : [ NgIf , NgFor , NodeItem , NgStyle ]
13
+ directives : [ NgIf , NgFor , NodeItem ]
14
14
} )
15
15
/**
16
16
* Node Item
@@ -21,65 +21,18 @@ export class NodeItem {
21
21
22
22
@Input ( ) node : any ;
23
23
@Input ( ) changedNodes : any ;
24
+ @Input ( ) selectedNode : any ;
25
+ @Input ( ) openedNodes : Array < any > ;
24
26
25
27
private collapsed : any ;
26
- private color : any ;
27
- private borderColor : any ;
28
28
private isUpdated : boolean = false ;
29
+ private isSelected : boolean = false ;
29
30
30
31
constructor (
31
32
private userActions : UserActions ,
32
33
private componentDataStore : ComponentDataStore ,
33
34
private _ngZone : NgZone
34
- ) {
35
-
36
- this . borderColor = 'rgba(0, 0, 0, 0.125)' ;
37
- this . color = '#666' ;
38
-
39
- // Listen for changes in selected node
40
- this . componentDataStore . dataStream
41
- . filter ( ( data ) => {
42
- return data . action && data . action === UserActionType . SELECT_NODE &&
43
- data . selectedNode && data . selectedNode . id ;
44
- } )
45
- . map ( ( { selectedNode } : any ) => selectedNode )
46
- . subscribe ( ( selectedNode : any ) => {
47
- const isSelected = this . node && selectedNode &&
48
- selectedNode . id === this . node . id ;
49
- this . update ( isSelected ) ;
50
- } ) ;
51
-
52
- this . componentDataStore . dataStream
53
- . filter ( ( data : any ) => {
54
- return data . action && data . action === UserActionType . OPEN_CLOSE_TREE &&
55
- data . openedNodes . indexOf ( this . node . id ) > - 1 ;
56
- } )
57
- . subscribe ( ( data ) => {
58
- this . node . isOpen = false ;
59
- this . _ngZone . run ( ( ) => undefined ) ;
60
- } ) ;
61
-
62
- this . componentDataStore . dataStream
63
- . filter ( ( data : any ) => {
64
- return data . action && data . action === UserActionType . OPEN_CLOSE_TREE &&
65
- data . selectedNode . id === this . node . id ;
66
- } )
67
- . subscribe ( ( data ) => {
68
- this . userActions . selectNode ( { node : this . node } ) ;
69
- } ) ;
70
- }
71
-
72
- /**
73
- * Update the state of the node based on selection
74
- * @param {Boolean } isSelected
75
- */
76
- update ( isSelected ) {
77
- this . node . isSelected = isSelected ;
78
- this . borderColor = this . node . isSelected ? '#0074D9' :
79
- 'rgba(0, 0, 0, 0.125)' ;
80
- this . color = this . node . isSelected ? '#222' : '#888' ;
81
- this . _ngZone . run ( ( ) => undefined ) ;
82
- }
35
+ ) { }
83
36
84
37
getNodeDetails ( node ) {
85
38
@@ -128,7 +81,6 @@ export class NodeItem {
128
81
*/
129
82
onClick ( $event ) {
130
83
this . userActions . selectNode ( { node : this . node } ) ;
131
- this . _ngZone . run ( ( ) => undefined ) ;
132
84
$event . preventDefault ( ) ;
133
85
$event . stopPropagation ( ) ;
134
86
}
@@ -168,13 +120,21 @@ export class NodeItem {
168
120
$event . stopPropagation ( ) ;
169
121
}
170
122
171
- ngOnChanges ( ) {
172
- if ( this . changedNodes && this . node ) {
123
+ ngOnChanges ( changes ) {
124
+ if ( this . selectedNode && this . node ) {
125
+ this . isSelected = ( this . selectedNode . id === this . node . id ) ;
126
+ }
127
+ if ( changes . changedNodes && this . node ) {
173
128
this . isUpdated = this . changedNodes . indexOf ( this . node . id ) > 0 ;
174
129
setTimeout ( ( ) => {
175
130
this . isUpdated = false ;
176
131
} , 2000 ) ;
177
132
}
133
+ if ( this . openedNodes && this . node ) {
134
+ if ( this . openedNodes . indexOf ( this . node . id ) > - 1 ) {
135
+ this . node . isOpen = false ;
136
+ }
137
+ }
178
138
}
179
139
180
140
}
0 commit comments