UNPKG

igniteui-webcomponents-datasources

Version:

Reference custom data providers for the Ignite UI Web Components data source.

1,278 lines (1,268 loc) 185 kB
/*! THIS INFRAGISTICS ULTIMATE SOFTWARE LICENSE AGREEMENT ("AGREEMENT") LOCATED HERE: https://www.infragistics.com/legal/license/igultimate-la https://www.infragistics.com/legal/license/igultimate-eula GOVERNS THE LICENSING, INSTALLATION AND USE OF INFRAGISTICS SOFTWARE. BY DOWNLOADING AND/OR INSTALLING AND USING INFRAGISTICS SOFTWARE: you are indicating that you have read and understand this Agreement, and agree to be legally bound by it on behalf of the yourself and your company. */ import { fromEnum, XName, DataSourceSchemaPropertyType, XDocument, XmlNodeType, typeCast, XElement, ODataDataSourceSchema, XNamespace, markType, AsyncVirtualDataSourceProviderTaskDataHolder, SortDescriptionCollection, ListSortDirection, DataSourceSummaryScope, stringIsNullOrEmpty, Convert, DefaultSectionInformation, DataSourceSummaryOperand, DefaultSummaryResult, AsyncVirtualDataTask, AsyncDataSourcePageTaskHolder, ODataDataSourceFilterExpressionVisitor, TransactionType, AsyncVirtualDataSourceProviderWorker, AsyncVirtualDataSourceDataProviderWorkerSettings, FilterExpressionCollection, SummaryDescriptionCollection, DataSourcePageRequestPriority, runOn, DataSourceDataProviderSchemaChangedEventArgs, stringContains, Base, IDataSourceVirtualDataProvider_$type, VirtualDataSource, LocalDataSource, DefaultDataSourceSchema } from 'igniteui-webcomponents-core'; import { __values, __extends, __generator } from 'tslib'; var EntityProperty = /** @class */ /*@__PURE__*/ (function () { function EntityProperty(name, schemaType) { this._name = null; this._isNullable = false; this._type = null; this.name = name; this.type = schemaType; } Object.defineProperty(EntityProperty.prototype, "name", { get: function () { return this._name; }, set: function (value) { this._name = value; }, enumerable: false, configurable: true }); Object.defineProperty(EntityProperty.prototype, "isNullable", { get: function () { return this._isNullable; }, set: function (value) { this._isNullable = value; }, enumerable: false, configurable: true }); Object.defineProperty(EntityProperty.prototype, "type", { get: function () { return this._type; }, set: function (value) { this._type = value; }, enumerable: false, configurable: true }); return EntityProperty; }()); function toArray(en) { return Array.from(fromEnum(en)); } function first(iter) { var e_1, _a; try { for (var iter_1 = __values(iter), iter_1_1 = iter_1.next(); !iter_1_1.done; iter_1_1 = iter_1.next()) { var v = iter_1_1.value; return v; } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (iter_1_1 && !iter_1_1.done && (_a = iter_1.return)) _a.call(iter_1); } finally { if (e_1) throw e_1.error; } } throw new Error("Iterable contained no elements, expected at least one"); } var LinkedList = /** @class */ /*@__PURE__*/ (function () { function LinkedList() { } Object.defineProperty(LinkedList.prototype, "first", { get: function () { return this._first; }, enumerable: false, configurable: true }); Object.defineProperty(LinkedList.prototype, "last", { get: function () { return this._last; }, enumerable: false, configurable: true }); LinkedList.prototype.addFirst = function (item) { if (this._first == null) { this._first = new LinkedListNode(item); this._last = this._first; } else { var oldFirst = this._first; this._first = new LinkedListNode(item); this._first.next = oldFirst; oldFirst.prev = this._first; } }; LinkedList.prototype.addLast = function (item) { if (this._last == null) { this._first = new LinkedListNode(item); this._last = this._first; } else { var oldLast = this._last; this._last = new LinkedListNode(item); this._last.prev = oldLast; oldLast.next = this._last; } }; LinkedList.prototype.removeFirst = function () { this.remove(this.first); }; LinkedList.prototype.clear = function () { this._first = null; this._last = null; }; LinkedList.prototype.contains = function (value) { var curr = this.first; while (curr != null) { if (curr.value === value) { return true; } curr = curr.next; } return false; }; LinkedList.prototype.removeValue = function (value) { var curr = this.first; while (curr != null) { if (curr.value === value) { this.remove(curr); return; } curr = curr.next; } }; LinkedList.prototype.remove = function (node) { if (this._first == node) { this._first = node.next; if (node.next != null) { node.next.prev = null; } } if (this._last == node) { this._last = node.prev; if (node.prev != null) { node.prev.next = null; } } if (node.prev != null) { node.prev.next = node.next; } if (node.next != null) { node.next.prev = node.prev; } node.next = null; node.prev = null; }; return LinkedList; }()); var LinkedListNode = /** @class */ /*@__PURE__*/ (function () { function LinkedListNode(item) { if (item !== undefined) { this.value = item; } } Object.defineProperty(LinkedListNode.prototype, "value", { get: function () { return this._value; }, set: function (value) { this._value = value; }, enumerable: false, configurable: true }); Object.defineProperty(LinkedListNode.prototype, "prev", { get: function () { return this._prev; }, set: function (value) { this._prev = value; }, enumerable: false, configurable: true }); Object.defineProperty(LinkedListNode.prototype, "next", { get: function () { return this._next; }, set: function (value) { this._next = value; }, enumerable: false, configurable: true }); return LinkedListNode; }()); var Entity = /** @class */ /*@__PURE__*/ (function () { function Entity(name, entityNode) { this._properties = null; this._primaryKey = null; this._name = null; this.name = name; this.loadProperties(entityNode); this.loadPrimaryKey(entityNode); } Object.defineProperty(Entity.prototype, "name", { get: function () { return this._name; }, set: function (value) { this._name = value; }, enumerable: false, configurable: true }); Object.defineProperty(Entity.prototype, "properties", { get: function () { if (null == this._properties) { this._properties = new Map(); } return this._properties; }, enumerable: false, configurable: true }); Object.defineProperty(Entity.prototype, "primaryKey", { get: function () { if (null == this._primaryKey) { this._primaryKey = []; } return this._primaryKey; }, enumerable: false, configurable: true }); Entity.prototype.loadProperties = function (entityNode) { var children = toArray(entityNode.elements()); var elementCount = children.length; var nameAttr = XName.get("Name", ""); var typeAttr = XName.get("Type", ""); for (var i = 0; i < elementCount; i++) { var node = children[i]; if (node.name.localName == "Property") { var name_1 = node.attribute(nameAttr).value; var type = node.attribute(typeAttr).value; this.properties.set(name_1, new EntityProperty(name_1, type)); } } ; }; Entity.prototype.loadPrimaryKey = function (entityNode) { var children = toArray(entityNode.elements()); var elementCount = children.length; var nameAttr = XName.get("Name", ""); for (var i = 0; i < elementCount; i++) { var node = children[i]; if (node.name.localName == "Key") { var subChildren = toArray(node.elements()); var keyNodeCOunt = subChildren.length; for (var j = 0; j < keyNodeCOunt; j++) { var keyNode = subChildren[j]; if (keyNode.name.localName == "PropertyRef") { this.primaryKey.push(keyNode.attribute(nameAttr).value); } } } } ; }; return Entity; }()); var EntitySet = /** @class */ /*@__PURE__*/ (function () { function EntitySet(name, entityType) { this._entityName = null; this._entityNamespace = null; this._entityType = null; this._name = null; this.name = name; this.entityType = entityType; if (entityType.indexOf(".") >= 0) { var parts = entityType.split('.'); if (parts.length == 2) { this.entityNamespace = parts[0]; this.entityName = parts[1]; } else { var i = entityType.lastIndexOf('.'); this.entityNamespace = entityType.substr(0, i); this.entityName = entityType.substr(i + 1); } } else { this.entityNamespace = entityType; this.entityName = entityType; } } Object.defineProperty(EntitySet.prototype, "entityName", { get: function () { return this._entityName; }, set: function (value) { this._entityName = value; }, enumerable: false, configurable: true }); Object.defineProperty(EntitySet.prototype, "entityNamespace", { get: function () { return this._entityNamespace; }, set: function (value) { this._entityNamespace = value; }, enumerable: false, configurable: true }); Object.defineProperty(EntitySet.prototype, "entityType", { get: function () { return this._entityType; }, set: function (value) { this._entityType = value; }, enumerable: false, configurable: true }); Object.defineProperty(EntitySet.prototype, "name", { get: function () { return this._name; }, set: function (value) { this._name = value; }, enumerable: false, configurable: true }); return EntitySet; }()); var ODataDataSourcePage = /** @class */ /*@__PURE__*/ (function () { function ODataDataSourcePage(sourceData_, schema, groupInformation, summaryInformation, pageIndex) { this._actualData = null; this._schema = null; this._pageIndex = 0; this._groupInformation = null; this._summaryInformation = null; if (sourceData_ == null) { this._actualData = null; } else { var count = (sourceData_.value.length); this._actualData = []; var dateProps = new Set(); for (var i = 0; i < schema.propertyNames.length; i++) { if (schema.propertyTypes[i] == DataSourceSchemaPropertyType.DateTimeValue || schema.propertyTypes[i] == DataSourceSchemaPropertyType.DateTimeOffsetValue) { dateProps.add(schema.propertyNames[i]); } } var value_ = void 0; var _loop_1 = function (i_) { var currItem_ = sourceData_.value[i_]; var dict = new Map(); var properties = Array.from(Object.keys(currItem_)); var values = (properties.map(function (k) { return currItem_[k]; })); for (var i1 = 0; i1 < properties.length; i1++) { value_ = values[i1]; if (dateProps.has(properties[i1])) { value_ = new Date(value_); } dict.set(properties[i1], value_); } this_1._actualData[i_] = dict; }; var this_1 = this; for (var i_ = 0; i_ < count; i_++) { _loop_1(i_); } } this._schema = schema; this._groupInformation = groupInformation; this._summaryInformation = summaryInformation; this._pageIndex = pageIndex; } ODataDataSourcePage.prototype.count = function () { return this._actualData.length; }; ODataDataSourcePage.prototype.getItemAtIndex = function (index) { return this._actualData[index]; }; ODataDataSourcePage.prototype.getItemValueAtIndex = function (index, valueName) { var item = this._actualData[index]; if (!item.has(valueName)) { return null; } return item.get(valueName); }; ODataDataSourcePage.prototype.pageIndex = function () { return this._pageIndex; }; ODataDataSourcePage.prototype.schema = function () { return this._schema; }; ODataDataSourcePage.prototype.getGroupInformation = function () { return this._groupInformation; }; ODataDataSourcePage.prototype.getSummaryInformation = function () { return this._summaryInformation; }; return ODataDataSourcePage; }()); var Schema = /** @class */ /*@__PURE__*/ (function () { function Schema(namespace, entityTypeElements, entitySetElements) { this._entities = null; this._entitySets = null; this._namespace = null; this.namespace = namespace; this.loadEntities(entityTypeElements); this.loadEntitySets(entitySetElements); } Object.defineProperty(Schema.prototype, "entities", { get: function () { if (null == this._entities) { this._entities = new Map(); } return this._entities; }, enumerable: false, configurable: true }); Object.defineProperty(Schema.prototype, "entitySets", { get: function () { if (null == this._entitySets) { this._entitySets = new Map(); } return this._entitySets; }, enumerable: false, configurable: true }); Object.defineProperty(Schema.prototype, "namespace", { get: function () { return this._namespace; }, set: function (value) { this._namespace = value; }, enumerable: false, configurable: true }); Schema.prototype.loadEntities = function (entityTypeElements) { var list = entityTypeElements; var elementCount = list.length; var name = XName.get("Name", ""); for (var i = 0; i < elementCount; i++) { var node = list[i]; var entity = new Entity(node.attribute(name).value, node); this.entities.set(entity.name, entity); } ; }; Schema.prototype.loadEntitySets = function (entitySetElements) { var list = entitySetElements; var elementCount = list.length; var nameAttr = XName.get("Name", ""); var entityType = XName.get("EntityType", ""); for (var i = 0; i < elementCount; i++) { var node = list[i]; var entitySet = new EntitySet(node.attribute(nameAttr).value, node.attribute(entityType).value); this.entitySets.set(entitySet.name, entitySet); } ; }; return Schema; }()); var ODataSchemaProvider = /** @class */ /*@__PURE__*/ (function () { function ODataSchemaProvider(metadataDocument) { this._entityTypeSchemaNamespace = null; this._entitySetSchemaNamespace = null; this._schema = null; if (null == metadataDocument) { return; } var xmlDoc = XDocument.parse(metadataDocument); var schemaElements = toArray(first(fromEnum(first(fromEnum(xmlDoc.elements())).elements())).elements1(XName.get("Schema", ODataSchemaProvider.nS.namespaceName))); if (null == schemaElements) { return; } var entitySetElements = null; var entityTypeElements = null; var elementCount = schemaElements.length; var entityContainer = XName.get("EntityContainer", ODataSchemaProvider.nS.namespaceName); var entitySet = XName.get("EntitySet", ODataSchemaProvider.nS.namespaceName); var namespaceAttribute = XName.get("Namespace", ""); var entityType = XName.get("EntityType", ODataSchemaProvider.nS.namespaceName); for (var i = 0; i < elementCount; i++) { var node = schemaElements[i]; if (node.nodeType != XmlNodeType.Element) { continue; } var schemaElement = schemaElements[i]; if (null == entitySetElements) { var nodes = toArray(schemaElement.elements1(entityContainer)); if (null != nodes && nodes.length > 0) { entitySetElements = toArray((typeCast(XElement.$type, nodes[0])).elements1(entitySet)); if (null != entitySetElements) { this._entitySetSchemaNamespace = schemaElement.attribute(namespaceAttribute).value; } } } if (null == entityTypeElements) { entityTypeElements = toArray(schemaElement.elements1(entityType)); if (null != entityTypeElements) { this._entityTypeSchemaNamespace = schemaElement.attribute(namespaceAttribute).value; } } } if (null == entitySetElements || null == entityTypeElements) { return; } this.schema = new Schema(this._entityTypeSchemaNamespace, entityTypeElements, entitySetElements); } Object.defineProperty(ODataSchemaProvider.prototype, "schema", { get: function () { return this._schema; }, set: function (value) { this._schema = value; }, enumerable: false, configurable: true }); ODataSchemaProvider.prototype.getODataDataSourceSchema = function (entitySet) { var e_1, _a, e_2, _b; if (this.schema == null) { return null; } var valueNames = []; var valueTypes = []; var primaryKey = []; var es = this.schema.entitySets.get(entitySet); if (null != es) { var entity = this.schema.entities.get(es.entityName); if (null != entity) { try { for (var _c = __values(entity.properties.values()), _d = _c.next(); !_d.done; _d = _c.next()) { var property = _d.value; valueNames.push(property.name); if (property.type == "Edm.String") { valueTypes.push(DataSourceSchemaPropertyType.StringValue); } else if (property.type == "Edm.Int16" || property.type == "Edm.Int32") { valueTypes.push(DataSourceSchemaPropertyType.IntValue); } else if (property.type == "Edm.Double") { valueTypes.push(DataSourceSchemaPropertyType.DoubleValue); } else if (property.type == "Edm.Single") { valueTypes.push(DataSourceSchemaPropertyType.SingleValue); } else if (property.type == "Edm.Boolean") { valueTypes.push(DataSourceSchemaPropertyType.BooleanValue); } else if (property.type == "Edm.Byte") { valueTypes.push(DataSourceSchemaPropertyType.ShortValue); } else if (property.type == "Edm.DateTime" || property.type == "Edm.DateTimeOffset") { valueTypes.push(DataSourceSchemaPropertyType.DateTimeValue); } else if (property.type == "Edm.Int64") { valueTypes.push(DataSourceSchemaPropertyType.LongValue); } else if (property.type == "Edm.Decimal") { valueTypes.push(DataSourceSchemaPropertyType.DecimalValue); } else if (property.type == "Edm.SByte") { valueTypes.push(DataSourceSchemaPropertyType.ShortValue); } else { valueTypes.push(DataSourceSchemaPropertyType.ObjectValue); } } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (_d && !_d.done && (_a = _c.return)) _a.call(_c); } finally { if (e_1) throw e_1.error; } } try { for (var _e = __values(entity.primaryKey), _f = _e.next(); !_f.done; _f = _e.next()) { var k = _f.value; primaryKey.push(k); } } catch (e_2_1) { e_2 = { error: e_2_1 }; } finally { try { if (_f && !_f.done && (_b = _e.return)) _b.call(_e); } finally { if (e_2) throw e_2.error; } } } } return new ODataDataSourceSchema(valueNames, valueTypes, primaryKey); }; ODataSchemaProvider.nS = XNamespace.get("http://docs.oasis-open.org/odata/ns/edm"); return ODataSchemaProvider; }()); var ODataVirtualDataSourceProviderTaskDataHolder = /** @class */ /*@__PURE__*/ (function (_super) { __extends(ODataVirtualDataSourceProviderTaskDataHolder, _super); function ODataVirtualDataSourceProviderTaskDataHolder() { return _super !== null && _super.apply(this, arguments) || this; } ODataVirtualDataSourceProviderTaskDataHolder.$t = markType(ODataVirtualDataSourceProviderTaskDataHolder, 'ODataVirtualDataSourceProviderTaskDataHolder', AsyncVirtualDataSourceProviderTaskDataHolder.$type); return ODataVirtualDataSourceProviderTaskDataHolder; }(AsyncVirtualDataSourceProviderTaskDataHolder)); var ODataVirtualDataSourceDataProviderWorker = /** @class */ /*@__PURE__*/ (function (_super) { __extends(ODataVirtualDataSourceDataProviderWorker, _super); function ODataVirtualDataSourceDataProviderWorker(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._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._summaryScope = settings.summaryScope; _this._enableJsonp = settings.enableJsonp; _this._isAggregationSupported = settings.isAggregationSupported; window.setTimeout(_this.doWork, 100); return _this; } Object.defineProperty(ODataVirtualDataSourceDataProviderWorker.prototype, "sortDescriptions", { get: function () { return this._sortDescriptions; }, enumerable: false, configurable: true }); Object.defineProperty(ODataVirtualDataSourceDataProviderWorker.prototype, "filterExpressions", { get: function () { return this._filterExpressions; }, enumerable: false, configurable: true }); Object.defineProperty(ODataVirtualDataSourceDataProviderWorker.prototype, "desiredProperties", { get: function () { return this._desiredPropeties; }, enumerable: false, configurable: true }); ODataVirtualDataSourceDataProviderWorker.prototype.initialize = function () { _super.prototype.initialize.call(this); }; ODataVirtualDataSourceDataProviderWorker.prototype.getTaskDataHolder = function () { var holder = new ODataVirtualDataSourceProviderTaskDataHolder(); return holder; }; ODataVirtualDataSourceDataProviderWorker.prototype.getCompletedTaskData = function (holder, completed) { _super.prototype.getCompletedTaskData.call(this, holder, completed); }; ODataVirtualDataSourceDataProviderWorker.prototype.removeCompletedTaskData = function (holder, completed) { _super.prototype.removeCompletedTaskData.call(this, holder, completed); }; ODataVirtualDataSourceDataProviderWorker.prototype.getTasksData = function (holder) { _super.prototype.getTasksData.call(this, holder); }; ODataVirtualDataSourceDataProviderWorker.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*/]; } }); }; ODataVirtualDataSourceDataProviderWorker.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*/]; } }); }; ODataVirtualDataSourceDataProviderWorker.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*/]; } }); }; ODataVirtualDataSourceDataProviderWorker.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 == ODataVirtualDataSourceDataProviderWorker.schemaRequestIndex) { result = task.result; schemaFetchCount = (result['@odata.count']); } else { result = task.result; } } catch (e) { this.retryIndex(pageIndex, currentDelay); return; } if (schemaFetchCount >= 0) { this.actualCount = schemaFetchCount; } else { this.actualCount = (result['@odata.count']); } 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); }; ODataVirtualDataSourceDataProviderWorker.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 ODataDataSourcePage(result, schema, groupInformation, summaryInformation, pageIndex); if (!this.isLastPage(pageIndex) && page.count() > 0 && !this.populatedActualPageSize) { this.populatedActualPageSize = true; this.actualPageSize = page.count(); } } else { page = new ODataDataSourcePage(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); } } }; ODataVirtualDataSourceDataProviderWorker.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; } 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 commandText = this._entitySet + "?$orderby=" + orderBy + "&$apply="; if (!stringIsNullOrEmpty(filter)) { commandText += "filter(" + filter + ")/"; } commandText += "groupby((" + groupBy + "), aggregate($count as $__count" + summary + "))"; 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: this._baseUri + "/" + commandText, enableJsonpCallback: this._enableJsonp, method: 'GET', headers: headers, data: null }; run_ = function () { odatajs.oData.request(request, success_1, failure_1); }; run_(); } catch (e) { failureAction(); } }; ODataVirtualDataSourceDataProviderWorker.prototype.groupError = function (err, finishAction, failureAction, groupInformation) { this._groupInformation = null; }; ODataVirtualDataSourceDataProviderWorker.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; if (data && data.value && data.value.length > 0) { var currentIndex = 0; for (var i = 0; i < data.value.length; i++) { this.addGroup(groupInformation, groupNames, groupNames, currentIndex, data.value[i]); } } this._groupInformation = groupInformation; finishAction(this._groupInformation); }; ODataVirtualDataSourceDataProviderWorker.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; if (group["$__count"]) { groupCount = Convert.toInt321(group["$__count"]); } 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); }; ODataVirtualDataSourceDataProviderWorker.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 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: this._baseUri + "/" + commandText, enableJsonpCallback: this._enableJsonp, method: 'GET', headers: headers, data: null }; run_ = function () { odatajs.oData.request(request, success_2, failure_2); }; run_(); } catch (e) { failureAction(); } }; ODataVirtualDataSourceDataProviderWorker.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); }; ODataVirtualDataSourceDataProviderWorker.prototype.summaryError = function (err, finishAction, failureAction, summaryInformation) { this._summaryInformation = null; }; ODataVirtualDataSourceDataProviderWorker.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; }; ODataVirtualDataSourceDataProviderWorker.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; }; ODataVirtualDataSourceDataProviderWorker.prototype.resolveSchema = function (finishAction, failureAction) { var _this = this; var success_ = function (res) { var sp = new ODataSchemaProvider(res); var schema = sp.getODataDataSourceSchema(_this._entitySet); 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 ODataDataSourceSchema(propertyNames, propertyTypes, schema.primaryKey); } finishAction(schema); }; var failure_ = function () { return failureAction(); }; var baseUri_ = this._baseUri; var request = new XMLHttpRequest(); request.onreadystatechange = function () { if (request.readyState === 4) { if (request.status === 200) { success_(request.responseText); } else { failure_(); } } }; request.open('Get', baseUri_ + '/$metadata'); request.send(); ; }; ODataVirtualDataSourceDataProviderWorker.prototype.makeTaskForRequest = function (request, retryDelay) { var e_7, _a; var actualPageSize = 0; var sortDescriptions = null; actualPageSize = this.actualPageSize; sortDescriptions = this.sortDescri