igniteui-webcomponents-datasources
Version:
Reference custom data providers for the Ignite UI Web Components data source.
453 lines (452 loc) • 16.7 kB
JavaScript
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";
export let ODataVirtualDataSourceDataProvider = /*@__PURE__*/ (() => {
class ODataVirtualDataSourceDataProvider 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._schemaFetchQueued = false;
this._autoRefreshQueued = false;
this._batchCompleted = null;
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 ODataVirtualDataSourceDataProviderWorker(settings);
}
valid() {
return this.entitySet != null && this.baseUri != null;
}
getWorkerSettings() {
return ((() => {
let $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;
})());
}
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() != ODataVirtualDataSourceDataProviderWorker.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;
}
}
setItemValue(item, valueName, value) {
// does nothing for virtual data.
}
removeItem(item) {
// does nothing for virtual data.
}
addItem(item) {
// does nothing for virtual data.
}
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 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(ODataVirtualDataSourceDataProviderWorker.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;
}
createBatchRequest(changes) {
if (this._worker) {
this._worker.createBatchRequest(changes);
}
}
get batchCompleted() {
return this._batchCompleted;
}
set batchCompleted(value) {
this._batchCompleted = value;
}
}
ODataVirtualDataSourceDataProvider.$t = /*@__PURE__*/ markType(ODataVirtualDataSourceDataProvider, 'ODataVirtualDataSourceDataProvider', Base.$type, [IDataSourceVirtualDataProvider_$type]);
return ODataVirtualDataSourceDataProvider;
})();