UNPKG

igniteui-webcomponents-datasources

Version:

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

538 lines (537 loc) 19.9 kB
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 { RestVirtualDataSourceDataProviderWorker } from "./RestVirtualDataSourceDataProviderWorker"; import { RestVirtualDataSourceDataProviderWorkerSettings } from "./RestVirtualDataSourceDataProviderWorkerSettings"; import { DataSourceDataProviderSchemaChangedEventArgs } from "igniteui-webcomponents-core"; import { DataSourceSchemaPropertyType } from "igniteui-webcomponents-core"; import { stringContains } from "igniteui-webcomponents-core"; import { SummaryDescriptionCollection } from "igniteui-webcomponents-core"; export let RestVirtualDataSourceDataProvider = /*@__PURE__*/ (() => { class RestVirtualDataSourceDataProvider extends Base { constructor() { super(); 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._fixedFullCount = -1; this._provideFullCount = null; this._provideOrderByParameter = null; this._provideFilterParameter = null; this._provideAggregationParameter = null; this._provideAggregatedCount = null; this._provideUri = null; this._performFetch = null; this._providePagingParameter = null; this._provideDesiredPropertiesParameter = null; this._schemaFetchQueued = false; this._autoRefreshQueued = false; this._sortDescriptions = new SortDescriptionCollection(); this._sortDescriptions.onChanged = () => this.sortDescriptions_CollectionChanged(null, null); this._groupDescriptions = new SortDescriptionCollection(); this._groupDescriptions.onChanged = () => this.groupDescriptions_CollectionChanged(null, null); this._filterExpressions = new FilterExpressionCollection(); this._filterExpressions.onChanged = () => this.filterExpressions_CollectionChanged(null, null); this._summaryDescriptions = new SummaryDescriptionCollection(); this._summaryDescriptions.onChanged = () => this.summaryDescriptions_CollectionChanged(null, null); } filterExpressions_CollectionChanged(sender, e) { this.queueAutoRefresh(); } sortDescriptions_CollectionChanged(sender, e) { this.queueAutoRefresh(); } groupDescriptions_CollectionChanged(sender, e) { this.queueAutoRefresh(); } summaryDescriptions_CollectionChanged(sender, e) { this.queueAutoRefresh(); } addPageRequest(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); } } createWorker() { if (!this.valid()) { return; } this._callback = runOn(this, this.raisePageLoaded); let settings = this.getWorkerSettings(); this._worker = new RestVirtualDataSourceDataProviderWorker(settings); } valid() { return this.entitySet != null && this.baseUri != null; } getWorkerSettings() { return ((() => { let $ret = new RestVirtualDataSourceDataProviderWorkerSettings(); $ret.baseUri = this._baseUri; $ret.entitySet = this._entitySet; $ret.pageSizeRequested = this._pageSizeRequested; $ret.timeoutMilliseconds = this._timeoutMilliseconds; $ret.pageLoaded = this._callback; $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; $ret.performFetch = this.performFetch; $ret.provideAggregationParameter = this.provideAggregationParameter; $ret.provideAggregatedCount = this.provideAggregatedCount; $ret.provideDesiredPropertiesParameter = this.provideDesiredPropertiesParameter; $ret.provideFilterParameter = this.provideFilterParameter; $ret.provideFullCount = this.provideFullCount; $ret.provideItems = this.provideItems; $ret.provideOrderByParameter = this.provideOrderByParameter; $ret.providePagingParameter = this.providePagingParameter; $ret.provideUri = this.provideUri; $ret.fixedFullCount = this.fixedFullCount; return $ret; })()); } removePageRequest(pageIndex) { let 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); } removeAllPageRequests() { this._requests.clear(); if (this._worker == null) { return; } this._worker.removeAllPageRequests(); } close() { if (this._worker != null) { this._worker.shutdown(); this._worker = null; this._callback = null; } } get pageLoaded() { return this._pageLoaded; } set pageLoaded(value) { this._pageLoaded = value; this.queueAutoRefresh(); } raisePageLoaded(page, fullCount, actualPageSize) { if (this._pageLoaded != null) { this._currentFullCount = fullCount; if (this._currentSchema == null) { let 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() != RestVirtualDataSourceDataProviderWorker.schemaRequestIndex) { this._pageLoaded(page, fullCount, actualPageSize); } } } killWorker() { if (this._worker != null) { this._worker.shutdown(); this._worker = null; this._callback = null; } } get pageSizeRequested() { return this._pageSizeRequested; } set pageSizeRequested(value) { this._pageSizeRequested = value; this.queueAutoRefresh(); } get baseUri() { return this._baseUri; } set baseUri(value) { let oldValue = this._baseUri; this._baseUri = value; if (oldValue != this._baseUri) { this.queueAutoRefresh(); if (this.valid() && this.deferAutoRefresh) { this.queueSchemaFetch(); } } } get entitySet() { return this._entitySet; } set entitySet(value) { let oldValue = this._entitySet; this._entitySet = value; if (oldValue != this._entitySet) { this.queueAutoRefresh(); if (this.valid() && this.deferAutoRefresh) { this.queueSchemaFetch(); } } } get timeoutMilliseconds() { return this._timeoutMilliseconds; } set timeoutMilliseconds(value) { this._timeoutMilliseconds = value; this.queueAutoRefresh(); } getItemValue(item, valueName) { let dic = item; if (dic.has(valueName)) { return dic.get(valueName); } else { return null; } } get actualCount() { return this._currentFullCount; } get actualSchema() { return this._currentSchema; } get executionContext() { return this._executionContext; } set executionContext(value) { this._executionContext = value; this.queueAutoRefresh(); } get updateNotifier() { return this._updateNotifier; } set updateNotifier(value) { this._updateNotifier = value; } get deferAutoRefresh() { return this._deferAutoRefresh; } set deferAutoRefresh(value) { this._deferAutoRefresh = value; if (!this._deferAutoRefresh) { this.queueAutoRefresh(); } if (this._deferAutoRefresh && this.valid() && this._currentSchema == null) { this.queueSchemaFetch(); } } get isSortingSupported() { return true; } get isGroupingSupported() { return this.isAggregationSupported; } get isFilteringSupported() { return true; } get isAggregationSupported() { return this._isAggregationSupported; } set isAggregationSupported(isSupported) { this._isAggregationSupported = isSupported; } get sortDescriptions() { return this._sortDescriptions; } get groupDescriptions() { return this._groupDescriptions; } get propertiesRequested() { return this._propertiesRequested; } set propertiesRequested(value) { this._propertiesRequested = value; this.queueAutoRefresh(); } get schemaIncludedProperties() { return this._schemaIncludedProperties; } set schemaIncludedProperties(value) { this._schemaIncludedProperties = value; this.queueAutoRefresh(); } get filterExpressions() { return this._filterExpressions; } get summaryDescriptions() { return this._summaryDescriptions; } get summaryScope() { return this._summaryScope; } set summaryScope(value) { this._summaryScope = value; } get enableJsonp() { return this._enableJsonp; } set enableJsonp(isEnabled) { this._enableJsonp = isEnabled; } get fixedFullCount() { return this._fixedFullCount; } set fixedFullCount(value) { this._fixedFullCount = value; } get provideFullCount() { return this._provideFullCount; } set provideFullCount(value) { this._provideFullCount = value; } get provideOrderByParameter() { return this._provideOrderByParameter; } set provideOrderByParameter(value) { this._provideOrderByParameter = value; } get provideFilterParameter() { return this._provideFilterParameter; } set provideFilterParameter(value) { this._provideFilterParameter = value; } get provideAggregationParameter() { return this._provideAggregationParameter; } set provideAggregationParameter(value) { this._provideAggregationParameter = value; } get provideAggregatedCount() { return this._provideAggregatedCount; } set provideAggregatedCount(value) { this._provideAggregatedCount = value; } get provideUri() { return this._provideUri; } set provideUri(value) { this._provideUri = value; } get performFetch() { return this._performFetch; } set performFetch(value) { this._performFetch = value; } get providePagingParameter() { return this._providePagingParameter; } set providePagingParameter(value) { this._providePagingParameter = value; } get provideDesiredPropertiesParameter() { return this._provideDesiredPropertiesParameter; } set provideDesiredPropertiesParameter(value) { this._provideDesiredPropertiesParameter = value; } get provideItems() { return this._provideItems; } set provideItems(value) { this._provideItems = value; } get notifyUsingSourceIndexes() { return true; } get isItemIndexLookupSupported() { return false; } get isKeyIndexLookupSupported() { return false; } notifySetItem(index, oldItem, newItem) { if (this.updateNotifier != null) { this.updateNotifier.notifySetItem(index, oldItem, newItem); } } notifyClearItems() { if (this.updateNotifier != null) { this.updateNotifier.notifyClearItems(); } } notifyInsertItem(index, newItem) { if (this.updateNotifier != null) { this.updateNotifier.notifyInsertItem(index, newItem); } } notifyRemoveItem(index, oldItem) { if (this.updateNotifier != null) { this.updateNotifier.notifyRemoveItem(index, oldItem); } } queueSchemaFetch() { if (this._schemaFetchQueued) { return; } if (this.executionContext != null) { this._schemaFetchQueued = true; this.executionContext.enqueueAction(runOn(this, this.doSchemaFetchInternal)); } } doSchemaFetchInternal() { if (!this._schemaFetchQueued) { return; } this._schemaFetchQueued = false; this.schemaFetchInternal(); } schemaFetchInternal() { this.schemaFetchInternalOverride(); } schemaFetchInternalOverride() { if (!this.deferAutoRefresh) { return; } this.removeAllPageRequests(); this.killWorker(); this.createWorker(); this.addSchemaRequest(); } addSchemaRequest() { this._worker.addPageRequest(RestVirtualDataSourceDataProviderWorker.schemaRequestIndex, DataSourcePageRequestPriority.High); } queueAutoRefresh() { if (this.deferAutoRefresh) { return; } if (this._autoRefreshQueued) { return; } if (this.executionContext != null) { this._autoRefreshQueued = true; this.executionContext.enqueueAction(runOn(this, this.doRefreshInternal)); } } doRefreshInternal() { if (this.deferAutoRefresh) { this._autoRefreshQueued = false; return; } if (!this._autoRefreshQueued) { return; } this._autoRefreshQueued = false; this.refreshInternal(); } refreshInternal() { this.refreshInternalOverride(); } refreshInternalOverride() { this.removeAllPageRequests(); this.killWorker(); this.createWorker(); this._worker.addPageRequest(0, DataSourcePageRequestPriority.Normal); } flushAutoRefresh() { this.doRefreshInternal(); } refresh() { this.refreshInternal(); } indexOfItem(item) { return -1; } indexOfKey(key) { return -1; } resolveSchemaPropertyType(propertyPath) { if (this.actualSchema == null) { return DataSourceSchemaPropertyType.ObjectValue; } if (stringContains(propertyPath, ".")) { return DataSourceSchemaPropertyType.ObjectValue; } for (let i = 0; i < this.actualSchema.propertyNames.length; i++) { let name = this.actualSchema.propertyNames[i]; if (name == propertyPath) { return this.actualSchema.propertyTypes[i]; } } return DataSourceSchemaPropertyType.ObjectValue; } setItemValue(item, valueName, value) { // does nothing. } removeItem(item) { // does nothing. } addItem(item) { // does nothing. } createBatchRequest(changes) { if (this._worker != null) { this._worker.createBatchRequest(changes); } } get batchCompleted() { return this._batchCompleted; } set batchCompleted(v) { this._batchCompleted = v; } } RestVirtualDataSourceDataProvider.$t = /*@__PURE__*/ markType(RestVirtualDataSourceDataProvider, 'ODataVirtualDataSourceDataProvider', Base.$type, [IDataSourceVirtualDataProvider_$type]); return RestVirtualDataSourceDataProvider; })();