UNPKG

igniteui-angular-core

Version:

Ignite UI Angular Core logic used in multiple UI components.

874 lines (873 loc) 29.9 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 { __extends, __values } from "tslib"; import { Base, IList_$type, runOn, String_$type, EnumUtil, fromEnum, typeCast, Array_$type, delegateRemove, delegateCombine, markType } from "./type"; import { IDataSourceLocalDataProvider_$type } from "./IDataSourceLocalDataProvider"; import { IDataSourceSchema_$type } from "./IDataSourceSchema"; import { DataSourceSchemaPropertyType_$type } from "./DataSourceSchemaPropertyType"; import { DefaultDataSourceSchema } from "./DefaultDataSourceSchema"; import { SortDescriptionCollection } from "./SortDescriptionCollection"; import { FilterExpressionCollection } from "./FilterExpressionCollection"; import { SummaryDescriptionCollection } from "./SummaryDescriptionCollection"; import { Dictionary$2 } from "./Dictionary$2"; import { FastReflectionHelper } from "./FastReflectionHelper"; import { HashSet$1 } from "./HashSet$1"; import { DataSourceDataProviderSchemaChangedEventArgs } from "./DataSourceDataProviderSchemaChangedEventArgs"; import { List$1 } from "./List$1"; import { INotifyCollectionChanged_$type } from "./INotifyCollectionChanged"; import { getAllPropertyNames } from "./componentUtil"; import { stringStartsWith } from "./string"; /** * @hidden */ var DataSourceLocalDataProvider = /** @class */ /*@__PURE__*/ (function (_super) { __extends(DataSourceLocalDataProvider, _super); function DataSourceLocalDataProvider() { var _this = _super.call(this) || this; _this.n = null; _this.m = null; _this.g = null; _this.o = null; _this.f = 0; _this.aa = 5; _this.ab = null; _this.u = new Dictionary$2(String_$type, DataSourceSchemaPropertyType_$type, 0); _this.ad = null; _this.schemaChanged = null; _this.t = new Dictionary$2(String_$type, FastReflectionHelper.$, 0); _this.v = new HashSet$1(String_$type, 0); _this.j = null; _this.y = null; _this.r = false; _this.i = null; _this.h = null; _this.q = false; _this.a = null; _this.p = false; _this.b = null; _this.n = new SortDescriptionCollection(); _this.n.n(runOn(_this, _this.au)); _this.m = new SortDescriptionCollection(); _this.o = new SummaryDescriptionCollection(); _this.g = new FilterExpressionCollection(); return _this; } DataSourceLocalDataProvider.prototype.au = function (a, b) { this.queueAutoRefresh(); }; DataSourceLocalDataProvider.prototype.clone = function () { var a = new DataSourceLocalDataProvider(); a.deferAutoRefresh = this.deferAutoRefresh; a.executionContext = this.executionContext; a.dataSource = this.dataSource; a.propertiesRequested = this.propertiesRequested; a.schemaHints = this.schemaHints; a.summaryScope = this.summaryScope; for (var b = 0; b < this.groupDescriptions.k.count; b++) { a.groupDescriptions.add(this.groupDescriptions.k.item(b)); } for (var c = 0; c < this.sortDescriptions.k.count; c++) { a.sortDescriptions.add(this.sortDescriptions.k.item(c)); } for (var d = 0; d < this.filterExpressions.k.count; d++) { a.filterExpressions.add(this.filterExpressions.k.item(d)); } for (var e = 0; e < this.summaryDescriptions.k.count; e++) { a.summaryDescriptions.add(this.summaryDescriptions.k.item(e)); } return a; }; Object.defineProperty(DataSourceLocalDataProvider.prototype, "dataSource", { get: function () { return this.ab; }, set: function (a) { var b = this.ab; this.ab = a; if (b != this.ab) { this.ao("ItemsSource", b, this.ab); } }, enumerable: false, configurable: true }); Object.defineProperty(DataSourceLocalDataProvider.prototype, "schemaHints", { get: function () { return this.ad; }, set: function (a) { var b = this.ad; this.ad = a; if (b != this.ad) { this.ao("SchemaHints", b, this.ad); } }, enumerable: false, configurable: true }); DataSourceLocalDataProvider.prototype.ap = function () { if (this.ad == null) { return; } this.u.clear(); var a = this.ad.split(','); for (var b = 0; b < a.length; b++) { var c = a[b].trim().split(':'); if (c.length != 2) { continue; } var d = c[0]; var e = this.d(c[1]); this.u.addItem(d, e); } }; DataSourceLocalDataProvider.prototype.d = function (a) { var b = EnumUtil.parse(DataSourceSchemaPropertyType_$type, a, true); if (b != null) { return EnumUtil.getEnumValue(DataSourceSchemaPropertyType_$type, b); } return 11; }; DataSourceLocalDataProvider.prototype.getItemAtIndex = function (a) { if (this.y == null) { return null; } if (this.r) { return this.y[a]; } return this.y.item(a); }; DataSourceLocalDataProvider.prototype.getItemValue = function (a, b) { this.ak(); var c; var d = this.t.tryGetValue(b, c); c = d.p1; if (c == null && !this.v.contains(b)) { var e = b.split('.'); var f = a; var g = true; for (var h = 0; h < e.length; h++) { f = f[e[h]]; if ((f === undefined)) { g = false; break; } } if (g) { c = new FastReflectionHelper(false, b); this.t.addItem(b, c); } else { this.v.add_1(b); } } if (c == null) { return null; } var val_ = c.getPropertyValue(a); if ((val_ === undefined)) { return null; } return val_; }; DataSourceLocalDataProvider.prototype.setItemValue = function (a, b, c) { this.ak(); var d; var e = this.t.tryGetValue(b, d); d = e.p1; if (d == null) { return; } d.setPropertyValue(a, c); }; DataSourceLocalDataProvider.prototype.removeItem = function (a) { if (this.y != null) { var b = this.y.indexOf(a); if (this.r) { this.y.splice(b, 1); } else { this.y.removeAt(b); } this.notifyRemoveItem(b, a); } }; DataSourceLocalDataProvider.prototype.addItem = function (a) { if (this.y != null) { var b = this.actualCount; if (this.r) { this.y.splice(b, 0, a); } else { this.y.insert(b, a); } this.notifyInsertItem(this.actualCount - 1, a); } }; DataSourceLocalDataProvider.prototype.ak = function () { if (this.j == null) { this.j = this.actualSchema; if (this.schemaChanged != null) { this.schemaChanged(this, new DataSourceDataProviderSchemaChangedEventArgs(this.j, this.actualCount)); } } }; Object.defineProperty(DataSourceLocalDataProvider.prototype, "actualCount", { get: function () { if (this.y == null) { return 0; } if (this.r) { return (this.y.length); } return this.y.count; }, enumerable: false, configurable: true }); Object.defineProperty(DataSourceLocalDataProvider.prototype, "actualSchema", { get: function () { if (this.j == null) { if (this.y == null) { this.j = new DefaultDataSourceSchema([], [], null, null, []); } else { this.j = this.l(); } } return this.j; }, enumerable: false, configurable: true }); DataSourceLocalDataProvider.prototype.l = function () { var a = this.ac(); if (a == null) { return new DefaultDataSourceSchema([], [], null, null, []); } this.t.clear(); this.v.clear(); return this.k(a, null, 0); }; DataSourceLocalDataProvider.prototype.k = function (a, b, c) { var e_1, _a; if (c >= this.aa) { return null; } if (a == null) { return null; } if ((typeof a === 'function')) { return null; } if ((Array.isArray(a))) { return null; } var check_ = a; if ((check_ instanceof HTMLElement)) { return null; } var d = new List$1(String_$type, 0); var e = new HashSet$1(String_$type, 0); var f = new List$1(DataSourceSchemaPropertyType_$type, 0); var g = new List$1(List$1.$.specialize(String_$type), 0); var h = this.w(a); var i = new List$1(IDataSourceSchema_$type, 0); if (this.schemaIncludedProperties == null || this.schemaIncludedProperties.length > 0) { for (var j = 0; j < h.count; j++) { var k = h._inner[j]; if (this.schemaIncludedProperties != null && this.schemaIncludedProperties.length > 0) { var l = false; for (var m = 0; m < this.schemaIncludedProperties.length; m++) { if (this.schemaIncludedProperties[m] == k) { l = true; break; } } if (!l) { continue; } } if (stringStartsWith(k, "_")) { continue; } if (k == "$hashCode" || k == "$type") { continue; } if ((typeof check_[k] === 'function')) { continue; } if (e.contains(k)) { continue; } else { var n = b == null ? k : b + "." + k; d.add(k); e.add_1(k); this.t.addItem(n, new FastReflectionHelper(false, n)); if (this.u.containsKey(n)) { f.add(this.u.item(n)); this.u.removeItem(n); } else { f.add(this.c(a, k)); } g.add(this.x(a, k)); if (f._inner[f.count - 1] == 11) { i.add(this.k(a[k], n, c + 1)); } else { i.add(null); } } } try { for (var _b = __values(fromEnum(this.u)), _c = _b.next(); !_c.done; _c = _b.next()) { var o = _c.value; var p = o.key.split('.'); for (var q = 0; q < p.length; q++) { if (e.contains(p[q])) { continue; } else { d.add(p[q]); e.add_1(p[q]); f.add(q == p.length - 1 ? o.value : 11); g.add(new List$1(String_$type, 0)); } } } } 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; } } } var r = new Array(g.count); for (var s = 0; s < g.count; s++) { r[s] = g._inner[s].toArray(); } return new DefaultDataSourceSchema(d.toArray(), f.toArray(), null, r, i.toArray()); }; DataSourceLocalDataProvider.prototype.resolveSchemaPropertyType = function (a) { var b = a.split('.'); var c = a.indexOf("[") >= 0; if (b.length == 1) { for (var d = 0; d < this.actualSchema.propertyNames.length; d++) { if (this.actualSchema.propertyNames[d] == b[0]) { return this.actualSchema.propertyTypes[d]; } } if (c) { var e = this.ac(); var f = this.getItemValue(e, a); if (f == null) { return 11; } else { return DataSourceLocalDataProvider.e(f); } } return 11; } else { var g = this.ac(); var h = this.getItemValue(g, a); if (h == null) { return 11; } else { return DataSourceLocalDataProvider.e(h); } } }; DataSourceLocalDataProvider.prototype.setSchema = function (a) { this.j = a; if (this.schemaChanged != null) { this.schemaChanged(this, new DataSourceDataProviderSchemaChangedEventArgs(this.j, this.actualCount)); } }; DataSourceLocalDataProvider.prototype.w = function (schemaItem_) { var e_2, _a; var a = new HashSet$1(String_$type, 0); var propertyKey_ = null; var ret_ = new List$1(String_$type, 0); var exclusions_ = {}; for (propertyKey_ in schemaItem_) { if (!isNaN(propertyKey_)) { continue; } if (!exclusions_.hasOwnProperty(propertyKey_)) { ret_.add(propertyKey_); } } ; try { for (var _b = __values(fromEnum(ret_)), _c = _b.next(); !_c.done; _c = _b.next()) { var b = _c.value; a.add_1(b); } } 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; } } var c = (getAllPropertyNames(schemaItem_)); for (var e = 0; e < c.length; e++) { var d = c[e]; if (!a.contains(d)) { a.add_1(d); ret_.add(d); } } return ret_; }; DataSourceLocalDataProvider.prototype.am = function (a, item_, propertyName_, b) { if ((item_.__dataIntents !== undefined)) { if ((item_.__dataIntents[propertyName_] !== undefined)) { this.al(a, item_, propertyName_); } var selfName_ = "self." + propertyName_; if (!b && (item_.__dataIntents[selfName_] !== undefined)) { this.al(a, item_, selfName_); } var selfName2_ = "self_" + propertyName_; if (!b && (item_.__dataIntents[selfName2_] !== undefined)) { this.al(a, item_, selfName2_); } } }; DataSourceLocalDataProvider.prototype.al = function (a, item_, propertyName_) { var val_ = item_.__dataIntents[propertyName_]; var b = typeCast(Array_$type, val_) !== null; if (!b) { b = (Array.isArray(val_)); } if (b) { var c = val_; for (var d = 0; d < c.length; d++) { if (c[d] != null) { a.add(c[d].toString()); } } } }; DataSourceLocalDataProvider.prototype.x = function (item_, propertyName_) { var a = new List$1(String_$type, 0); var list_ = this.y; var dataIntents_ = null; this.am(a, item_, propertyName_, false); this.am(a, list_, propertyName_, true); return a; }; DataSourceLocalDataProvider.prototype.c = function (item_, propertyName_) { if (item_ == null) { return 11; } if ((item_[propertyName_] == undefined)) { return 11; } var value_ = item_[propertyName_]; return DataSourceLocalDataProvider.e(value_); }; DataSourceLocalDataProvider.e = function (value_) { if (value_ == null) { return 11; } if ((typeof value_ == 'number')) { return 5; } if ((typeof value_ == 'boolean')) { return 2; } if ((typeof value_ == 'string')) { return 0; } if ((typeof value_ == 'object')) { if ((value_ instanceof Date)) { return 8; } } return 11; }; DataSourceLocalDataProvider.prototype.ac = function () { var a = 0; if (this.r) { a = (this.y.length); } else { a = this.y.count; } for (var b = 0; b < a; b++) { var c = void 0; if (this.r) { c = this.y[b]; } else { c = this.y.item(b); } if (c != null) { return c; } } return null; }; DataSourceLocalDataProvider.prototype.ao = function (a, b, c) { this.aq(a, b, c); }; Object.defineProperty(DataSourceLocalDataProvider.prototype, "z", { get: function () { return this.y; }, enumerable: false, configurable: true }); DataSourceLocalDataProvider.prototype.aq = function (a, b, c) { switch (a) { case "ItemsSource": this.j = null; if (b != null) { if (typeCast(INotifyCollectionChanged_$type, b) !== null) { var d = typeCast(INotifyCollectionChanged_$type, b); d.collectionChanged = delegateRemove(d.collectionChanged, runOn(this, this.an)); } } if (this.dataSource != null) { this.r = false; if (typeCast(Array_$type, this.dataSource) !== null) { this.r = true; this.y = this.dataSource; } else if (typeCast(IList_$type, this.dataSource) !== null) { this.y = this.dataSource; } if (!this.r && this.y == null) { var source_ = this.dataSource; this.r = (Array.isArray(source_)); if (this.r) { this.y = this.dataSource; } } if (typeCast(INotifyCollectionChanged_$type, this.dataSource) !== null) { var e = typeCast(INotifyCollectionChanged_$type, this.dataSource); e.collectionChanged = delegateCombine(e.collectionChanged, runOn(this, this.an)); } } else { this.y = null; } this.ak(); break; case "DeferAutoRefresh": if (!c) { this.queueAutoRefresh(); } break; case "SchemaHints": this.j = null; this.ap(); this.ak(); break; } }; DataSourceLocalDataProvider.prototype.an = function (a, b) { switch (b.action) { case 0: if (b.newItems != null) { this.notifyInsertItem(b.newStartingIndex, b.newItems.item(0)); } break; case 1: if (b.oldItems != null) { this.notifyRemoveItem(b.oldStartingIndex, b.oldItems.item(0)); } break; case 2: if (b.newItems != null) { this.notifySetItem(b.newStartingIndex, b.oldItems.item(0), b.newItems.item(0)); } break; case 4: this.notifyClearItems(); break; } }; Object.defineProperty(DataSourceLocalDataProvider.prototype, "executionContext", { get: function () { return this.i; }, set: function (a) { this.i = a; }, enumerable: false, configurable: true }); Object.defineProperty(DataSourceLocalDataProvider.prototype, "s", { get: function () { return false; }, enumerable: false, configurable: true }); DataSourceLocalDataProvider.prototype.notifySetItem = function (a, b, c) { if (this.s) { if (this.r) { this.y[a] = c; } else { this.y.item(a, c); } } if (this.updateNotifier != null) { this.updateNotifier.notifySetItem(a, b, c); } }; DataSourceLocalDataProvider.prototype.notifyClearItems = function () { if (this.s) { if (this.r) { this.y.length = 0; } else { this.y.clear(); } } if (this.updateNotifier != null) { this.updateNotifier.notifyClearItems(); } }; DataSourceLocalDataProvider.prototype.notifyInsertItem = function (a, b) { if (this.s) { if (this.r) { this.y.splice(a, 0, b); } else { this.y.insert(a, b); } } var c = 0; if (this.r) { c = (this.y.length); } else { c = this.y.count; } if (this.y != null && c == 1 && (this.actualSchema == null || this.actualSchema.propertyNames.length == 0)) { this.j = null; this.ak(); } if (this.updateNotifier != null) { this.updateNotifier.notifyInsertItem(a, b); } }; DataSourceLocalDataProvider.prototype.notifyRemoveItem = function (a, b) { if (this.s) { if (this.r) { this.y.splice(a, 1); } else { this.y.remove(a); } } if (this.updateNotifier != null) { this.updateNotifier.notifyRemoveItem(a, b); } }; Object.defineProperty(DataSourceLocalDataProvider.prototype, "updateNotifier", { get: function () { return this.h; }, set: function (a) { this.h = a; }, enumerable: false, configurable: true }); Object.defineProperty(DataSourceLocalDataProvider.prototype, "deferAutoRefresh", { get: function () { return this.q; }, set: function (a) { var b = this.q; this.q = a; if (this.q != b) { this.ao("DeferAutoRefresh", b, this.q); } }, enumerable: false, configurable: true }); Object.defineProperty(DataSourceLocalDataProvider.prototype, "isSortingSupported", { get: function () { return false; }, enumerable: false, configurable: true }); Object.defineProperty(DataSourceLocalDataProvider.prototype, "isFilteringSupported", { get: function () { return false; }, enumerable: false, configurable: true }); Object.defineProperty(DataSourceLocalDataProvider.prototype, "sortDescriptions", { get: function () { return this.n; }, enumerable: false, configurable: true }); Object.defineProperty(DataSourceLocalDataProvider.prototype, "filterExpressions", { get: function () { return this.g; }, enumerable: false, configurable: true }); Object.defineProperty(DataSourceLocalDataProvider.prototype, "summaryDescriptions", { get: function () { return this.o; }, enumerable: false, configurable: true }); Object.defineProperty(DataSourceLocalDataProvider.prototype, "summaryScope", { get: function () { return this.f; }, set: function (a) { this.f = a; }, enumerable: false, configurable: true }); Object.defineProperty(DataSourceLocalDataProvider.prototype, "notifyUsingSourceIndexes", { get: function () { return true; }, enumerable: false, configurable: true }); Object.defineProperty(DataSourceLocalDataProvider.prototype, "propertiesRequested", { get: function () { return this.a; }, set: function (a) { var b = this.a; this.a = a; if (b != this.a) { } }, enumerable: false, configurable: true }); Object.defineProperty(DataSourceLocalDataProvider.prototype, "isItemIndexLookupSupported", { get: function () { return true; }, enumerable: false, configurable: true }); Object.defineProperty(DataSourceLocalDataProvider.prototype, "isKeyIndexLookupSupported", { get: function () { return false; }, enumerable: false, configurable: true }); Object.defineProperty(DataSourceLocalDataProvider.prototype, "isGroupingSupported", { get: function () { return false; }, enumerable: false, configurable: true }); Object.defineProperty(DataSourceLocalDataProvider.prototype, "groupDescriptions", { get: function () { return this.m; }, enumerable: false, configurable: true }); DataSourceLocalDataProvider.prototype.queueAutoRefresh = function () { if (this.deferAutoRefresh) { return; } if (this.p) { return; } if (this.executionContext != null) { this.p = true; this.executionContext.enqueueAction(runOn(this, this.aj)); } }; DataSourceLocalDataProvider.prototype.aj = function () { if (this.deferAutoRefresh) { this.p = false; return; } if (!this.p) { return; } this.p = false; this.ar(); }; DataSourceLocalDataProvider.prototype.ar = function () { this.as(); }; DataSourceLocalDataProvider.prototype.as = function () { }; DataSourceLocalDataProvider.prototype.flushAutoRefresh = function () { this.aj(); }; DataSourceLocalDataProvider.prototype.refresh = function () { this.ar(); }; DataSourceLocalDataProvider.prototype.indexOfItem = function (a) { if (this.y == null) { return -1; } return this.y.indexOf(a); }; DataSourceLocalDataProvider.prototype.indexOfKey = function (a) { return -1; }; Object.defineProperty(DataSourceLocalDataProvider.prototype, "schemaIncludedProperties", { get: function () { return this.b; }, set: function (a) { var b = this.b; this.b = a; if (b != this.b) { } }, enumerable: false, configurable: true }); DataSourceLocalDataProvider.$t = markType(DataSourceLocalDataProvider, 'DataSourceLocalDataProvider', Base.$, [IDataSourceLocalDataProvider_$type]); return DataSourceLocalDataProvider; }(Base)); export { DataSourceLocalDataProvider };