@@ -21,6 +21,7 @@ import { FilterService } from '../services/filter.service';
21
21
import { SortService } from '../services/sort.service' ;
22
22
import { castToPromise } from '../services/utilities' ;
23
23
import { SharedService } from '../services/shared.service' ;
24
+ import { refreshBackendDataset } from '../services/backend-utilities' ;
24
25
25
26
// using external non-typed js libraries
26
27
declare var Slick : any ;
@@ -142,58 +143,13 @@ export class GridMenuExtension implements Extension {
142
143
143
144
/** Refresh the dataset through the Backend Service */
144
145
refreshBackendDataset ( gridOptions ?: GridOption ) {
145
- let query = '' ;
146
-
147
146
// user can pass new set of grid options which will override current ones
148
147
if ( gridOptions ) {
149
148
this . sharedService . gridOptions = { ...this . sharedService . gridOptions , ...gridOptions } ;
150
149
}
151
150
152
151
const backendApi = this . sharedService . gridOptions . backendServiceApi ;
153
- if ( ! backendApi || ! backendApi . service || ! backendApi . process ) {
154
- throw new Error ( `BackendServiceApi requires at least a "process" function and a "service" defined` ) ;
155
- }
156
-
157
- if ( backendApi . service ) {
158
- query = backendApi . service . buildQuery ( ) ;
159
- }
160
-
161
- if ( query && query !== '' ) {
162
- // keep start time & end timestamps & return it after process execution
163
- const startTime = new Date ( ) ;
164
-
165
- if ( backendApi . preProcess ) {
166
- backendApi . preProcess ( ) ;
167
- }
168
-
169
- // the process could be an Observable (like HttpClient) or a Promise
170
- // in any case, we need to have a Promise so that we can await on it (if an Observable, convert it to Promise)
171
- const observableOrPromise = backendApi . process ( query ) ;
172
-
173
- castToPromise ( observableOrPromise ) . then ( ( processResult : GraphqlResult | any ) => {
174
- const endTime = new Date ( ) ;
175
-
176
- // from the result, call our internal post process to update the Dataset and Pagination info
177
- if ( processResult && backendApi && backendApi . internalPostProcess ) {
178
- backendApi . internalPostProcess ( processResult ) ;
179
- }
180
-
181
- // send the response process to the postProcess callback
182
- if ( backendApi && backendApi . postProcess ) {
183
- if ( processResult instanceof Object ) {
184
- processResult . metrics = {
185
- startTime,
186
- endTime,
187
- executionTime : endTime . valueOf ( ) - startTime . valueOf ( ) ,
188
- totalItemCount : this . sharedService . gridOptions && this . sharedService . gridOptions . pagination && this . sharedService . gridOptions . pagination . totalItems
189
- } ;
190
- // @deprecated
191
- processResult . statistics = processResult . metrics ;
192
- }
193
- backendApi . postProcess ( processResult ) ;
194
- }
195
- } ) ;
196
- }
152
+ refreshBackendDataset ( backendApi , this . sharedService . gridOptions ) ;
197
153
}
198
154
199
155
showGridMenu ( e ) {
0 commit comments