igniteui-webcomponents-datasources
Version:
Reference custom data providers for the Ignite UI Web Components data source.
689 lines (688 loc) • 26.5 kB
JavaScript
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 { 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";
var RestVirtualDataSourceDataProvider = /** @class */ /*@__PURE__*/ (function (_super) {
__extends(RestVirtualDataSourceDataProvider, _super);
function RestVirtualDataSourceDataProvider() {
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._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 = 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;
}
RestVirtualDataSourceDataProvider.prototype.filterExpressions_CollectionChanged = function (sender, e) {
this.queueAutoRefresh();
};
RestVirtualDataSourceDataProvider.prototype.sortDescriptions_CollectionChanged = function (sender, e) {
this.queueAutoRefresh();
};
RestVirtualDataSourceDataProvider.prototype.groupDescriptions_CollectionChanged = function (sender, e) {
this.queueAutoRefresh();
};
RestVirtualDataSourceDataProvider.prototype.summaryDescriptions_CollectionChanged = function (sender, e) {
this.queueAutoRefresh();
};
RestVirtualDataSourceDataProvider.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);
}
};
RestVirtualDataSourceDataProvider.prototype.createWorker = function () {
if (!this.valid()) {
return;
}
this._callback = runOn(this, this.raisePageLoaded);
var settings = this.getWorkerSettings();
this._worker = new RestVirtualDataSourceDataProviderWorker(settings);
};
RestVirtualDataSourceDataProvider.prototype.valid = function () {
return this.entitySet != null && this.baseUri != null;
};
RestVirtualDataSourceDataProvider.prototype.getWorkerSettings = function () {
var _this = this;
return ((function () {
var $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;
})());
};
RestVirtualDataSourceDataProvider.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);
};
RestVirtualDataSourceDataProvider.prototype.removeAllPageRequests = function () {
this._requests.clear();
if (this._worker == null) {
return;
}
this._worker.removeAllPageRequests();
};
RestVirtualDataSourceDataProvider.prototype.close = function () {
if (this._worker != null) {
this._worker.shutdown();
this._worker = null;
this._callback = null;
}
};
Object.defineProperty(RestVirtualDataSourceDataProvider.prototype, "pageLoaded", {
get: function () {
return this._pageLoaded;
},
set: function (value) {
this._pageLoaded = value;
this.queueAutoRefresh();
},
enumerable: false,
configurable: true
});
RestVirtualDataSourceDataProvider.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() != RestVirtualDataSourceDataProviderWorker.schemaRequestIndex) {
this._pageLoaded(page, fullCount, actualPageSize);
}
}
};
RestVirtualDataSourceDataProvider.prototype.killWorker = function () {
if (this._worker != null) {
this._worker.shutdown();
this._worker = null;
this._callback = null;
}
};
Object.defineProperty(RestVirtualDataSourceDataProvider.prototype, "pageSizeRequested", {
get: function () {
return this._pageSizeRequested;
},
set: function (value) {
this._pageSizeRequested = value;
this.queueAutoRefresh();
},
enumerable: false,
configurable: true
});
Object.defineProperty(RestVirtualDataSourceDataProvider.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(RestVirtualDataSourceDataProvider.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(RestVirtualDataSourceDataProvider.prototype, "timeoutMilliseconds", {
get: function () {
return this._timeoutMilliseconds;
},
set: function (value) {
this._timeoutMilliseconds = value;
this.queueAutoRefresh();
},
enumerable: false,
configurable: true
});
RestVirtualDataSourceDataProvider.prototype.getItemValue = function (item, valueName) {
var dic = item;
if (dic.has(valueName)) {
return dic.get(valueName);
}
else {
return null;
}
};
Object.defineProperty(RestVirtualDataSourceDataProvider.prototype, "actualCount", {
get: function () {
return this._currentFullCount;
},
enumerable: false,
configurable: true
});
Object.defineProperty(RestVirtualDataSourceDataProvider.prototype, "actualSchema", {
get: function () {
return this._currentSchema;
},
enumerable: false,
configurable: true
});
Object.defineProperty(RestVirtualDataSourceDataProvider.prototype, "executionContext", {
get: function () {
return this._executionContext;
},
set: function (value) {
this._executionContext = value;
this.queueAutoRefresh();
},
enumerable: false,
configurable: true
});
Object.defineProperty(RestVirtualDataSourceDataProvider.prototype, "updateNotifier", {
get: function () {
return this._updateNotifier;
},
set: function (value) {
this._updateNotifier = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(RestVirtualDataSourceDataProvider.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(RestVirtualDataSourceDataProvider.prototype, "isSortingSupported", {
get: function () {
return true;
},
enumerable: false,
configurable: true
});
Object.defineProperty(RestVirtualDataSourceDataProvider.prototype, "isGroupingSupported", {
get: function () {
return this.isAggregationSupported;
},
enumerable: false,
configurable: true
});
Object.defineProperty(RestVirtualDataSourceDataProvider.prototype, "isFilteringSupported", {
get: function () {
return true;
},
enumerable: false,
configurable: true
});
Object.defineProperty(RestVirtualDataSourceDataProvider.prototype, "isAggregationSupported", {
get: function () {
return this._isAggregationSupported;
},
set: function (isSupported) {
this._isAggregationSupported = isSupported;
},
enumerable: false,
configurable: true
});
Object.defineProperty(RestVirtualDataSourceDataProvider.prototype, "sortDescriptions", {
get: function () {
return this._sortDescriptions;
},
enumerable: false,
configurable: true
});
Object.defineProperty(RestVirtualDataSourceDataProvider.prototype, "groupDescriptions", {
get: function () {
return this._groupDescriptions;
},
enumerable: false,
configurable: true
});
Object.defineProperty(RestVirtualDataSourceDataProvider.prototype, "propertiesRequested", {
get: function () {
return this._propertiesRequested;
},
set: function (value) {
this._propertiesRequested = value;
this.queueAutoRefresh();
},
enumerable: false,
configurable: true
});
Object.defineProperty(RestVirtualDataSourceDataProvider.prototype, "schemaIncludedProperties", {
get: function () {
return this._schemaIncludedProperties;
},
set: function (value) {
this._schemaIncludedProperties = value;
this.queueAutoRefresh();
},
enumerable: false,
configurable: true
});
Object.defineProperty(RestVirtualDataSourceDataProvider.prototype, "filterExpressions", {
get: function () {
return this._filterExpressions;
},
enumerable: false,
configurable: true
});
Object.defineProperty(RestVirtualDataSourceDataProvider.prototype, "summaryDescriptions", {
get: function () {
return this._summaryDescriptions;
},
enumerable: false,
configurable: true
});
Object.defineProperty(RestVirtualDataSourceDataProvider.prototype, "summaryScope", {
get: function () {
return this._summaryScope;
},
set: function (value) {
this._summaryScope = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(RestVirtualDataSourceDataProvider.prototype, "enableJsonp", {
get: function () {
return this._enableJsonp;
},
set: function (isEnabled) {
this._enableJsonp = isEnabled;
},
enumerable: false,
configurable: true
});
Object.defineProperty(RestVirtualDataSourceDataProvider.prototype, "fixedFullCount", {
get: function () {
return this._fixedFullCount;
},
set: function (value) {
this._fixedFullCount = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(RestVirtualDataSourceDataProvider.prototype, "provideFullCount", {
get: function () {
return this._provideFullCount;
},
set: function (value) {
this._provideFullCount = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(RestVirtualDataSourceDataProvider.prototype, "provideOrderByParameter", {
get: function () {
return this._provideOrderByParameter;
},
set: function (value) {
this._provideOrderByParameter = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(RestVirtualDataSourceDataProvider.prototype, "provideFilterParameter", {
get: function () {
return this._provideFilterParameter;
},
set: function (value) {
this._provideFilterParameter = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(RestVirtualDataSourceDataProvider.prototype, "provideAggregationParameter", {
get: function () {
return this._provideAggregationParameter;
},
set: function (value) {
this._provideAggregationParameter = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(RestVirtualDataSourceDataProvider.prototype, "provideAggregatedCount", {
get: function () {
return this._provideAggregatedCount;
},
set: function (value) {
this._provideAggregatedCount = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(RestVirtualDataSourceDataProvider.prototype, "provideUri", {
get: function () {
return this._provideUri;
},
set: function (value) {
this._provideUri = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(RestVirtualDataSourceDataProvider.prototype, "performFetch", {
get: function () {
return this._performFetch;
},
set: function (value) {
this._performFetch = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(RestVirtualDataSourceDataProvider.prototype, "providePagingParameter", {
get: function () {
return this._providePagingParameter;
},
set: function (value) {
this._providePagingParameter = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(RestVirtualDataSourceDataProvider.prototype, "provideDesiredPropertiesParameter", {
get: function () {
return this._provideDesiredPropertiesParameter;
},
set: function (value) {
this._provideDesiredPropertiesParameter = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(RestVirtualDataSourceDataProvider.prototype, "provideItems", {
get: function () {
return this._provideItems;
},
set: function (value) {
this._provideItems = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(RestVirtualDataSourceDataProvider.prototype, "notifyUsingSourceIndexes", {
get: function () {
return true;
},
enumerable: false,
configurable: true
});
Object.defineProperty(RestVirtualDataSourceDataProvider.prototype, "isItemIndexLookupSupported", {
get: function () {
return false;
},
enumerable: false,
configurable: true
});
Object.defineProperty(RestVirtualDataSourceDataProvider.prototype, "isKeyIndexLookupSupported", {
get: function () {
return false;
},
enumerable: false,
configurable: true
});
RestVirtualDataSourceDataProvider.prototype.notifySetItem = function (index, oldItem, newItem) {
if (this.updateNotifier != null) {
this.updateNotifier.notifySetItem(index, oldItem, newItem);
}
};
RestVirtualDataSourceDataProvider.prototype.notifyClearItems = function () {
if (this.updateNotifier != null) {
this.updateNotifier.notifyClearItems();
}
};
RestVirtualDataSourceDataProvider.prototype.notifyInsertItem = function (index, newItem) {
if (this.updateNotifier != null) {
this.updateNotifier.notifyInsertItem(index, newItem);
}
};
RestVirtualDataSourceDataProvider.prototype.notifyRemoveItem = function (index, oldItem) {
if (this.updateNotifier != null) {
this.updateNotifier.notifyRemoveItem(index, oldItem);
}
};
RestVirtualDataSourceDataProvider.prototype.queueSchemaFetch = function () {
if (this._schemaFetchQueued) {
return;
}
if (this.executionContext != null) {
this._schemaFetchQueued = true;
this.executionContext.enqueueAction(runOn(this, this.doSchemaFetchInternal));
}
};
RestVirtualDataSourceDataProvider.prototype.doSchemaFetchInternal = function () {
if (!this._schemaFetchQueued) {
return;
}
this._schemaFetchQueued = false;
this.schemaFetchInternal();
};
RestVirtualDataSourceDataProvider.prototype.schemaFetchInternal = function () {
this.schemaFetchInternalOverride();
};
RestVirtualDataSourceDataProvider.prototype.schemaFetchInternalOverride = function () {
if (!this.deferAutoRefresh) {
return;
}
this.removeAllPageRequests();
this.killWorker();
this.createWorker();
this.addSchemaRequest();
};
RestVirtualDataSourceDataProvider.prototype.addSchemaRequest = function () {
this._worker.addPageRequest(RestVirtualDataSourceDataProviderWorker.schemaRequestIndex, DataSourcePageRequestPriority.High);
};
RestVirtualDataSourceDataProvider.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));
}
};
RestVirtualDataSourceDataProvider.prototype.doRefreshInternal = function () {
if (this.deferAutoRefresh) {
this._autoRefreshQueued = false;
return;
}
if (!this._autoRefreshQueued) {
return;
}
this._autoRefreshQueued = false;
this.refreshInternal();
};
RestVirtualDataSourceDataProvider.prototype.refreshInternal = function () {
this.refreshInternalOverride();
};
RestVirtualDataSourceDataProvider.prototype.refreshInternalOverride = function () {
this.removeAllPageRequests();
this.killWorker();
this.createWorker();
this._worker.addPageRequest(0, DataSourcePageRequestPriority.Normal);
};
RestVirtualDataSourceDataProvider.prototype.flushAutoRefresh = function () {
this.doRefreshInternal();
};
RestVirtualDataSourceDataProvider.prototype.refresh = function () {
this.refreshInternal();
};
RestVirtualDataSourceDataProvider.prototype.indexOfItem = function (item) {
return -1;
};
RestVirtualDataSourceDataProvider.prototype.indexOfKey = function (key) {
return -1;
};
RestVirtualDataSourceDataProvider.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;
};
RestVirtualDataSourceDataProvider.prototype.setItemValue = function (item, valueName, value) {
// does nothing.
};
RestVirtualDataSourceDataProvider.prototype.removeItem = function (item) {
// does nothing.
};
RestVirtualDataSourceDataProvider.prototype.addItem = function (item) {
// does nothing.
};
RestVirtualDataSourceDataProvider.prototype.createBatchRequest = function (changes) {
if (this._worker != null) {
this._worker.createBatchRequest(changes);
}
};
Object.defineProperty(RestVirtualDataSourceDataProvider.prototype, "batchCompleted", {
get: function () {
return this._batchCompleted;
},
set: function (v) {
this._batchCompleted = v;
},
enumerable: false,
configurable: true
});
RestVirtualDataSourceDataProvider.$t = markType(RestVirtualDataSourceDataProvider, 'ODataVirtualDataSourceDataProvider', Base.$type, [IDataSourceVirtualDataProvider_$type]);
return RestVirtualDataSourceDataProvider;
}(Base));
export { RestVirtualDataSourceDataProvider };