UNPKG

igniteui-angular-core

Version:

Ignite UI Angular Core logic used in multiple UI components.

184 lines (182 loc) 5.83 kB
import { IgxDataSourceSortDescriptionCollection } from "./igx-data-source-sort-description-collection"; import { IgxDataSourceGroupDescriptionCollection } from "./igx-data-source-group-description-collection"; import { IgxDataSourceSummaryDescriptionCollection } from "./igx-data-source-summary-description-collection"; import { IgxFilterExpressionCollection } from "./igx-filter-expression-collection"; import { TypeRegistrar } from "./type"; /** * The base class for generic data sources. */ export class IgxBaseGenericDataSource { constructor() { this._zoneRunner = null; this._implementation = this.createImplementation(); this._implementation.externalObject = this; this.onImplementationCreated(); if (this._initializeAdapters) { this._initializeAdapters(); } } createImplementation() { return null; } /** * @hidden */ get i() { return this._implementation; } /** * @hidden */ static _createFromInternal(internal) { if (!internal) { return null; } if (!internal.$type) { return null; } let name = internal.$type.name; let externalName = "Igx" + name + "Component"; if (!TypeRegistrar.isRegistered(externalName)) { return null; } return TypeRegistrar.create(externalName); } onImplementationCreated() { } _provideImplementation(i) { this._implementation = i; this._implementation.externalObject = this; this.onImplementationCreated(); } /** * Gets or sets the execution context that the data source should synchronize asynchronous actions with, or use to defer delayed actions. */ get executionContext() { return this.i.t; } set executionContext(v) { this.i.t = v; } /** * Gets the current sort that is applied to the data source. */ get sortDescriptions() { const r = this.i.m; if (r == null) { return null; } if (!r.externalObject) { let e = new IgxDataSourceSortDescriptionCollection(); if (r.$type) { e._implementation = r; } else { if (e.i.setNativeElement) { e.i.setNativeElement(r); } } r.externalObject = e; } return r.externalObject; } /** * Gets the current grouping that is applied to the data source. */ get groupDescriptions() { const r = this.i.k; if (r == null) { return null; } if (!r.externalObject) { let e = new IgxDataSourceGroupDescriptionCollection(); if (r.$type) { e._implementation = r; } else { if (e.i.setNativeElement) { e.i.setNativeElement(r); } } r.externalObject = e; } return r.externalObject; } /** * Gets the current summaries that are applied to the data source. */ get summaryDescriptions() { const r = this.i.o; if (r == null) { return null; } if (!r.externalObject) { let e = new IgxDataSourceSummaryDescriptionCollection(); if (r.$type) { e._implementation = r; } else { if (e.i.setNativeElement) { e.i.setNativeElement(r); } } r.externalObject = e; } return r.externalObject; } /** * Gets the current filter that is applied to the data source. */ get filterExpressions() { const r = this.i.q; if (r == null) { return null; } if (!r.externalObject) { let e = new IgxFilterExpressionCollection(); if (r.$type) { e._implementation = r; } else { if (e.i.setNativeElement) { e.i.setNativeElement(r); } } r.externalObject = e; } return r.externalObject; } findByName(name) { if (this.findEphemera) { if (name && name.indexOf("@@e:") == 0) { return this.findEphemera(name); } } if (this.sortDescriptions != null && this.sortDescriptions.findByName && this.sortDescriptions.findByName(name)) { return this.sortDescriptions.findByName(name); } if (this.groupDescriptions != null && this.groupDescriptions.findByName && this.groupDescriptions.findByName(name)) { return this.groupDescriptions.findByName(name); } if (this.summaryDescriptions != null && this.summaryDescriptions.findByName && this.summaryDescriptions.findByName(name)) { return this.summaryDescriptions.findByName(name); } if (this.filterExpressions != null && this.filterExpressions.findByName && this.filterExpressions.findByName(name)) { return this.filterExpressions.findByName(name); } return null; } /** * Called to manually queue a refresh of the data source. */ queueAutoRefresh() { this.i.z(); } _runInZone(act) { if (this._zoneRunner != null) { this._zoneRunner(act); } else { act(); } } }