1
1
import { ApplicationRef , ComponentRef , Injectable , Type , ViewContainerRef } from '@angular/core' ;
2
- import { Column , CurrentFilter , Extension , ExtensionName , GridOption } from '../models/index' ;
2
+ import { Column , CurrentFilter , Extension , ExtensionName , GridOption , SlickEventHandler } from '../models/index' ;
3
3
import { ExtensionUtility } from './extensionUtility' ;
4
4
import { AngularUtilService } from '../services/angularUtilService' ;
5
5
import { FilterService } from '../services/filter.service' ;
@@ -24,8 +24,8 @@ export interface CreatedView {
24
24
@Injectable ( )
25
25
export class RowDetailViewExtension implements Extension {
26
26
rowDetailContainer : ViewContainerRef ;
27
- private _eventHandler : any = new Slick . EventHandler ( ) ;
28
- private _extension : any ;
27
+ private _addon : any ;
28
+ private _eventHandler : SlickEventHandler ;
29
29
private _preloadComponent : Type < object > ;
30
30
private _views : CreatedView [ ] = [ ] ;
31
31
private _viewComponent : Type < object > ;
@@ -38,14 +38,20 @@ export class RowDetailViewExtension implements Extension {
38
38
private extensionUtility : ExtensionUtility ,
39
39
private filterService : FilterService ,
40
40
private sharedService : SharedService ,
41
- ) { }
41
+ ) {
42
+ this . _eventHandler = new Slick . EventHandler ( ) ;
43
+ }
44
+
45
+ get eventHandler ( ) : SlickEventHandler {
46
+ return this . _eventHandler ;
47
+ }
42
48
43
49
dispose ( ) {
44
50
// unsubscribe all SlickGrid events
45
51
this . _eventHandler . unsubscribeAll ( ) ;
46
52
47
- if ( this . _extension && this . _extension . destroy ) {
48
- this . _extension . destroy ( ) ;
53
+ if ( this . _addon && this . _addon . destroy ) {
54
+ this . _addon . destroy ( ) ;
49
55
}
50
56
51
57
// also unsubscribe all RxJS subscriptions
@@ -67,7 +73,7 @@ export class RowDetailViewExtension implements Extension {
67
73
}
68
74
69
75
if ( gridOptions && gridOptions . rowDetailView ) {
70
- if ( ! this . _extension ) {
76
+ if ( ! this . _addon ) {
71
77
if ( typeof gridOptions . rowDetailView . process === 'function' ) {
72
78
// we need to keep the user "process" method and replace it with our own execution method
73
79
// we do this because when we get the item detail, we need to call "onAsyncResponse.notify" for the plugin to work
@@ -89,25 +95,27 @@ export class RowDetailViewExtension implements Extension {
89
95
}
90
96
91
97
// finally register the Row Detail View Plugin
92
- this . _extension = new Slick . Plugins . RowDetailView ( gridOptions . rowDetailView ) ;
98
+ this . _addon = new Slick . Plugins . RowDetailView ( gridOptions . rowDetailView ) ;
99
+ }
100
+ const selectionColumn : Column = this . _addon . getColumnDefinition ( ) ;
101
+ if ( typeof selectionColumn === 'object' ) {
102
+ selectionColumn . excludeFromExport = true ;
103
+ selectionColumn . excludeFromColumnPicker = true ;
104
+ selectionColumn . excludeFromGridMenu = true ;
105
+ selectionColumn . excludeFromQuery = true ;
106
+ selectionColumn . excludeFromHeaderMenu = true ;
107
+ columnDefinitions . unshift ( selectionColumn ) ;
93
108
}
94
- const selectionColumn : Column = this . _extension . getColumnDefinition ( ) ;
95
- selectionColumn . excludeFromExport = true ;
96
- selectionColumn . excludeFromColumnPicker = true ;
97
- selectionColumn . excludeFromGridMenu = true ;
98
- selectionColumn . excludeFromQuery = true ;
99
- selectionColumn . excludeFromHeaderMenu = true ;
100
- columnDefinitions . unshift ( selectionColumn ) ;
101
109
}
102
- return this . _extension ;
110
+ return this . _addon ;
103
111
}
104
112
return null ;
105
113
}
106
114
107
115
register ( rowSelectionPlugin ?: any ) {
108
116
if ( this . sharedService && this . sharedService . grid && this . sharedService . gridOptions ) {
109
117
// the plugin has to be created BEFORE the grid (else it behaves oddly), but we can only watch grid events AFTER the grid is created
110
- this . sharedService . grid . registerPlugin ( this . _extension ) ;
118
+ this . sharedService . grid . registerPlugin ( this . _addon ) ;
111
119
112
120
// this also requires the Row Selection Model to be registered as well
113
121
if ( ! rowSelectionPlugin || ! this . sharedService . grid . getSelectionModel ( ) ) {
@@ -116,28 +124,25 @@ export class RowDetailViewExtension implements Extension {
116
124
this . sharedService . grid . setSelectionModel ( rowSelectionPlugin ) ;
117
125
}
118
126
119
- // this._extension = this.create(this.sharedService.allColumns, this.sharedService.gridOptions);
120
- this . sharedService . grid . registerPlugin ( this . _extension ) ;
121
-
122
127
// hook all events
123
128
if ( this . sharedService . grid && this . sharedService . gridOptions . rowDetailView ) {
124
129
if ( this . sharedService . gridOptions . rowDetailView . onExtensionRegistered ) {
125
- this . sharedService . gridOptions . rowDetailView . onExtensionRegistered ( this . _extension ) ;
130
+ this . sharedService . gridOptions . rowDetailView . onExtensionRegistered ( this . _addon ) ;
126
131
}
127
- this . _eventHandler . subscribe ( this . _extension . onAsyncResponse , ( e : any , args : { item : any ; detailView : any } ) => {
132
+ this . _eventHandler . subscribe ( this . _addon . onAsyncResponse , ( e : any , args : { item : any ; detailView : any } ) => {
128
133
if ( this . sharedService . gridOptions . rowDetailView && typeof this . sharedService . gridOptions . rowDetailView . onAsyncResponse === 'function' ) {
129
134
this . sharedService . gridOptions . rowDetailView . onAsyncResponse ( e , args ) ;
130
135
}
131
136
} ) ;
132
- this . _eventHandler . subscribe ( this . _extension . onAsyncEndUpdate , ( e : any , args : { grid : any ; item : any ; } ) => {
137
+ this . _eventHandler . subscribe ( this . _addon . onAsyncEndUpdate , ( e : any , args : { grid : any ; item : any ; } ) => {
133
138
// triggers after backend called "onAsyncResponse.notify()"
134
139
this . renderViewModel ( args && args . item ) ;
135
140
136
141
if ( this . sharedService . gridOptions . rowDetailView && typeof this . sharedService . gridOptions . rowDetailView . onAsyncEndUpdate === 'function' ) {
137
142
this . sharedService . gridOptions . rowDetailView . onAsyncEndUpdate ( e , args ) ;
138
143
}
139
144
} ) ;
140
- this . _eventHandler . subscribe ( this . _extension . onAfterRowDetailToggle , ( e : any , args : { grid : any ; item : any ; expandedRows : any [ ] ; } ) => {
145
+ this . _eventHandler . subscribe ( this . _addon . onAfterRowDetailToggle , ( e : any , args : { grid : any ; item : any ; expandedRows : any [ ] ; } ) => {
141
146
// display preload template & re-render all the other Detail Views after toggling
142
147
// the preload View will eventually go away once the data gets loaded after the "onAsyncEndUpdate" event
143
148
this . renderPreloadView ( ) ;
@@ -147,23 +152,23 @@ export class RowDetailViewExtension implements Extension {
147
152
this . sharedService . gridOptions . rowDetailView . onAfterRowDetailToggle ( e , args ) ;
148
153
}
149
154
} ) ;
150
- this . _eventHandler . subscribe ( this . _extension . onBeforeRowDetailToggle , ( e : any , args : { grid : any ; item : any ; } ) => {
155
+ this . _eventHandler . subscribe ( this . _addon . onBeforeRowDetailToggle , ( e : any , args : { grid : any ; item : any ; } ) => {
151
156
// before toggling row detail, we need to create View Component if it doesn't exist
152
157
this . onBeforeRowDetailToggle ( e , args ) ;
153
158
154
159
if ( this . sharedService . gridOptions . rowDetailView && typeof this . sharedService . gridOptions . rowDetailView . onBeforeRowDetailToggle === 'function' ) {
155
160
this . sharedService . gridOptions . rowDetailView . onBeforeRowDetailToggle ( e , args ) ;
156
161
}
157
162
} ) ;
158
- this . _eventHandler . subscribe ( this . _extension . onRowBackToViewportRange , ( e : any , args : { grid : any ; item : any ; rowId : number ; rowIndex : number ; expandedRows : any [ ] ; rowIdsOutOfViewport : number [ ] ; } ) => {
163
+ this . _eventHandler . subscribe ( this . _addon . onRowBackToViewportRange , ( e : any , args : { grid : any ; item : any ; rowId : number ; rowIndex : number ; expandedRows : any [ ] ; rowIdsOutOfViewport : number [ ] ; } ) => {
159
164
// when row is back to viewport range, we will re-render the View Component(s)
160
165
this . onRowBackToViewportRange ( e , args ) ;
161
166
162
167
if ( this . sharedService . gridOptions . rowDetailView && typeof this . sharedService . gridOptions . rowDetailView . onRowBackToViewportRange === 'function' ) {
163
168
this . sharedService . gridOptions . rowDetailView . onRowBackToViewportRange ( e , args ) ;
164
169
}
165
170
} ) ;
166
- this . _eventHandler . subscribe ( this . _extension . onRowOutOfViewportRange , ( e : any , args : { grid : any ; item : any ; rowId : number ; rowIndex : number ; expandedRows : any [ ] ; rowIdsOutOfViewport : number [ ] ; } ) => {
171
+ this . _eventHandler . subscribe ( this . _addon . onRowOutOfViewportRange , ( e : any , args : { grid : any ; item : any ; rowId : number ; rowIndex : number ; expandedRows : any [ ] ; rowIdsOutOfViewport : number [ ] ; } ) => {
167
172
if ( this . sharedService . gridOptions . rowDetailView && typeof this . sharedService . gridOptions . rowDetailView . onRowOutOfViewportRange === 'function' ) {
168
173
this . sharedService . gridOptions . rowDetailView . onRowOutOfViewportRange ( e , args ) ;
169
174
}
@@ -182,7 +187,7 @@ export class RowDetailViewExtension implements Extension {
182
187
this . filterService . onFilterChanged . subscribe ( ( currentFilters : CurrentFilter [ ] ) => this . redrawAllViewComponents ( ) )
183
188
) ;
184
189
}
185
- return this . _extension ;
190
+ return this . _addon ;
186
191
}
187
192
return null ;
188
193
}
@@ -219,8 +224,8 @@ export class RowDetailViewExtension implements Extension {
219
224
* @param item
220
225
*/
221
226
private notifyTemplate ( item : any ) {
222
- if ( this . _extension ) {
223
- this . _extension . onAsyncResponse . notify ( { item } , undefined , this ) ;
227
+ if ( this . _addon ) {
228
+ this . _addon . onAsyncResponse . notify ( { item } , undefined , this ) ;
224
229
}
225
230
}
226
231
@@ -275,23 +280,19 @@ export class RowDetailViewExtension implements Extension {
275
280
// expanding
276
281
if ( args && args . item && args . item . __collapsed ) {
277
282
// expanding row detail
278
- if ( args && args . item ) {
279
- const viewInfo : CreatedView = {
280
- id : args . item . id ,
281
- dataContext : args . item
282
- } ;
283
- this . addToArrayWhenNotFound ( this . _views , viewInfo ) ;
284
- }
283
+ const viewInfo : CreatedView = {
284
+ id : args . item . id ,
285
+ dataContext : args . item
286
+ } ;
287
+ this . addToArrayWhenNotFound ( this . _views , viewInfo ) ;
285
288
} else {
286
289
// collapsing, so dispose of the View/Component
287
290
const foundViewIndex = this . _views . findIndex ( ( view : CreatedView ) => view . id === args . item . id ) ;
288
- if ( foundViewIndex >= 0 ) {
289
- if ( this . _views . hasOwnProperty ( foundViewIndex ) ) {
290
- const compRef = this . _views [ foundViewIndex ] . componentRef ;
291
- this . appRef . detachView ( compRef . hostView ) ;
292
- compRef . destroy ( ) ;
293
- this . _views . splice ( foundViewIndex , 1 ) ;
294
- }
291
+ if ( foundViewIndex >= 0 && this . _views . hasOwnProperty ( foundViewIndex ) ) {
292
+ const compRef = this . _views [ foundViewIndex ] . componentRef ;
293
+ this . appRef . detachView ( compRef . hostView ) ;
294
+ compRef . destroy ( ) ;
295
+ this . _views . splice ( foundViewIndex , 1 ) ;
295
296
}
296
297
}
297
298
}
0 commit comments