igniteui-webcomponents-datasources
Version:
Reference custom data providers for the Ignite UI Web Components data source.
969 lines (968 loc) • 40.5 kB
JavaScript
import { __extends, __generator, __values } from "tslib";
import { AsyncVirtualDataSourceProviderWorker } from "igniteui-webcomponents-core";
import { SortDescriptionCollection } from "igniteui-webcomponents-core";
import { RestVirtualDataSourceProviderTaskDataHolder } from "./RestVirtualDataSourceProviderTaskDataHolder";
import { AsyncDataSourcePageTaskHolder } from "igniteui-webcomponents-core";
import { AsyncVirtualDataTask } from "igniteui-webcomponents-core";
import { RestVirtualDataSourcePage } from "./RestVirtualDataSourcePage";
import { DefaultSectionInformation } from "igniteui-webcomponents-core";
import { Convert } from "igniteui-webcomponents-core";
import { ODataDataSourceFilterExpressionVisitor } from "igniteui-webcomponents-core";
import { ListSortDirection } from "igniteui-webcomponents-core";
import { stringIsNullOrEmpty } from "igniteui-webcomponents-core";
import { DataSourceSummaryOperand } from "igniteui-webcomponents-core";
import { DataSourceSummaryScope } from "igniteui-webcomponents-core";
import { DefaultSummaryResult } from "igniteui-webcomponents-core";
import { LocalDataSource } from "igniteui-webcomponents-core";
import { DefaultDataSourceSchema } from "igniteui-webcomponents-core";
var RestVirtualDataSourceDataProviderWorker = /** @class */ /*@__PURE__*/ (function (_super) {
__extends(RestVirtualDataSourceDataProviderWorker, _super);
function RestVirtualDataSourceDataProviderWorker(settings) {
var e_1, _a;
var _this = _super.call(this, settings) || this;
_this._baseUri = null;
_this._entitySet = null;
_this._sortDescriptions = null;
_this._groupDescriptions = null;
_this._filterExpressions = null;
_this._summaryDescriptions = null;
_this._desiredPropeties = null;
_this._schemaIncludedProperties = null;
_this._enableJsonp = true;
_this._isAggregationSupported = false;
_this._provideFullCount = null;
_this._provideOrderByParameter = null;
_this._provideFilterParameter = null;
_this._provideAggregationParameter = null;
_this._provideAggregatedCount = null;
_this._providePagingParameter = null;
_this._provideDesiredPropertiesParameter = null;
_this._provideUri = null;
_this._performFetch = null;
_this._fixedFullCount = -1;
_this._groupInformation = null;
_this._summaryInformation = null;
_this._filterString = null;
_this._selectedString = null;
_this.doWork = _this.doWork.bind(_this);
_this._baseUri = settings.baseUri;
_this._entitySet = settings.entitySet;
_this._sortDescriptions = settings.sortDescriptions;
_this._groupDescriptions = settings.groupDescriptions;
if (_this._groupDescriptions != null && _this._groupDescriptions.size() > 0) {
_this._sortDescriptions = new SortDescriptionCollection();
try {
for (var _b = __values(_this.iter(settings.sortDescriptions)), _c = _b.next(); !_c.done; _c = _b.next()) {
var sd = _c.value;
_this._sortDescriptions.add(sd);
}
}
catch (e_1_1) {
e_1 = { error: e_1_1 };
}
finally {
try {
if (_c && !_c.done && (_a = _b.return))
_a.call(_b);
}
finally {
if (e_1)
throw e_1.error;
}
}
for (var i = 0; i < _this._groupDescriptions.size(); i++) {
_this._sortDescriptions.insert(i, _this._groupDescriptions.get(i));
}
}
_this._filterExpressions = settings.filterExpressions;
_this._desiredPropeties = settings.propertiesRequested;
if (settings.schemaIncludedProperties != null) {
_this._schemaIncludedProperties = new Set();
for (var i = 0; i < settings.schemaIncludedProperties.length; i++) {
_this._schemaIncludedProperties.add(settings.schemaIncludedProperties[i]);
}
}
_this._summaryDescriptions = settings.summaryDescriptions;
_this._fixedFullCount = settings.fixedFullCount;
_this._summaryScope = settings.summaryScope;
_this._enableJsonp = settings.enableJsonp;
_this._provideFullCount = settings.provideFullCount;
_this._performFetch = settings.performFetch;
_this._provideAggregationParameter = settings.provideAggregationParameter;
_this._provideFilterParameter = settings.provideFilterParameter;
_this._provideOrderByParameter = settings.provideOrderByParameter;
_this._provideUri = settings.provideUri;
_this._providePagingParameter = settings.providePagingParameter;
_this._provideDesiredPropertiesParameter = settings.provideDesiredPropertiesParameter;
_this._provideItems = settings.provideItems;
_this._provideAggregatedCount = settings.provideAggregatedCount;
if (!_this._provideItems) {
_this._provideItems = function (res) {
return res ? res.items : null;
};
}
if (!_this._provideFullCount) {
_this._provideFullCount = function (p) {
if (p.fullCount) {
return p.fullCount;
}
else {
return _this._fixedFullCount >= 0 ? _this._fixedFullCount : 0;
}
};
}
if (!_this._provideOrderByParameter) {
_this._provideOrderByParameter = function (args, orderByString, orderBy) {
args.push({ name: "orderBy", value: encodeURIComponent(orderByString) });
};
}
if (!_this._providePagingParameter) {
_this._providePagingParameter = function (args, skip, take) {
args.push({ name: "skip", value: skip });
args.push({ name: "take", value: take });
};
}
if (!_this._provideAggregationParameter) {
_this._provideAggregationParameter = function (args, fetchCountOnly, groupByString, groupBy, summaryString, summary) {
args.push({ name: "groupBy", value: groupByString });
args.push({ name: "aggregate", value: "count" });
};
}
if (!_this._provideUri) {
_this._provideUri = function (baseUri, entitySet, args) {
var requestUri = baseUri;
requestUri += "/" + entitySet;
if (args.length > 0) {
requestUri += "?";
}
var argsString = "";
for (var i = 0; i < args.length; i++) {
if (i > 0) {
argsString += "&";
}
argsString += args[i].name + "=" + args[i].value;
}
return requestUri + argsString;
};
}
_this._isAggregationSupported = settings.isAggregationSupported;
window.setTimeout(_this.doWork, 100);
return _this;
}
Object.defineProperty(RestVirtualDataSourceDataProviderWorker.prototype, "sortDescriptions", {
get: function () {
return this._sortDescriptions;
},
enumerable: false,
configurable: true
});
Object.defineProperty(RestVirtualDataSourceDataProviderWorker.prototype, "filterExpressions", {
get: function () {
return this._filterExpressions;
},
enumerable: false,
configurable: true
});
Object.defineProperty(RestVirtualDataSourceDataProviderWorker.prototype, "desiredProperties", {
get: function () {
return this._desiredPropeties;
},
enumerable: false,
configurable: true
});
RestVirtualDataSourceDataProviderWorker.prototype.initialize = function () {
_super.prototype.initialize.call(this);
};
RestVirtualDataSourceDataProviderWorker.prototype.getTaskDataHolder = function () {
var holder = new RestVirtualDataSourceProviderTaskDataHolder();
return holder;
};
RestVirtualDataSourceDataProviderWorker.prototype.getCompletedTaskData = function (holder, completed) {
_super.prototype.getCompletedTaskData.call(this, holder, completed);
};
RestVirtualDataSourceDataProviderWorker.prototype.removeCompletedTaskData = function (holder, completed) {
_super.prototype.removeCompletedTaskData.call(this, holder, completed);
};
RestVirtualDataSourceDataProviderWorker.prototype.getTasksData = function (holder) {
_super.prototype.getTasksData.call(this, holder);
};
RestVirtualDataSourceDataProviderWorker.prototype.iter = function (coll) {
var i;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
i = 0;
_a.label = 1;
case 1:
if (!(i < coll.size()))
return [3 /*break*/, 4];
return [4 /*yield*/, coll.get(i)];
case 2:
_a.sent();
_a.label = 3;
case 3:
i++;
return [3 /*break*/, 1];
case 4: return [2 /*return*/];
}
});
};
RestVirtualDataSourceDataProviderWorker.prototype.iterFilter = function (coll) {
var i;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
i = 0;
_a.label = 1;
case 1:
if (!(i < coll.size()))
return [3 /*break*/, 4];
return [4 /*yield*/, coll.get(i)];
case 2:
_a.sent();
_a.label = 3;
case 3:
i++;
return [3 /*break*/, 1];
case 4: return [2 /*return*/];
}
});
};
RestVirtualDataSourceDataProviderWorker.prototype.iterSummaries = function (summaries) {
var i;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
i = 0;
_a.label = 1;
case 1:
if (!(i < summaries.size()))
return [3 /*break*/, 4];
return [4 /*yield*/, summaries.get(i)];
case 2:
_a.sent();
_a.label = 3;
case 3:
i++;
return [3 /*break*/, 1];
case 4: return [2 /*return*/];
}
});
};
RestVirtualDataSourceDataProviderWorker.prototype.processCompletedTask = function (completedTask, currentDelay, pageIndex, taskDataHolder) {
var _this = this;
var h = taskDataHolder;
var schema = null;
var result = null;
var schemaFetchCount = -1;
var task = completedTask.task;
try {
if (task.hasErrors) {
this.retryIndex(pageIndex, currentDelay);
return;
}
if (pageIndex == RestVirtualDataSourceDataProviderWorker.schemaRequestIndex) {
result = task.result;
schemaFetchCount = (this._provideFullCount(result));
}
else {
result = task.result;
}
}
catch (e) {
this.retryIndex(pageIndex, currentDelay);
return;
}
if (schemaFetchCount >= 0) {
this.actualCount = schemaFetchCount;
}
else {
this.actualCount = (this._provideFullCount(result));
}
schema = this.actualSchema;
if (schema == null) {
var requests_1 = 0;
this.resolveSchema(function (s) {
// resolveSchema success callback
_this.actualSchema = s;
if (_this._isAggregationSupported && (_this._groupDescriptions.size() !== 0 || _this._summaryDescriptions.size() !== 0)) {
if (_this._groupDescriptions.size() > 0) {
requests_1++;
_this.resolveGroupInformation(function (g) {
// group info success
requests_1--;
if (requests_1 === 0) {
_this.finishProcessingCompletedTask(task, pageIndex, s, result);
}
}, function () {
// group info failure
_this.retryIndex(pageIndex, currentDelay);
return;
});
}
if (_this._summaryDescriptions.size() > 0) {
requests_1++;
_this.resolveSummaryInformation(function (g) {
// summary info success
requests_1--;
if (requests_1 === 0) {
_this.finishProcessingCompletedTask(task, pageIndex, s, result);
}
}, function () {
// summary info failure
_this.retryIndex(pageIndex, currentDelay);
return;
});
}
}
else {
_this.finishProcessingCompletedTask(task, pageIndex, s, result);
}
}, function () {
// resolveSchema failure callback
_this.retryIndex(pageIndex, currentDelay);
return;
});
return;
}
this.finishProcessingCompletedTask(task, pageIndex, schema, result);
};
RestVirtualDataSourceDataProviderWorker.prototype.finishProcessingCompletedTask = function (task, pageIndex, schema, result) {
var _this = this;
var executionContext;
var pageLoaded;
var groupInformation;
var summaryInformation;
this.actualSchema = schema;
executionContext = this.executionContext;
groupInformation = this._groupInformation;
summaryInformation = this._summaryInformation;
pageLoaded = this.pageLoaded;
var page = null;
if (result != null) {
page = new RestVirtualDataSourcePage(result, schema, groupInformation, summaryInformation, pageIndex);
if (!this.isLastPage(pageIndex) && page.count() > 0 && !this.populatedActualPageSize) {
this.populatedActualPageSize = true;
this.actualPageSize = page.count();
}
}
else {
page = new RestVirtualDataSourcePage(null, schema, groupInformation, summaryInformation, pageIndex);
}
if (this.pageLoaded != null) {
if (this.executionContext != null) {
if (executionContext == null || pageLoaded == null) {
this.shutdown();
return;
}
executionContext.execute(function () { return pageLoaded(page, _this.actualCount, _this.actualPageSize); });
}
else {
if (pageLoaded == null) {
this.shutdown();
return;
}
pageLoaded(page, this.actualCount, this.actualPageSize);
}
}
};
RestVirtualDataSourceDataProviderWorker.prototype.resolveGroupInformation = function (finishAction, failureAction) {
var e_2, _a;
var _this = this;
if (this._groupInformation != null) {
finishAction(this._groupInformation);
return;
}
var orderBy = "";
var groupBy = "";
var filter = null;
var summary = "";
if (this._groupDescriptions == null || this._groupDescriptions.size() == 0) {
finishAction(null);
return;
}
if (this._provideAggregationParameter == null) {
finishAction(null);
return;
}
filter = this._filterString;
this.updateFilterString();
if (this._groupDescriptions != null) {
var first1 = true;
try {
for (var _b = __values(this.iter(this._groupDescriptions)), _c = _b.next(); !_c.done; _c = _b.next()) {
var group = _c.value;
if (first1) {
first1 = false;
}
else {
orderBy += ", ";
groupBy += ", ";
}
groupBy += group.propertyName;
if (group.direction === ListSortDirection.Descending) {
orderBy += group.propertyName + " desc";
}
else {
orderBy += group.propertyName + " asc";
}
}
}
catch (e_2_1) {
e_2 = { error: e_2_1 };
}
finally {
try {
if (_c && !_c.done && (_a = _b.return))
_a.call(_b);
}
finally {
if (e_2)
throw e_2.error;
}
}
}
if (this._summaryScope === DataSourceSummaryScope.Both || this._summaryScope === DataSourceSummaryScope.Groups) {
var summaryParameters = this.getSummaryQueryParameters(true);
if (!stringIsNullOrEmpty(summaryParameters)) {
summary = ", " + summaryParameters;
}
}
var args = [];
if (this._provideOrderByParameter) {
this._provideOrderByParameter(args, orderBy, this._groupDescriptions);
}
if (this._provideFilterParameter && filter != null) {
this._provideFilterParameter(args, filter, this._filterExpressions);
}
if (this._provideAggregationParameter) {
this._provideAggregationParameter(args, true, groupBy, this._groupDescriptions, summary, this._summaryDescriptions);
}
var uri = this._provideUri(this._baseUri, this._entitySet, args);
try {
var groupInformation_1 = [];
var success_1 = function (data, response) { return _this.groupSuccess(data, response, finishAction, failureAction, groupInformation_1); };
var failure_1 = function (err) { return _this.groupError(err, finishAction, failureAction, groupInformation_1); };
var run_ = null;
var headers = { 'Content-Type': 'application/json', Accept: 'application/json' };
var request = {
requestUri: uri,
enableJsonpCallback: this._enableJsonp,
method: 'GET',
headers: headers,
data: null
};
run_ = function () {
_this.fetchUri(request, success_1, failure_1);
};
run_();
}
catch (e) {
failureAction();
}
};
RestVirtualDataSourceDataProviderWorker.prototype.fetchUri = function (request, success, failure) {
if (this._performFetch) {
this._performFetch(request, success, failure);
}
else {
fetch(request.requestUri, {
method: request.method,
headers: request.headers,
}).then(function (res) {
res.json().then(function (j) {
success(j, res);
});
}).catch(function (e) {
failure(e);
});
}
};
RestVirtualDataSourceDataProviderWorker.prototype.groupError = function (err, finishAction, failureAction, groupInformation) {
this._groupInformation = null;
};
RestVirtualDataSourceDataProviderWorker.prototype.groupSuccess = function (data, response, finishAction, failureAction, groupInformation) {
var e_3, _a;
var groupNames = [];
try {
for (var _b = __values(this.iter(this._groupDescriptions)), _c = _b.next(); !_c.done; _c = _b.next()) {
var group = _c.value;
groupNames.push(group.propertyName);
}
}
catch (e_3_1) {
e_3 = { error: e_3_1 };
}
finally {
try {
if (_c && !_c.done && (_a = _b.return))
_a.call(_b);
}
finally {
if (e_3)
throw e_3.error;
}
}
var groupNamesArray = groupNames;
var items = this._provideItems(data);
if (items && items.length > 0) {
var currentIndex = 0;
for (var i = 0; i < items.length; i++) {
this.addGroup(groupInformation, groupNames, groupNames, currentIndex, items[i]);
}
}
this._groupInformation = groupInformation;
finishAction(this._groupInformation);
};
RestVirtualDataSourceDataProviderWorker.prototype.addGroup = function (groupInformation, groupNames, groupNamesArray, currentIndex, group) {
var e_4, _a;
var groupValues = [];
try {
for (var groupNames_1 = __values(groupNames), groupNames_1_1 = groupNames_1.next(); !groupNames_1_1.done; groupNames_1_1 = groupNames_1.next()) {
var name_1 = groupNames_1_1.value;
if (group[name_1]) {
groupValues.push(group[name_1]);
}
}
}
catch (e_4_1) {
e_4 = { error: e_4_1 };
}
finally {
try {
if (groupNames_1_1 && !groupNames_1_1.done && (_a = groupNames_1.return))
_a.call(groupNames_1);
}
finally {
if (e_4)
throw e_4.error;
}
}
var groupCount = 0;
//todo: make this customizable
if (this._provideAggregatedCount) {
var ct = this._provideAggregatedCount(group);
}
else {
if (group["aggregatedCount"]) {
groupCount = Convert.toInt321(group["aggregatedCount"]);
}
}
var summaryResults = null;
if (this._summaryScope == DataSourceSummaryScope.Both || this._summaryScope == DataSourceSummaryScope.Groups) {
summaryResults = this.createSummaryResults(group);
}
var groupInfo = new DefaultSectionInformation(currentIndex, currentIndex + (groupCount - 1), groupNamesArray, groupValues, summaryResults);
groupInformation.push(groupInfo);
};
RestVirtualDataSourceDataProviderWorker.prototype.resolveSummaryInformation = function (finishAction, failureAction) {
var _this = this;
if (this._summaryInformation != null) {
finishAction(this._summaryInformation);
return;
}
var filter = null;
var summary = null;
if (this._summaryDescriptions == null ||
this._summaryDescriptions.size() == 0 ||
this._summaryScope == DataSourceSummaryScope.Groups ||
this._summaryScope == DataSourceSummaryScope.None) {
finishAction(null);
return;
}
filter = this._filterString;
this.updateFilterString();
summary = this.getSummaryQueryParameters(false);
var args = [];
// if (this._provideOrderByParameter) {
// args.push({ name: "orderBy", value: this._provideOrderByParameter(orderBy, this._sortDescriptions) });
// }
if (this._provideFilterParameter && filter != null) {
this._provideFilterParameter(args, filter, this._filterExpressions);
}
if (this._provideAggregationParameter) {
this._provideAggregationParameter(args, true, null, null, summary, this._summaryDescriptions);
}
var uri = this._provideUri(this._baseUri, this._entitySet, args);
// let commandText = this._entitySet + "?$apply=";
// if (!stringIsNullOrEmpty(filter)) {
// commandText += "filter(" + filter + ")/";
// }
// commandText += "aggregate(" + summary + ")";
try {
var summaryInformation_1 = [];
var success_2 = function (data, response) { return _this.summarySuccess(data, response, finishAction, failureAction, summaryInformation_1); };
var failure_2 = function (err) { return _this.summaryError(err, finishAction, failureAction, summaryInformation_1); };
var run_ = null;
var headers = { 'Content-Type': 'application/json', Accept: 'application/json' };
var request = {
requestUri: uri,
enableJsonpCallback: this._enableJsonp,
method: 'GET',
headers: headers,
data: null
};
run_ = function () {
_this.fetchUri(request, success_2, failure_2);
};
run_();
}
catch (e) {
failureAction();
}
};
RestVirtualDataSourceDataProviderWorker.prototype.summarySuccess = function (data, response, finishAction, failureAction, summaryInformation) {
if (data && data.value && data.value.length > 0) {
summaryInformation = this.createSummaryResults(data.value[0]);
}
this._summaryInformation = summaryInformation;
finishAction(this._summaryInformation);
};
RestVirtualDataSourceDataProviderWorker.prototype.summaryError = function (err, finishAction, failureAction, summaryInformation) {
this._summaryInformation = null;
};
RestVirtualDataSourceDataProviderWorker.prototype.getSummaryQueryParameters = function (ignoreCount) {
var e_5, _a;
var result = "";
if (this._summaryDescriptions != null) {
var first = true;
var countExists = false;
try {
for (var _b = __values(this.iterSummaries(this._summaryDescriptions)), _c = _b.next(); !_c.done; _c = _b.next()) {
var summary = _c.value;
if (summary.operand == DataSourceSummaryOperand.Count && (ignoreCount || countExists)) {
continue;
}
if (!first) {
result += ", ";
}
switch (summary.operand) {
case DataSourceSummaryOperand.Average:
result += summary.propertyName + " with average as " + summary.propertyName + "Average";
break;
case DataSourceSummaryOperand.Min:
result += summary.propertyName + " with min as " + summary.propertyName + "Min";
break;
case DataSourceSummaryOperand.Max:
result += summary.propertyName + " with max as " + summary.propertyName + "Max";
break;
case DataSourceSummaryOperand.Sum:
result += summary.propertyName + " with sum as " + summary.propertyName + "Sum";
break;
case DataSourceSummaryOperand.Count:
result += "$count as $__count";
countExists = true;
break;
}
first = false;
}
}
catch (e_5_1) {
e_5 = { error: e_5_1 };
}
finally {
try {
if (_c && !_c.done && (_a = _b.return))
_a.call(_b);
}
finally {
if (e_5)
throw e_5.error;
}
}
}
return result;
};
RestVirtualDataSourceDataProviderWorker.prototype.createSummaryResults = function (data) {
var e_6, _a;
var summaryResults = [];
try {
for (var _b = __values(this.iterSummaries(this._summaryDescriptions)), _c = _b.next(); !_c.done; _c = _b.next()) {
var summary = _c.value;
var summaryName = summary.propertyName;
switch (summary.operand) {
case DataSourceSummaryOperand.Average:
summaryName += "Average";
break;
case DataSourceSummaryOperand.Min:
summaryName += "Min";
break;
case DataSourceSummaryOperand.Max:
summaryName += "Max";
break;
case DataSourceSummaryOperand.Sum:
summaryName += "Sum";
break;
case DataSourceSummaryOperand.Count:
summaryName = "$__count";
break;
}
var summaryValue = null;
if (data && data[summaryName]) {
summaryValue = data[summaryName];
}
var summaryResult = new DefaultSummaryResult(summary.propertyName, summary.operand, summaryValue);
summaryResults.push(summaryResult);
}
}
catch (e_6_1) {
e_6 = { error: e_6_1 };
}
finally {
try {
if (_c && !_c.done && (_a = _b.return))
_a.call(_b);
}
finally {
if (e_6)
throw e_6.error;
}
}
return summaryResults;
};
RestVirtualDataSourceDataProviderWorker.prototype.resolveSchemaFromItems = function (items) {
var lds = new LocalDataSource();
lds.dataSource = items;
lds.flushAutoRefresh();
return lds.actualSchema;
};
RestVirtualDataSourceDataProviderWorker.prototype.resolveSchema = function (finishAction, failureAction) {
var _this = this;
if (!this._provideItems || !this._providePagingParameter) {
failureAction("required providers for items and paging are not specified");
return;
}
var success_ = function (res) {
var items = _this._provideItems(res);
if (items && items.length > 0) {
var schema = _this.resolveSchemaFromItems(items);
if (_this._schemaIncludedProperties != null) {
var propertyNames = [];
var propertyTypes = [];
for (var i = 0; i < schema.propertyNames.length; i++) {
if (!_this._schemaIncludedProperties.has(schema.propertyNames[i])) {
continue;
}
propertyNames.push(schema.propertyNames[i]);
propertyTypes.push(schema.propertyTypes[i]);
}
schema = new DefaultDataSourceSchema(propertyNames, propertyTypes, schema.primaryKey, schema.propertyDataIntents, schema.subSchemas);
}
finishAction(schema);
}
else {
failureAction("could not find items to resolve schema");
}
};
var failure_ = function (e) { return failureAction(e); };
var args = [];
if (this._providePagingParameter) {
this._providePagingParameter(args, 0, this.actualPageSize);
}
var uri = this._provideUri(this._baseUri, this._entitySet, args);
try {
var run_ = null;
var headers = { 'Content-Type': 'application/json', Accept: 'application/json' };
var request = {
requestUri: uri,
enableJsonpCallback: this._enableJsonp,
method: 'GET',
headers: headers,
data: null
};
run_ = function () {
_this.fetchUri(request, success_, failure_);
};
run_();
}
catch (e) {
failureAction(e);
}
};
RestVirtualDataSourceDataProviderWorker.prototype.makeTaskForRequest = function (request, retryDelay) {
var e_7, _a;
var args = [];
// if (this._provideAggregationParameter) {
// args.push({ name: "apply", value: this._provideAggregationParameter(true, groupBy, this._groupDescriptions, summary, this._summaryDescriptions) });
// }
var actualPageSize = 0;
var sortDescriptions = null;
actualPageSize = this.actualPageSize;
sortDescriptions = this.sortDescriptions;
//let requestUrl: string = this._baseUri;
//requestUrl += "/" + this._entitySet;
var queryStarted = false;
this.updateFilterString();
if (this._filterString != null) {
if (this._provideFilterParameter) {
this._provideFilterParameter(args, this._filterString, this._filterExpressions);
}
}
if (this.sortDescriptions != null) {
var sortString = null;
try {
for (var _b = __values(this.iter(this.sortDescriptions)), _c = _b.next(); !_c.done; _c = _b.next()) {
var sort = _c.value;
if (sortString == null) {
sortString = "";
}
else {
sortString += ", ";
}
if (sort.direction == ListSortDirection.Descending) {
sortString += sort.propertyName + " desc";
}
else {
sortString += sort.propertyName;
}
}
}
catch (e_7_1) {
e_7 = { error: e_7_1 };
}
finally {
try {
if (_c && !_c.done && (_a = _b.return))
_a.call(_b);
}
finally {
if (e_7)
throw e_7.error;
}
}
if (sortString != null) {
if (this._provideOrderByParameter) {
this._provideOrderByParameter(args, sortString, this._sortDescriptions);
}
}
}
if (this.desiredProperties != null && this.desiredProperties.length > 0) {
var selectString = "";
var first = true;
var $t = this.desiredProperties;
for (var i = 0; i < $t.length; i++) {
var select = $t[i];
if (first) {
first = false;
}
else {
selectString += ", ";
}
selectString += select;
}
if (this._provideDesiredPropertiesParameter) {
this._provideDesiredPropertiesParameter(args, selectString, this._desiredPropeties);
}
}
if (this._providePagingParameter) {
if (request.index == RestVirtualDataSourceDataProviderWorker.schemaRequestIndex) {
this._providePagingParameter(args, 0, actualPageSize);
}
else {
this._providePagingParameter(args, request.index * actualPageSize, actualPageSize);
}
}
var task = new AsyncVirtualDataTask();
var uri = this._provideUri(this._baseUri, this._entitySet, args);
if (request.index == RestVirtualDataSourceDataProviderWorker.schemaRequestIndex) {
this.executeRequest(uri, queryStarted, 0, actualPageSize, task);
}
else {
this.executeRequest(uri, queryStarted, request.index * actualPageSize, actualPageSize, task);
}
request.taskHolder = new AsyncDataSourcePageTaskHolder();
request.taskHolder.task = task;
this.tasks.add(request);
};
RestVirtualDataSourceDataProviderWorker.prototype.updateFilterString = function () {
var e_8, _a;
if (this.filterExpressions != null && this.filterExpressions.size() > 0 && this._filterString == null) {
var sb = "";
var first = true;
try {
for (var _b = __values(this.iterFilter(this.filterExpressions)), _c = _b.next(); !_c.done; _c = _b.next()) {
var expr = _c.value;
if (first) {
first = false;
}
else {
sb += " AND ";
}
var visitor = new ODataDataSourceFilterExpressionVisitor(0);
visitor.visit(expr);
var txt = visitor.toString();
if (this.filterExpressions.size() > 1) {
txt = "(" + txt + ")";
}
sb += (txt);
}
}
catch (e_8_1) {
e_8 = { error: e_8_1 };
}
finally {
try {
if (_c && !_c.done && (_a = _b.return))
_a.call(_b);
}
finally {
if (e_8)
throw e_8.error;
}
}
this._filterString = sb;
}
};
RestVirtualDataSourceDataProviderWorker.prototype.executeRequest = function (requestUrl, queryStarted, skip, top, task) {
var _this = this;
// if (!queryStarted) {
// queryStarted = true;
// requestUrl += "?";
// } else {
// requestUrl += "&";
// }
// requestUrl += "$skip=" + skip + "&$top=" + top + "&$count=true";
var requestUrl_ = requestUrl;
var self_ = this;
var success_ = function (data, response) { return _this.success(task, data, response); };
var failure_ = function (err) { return _this.error(task, err); };
var run_ = null;
var headers = { 'Content-Type': 'application/json', Accept: 'application/json' };
var request = {
requestUri: requestUrl_,
enableJsonpCallback: this._enableJsonp,
method: 'GET',
headers: headers,
data: null
};
run_ = function () {
_this.fetchUri(request, success_, failure_);
};
task.run = run_;
};
RestVirtualDataSourceDataProviderWorker.prototype.success = function (t, data, response) {
t.result = data;
t.isCompleted = true;
};
RestVirtualDataSourceDataProviderWorker.prototype.error = function (t, result) {
t.isCompleted = true;
t.hasErrors = true;
};
RestVirtualDataSourceDataProviderWorker.prototype.createBatchRequest = function (changes) {
//TODO: updates
};
RestVirtualDataSourceDataProviderWorker.prototype.getRequestUriWithKey = function (key) {
var result = "";
var keys = Object.keys(key);
for (var i = 0; i < keys.length; i++) {
if (i > 0) {
result += ",";
}
result += "".concat(keys[i], "=").concat(key[keys[i]]);
}
return "".concat(this._entitySet, "(").concat(result, ")");
};
RestVirtualDataSourceDataProviderWorker.schemaRequestIndex = -1;
return RestVirtualDataSourceDataProviderWorker;
}(AsyncVirtualDataSourceProviderWorker));
export { RestVirtualDataSourceDataProviderWorker };