UNPKG

igniteui-webcomponents-datasources

Version:

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

560 lines (559 loc) 21.9 kB
import { __extends } from "tslib"; import { Base, runOn, markType } from "igniteui-webcomponents-core"; import { IDataSourceVirtualDataProvider_$type } from "igniteui-webcomponents-core"; import { SortDescriptionCollection } from "igniteui-webcomponents-core"; import { FilterExpressionCollection } from "igniteui-webcomponents-core"; import { LinkedList } from "./util"; import { DataSourcePageRequestPriority } from "igniteui-webcomponents-core"; import { ODataVirtualDataSourceDataProviderWorker } from "./ODataVirtualDataSourceDataProviderWorker"; import { ODataVirtualDataSourceDataProviderWorkerSettings } from "./ODataVirtualDataSourceDataProviderWorkerSettings"; import { DataSourceDataProviderSchemaChangedEventArgs } from "igniteui-webcomponents-core"; import { DataSourceSchemaPropertyType } from "igniteui-webcomponents-core"; import { stringContains } from "igniteui-webcomponents-core"; import { SummaryDescriptionCollection } from "igniteui-webcomponents-core"; var ODataVirtualDataSourceDataProvider = /** @class */ /*@__PURE__*/ (function (_super) { __extends(ODataVirtualDataSourceDataProvider, _super); function ODataVirtualDataSourceDataProvider() { var _this = _super.call(this) || this; _this._worker = null; _this._requests = new LinkedList(); _this._callback = null; _this._pageLoaded = null; _this._pageSizeRequested = 50; _this._baseUri = null; _this._entitySet = null; _this._timeoutMilliseconds = 10000; _this.schemaChanged = null; _this._currentFullCount = 0; _this._currentSchema = null; _this._executionContext = null; _this._updateNotifier = null; _this._deferAutoRefresh = false; _this._sortDescriptions = null; _this._groupDescriptions = null; _this._propertiesRequested = null; _this._schemaIncludedProperties = null; _this._filterExpressions = null; _this._summaryDescriptions = null; _this._enableJsonp = true; _this._schemaFetchQueued = false; _this._autoRefreshQueued = false; _this._batchCompleted = null; _this._sortDescriptions = new SortDescriptionCollection(); _this._sortDescriptions.onChanged = function () { return _this.sortDescriptions_CollectionChanged(null, null); }; _this._groupDescriptions = new SortDescriptionCollection(); _this._groupDescriptions.onChanged = function () { return _this.groupDescriptions_CollectionChanged(null, null); }; _this._filterExpressions = new FilterExpressionCollection(); _this._filterExpressions.onChanged = function () { return _this.filterExpressions_CollectionChanged(null, null); }; _this._summaryDescriptions = new SummaryDescriptionCollection(); _this._summaryDescriptions.onChanged = function () { return _this.summaryDescriptions_CollectionChanged(null, null); }; return _this; } ODataVirtualDataSourceDataProvider.prototype.filterExpressions_CollectionChanged = function (sender, e) { this.queueAutoRefresh(); }; ODataVirtualDataSourceDataProvider.prototype.sortDescriptions_CollectionChanged = function (sender, e) { this.queueAutoRefresh(); }; ODataVirtualDataSourceDataProvider.prototype.groupDescriptions_CollectionChanged = function (sender, e) { this.queueAutoRefresh(); }; ODataVirtualDataSourceDataProvider.prototype.summaryDescriptions_CollectionChanged = function (sender, e) { this.queueAutoRefresh(); }; ODataVirtualDataSourceDataProvider.prototype.addPageRequest = function (pageIndex, priority) { if (this.deferAutoRefresh) { return; } if (this._worker != null && this._worker.isShutdown) { this._worker = null; this._callback = null; } if (this._worker == null) { this.createWorker(); } if (priority == DataSourcePageRequestPriority.High) { this._requests.addFirst(pageIndex); } else { this._requests.addLast(pageIndex); } if (!this._worker.addPageRequest(pageIndex, priority)) { this._worker = null; this._callback = null; this.addPageRequest(pageIndex, priority); } }; ODataVirtualDataSourceDataProvider.prototype.createWorker = function () { if (!this.valid()) { return; } this._callback = runOn(this, this.raisePageLoaded); var settings = this.getWorkerSettings(); this._worker = new ODataVirtualDataSourceDataProviderWorker(settings); }; ODataVirtualDataSourceDataProvider.prototype.valid = function () { return this.entitySet != null && this.baseUri != null; }; ODataVirtualDataSourceDataProvider.prototype.getWorkerSettings = function () { var _this = this; return ((function () { var $ret = new ODataVirtualDataSourceDataProviderWorkerSettings(); $ret.baseUri = _this._baseUri; $ret.entitySet = _this._entitySet; $ret.pageSizeRequested = _this._pageSizeRequested; $ret.timeoutMilliseconds = _this._timeoutMilliseconds; $ret.pageLoaded = _this._callback; $ret.batchCompleted = _this._batchCompleted; $ret.executionContext = _this._executionContext; $ret.sortDescriptions = _this._sortDescriptions; $ret.groupDescriptions = _this._groupDescriptions; $ret.filterExpressions = _this._filterExpressions; $ret.propertiesRequested = _this._propertiesRequested; $ret.schemaIncludedProperties = _this._schemaIncludedProperties; $ret.summaryDescriptions = _this._summaryDescriptions; $ret.summaryScope = _this._summaryScope; $ret.enableJsonp = _this._enableJsonp; $ret.isAggregationSupported = _this.isAggregationSupported; return $ret; })()); }; ODataVirtualDataSourceDataProvider.prototype.removePageRequest = function (pageIndex) { var current = this._requests.first; while (current != null) { if (current.value == pageIndex) { this._requests.remove(current); } current = current.next; } if (this._worker == null) { return; } this._worker.removePageRequest(pageIndex); }; ODataVirtualDataSourceDataProvider.prototype.removeAllPageRequests = function () { this._requests.clear(); if (this._worker == null) { return; } this._worker.removeAllPageRequests(); }; ODataVirtualDataSourceDataProvider.prototype.close = function () { if (this._worker != null) { this._worker.shutdown(); this._worker = null; this._callback = null; } }; Object.defineProperty(ODataVirtualDataSourceDataProvider.prototype, "pageLoaded", { get: function () { return this._pageLoaded; }, set: function (value) { this._pageLoaded = value; this.queueAutoRefresh(); }, enumerable: false, configurable: true }); ODataVirtualDataSourceDataProvider.prototype.raisePageLoaded = function (page, fullCount, actualPageSize) { if (this._pageLoaded != null) { this._currentFullCount = fullCount; if (this._currentSchema == null) { var currentSchema = null; if (page != null) { currentSchema = page.schema(); } this._currentSchema = currentSchema; if (this.schemaChanged != null) { this.schemaChanged(this, new DataSourceDataProviderSchemaChangedEventArgs(this._currentSchema, this._currentFullCount)); } } if (page.pageIndex() != ODataVirtualDataSourceDataProviderWorker.schemaRequestIndex) { this._pageLoaded(page, fullCount, actualPageSize); } } }; ODataVirtualDataSourceDataProvider.prototype.killWorker = function () { if (this._worker != null) { this._worker.shutdown(); this._worker = null; this._callback = null; } }; Object.defineProperty(ODataVirtualDataSourceDataProvider.prototype, "pageSizeRequested", { get: function () { return this._pageSizeRequested; }, set: function (value) { this._pageSizeRequested = value; this.queueAutoRefresh(); }, enumerable: false, configurable: true }); Object.defineProperty(ODataVirtualDataSourceDataProvider.prototype, "baseUri", { get: function () { return this._baseUri; }, set: function (value) { var oldValue = this._baseUri; this._baseUri = value; if (oldValue != this._baseUri) { this.queueAutoRefresh(); if (this.valid() && this.deferAutoRefresh) { this.queueSchemaFetch(); } } }, enumerable: false, configurable: true }); Object.defineProperty(ODataVirtualDataSourceDataProvider.prototype, "entitySet", { get: function () { return this._entitySet; }, set: function (value) { var oldValue = this._entitySet; this._entitySet = value; if (oldValue != this._entitySet) { this.queueAutoRefresh(); if (this.valid() && this.deferAutoRefresh) { this.queueSchemaFetch(); } } }, enumerable: false, configurable: true }); Object.defineProperty(ODataVirtualDataSourceDataProvider.prototype, "timeoutMilliseconds", { get: function () { return this._timeoutMilliseconds; }, set: function (value) { this._timeoutMilliseconds = value; this.queueAutoRefresh(); }, enumerable: false, configurable: true }); ODataVirtualDataSourceDataProvider.prototype.getItemValue = function (item, valueName) { var dic = item; if (dic.has(valueName)) { return dic.get(valueName); } else { return null; } }; ODataVirtualDataSourceDataProvider.prototype.setItemValue = function (item, valueName, value) { // does nothing for virtual data. }; ODataVirtualDataSourceDataProvider.prototype.removeItem = function (item) { // does nothing for virtual data. }; ODataVirtualDataSourceDataProvider.prototype.addItem = function (item) { // does nothing for virtual data. }; Object.defineProperty(ODataVirtualDataSourceDataProvider.prototype, "actualCount", { get: function () { return this._currentFullCount; }, enumerable: false, configurable: true }); Object.defineProperty(ODataVirtualDataSourceDataProvider.prototype, "actualSchema", { get: function () { return this._currentSchema; }, enumerable: false, configurable: true }); Object.defineProperty(ODataVirtualDataSourceDataProvider.prototype, "executionContext", { get: function () { return this._executionContext; }, set: function (value) { this._executionContext = value; this.queueAutoRefresh(); }, enumerable: false, configurable: true }); Object.defineProperty(ODataVirtualDataSourceDataProvider.prototype, "updateNotifier", { get: function () { return this._updateNotifier; }, set: function (value) { this._updateNotifier = value; }, enumerable: false, configurable: true }); Object.defineProperty(ODataVirtualDataSourceDataProvider.prototype, "deferAutoRefresh", { get: function () { return this._deferAutoRefresh; }, set: function (value) { this._deferAutoRefresh = value; if (!this._deferAutoRefresh) { this.queueAutoRefresh(); } if (this._deferAutoRefresh && this.valid() && this._currentSchema == null) { this.queueSchemaFetch(); } }, enumerable: false, configurable: true }); Object.defineProperty(ODataVirtualDataSourceDataProvider.prototype, "isSortingSupported", { get: function () { return true; }, enumerable: false, configurable: true }); Object.defineProperty(ODataVirtualDataSourceDataProvider.prototype, "isGroupingSupported", { get: function () { return this.isAggregationSupported; }, enumerable: false, configurable: true }); Object.defineProperty(ODataVirtualDataSourceDataProvider.prototype, "isFilteringSupported", { get: function () { return true; }, enumerable: false, configurable: true }); Object.defineProperty(ODataVirtualDataSourceDataProvider.prototype, "isAggregationSupported", { get: function () { return this._isAggregationSupported; }, set: function (isSupported) { this._isAggregationSupported = isSupported; }, enumerable: false, configurable: true }); Object.defineProperty(ODataVirtualDataSourceDataProvider.prototype, "sortDescriptions", { get: function () { return this._sortDescriptions; }, enumerable: false, configurable: true }); Object.defineProperty(ODataVirtualDataSourceDataProvider.prototype, "groupDescriptions", { get: function () { return this._groupDescriptions; }, enumerable: false, configurable: true }); Object.defineProperty(ODataVirtualDataSourceDataProvider.prototype, "propertiesRequested", { get: function () { return this._propertiesRequested; }, set: function (value) { this._propertiesRequested = value; this.queueAutoRefresh(); }, enumerable: false, configurable: true }); Object.defineProperty(ODataVirtualDataSourceDataProvider.prototype, "schemaIncludedProperties", { get: function () { return this._schemaIncludedProperties; }, set: function (value) { this._schemaIncludedProperties = value; this.queueAutoRefresh(); }, enumerable: false, configurable: true }); Object.defineProperty(ODataVirtualDataSourceDataProvider.prototype, "filterExpressions", { get: function () { return this._filterExpressions; }, enumerable: false, configurable: true }); Object.defineProperty(ODataVirtualDataSourceDataProvider.prototype, "summaryDescriptions", { get: function () { return this._summaryDescriptions; }, enumerable: false, configurable: true }); Object.defineProperty(ODataVirtualDataSourceDataProvider.prototype, "summaryScope", { get: function () { return this._summaryScope; }, set: function (value) { this._summaryScope = value; }, enumerable: false, configurable: true }); Object.defineProperty(ODataVirtualDataSourceDataProvider.prototype, "enableJsonp", { get: function () { return this._enableJsonp; }, set: function (isEnabled) { this._enableJsonp = isEnabled; }, enumerable: false, configurable: true }); Object.defineProperty(ODataVirtualDataSourceDataProvider.prototype, "notifyUsingSourceIndexes", { get: function () { return true; }, enumerable: false, configurable: true }); Object.defineProperty(ODataVirtualDataSourceDataProvider.prototype, "isItemIndexLookupSupported", { get: function () { return false; }, enumerable: false, configurable: true }); Object.defineProperty(ODataVirtualDataSourceDataProvider.prototype, "isKeyIndexLookupSupported", { get: function () { return false; }, enumerable: false, configurable: true }); ODataVirtualDataSourceDataProvider.prototype.notifySetItem = function (index, oldItem, newItem) { if (this.updateNotifier != null) { this.updateNotifier.notifySetItem(index, oldItem, newItem); } }; ODataVirtualDataSourceDataProvider.prototype.notifyClearItems = function () { if (this.updateNotifier != null) { this.updateNotifier.notifyClearItems(); } }; ODataVirtualDataSourceDataProvider.prototype.notifyInsertItem = function (index, newItem) { if (this.updateNotifier != null) { this.updateNotifier.notifyInsertItem(index, newItem); } }; ODataVirtualDataSourceDataProvider.prototype.notifyRemoveItem = function (index, oldItem) { if (this.updateNotifier != null) { this.updateNotifier.notifyRemoveItem(index, oldItem); } }; ODataVirtualDataSourceDataProvider.prototype.queueSchemaFetch = function () { if (this._schemaFetchQueued) { return; } if (this.executionContext != null) { this._schemaFetchQueued = true; this.executionContext.enqueueAction(runOn(this, this.doSchemaFetchInternal)); } }; ODataVirtualDataSourceDataProvider.prototype.doSchemaFetchInternal = function () { if (!this._schemaFetchQueued) { return; } this._schemaFetchQueued = false; this.schemaFetchInternal(); }; ODataVirtualDataSourceDataProvider.prototype.schemaFetchInternal = function () { this.schemaFetchInternalOverride(); }; ODataVirtualDataSourceDataProvider.prototype.schemaFetchInternalOverride = function () { if (!this.deferAutoRefresh) { return; } this.removeAllPageRequests(); this.killWorker(); this.createWorker(); this.addSchemaRequest(); }; ODataVirtualDataSourceDataProvider.prototype.addSchemaRequest = function () { this._worker.addPageRequest(ODataVirtualDataSourceDataProviderWorker.schemaRequestIndex, DataSourcePageRequestPriority.High); }; ODataVirtualDataSourceDataProvider.prototype.queueAutoRefresh = function () { if (this.deferAutoRefresh) { return; } if (this._autoRefreshQueued) { return; } if (this.executionContext != null) { this._autoRefreshQueued = true; this.executionContext.enqueueAction(runOn(this, this.doRefreshInternal)); } }; ODataVirtualDataSourceDataProvider.prototype.doRefreshInternal = function () { if (this.deferAutoRefresh) { this._autoRefreshQueued = false; return; } if (!this._autoRefreshQueued) { return; } this._autoRefreshQueued = false; this.refreshInternal(); }; ODataVirtualDataSourceDataProvider.prototype.refreshInternal = function () { this.refreshInternalOverride(); }; ODataVirtualDataSourceDataProvider.prototype.refreshInternalOverride = function () { this.removeAllPageRequests(); this.killWorker(); this.createWorker(); this._worker.addPageRequest(0, DataSourcePageRequestPriority.Normal); }; ODataVirtualDataSourceDataProvider.prototype.flushAutoRefresh = function () { this.doRefreshInternal(); }; ODataVirtualDataSourceDataProvider.prototype.refresh = function () { this.refreshInternal(); }; ODataVirtualDataSourceDataProvider.prototype.indexOfItem = function (item) { return -1; }; ODataVirtualDataSourceDataProvider.prototype.indexOfKey = function (key) { return -1; }; ODataVirtualDataSourceDataProvider.prototype.resolveSchemaPropertyType = function (propertyPath) { if (this.actualSchema == null) { return DataSourceSchemaPropertyType.ObjectValue; } if (stringContains(propertyPath, ".")) { return DataSourceSchemaPropertyType.ObjectValue; } for (var i = 0; i < this.actualSchema.propertyNames.length; i++) { var name_1 = this.actualSchema.propertyNames[i]; if (name_1 == propertyPath) { return this.actualSchema.propertyTypes[i]; } } return DataSourceSchemaPropertyType.ObjectValue; }; ODataVirtualDataSourceDataProvider.prototype.createBatchRequest = function (changes) { if (this._worker) { this._worker.createBatchRequest(changes); } }; Object.defineProperty(ODataVirtualDataSourceDataProvider.prototype, "batchCompleted", { get: function () { return this._batchCompleted; }, set: function (value) { this._batchCompleted = value; }, enumerable: false, configurable: true }); ODataVirtualDataSourceDataProvider.$t = markType(ODataVirtualDataSourceDataProvider, 'ODataVirtualDataSourceDataProvider', Base.$type, [IDataSourceVirtualDataProvider_$type]); return ODataVirtualDataSourceDataProvider; }(Base)); export { ODataVirtualDataSourceDataProvider };