igniteui-angular-core
Version:
Ignite UI Angular Core logic used in multiple UI components.
644 lines (643 loc) • 21.1 kB
JavaScript
/*
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 { Base, IList_$type, runOn, String_$type, EnumUtil, fromEnum, typeCast, Array_$type, 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 { stringStartsWith } from "./string";
/**
* @hidden
*/
export let DataSourceLocalDataProvider = /*@__PURE__*/ (() => {
class DataSourceLocalDataProvider extends Base {
constructor() {
super();
this.m = null;
this.l = null;
this.f = null;
this.n = null;
this.e = 0;
this.z = 5;
this.aa = null;
this.t = new Dictionary$2(String_$type, DataSourceSchemaPropertyType_$type, 0);
this.ac = null;
this.schemaChanged = null;
this.s = new Dictionary$2(String_$type, FastReflectionHelper.$, 0);
this.u = new HashSet$1(String_$type, 0);
this.i = null;
this.x = null;
this.q = false;
this.h = null;
this.g = null;
this.p = false;
this.a = null;
this.o = false;
this.m = new SortDescriptionCollection();
this.m.n(runOn(this, this.as));
this.l = new SortDescriptionCollection();
this.n = new SummaryDescriptionCollection();
this.f = new FilterExpressionCollection();
}
as(a, b) {
this.queueAutoRefresh();
}
get dataSource() {
return this.aa;
}
set dataSource(a) {
let b = this.aa;
this.aa = a;
if (b != this.aa) {
this.am("ItemsSource", b, this.aa);
}
}
get af() {
return this.ac;
}
set af(a) {
let b = this.ac;
this.ac = a;
if (b != this.ac) {
this.am("SchemaHints", b, this.ac);
}
}
an() {
if (this.ac == null) {
return;
}
this.t.clear();
let a = this.ac.split(',');
for (let b = 0; b < a.length; b++) {
let c = a[b].trim().split(':');
if (c.length != 2) {
continue;
}
let d = c[0];
let e = this.c(c[1]);
this.t.addItem(d, e);
}
}
c(a) {
let b = EnumUtil.parse(DataSourceSchemaPropertyType_$type, a, true);
if (b != null) {
return EnumUtil.getEnumValue(DataSourceSchemaPropertyType_$type, b);
}
return 11;
}
getItemAtIndex(a) {
if (this.x == null) {
return null;
}
if (this.q) {
return this.x[a];
}
return this.x.item(a);
}
getItemValue(a, b) {
this.aj();
let c;
let d = this.s.tryGetValue(b, c);
c = d.p1;
if (c == null && !this.u.contains(b)) {
let e = b.split('.');
let f = a;
let g = true;
for (let h = 0; h < e.length; h++) {
f = f[e[h]];
if ((f === undefined)) {
g = false;
break;
}
}
if (g) {
c = new FastReflectionHelper(false, b);
this.s.addItem(b, c);
}
else {
this.u.add_1(b);
}
}
if (c == null) {
return null;
}
let val_ = c.getPropertyValue(a);
if ((val_ === undefined)) {
return null;
}
return val_;
}
setItemValue(a, b, c) {
this.aj();
let d;
let e = this.s.tryGetValue(b, d);
d = e.p1;
if (d == null) {
return;
}
d.setPropertyValue(a, c);
}
removeItem(a) {
if (this.x != null) {
let b = this.x.indexOf(a);
if (this.q) {
this.x.splice(b, 1);
}
else {
this.x.removeAt(b);
}
this.notifyRemoveItem(b, a);
}
}
addItem(a) {
if (this.x != null) {
let b = this.actualCount;
if (this.q) {
this.x.splice(b, 0, a);
}
else {
this.x.insert(b, a);
}
this.notifyInsertItem(this.actualCount - 1, a);
}
}
aj() {
if (this.i == null) {
this.i = this.actualSchema;
if (this.schemaChanged != null) {
this.schemaChanged(this, new DataSourceDataProviderSchemaChangedEventArgs(this.i, this.actualCount));
}
}
}
get actualCount() {
if (this.x == null) {
return 0;
}
if (this.q) {
return (this.x.length);
}
return this.x.count;
}
get actualSchema() {
if (this.i == null) {
if (this.x == null) {
this.i = new DefaultDataSourceSchema([], [], null, null, []);
}
else {
this.i = this.k();
}
}
return this.i;
}
k() {
let a = this.ab();
if (a == null) {
return new DefaultDataSourceSchema([], [], null, null, []);
}
this.s.clear();
this.u.clear();
return this.j(a, null, 0);
}
j(a, b, c) {
if (c >= this.z) {
return null;
}
if (a == null) {
return null;
}
if ((typeof a === 'function')) {
return null;
}
if ((Array.isArray(a))) {
return null;
}
let check_ = a;
if ((check_ instanceof HTMLElement)) {
return null;
}
let d = new List$1(String_$type, 0);
let e = new HashSet$1(String_$type, 0);
let f = new List$1(DataSourceSchemaPropertyType_$type, 0);
let g = new List$1(List$1.$.specialize(String_$type), 0);
let h = this.v(a);
let i = new List$1(IDataSourceSchema_$type, 0);
for (let j = 0; j < h.count; j++) {
let k = h._inner[j];
if (stringStartsWith(k, "_")) {
continue;
}
if (k == "$hashCode" || k == "$type") {
continue;
}
if (e.contains(k)) {
continue;
}
else {
let l = b == null ? k : b + "." + k;
d.add(k);
e.add_1(k);
this.s.addItem(l, new FastReflectionHelper(false, l));
if (this.t.containsKey(l)) {
f.add(this.t.item(l));
this.t.removeItem(l);
}
else {
f.add(this.b(a, k));
}
g.add(this.w(a, k));
if (f._inner[f.count - 1] == 11) {
i.add(this.j(a[k], l, c + 1));
}
else {
i.add(null);
}
}
}
for (let m of fromEnum(this.t)) {
let n = m.key.split('.');
for (let o = 0; o < n.length; o++) {
if (e.contains(n[o])) {
continue;
}
else {
d.add(n[o]);
e.add_1(n[o]);
f.add(o == n.length - 1 ? m.value : 11);
g.add(new List$1(String_$type, 0));
}
}
}
let p = new Array(g.count);
for (let q = 0; q < g.count; q++) {
p[q] = g._inner[q].toArray();
}
return new DefaultDataSourceSchema(d.toArray(), f.toArray(), null, p, i.toArray());
}
resolveSchemaPropertyType(a) {
let b = a.split('.');
if (b.length == 1) {
for (let c = 0; c < this.actualSchema.propertyNames.length; c++) {
if (this.actualSchema.propertyNames[c] == b[0]) {
return this.actualSchema.propertyTypes[c];
}
}
return 11;
}
else {
let d = this.ab();
let e = this.getItemValue(d, a);
if (e == null) {
return 11;
}
else {
return DataSourceLocalDataProvider.d(e);
}
}
}
ar(a) {
this.i = a;
if (this.schemaChanged != null) {
this.schemaChanged(this, new DataSourceDataProviderSchemaChangedEventArgs(this.i, this.actualCount));
}
}
v(schemaItem_) {
let propertyKey_ = null;
let ret_ = new List$1(String_$type, 0);
let exclusions_ = {};
for (propertyKey_ in schemaItem_) {
if (!isNaN(propertyKey_)) {
continue;
}
if (!exclusions_.hasOwnProperty(propertyKey_)) {
ret_.add(propertyKey_);
}
}
;
return ret_;
}
al(a, item_, propertyName_, b) {
if ((item_.__dataIntents !== undefined)) {
if ((item_.__dataIntents[propertyName_] !== undefined)) {
this.ak(a, item_, propertyName_);
}
let selfName_ = "self." + propertyName_;
if (!b && (item_.__dataIntents[selfName_] !== undefined)) {
this.ak(a, item_, selfName_);
}
let selfName2_ = "self_" + propertyName_;
if (!b && (item_.__dataIntents[selfName2_] !== undefined)) {
this.ak(a, item_, selfName2_);
}
}
}
ak(a, item_, propertyName_) {
let val_ = item_.__dataIntents[propertyName_];
let b = typeCast(Array_$type, val_) !== null;
if (!b) {
b = (Array.isArray(val_));
}
if (b) {
let c = val_;
for (let d = 0; d < c.length; d++) {
if (c[d] != null) {
a.add(c[d].toString());
}
}
}
}
w(item_, propertyName_) {
let a = new List$1(String_$type, 0);
let list_ = this.x;
let dataIntents_ = null;
this.al(a, item_, propertyName_, false);
this.al(a, list_, propertyName_, true);
return a;
}
b(item_, propertyName_) {
if (item_ == null) {
return 11;
}
if ((item_[propertyName_] == undefined)) {
return 11;
}
let value_ = item_[propertyName_];
return DataSourceLocalDataProvider.d(value_);
}
static d(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;
}
ab() {
let a = 0;
if (this.q) {
a = (this.x.length);
}
else {
a = this.x.count;
}
for (let b = 0; b < a; b++) {
let c;
if (this.q) {
c = this.x[b];
}
else {
c = this.x.item(b);
}
if (c != null) {
return c;
}
}
return null;
}
am(a, b, c) {
this.ao(a, b, c);
}
get y() {
return this.x;
}
ao(a, b, c) {
switch (a) {
case "ItemsSource":
this.i = null;
if (this.dataSource != null) {
this.q = false;
if (typeCast(Array_$type, this.dataSource) !== null) {
this.q = true;
this.x = this.dataSource;
}
else if (typeCast(IList_$type, this.dataSource) !== null) {
this.x = this.dataSource;
}
if (!this.q && this.x == null) {
let source_ = this.dataSource;
this.q = (Array.isArray(source_));
if (this.q) {
this.x = this.dataSource;
}
}
}
else {
this.x = null;
}
this.aj();
break;
case "DeferAutoRefresh":
if (!c) {
this.queueAutoRefresh();
}
break;
case "SchemaHints":
this.i = null;
this.an();
this.aj();
break;
}
}
get executionContext() {
return this.h;
}
set executionContext(a) {
this.h = a;
}
get r() {
return false;
}
notifySetItem(a, b, c) {
if (this.r) {
if (this.q) {
this.x[a] = c;
}
else {
this.x.item(a, c);
}
}
if (this.updateNotifier != null) {
this.updateNotifier.notifySetItem(a, b, c);
}
}
notifyClearItems() {
if (this.r) {
if (this.q) {
this.x.length = 0;
}
else {
this.x.clear();
}
}
if (this.updateNotifier != null) {
this.updateNotifier.notifyClearItems();
}
}
notifyInsertItem(a, b) {
if (this.r) {
if (this.q) {
this.x.splice(a, 0, b);
}
else {
this.x.insert(a, b);
}
}
let c = 0;
if (this.q) {
c = (this.x.length);
}
else {
c = this.x.count;
}
if (this.x != null && c == 1 && (this.actualSchema == null || this.actualSchema.propertyNames.length == 0)) {
this.i = null;
this.aj();
}
if (this.updateNotifier != null) {
this.updateNotifier.notifyInsertItem(a, b);
}
}
notifyRemoveItem(a, b) {
if (this.r) {
if (this.q) {
this.x.splice(a, 1);
}
else {
this.x.remove(a);
}
}
if (this.updateNotifier != null) {
this.updateNotifier.notifyRemoveItem(a, b);
}
}
get updateNotifier() {
return this.g;
}
set updateNotifier(a) {
this.g = a;
}
get deferAutoRefresh() {
return this.p;
}
set deferAutoRefresh(a) {
let b = this.p;
this.p = a;
if (this.p != b) {
this.am("DeferAutoRefresh", b, this.p);
}
}
get isSortingSupported() {
return false;
}
get isFilteringSupported() {
return false;
}
get sortDescriptions() {
return this.m;
}
get filterExpressions() {
return this.f;
}
get summaryDescriptions() {
return this.n;
}
get summaryScope() {
return this.e;
}
set summaryScope(a) {
this.e = a;
}
get notifyUsingSourceIndexes() {
return true;
}
get propertiesRequested() {
return this.a;
}
set propertiesRequested(a) {
let b = this.a;
this.a = a;
if (b != this.a) {
}
}
get isItemIndexLookupSupported() {
return true;
}
get isKeyIndexLookupSupported() {
return false;
}
get isGroupingSupported() {
return false;
}
get groupDescriptions() {
return this.l;
}
queueAutoRefresh() {
if (this.deferAutoRefresh) {
return;
}
if (this.o) {
return;
}
if (this.executionContext != null) {
this.o = true;
this.executionContext.enqueueAction(runOn(this, this.ai));
}
}
ai() {
if (this.deferAutoRefresh) {
this.o = false;
return;
}
if (!this.o) {
return;
}
this.o = false;
this.ap();
}
ap() {
this.aq();
}
aq() {
}
flushAutoRefresh() {
this.ai();
}
refresh() {
this.ap();
}
indexOfItem(a) {
if (this.x == null) {
return -1;
}
return this.x.indexOf(a);
}
indexOfKey(a) {
return -1;
}
}
DataSourceLocalDataProvider.$t = markType(DataSourceLocalDataProvider, 'DataSourceLocalDataProvider', Base.$, [IDataSourceLocalDataProvider_$type]);
return DataSourceLocalDataProvider;
})();