igniteui-webcomponents-datasources 1.4.1 → 3.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/bundles/igniteui-webcomponents-datasources.umd.js +2279 -1
  2. package/bundles/igniteui-webcomponents-datasources.umd.min.js +7 -2
  3. package/esm2015/igniteui-webcomponents-datasources.js +0 -1
  4. package/esm2015/lib/Entity.js +0 -1
  5. package/esm2015/lib/EntityProperty.js +0 -1
  6. package/esm2015/lib/EntitySet.js +0 -1
  7. package/esm2015/lib/ODataDataSourcePage.js +0 -1
  8. package/esm2015/lib/ODataSchemaProvider.js +0 -1
  9. package/esm2015/lib/ODataVirtualDataSource.js +0 -1
  10. package/esm2015/lib/ODataVirtualDataSourceDataProvider.js +0 -1
  11. package/esm2015/lib/ODataVirtualDataSourceDataProviderWorker.js +0 -1
  12. package/esm2015/lib/ODataVirtualDataSourceDataProviderWorkerSettings.js +0 -1
  13. package/esm2015/lib/ODataVirtualDataSourceProviderTaskDataHolder.js +0 -1
  14. package/esm2015/lib/RestVirtualDataSource.js +272 -0
  15. package/esm2015/lib/RestVirtualDataSourceDataProvider.js +528 -0
  16. package/esm2015/lib/RestVirtualDataSourceDataProviderWorker.js +744 -0
  17. package/esm2015/lib/RestVirtualDataSourceDataProviderWorkerSettings.js +154 -0
  18. package/esm2015/lib/RestVirtualDataSourcePage.js +67 -0
  19. package/esm2015/lib/RestVirtualDataSourceProviderTaskDataHolder.js +8 -0
  20. package/esm2015/lib/Schema.js +0 -1
  21. package/esm2015/lib/util.js +0 -1
  22. package/esm2015/public_api.js +6 -1
  23. package/esm5/igniteui-webcomponents-datasources.js +0 -1
  24. package/esm5/lib/Entity.js +0 -1
  25. package/esm5/lib/EntityProperty.js +0 -1
  26. package/esm5/lib/EntitySet.js +0 -1
  27. package/esm5/lib/ODataDataSourcePage.js +0 -1
  28. package/esm5/lib/ODataSchemaProvider.js +0 -1
  29. package/esm5/lib/ODataVirtualDataSource.js +0 -1
  30. package/esm5/lib/ODataVirtualDataSourceDataProvider.js +0 -1
  31. package/esm5/lib/ODataVirtualDataSourceDataProviderWorker.js +0 -1
  32. package/esm5/lib/ODataVirtualDataSourceDataProviderWorkerSettings.js +0 -1
  33. package/esm5/lib/ODataVirtualDataSourceProviderTaskDataHolder.js +0 -1
  34. package/esm5/lib/RestVirtualDataSource.js +357 -0
  35. package/esm5/lib/RestVirtualDataSourceDataProvider.js +675 -0
  36. package/esm5/lib/RestVirtualDataSourceDataProviderWorker.js +948 -0
  37. package/esm5/lib/RestVirtualDataSourceDataProviderWorkerSettings.js +240 -0
  38. package/esm5/lib/RestVirtualDataSourcePage.js +73 -0
  39. package/esm5/lib/RestVirtualDataSourceProviderTaskDataHolder.js +12 -0
  40. package/esm5/lib/Schema.js +0 -1
  41. package/esm5/lib/util.js +0 -1
  42. package/esm5/public_api.js +6 -1
  43. package/fesm2015/igniteui-webcomponents-datasources.js +1754 -3
  44. package/fesm5/igniteui-webcomponents-datasources.js +2275 -3
  45. package/lib/RestVirtualDataSource.d.ts +60 -0
  46. package/lib/RestVirtualDataSourceDataProvider.d.ts +135 -0
  47. package/lib/RestVirtualDataSourceDataProviderWorker.d.ts +69 -0
  48. package/lib/RestVirtualDataSourceDataProviderWorkerSettings.d.ts +60 -0
  49. package/lib/RestVirtualDataSourcePage.d.ts +19 -0
  50. package/lib/RestVirtualDataSourceProviderTaskDataHolder.d.ts +5 -0
  51. package/package.json +3 -3
  52. package/public_api.d.ts +6 -0
  53. package/bundles/igniteui-webcomponents-datasources.umd.js.map +0 -1
  54. package/bundles/igniteui-webcomponents-datasources.umd.min.js.map +0 -1
  55. package/esm2015/igniteui-webcomponents-datasources.js.map +0 -1
  56. package/esm2015/lib/Entity.js.map +0 -1
  57. package/esm2015/lib/EntityProperty.js.map +0 -1
  58. package/esm2015/lib/EntitySet.js.map +0 -1
  59. package/esm2015/lib/ODataDataSourcePage.js.map +0 -1
  60. package/esm2015/lib/ODataSchemaProvider.js.map +0 -1
  61. package/esm2015/lib/ODataVirtualDataSource.js.map +0 -1
  62. package/esm2015/lib/ODataVirtualDataSourceDataProvider.js.map +0 -1
  63. package/esm2015/lib/ODataVirtualDataSourceDataProviderWorker.js.map +0 -1
  64. package/esm2015/lib/ODataVirtualDataSourceDataProviderWorkerSettings.js.map +0 -1
  65. package/esm2015/lib/ODataVirtualDataSourceProviderTaskDataHolder.js.map +0 -1
  66. package/esm2015/lib/Schema.js.map +0 -1
  67. package/esm2015/lib/util.js.map +0 -1
  68. package/esm2015/public_api.js.map +0 -1
  69. package/esm5/igniteui-webcomponents-datasources.js.map +0 -1
  70. package/esm5/lib/Entity.js.map +0 -1
  71. package/esm5/lib/EntityProperty.js.map +0 -1
  72. package/esm5/lib/EntitySet.js.map +0 -1
  73. package/esm5/lib/ODataDataSourcePage.js.map +0 -1
  74. package/esm5/lib/ODataSchemaProvider.js.map +0 -1
  75. package/esm5/lib/ODataVirtualDataSource.js.map +0 -1
  76. package/esm5/lib/ODataVirtualDataSourceDataProvider.js.map +0 -1
  77. package/esm5/lib/ODataVirtualDataSourceDataProviderWorker.js.map +0 -1
  78. package/esm5/lib/ODataVirtualDataSourceDataProviderWorkerSettings.js.map +0 -1
  79. package/esm5/lib/ODataVirtualDataSourceProviderTaskDataHolder.js.map +0 -1
  80. package/esm5/lib/Schema.js.map +0 -1
  81. package/esm5/lib/util.js.map +0 -1
  82. package/esm5/public_api.js.map +0 -1
  83. package/fesm2015/igniteui-webcomponents-datasources.js.map +0 -1
  84. package/fesm5/igniteui-webcomponents-datasources.js.map +0 -1
@@ -0,0 +1,744 @@
1
+ import { AsyncVirtualDataSourceProviderWorker } from "igniteui-webcomponents-core";
2
+ import { SortDescriptionCollection } from "igniteui-webcomponents-core";
3
+ import { RestVirtualDataSourceProviderTaskDataHolder } from "./RestVirtualDataSourceProviderTaskDataHolder";
4
+ import { AsyncDataSourcePageTaskHolder } from "igniteui-webcomponents-core";
5
+ import { AsyncVirtualDataTask } from "igniteui-webcomponents-core";
6
+ import { RestVirtualDataSourcePage } from "./RestVirtualDataSourcePage";
7
+ import { DefaultSectionInformation } from "igniteui-webcomponents-core";
8
+ import { Convert } from "igniteui-webcomponents-core";
9
+ import { ODataDataSourceFilterExpressionVisitor } from "igniteui-webcomponents-core";
10
+ import { ListSortDirection } from "igniteui-webcomponents-core";
11
+ import { stringIsNullOrEmpty } from "igniteui-webcomponents-core";
12
+ import { SummaryOperand } from "igniteui-webcomponents-core";
13
+ import { DataSourceSummaryScope } from "igniteui-webcomponents-core";
14
+ import { DefaultSummaryResult } from "igniteui-webcomponents-core";
15
+ import { LocalDataSource } from "igniteui-webcomponents-core";
16
+ export let RestVirtualDataSourceDataProviderWorker = /*@__PURE__*/ (() => {
17
+ class RestVirtualDataSourceDataProviderWorker extends AsyncVirtualDataSourceProviderWorker {
18
+ constructor(settings) {
19
+ super(settings);
20
+ this._baseUri = null;
21
+ this._entitySet = null;
22
+ this._sortDescriptions = null;
23
+ this._groupDescriptions = null;
24
+ this._filterExpressions = null;
25
+ this._summaryDescriptions = null;
26
+ this._desiredPropeties = null;
27
+ this._enableJsonp = true;
28
+ this._isAggregationSupported = false;
29
+ this._provideFullCount = null;
30
+ this._provideOrderByParameter = null;
31
+ this._provideFilterParameter = null;
32
+ this._provideAggregationParameter = null;
33
+ this._provideAggregatedCount = null;
34
+ this._providePagingParameter = null;
35
+ this._provideDesiredPropertiesParameter = null;
36
+ this._provideUri = null;
37
+ this._performFetch = null;
38
+ this._fixedFullCount = -1;
39
+ this._groupInformation = null;
40
+ this._summaryInformation = null;
41
+ this._filterString = null;
42
+ this._selectedString = null;
43
+ this.doWork = this.doWork.bind(this);
44
+ this._baseUri = settings.baseUri;
45
+ this._entitySet = settings.entitySet;
46
+ this._sortDescriptions = settings.sortDescriptions;
47
+ this._groupDescriptions = settings.groupDescriptions;
48
+ if (this._groupDescriptions != null && this._groupDescriptions.size() > 0) {
49
+ this._sortDescriptions = new SortDescriptionCollection();
50
+ for (let sd of this.iter(settings.sortDescriptions)) {
51
+ this._sortDescriptions.add(sd);
52
+ }
53
+ for (let i = 0; i < this._groupDescriptions.size(); i++) {
54
+ this._sortDescriptions.insert(i, this._groupDescriptions.get(i));
55
+ }
56
+ }
57
+ this._filterExpressions = settings.filterExpressions;
58
+ this._desiredPropeties = settings.propertiesRequested;
59
+ this._summaryDescriptions = settings.summaryDescriptions;
60
+ this._fixedFullCount = settings.fixedFullCount;
61
+ this._summaryScope = settings.summaryScope;
62
+ this._enableJsonp = settings.enableJsonp;
63
+ this._provideFullCount = settings.provideFullCount;
64
+ this._performFetch = settings.performFetch;
65
+ this._provideAggregationParameter = settings.provideAggregationParameter;
66
+ this._provideFilterParameter = settings.provideFilterParameter;
67
+ this._provideOrderByParameter = settings.provideOrderByParameter;
68
+ this._provideUri = settings.provideUri;
69
+ this._providePagingParameter = settings.providePagingParameter;
70
+ this._provideDesiredPropertiesParameter = settings.provideDesiredPropertiesParameter;
71
+ this._provideItems = settings.provideItems;
72
+ this._provideAggregatedCount = settings.provideAggregatedCount;
73
+ if (!this._provideItems) {
74
+ this._provideItems = (res) => {
75
+ return res ? res.items : null;
76
+ };
77
+ }
78
+ if (!this._provideFullCount) {
79
+ this._provideFullCount = (p) => {
80
+ if (p.fullCount) {
81
+ return p.fullCount;
82
+ }
83
+ else {
84
+ return this._fixedFullCount >= 0 ? this._fixedFullCount : 0;
85
+ }
86
+ };
87
+ }
88
+ if (!this._provideOrderByParameter) {
89
+ this._provideOrderByParameter = (args, orderByString, orderBy) => {
90
+ args.push({ name: "orderBy", value: encodeURIComponent(orderByString) });
91
+ };
92
+ }
93
+ if (!this._providePagingParameter) {
94
+ this._providePagingParameter = (args, skip, take) => {
95
+ args.push({ name: "skip", value: skip });
96
+ args.push({ name: "take", value: take });
97
+ };
98
+ }
99
+ if (!this._provideAggregationParameter) {
100
+ this._provideAggregationParameter = (args, fetchCountOnly, groupByString, groupBy, summaryString, summary) => {
101
+ args.push({ name: "groupBy", value: groupByString });
102
+ args.push({ name: "aggregate", value: "count" });
103
+ };
104
+ }
105
+ if (!this._provideUri) {
106
+ this._provideUri = (baseUri, entitySet, args) => {
107
+ let requestUri = baseUri;
108
+ requestUri += "/" + entitySet;
109
+ if (args.length > 0) {
110
+ requestUri += "?";
111
+ }
112
+ let argsString = "";
113
+ for (var i = 0; i < args.length; i++) {
114
+ if (i > 0) {
115
+ argsString += "&";
116
+ }
117
+ argsString += args[i].name + "=" + args[i].value;
118
+ }
119
+ return requestUri + argsString;
120
+ };
121
+ }
122
+ this._isAggregationSupported = settings.isAggregationSupported;
123
+ window.setTimeout(this.doWork, 100);
124
+ }
125
+ get sortDescriptions() {
126
+ return this._sortDescriptions;
127
+ }
128
+ get filterExpressions() {
129
+ return this._filterExpressions;
130
+ }
131
+ get desiredProperties() {
132
+ return this._desiredPropeties;
133
+ }
134
+ initialize() {
135
+ super.initialize();
136
+ }
137
+ getTaskDataHolder() {
138
+ let holder = new RestVirtualDataSourceProviderTaskDataHolder();
139
+ return holder;
140
+ }
141
+ getCompletedTaskData(holder, completed) {
142
+ super.getCompletedTaskData(holder, completed);
143
+ }
144
+ removeCompletedTaskData(holder, completed) {
145
+ super.removeCompletedTaskData(holder, completed);
146
+ }
147
+ getTasksData(holder) {
148
+ super.getTasksData(holder);
149
+ }
150
+ *iter(coll) {
151
+ for (let i = 0; i < coll.size(); i++) {
152
+ yield coll.get(i);
153
+ }
154
+ }
155
+ *iterFilter(coll) {
156
+ for (let i = 0; i < coll.size(); i++) {
157
+ yield coll.get(i);
158
+ }
159
+ }
160
+ *iterSummaries(summaries) {
161
+ for (let i = 0; i < summaries.size(); i++) {
162
+ yield summaries.get(i);
163
+ }
164
+ }
165
+ processCompletedTask(completedTask, currentDelay, pageIndex, taskDataHolder) {
166
+ let h = taskDataHolder;
167
+ let schema = null;
168
+ let result = null;
169
+ let schemaFetchCount = -1;
170
+ let task = completedTask.task;
171
+ try {
172
+ if (task.hasErrors) {
173
+ this.retryIndex(pageIndex, currentDelay);
174
+ return;
175
+ }
176
+ if (pageIndex == RestVirtualDataSourceDataProviderWorker.schemaRequestIndex) {
177
+ result = task.result;
178
+ schemaFetchCount = (this._provideFullCount(result));
179
+ }
180
+ else {
181
+ result = task.result;
182
+ }
183
+ }
184
+ catch (e) {
185
+ this.retryIndex(pageIndex, currentDelay);
186
+ return;
187
+ }
188
+ if (schemaFetchCount >= 0) {
189
+ this.actualCount = schemaFetchCount;
190
+ }
191
+ else {
192
+ this.actualCount = (this._provideFullCount(result));
193
+ }
194
+ schema = this.actualSchema;
195
+ if (schema == null) {
196
+ let requests = 0;
197
+ this.resolveSchema((s) => {
198
+ // resolveSchema success callback
199
+ this.actualSchema = s;
200
+ if (this._isAggregationSupported && (this._groupDescriptions.size() !== 0 || this._summaryDescriptions.size() !== 0)) {
201
+ if (this._groupDescriptions.size() > 0) {
202
+ requests++;
203
+ this.resolveGroupInformation((g) => {
204
+ // group info success
205
+ requests--;
206
+ if (requests === 0) {
207
+ this.finishProcessingCompletedTask(task, pageIndex, s, result);
208
+ }
209
+ }, () => {
210
+ // group info failure
211
+ this.retryIndex(pageIndex, currentDelay);
212
+ return;
213
+ });
214
+ }
215
+ if (this._summaryDescriptions.size() > 0) {
216
+ requests++;
217
+ this.resolveSummaryInformation((g) => {
218
+ // summary info success
219
+ requests--;
220
+ if (requests === 0) {
221
+ this.finishProcessingCompletedTask(task, pageIndex, s, result);
222
+ }
223
+ }, () => {
224
+ // summary info failure
225
+ this.retryIndex(pageIndex, currentDelay);
226
+ return;
227
+ });
228
+ }
229
+ }
230
+ else {
231
+ this.finishProcessingCompletedTask(task, pageIndex, s, result);
232
+ }
233
+ }, () => {
234
+ // resolveSchema failure callback
235
+ this.retryIndex(pageIndex, currentDelay);
236
+ return;
237
+ });
238
+ return;
239
+ }
240
+ this.finishProcessingCompletedTask(task, pageIndex, schema, result);
241
+ }
242
+ finishProcessingCompletedTask(task, pageIndex, schema, result) {
243
+ let executionContext;
244
+ let pageLoaded;
245
+ let groupInformation;
246
+ let summaryInformation;
247
+ this.actualSchema = schema;
248
+ executionContext = this.executionContext;
249
+ groupInformation = this._groupInformation;
250
+ summaryInformation = this._summaryInformation;
251
+ pageLoaded = this.pageLoaded;
252
+ let page = null;
253
+ if (result != null) {
254
+ page = new RestVirtualDataSourcePage(result, schema, groupInformation, summaryInformation, pageIndex);
255
+ if (!this.isLastPage(pageIndex) && page.count() > 0 && !this.populatedActualPageSize) {
256
+ this.populatedActualPageSize = true;
257
+ this.actualPageSize = page.count();
258
+ }
259
+ }
260
+ else {
261
+ page = new RestVirtualDataSourcePage(null, schema, groupInformation, summaryInformation, pageIndex);
262
+ }
263
+ if (this.pageLoaded != null) {
264
+ if (this.executionContext != null) {
265
+ if (executionContext == null || pageLoaded == null) {
266
+ this.shutdown();
267
+ return;
268
+ }
269
+ executionContext.execute(() => pageLoaded(page, this.actualCount, this.actualPageSize));
270
+ }
271
+ else {
272
+ if (pageLoaded == null) {
273
+ this.shutdown();
274
+ return;
275
+ }
276
+ pageLoaded(page, this.actualCount, this.actualPageSize);
277
+ }
278
+ }
279
+ }
280
+ resolveGroupInformation(finishAction, failureAction) {
281
+ if (this._groupInformation != null) {
282
+ finishAction(this._groupInformation);
283
+ return;
284
+ }
285
+ let orderBy = "";
286
+ let groupBy = "";
287
+ let filter = null;
288
+ let summary = "";
289
+ if (this._groupDescriptions == null || this._groupDescriptions.size() == 0) {
290
+ finishAction(null);
291
+ return;
292
+ }
293
+ if (this._provideAggregationParameter == null) {
294
+ finishAction(null);
295
+ return;
296
+ }
297
+ filter = this._filterString;
298
+ this.updateFilterString();
299
+ if (this._groupDescriptions != null) {
300
+ let first1 = true;
301
+ for (let group of this.iter(this._groupDescriptions)) {
302
+ if (first1) {
303
+ first1 = false;
304
+ }
305
+ else {
306
+ orderBy += ", ";
307
+ groupBy += ", ";
308
+ }
309
+ groupBy += group.propertyName;
310
+ if (group.direction === ListSortDirection.Descending) {
311
+ orderBy += group.propertyName + " desc";
312
+ }
313
+ else {
314
+ orderBy += group.propertyName + " asc";
315
+ }
316
+ }
317
+ }
318
+ if (this._summaryScope === DataSourceSummaryScope.Both || this._summaryScope === DataSourceSummaryScope.Groups) {
319
+ let summaryParameters = this.getSummaryQueryParameters(true);
320
+ if (!stringIsNullOrEmpty(summaryParameters)) {
321
+ summary = ", " + summaryParameters;
322
+ }
323
+ }
324
+ let args = [];
325
+ if (this._provideOrderByParameter) {
326
+ this._provideOrderByParameter(args, orderBy, this._groupDescriptions);
327
+ }
328
+ if (this._provideFilterParameter && filter != null) {
329
+ this._provideFilterParameter(args, filter, this._filterExpressions);
330
+ }
331
+ if (this._provideAggregationParameter) {
332
+ this._provideAggregationParameter(args, true, groupBy, this._groupDescriptions, summary, this._summaryDescriptions);
333
+ }
334
+ var uri = this._provideUri(this._baseUri, this._entitySet, args);
335
+ try {
336
+ let groupInformation = [];
337
+ let success_ = (data, response) => this.groupSuccess(data, response, finishAction, failureAction, groupInformation);
338
+ let failure_ = (err) => this.groupError(err, finishAction, failureAction, groupInformation);
339
+ let run_ = null;
340
+ var headers = { 'Content-Type': 'application/json', Accept: 'application/json' };
341
+ var request = {
342
+ requestUri: uri,
343
+ enableJsonpCallback: this._enableJsonp,
344
+ method: 'GET',
345
+ headers: headers,
346
+ data: null
347
+ };
348
+ run_ = () => {
349
+ this.fetchUri(request, success_, failure_);
350
+ };
351
+ run_();
352
+ }
353
+ catch (e) {
354
+ failureAction();
355
+ }
356
+ }
357
+ fetchUri(request, success, failure) {
358
+ if (this._performFetch) {
359
+ this._performFetch(request, success, failure);
360
+ }
361
+ else {
362
+ fetch(request.requestUri, {
363
+ method: request.method,
364
+ headers: request.headers,
365
+ }).then((res) => {
366
+ res.json().then((j) => {
367
+ success(j, res);
368
+ });
369
+ }).catch((e) => {
370
+ failure(e);
371
+ });
372
+ }
373
+ }
374
+ groupError(err, finishAction, failureAction, groupInformation) {
375
+ this._groupInformation = null;
376
+ }
377
+ groupSuccess(data, response, finishAction, failureAction, groupInformation) {
378
+ let groupNames = [];
379
+ for (let group of this.iter(this._groupDescriptions)) {
380
+ groupNames.push(group.propertyName);
381
+ }
382
+ let groupNamesArray = groupNames;
383
+ let items = this._provideItems(data);
384
+ if (items && items.length > 0) {
385
+ let currentIndex = 0;
386
+ for (let i = 0; i < items.length; i++) {
387
+ this.addGroup(groupInformation, groupNames, groupNames, currentIndex, items[i]);
388
+ }
389
+ }
390
+ this._groupInformation = groupInformation;
391
+ finishAction(this._groupInformation);
392
+ }
393
+ addGroup(groupInformation, groupNames, groupNamesArray, currentIndex, group) {
394
+ let groupValues = [];
395
+ for (let name of groupNames) {
396
+ if (group[name]) {
397
+ groupValues.push(group[name]);
398
+ }
399
+ }
400
+ let groupCount = 0;
401
+ //todo: make this customizable
402
+ if (this._provideAggregatedCount) {
403
+ let ct = this._provideAggregatedCount(group);
404
+ }
405
+ else {
406
+ if (group["aggregatedCount"]) {
407
+ groupCount = Convert.toInt321(group["aggregatedCount"]);
408
+ }
409
+ }
410
+ let summaryResults = null;
411
+ if (this._summaryScope == DataSourceSummaryScope.Both || this._summaryScope == DataSourceSummaryScope.Groups) {
412
+ summaryResults = this.createSummaryResults(group);
413
+ }
414
+ let groupInfo = new DefaultSectionInformation(currentIndex, currentIndex + (groupCount - 1), groupNamesArray, groupValues, summaryResults);
415
+ groupInformation.push(groupInfo);
416
+ }
417
+ resolveSummaryInformation(finishAction, failureAction) {
418
+ if (this._summaryInformation != null) {
419
+ finishAction(this._summaryInformation);
420
+ return;
421
+ }
422
+ let filter = null;
423
+ let summary = null;
424
+ if (this._summaryDescriptions == null ||
425
+ this._summaryDescriptions.size() == 0 ||
426
+ this._summaryScope == DataSourceSummaryScope.Groups ||
427
+ this._summaryScope == DataSourceSummaryScope.None) {
428
+ finishAction(null);
429
+ return;
430
+ }
431
+ filter = this._filterString;
432
+ this.updateFilterString();
433
+ summary = this.getSummaryQueryParameters(false);
434
+ let args = [];
435
+ // if (this._provideOrderByParameter) {
436
+ // args.push({ name: "orderBy", value: this._provideOrderByParameter(orderBy, this._sortDescriptions) });
437
+ // }
438
+ if (this._provideFilterParameter && filter != null) {
439
+ this._provideFilterParameter(args, filter, this._filterExpressions);
440
+ }
441
+ if (this._provideAggregationParameter) {
442
+ this._provideAggregationParameter(args, true, null, null, summary, this._summaryDescriptions);
443
+ }
444
+ var uri = this._provideUri(this._baseUri, this._entitySet, args);
445
+ // let commandText = this._entitySet + "?$apply=";
446
+ // if (!stringIsNullOrEmpty(filter)) {
447
+ // commandText += "filter(" + filter + ")/";
448
+ // }
449
+ // commandText += "aggregate(" + summary + ")";
450
+ try {
451
+ let summaryInformation = [];
452
+ let success_ = (data, response) => this.summarySuccess(data, response, finishAction, failureAction, summaryInformation);
453
+ let failure_ = (err) => this.summaryError(err, finishAction, failureAction, summaryInformation);
454
+ let run_ = null;
455
+ var headers = { 'Content-Type': 'application/json', Accept: 'application/json' };
456
+ var request = {
457
+ requestUri: uri,
458
+ enableJsonpCallback: this._enableJsonp,
459
+ method: 'GET',
460
+ headers: headers,
461
+ data: null
462
+ };
463
+ run_ = () => {
464
+ this.fetchUri(request, success_, failure_);
465
+ };
466
+ run_();
467
+ }
468
+ catch (e) {
469
+ failureAction();
470
+ }
471
+ }
472
+ summarySuccess(data, response, finishAction, failureAction, summaryInformation) {
473
+ if (data && data.value && data.value.length > 0) {
474
+ summaryInformation = this.createSummaryResults(data.value[0]);
475
+ }
476
+ this._summaryInformation = summaryInformation;
477
+ finishAction(this._summaryInformation);
478
+ }
479
+ summaryError(err, finishAction, failureAction, summaryInformation) {
480
+ this._summaryInformation = null;
481
+ }
482
+ getSummaryQueryParameters(ignoreCount) {
483
+ let result = "";
484
+ if (this._summaryDescriptions != null) {
485
+ let first = true;
486
+ let countExists = false;
487
+ for (let summary of this.iterSummaries(this._summaryDescriptions)) {
488
+ if (summary.operand == SummaryOperand.Count && (ignoreCount || countExists)) {
489
+ continue;
490
+ }
491
+ if (!first) {
492
+ result += ", ";
493
+ }
494
+ switch (summary.operand) {
495
+ case SummaryOperand.Average:
496
+ result += summary.propertyName + " with average as " + summary.propertyName + "Average";
497
+ break;
498
+ case SummaryOperand.Min:
499
+ result += summary.propertyName + " with min as " + summary.propertyName + "Min";
500
+ break;
501
+ case SummaryOperand.Max:
502
+ result += summary.propertyName + " with max as " + summary.propertyName + "Max";
503
+ break;
504
+ case SummaryOperand.Sum:
505
+ result += summary.propertyName + " with sum as " + summary.propertyName + "Sum";
506
+ break;
507
+ case SummaryOperand.Count:
508
+ result += "$count as $__count";
509
+ countExists = true;
510
+ break;
511
+ }
512
+ first = false;
513
+ }
514
+ }
515
+ return result;
516
+ }
517
+ createSummaryResults(data) {
518
+ let summaryResults = [];
519
+ for (let summary of this.iterSummaries(this._summaryDescriptions)) {
520
+ let summaryName = summary.propertyName;
521
+ switch (summary.operand) {
522
+ case SummaryOperand.Average:
523
+ summaryName += "Average";
524
+ break;
525
+ case SummaryOperand.Min:
526
+ summaryName += "Min";
527
+ break;
528
+ case SummaryOperand.Max:
529
+ summaryName += "Max";
530
+ break;
531
+ case SummaryOperand.Sum:
532
+ summaryName += "Sum";
533
+ break;
534
+ case SummaryOperand.Count:
535
+ summaryName = "$__count";
536
+ break;
537
+ }
538
+ let summaryValue = null;
539
+ if (data && data[summaryName]) {
540
+ summaryValue = data[summaryName];
541
+ }
542
+ let summaryResult = new DefaultSummaryResult(summary.propertyName, summary.operand, summaryValue);
543
+ summaryResults.push(summaryResult);
544
+ }
545
+ return summaryResults;
546
+ }
547
+ resolveSchemaFromItems(items) {
548
+ let lds = new LocalDataSource();
549
+ lds.dataSource = items;
550
+ lds.flushAutoRefresh();
551
+ return lds.actualSchema;
552
+ }
553
+ resolveSchema(finishAction, failureAction) {
554
+ if (!this._provideItems || !this._providePagingParameter) {
555
+ failureAction("required providers for items and paging are not specified");
556
+ return;
557
+ }
558
+ let success_ = (res) => {
559
+ let items = this._provideItems(res);
560
+ if (items && items.length > 0) {
561
+ let schema = this.resolveSchemaFromItems(items);
562
+ finishAction(schema);
563
+ }
564
+ else {
565
+ failureAction("could not find items to resolve schema");
566
+ }
567
+ };
568
+ let failure_ = (e) => failureAction(e);
569
+ let args = [];
570
+ if (this._providePagingParameter) {
571
+ this._providePagingParameter(args, 0, this.actualPageSize);
572
+ }
573
+ let uri = this._provideUri(this._baseUri, this._entitySet, args);
574
+ try {
575
+ let run_ = null;
576
+ var headers = { 'Content-Type': 'application/json', Accept: 'application/json' };
577
+ var request = {
578
+ requestUri: uri,
579
+ enableJsonpCallback: this._enableJsonp,
580
+ method: 'GET',
581
+ headers: headers,
582
+ data: null
583
+ };
584
+ run_ = () => {
585
+ this.fetchUri(request, success_, failure_);
586
+ };
587
+ run_();
588
+ }
589
+ catch (e) {
590
+ failureAction(e);
591
+ }
592
+ }
593
+ makeTaskForRequest(request, retryDelay) {
594
+ let args = [];
595
+ // if (this._provideAggregationParameter) {
596
+ // args.push({ name: "apply", value: this._provideAggregationParameter(true, groupBy, this._groupDescriptions, summary, this._summaryDescriptions) });
597
+ // }
598
+ let actualPageSize = 0;
599
+ let sortDescriptions = null;
600
+ actualPageSize = this.actualPageSize;
601
+ sortDescriptions = this.sortDescriptions;
602
+ //let requestUrl: string = this._baseUri;
603
+ //requestUrl += "/" + this._entitySet;
604
+ let queryStarted = false;
605
+ this.updateFilterString();
606
+ if (this._filterString != null) {
607
+ if (this._provideFilterParameter) {
608
+ this._provideFilterParameter(args, this._filterString, this._filterExpressions);
609
+ }
610
+ }
611
+ if (this.sortDescriptions != null) {
612
+ let sortString = null;
613
+ for (let sort of this.iter(this.sortDescriptions)) {
614
+ if (sortString == null) {
615
+ sortString = "";
616
+ }
617
+ else {
618
+ sortString += ", ";
619
+ }
620
+ if (sort.direction == ListSortDirection.Descending) {
621
+ sortString += sort.propertyName + " desc";
622
+ }
623
+ else {
624
+ sortString += sort.propertyName;
625
+ }
626
+ }
627
+ if (sortString != null) {
628
+ if (this._provideOrderByParameter) {
629
+ this._provideOrderByParameter(args, sortString, this._sortDescriptions);
630
+ }
631
+ }
632
+ }
633
+ if (this.desiredProperties != null && this.desiredProperties.length > 0) {
634
+ let selectString = "";
635
+ let first = true;
636
+ let $t = this.desiredProperties;
637
+ for (let i = 0; i < $t.length; i++) {
638
+ let select = $t[i];
639
+ if (first) {
640
+ first = false;
641
+ }
642
+ else {
643
+ selectString += ", ";
644
+ }
645
+ selectString += select;
646
+ }
647
+ if (this._provideDesiredPropertiesParameter) {
648
+ this._provideDesiredPropertiesParameter(args, selectString, this._desiredPropeties);
649
+ }
650
+ }
651
+ if (this._providePagingParameter) {
652
+ if (request.index == RestVirtualDataSourceDataProviderWorker.schemaRequestIndex) {
653
+ this._providePagingParameter(args, 0, actualPageSize);
654
+ }
655
+ else {
656
+ this._providePagingParameter(args, request.index * actualPageSize, actualPageSize);
657
+ }
658
+ }
659
+ let task = new AsyncVirtualDataTask();
660
+ let uri = this._provideUri(this._baseUri, this._entitySet, args);
661
+ if (request.index == RestVirtualDataSourceDataProviderWorker.schemaRequestIndex) {
662
+ this.executeRequest(uri, queryStarted, 0, actualPageSize, task);
663
+ }
664
+ else {
665
+ this.executeRequest(uri, queryStarted, request.index * actualPageSize, actualPageSize, task);
666
+ }
667
+ request.taskHolder = new AsyncDataSourcePageTaskHolder();
668
+ request.taskHolder.task = task;
669
+ this.tasks.add(request);
670
+ }
671
+ updateFilterString() {
672
+ if (this.filterExpressions != null && this.filterExpressions.size() > 0 && this._filterString == null) {
673
+ let sb = "";
674
+ let first = true;
675
+ for (let expr of this.iterFilter(this.filterExpressions)) {
676
+ if (first) {
677
+ first = false;
678
+ }
679
+ else {
680
+ sb += " AND ";
681
+ }
682
+ let visitor = new ODataDataSourceFilterExpressionVisitor(0);
683
+ visitor.visit(expr);
684
+ let txt = visitor.toString();
685
+ if (this.filterExpressions.size() > 1) {
686
+ txt = "(" + txt + ")";
687
+ }
688
+ sb += (txt);
689
+ }
690
+ this._filterString = sb;
691
+ }
692
+ }
693
+ executeRequest(requestUrl, queryStarted, skip, top, task) {
694
+ // if (!queryStarted) {
695
+ // queryStarted = true;
696
+ // requestUrl += "?";
697
+ // } else {
698
+ // requestUrl += "&";
699
+ // }
700
+ // requestUrl += "$skip=" + skip + "&$top=" + top + "&$count=true";
701
+ let requestUrl_ = requestUrl;
702
+ let self_ = this;
703
+ let success_ = (data, response) => this.success(task, data, response);
704
+ let failure_ = (err) => this.error(task, err);
705
+ let run_ = null;
706
+ var headers = { 'Content-Type': 'application/json', Accept: 'application/json' };
707
+ var request = {
708
+ requestUri: requestUrl_,
709
+ enableJsonpCallback: this._enableJsonp,
710
+ method: 'GET',
711
+ headers: headers,
712
+ data: null
713
+ };
714
+ run_ = () => {
715
+ this.fetchUri(request, success_, failure_);
716
+ };
717
+ task.run = run_;
718
+ }
719
+ success(t, data, response) {
720
+ t.result = data;
721
+ t.isCompleted = true;
722
+ }
723
+ error(t, result) {
724
+ t.isCompleted = true;
725
+ t.hasErrors = true;
726
+ }
727
+ createBatchRequest(changes) {
728
+ //TODO: updates
729
+ }
730
+ getRequestUriWithKey(key) {
731
+ let result = "";
732
+ const keys = Object.keys(key);
733
+ for (let i = 0; i < keys.length; i++) {
734
+ if (i > 0) {
735
+ result += ",";
736
+ }
737
+ result += `${keys[i]}=${key[keys[i]]}`;
738
+ }
739
+ return `${this._entitySet}(${result})`;
740
+ }
741
+ }
742
+ RestVirtualDataSourceDataProviderWorker.schemaRequestIndex = -1;
743
+ return RestVirtualDataSourceDataProviderWorker;
744
+ })();