UNPKG

@anglr/grid

Version:
189 lines 9.39 kB
import { Directive, ElementRef, HostBinding, Injector, inject } from '@angular/core'; import { toObservable } from '@angular/core/rxjs-interop'; import { extend } from '@jscrpt/common/extend'; import { skip } from 'rxjs'; import { GridPluginType } from '../../../misc/enums'; import * as i0 from "@angular/core"; /** * Abstract component for content renderers * @deprecated use new MatrixGrid with MatrixContentRenderer instead */ export class BodyHeaderContentRendererAbstractComponent { /** * Null safe grid plugin instances */ get gridPluginsInstance() { if (!this.gridPlugins) { throw new Error('BodyHeaderContentRendererAbstractComponent: missing gridPlugins!'); } return this.gridPlugins; } //######################### public properties - implementation of TableContentRenderer ######################### /** * Options for content renderer */ get options() { return this.ɵoptions; } set options(options) { this.ɵoptions = extend(true, this.ɵoptions, options); } //######################### public properties - hosts ######################### /** * Css class applied to grid itself */ get cssClass() { return this.ɵoptions.cssClasses.containerDiv; } //######################### constructor ######################### constructor(pluginElement, gridPlugins, defaultOptions, options) { this.pluginElement = pluginElement; this.gridPlugins = gridPlugins; /** * Angular injector used for injecting dependencies */ this.injector = inject(Injector); this.ɵoptions = extend(true, {}, defaultOptions, options); } //######################### public methods - implementation of OnDestroy ######################### /** * Called when component is destroyed */ ngOnDestroy() { this.metadataChangedSubscription?.unsubscribe(); this.metadataChangedSubscription = null; this.dataChangedSubscription?.unsubscribe(); this.dataChangedSubscription = null; } //######################### public methods - implementation of TableContentRenderer ######################### /** * Explicitly runs invalidation of content (change detection) */ invalidateVisuals() { this.ɵinvalidateVisuals(); } /** * @inheritdoc */ initialize(force) { const metadataSelector = this.gridPluginsInstance[GridPluginType.MetadataSelector]; if (force || (this.metadataSelector && this.metadataSelector != metadataSelector)) { this.metadataChangedSubscription?.unsubscribe(); this.metadataChangedSubscription = null; this.metadataSelector = null; } if (!this.metadataSelector) { this.metadataSelector = metadataSelector; this.metadataChangedSubscription = toObservable(this.metadataSelector.metadata, { injector: this.injector }) .pipe(skip(1)) .subscribe(() => this.ɵinvalidateVisuals()); } const dataLoader = this.gridPluginsInstance[GridPluginType.DataLoader]; if (force || (this.dataLoader && this.dataLoader != dataLoader)) { this.dataChangedSubscription?.unsubscribe(); this.dataChangedSubscription = null; this.dataLoader = null; } if (!this.dataLoader) { this.dataLoader = dataLoader; this.dataChangedSubscription = toObservable(this.dataLoader.result, { injector: this.injector }).subscribe(() => this.ɵinvalidateVisuals()); } this.gridPluginsInstance['HEADER_CONTENT_RENDERER'].initialize(force); this.gridPluginsInstance['BODY_CONTENT_RENDERER'].initialize(force); this.ɵinvalidateVisuals(); } /** * @inheritdoc */ initOptions() { if (this.ɵoptions.plugins) { if (this.ɵoptions.plugins.bodyRenderer) { if (this.ɵoptions.plugins.bodyRenderer.instance && this.ɵoptions.plugins.bodyRenderer.instance != this.gridPluginsInstance['BODY_CONTENT_RENDERER']) { this.gridPluginsInstance['BODY_CONTENT_RENDERER'] = this.ɵoptions.plugins.bodyRenderer.instance; this.ɵoptions.plugins.bodyRenderer.instance.gridPlugins = this.gridPlugins; } if (this.gridPluginsInstance['BODY_CONTENT_RENDERER']) { if (this.ɵoptions.plugins && this.ɵoptions.plugins.bodyRenderer && this.ɵoptions.plugins.bodyRenderer.options) { this.gridPluginsInstance['BODY_CONTENT_RENDERER'].options = this.ɵoptions.plugins.bodyRenderer.options; } this.gridPluginsInstance['BODY_CONTENT_RENDERER'].initOptions(); } } if (this.ɵoptions.plugins.headerRenderer) { if (this.ɵoptions.plugins.headerRenderer.instance && this.ɵoptions.plugins.headerRenderer.instance != this.gridPluginsInstance['HEADER_CONTENT_RENDERER']) { this.gridPluginsInstance['HEADER_CONTENT_RENDERER'] = this.ɵoptions.plugins.headerRenderer.instance; this.ɵoptions.plugins.headerRenderer.instance.gridPlugins = this.gridPlugins; } if (this.gridPluginsInstance['HEADER_CONTENT_RENDERER']) { if (this.ɵoptions.plugins && this.ɵoptions.plugins.headerRenderer && this.ɵoptions.plugins.headerRenderer.options) { this.gridPluginsInstance['HEADER_CONTENT_RENDERER'].options = this.ɵoptions.plugins.headerRenderer.options; } this.gridPluginsInstance['HEADER_CONTENT_RENDERER'].initOptions(); } } } } //######################### protected methods - template bindings ######################### /** * Sets body renderer component * @param bodyRenderer - Created body renderer that is rendered */ setBodyRendererComponent(bodyRenderer) { if (!bodyRenderer) { return; } this.gridPluginsInstance['BODY_CONTENT_RENDERER'] = bodyRenderer; if (this.ɵoptions.plugins && this.ɵoptions.plugins.bodyRenderer && this.ɵoptions.plugins.bodyRenderer.options) { bodyRenderer.options = this.ɵoptions.plugins.bodyRenderer.options; } bodyRenderer.initOptions(); if (this.ɵoptions.plugins && this.ɵoptions.plugins.bodyRenderer && this.ɵoptions.plugins.bodyRenderer.instanceCallback) { this.ɵoptions.plugins.bodyRenderer.instanceCallback(bodyRenderer); } } /** * Sets header renderer component * @param headerRenderer - Created header renderer that is rendered */ setHeaderRendererComponent(headerRenderer) { if (!headerRenderer) { return; } this.gridPluginsInstance['HEADER_CONTENT_RENDERER'] = headerRenderer; if (this.ɵoptions.plugins && this.ɵoptions.plugins.headerRenderer && this.ɵoptions.plugins.headerRenderer.options) { headerRenderer.options = this.ɵoptions.plugins.headerRenderer.options; } headerRenderer.initOptions(); if (this.ɵoptions.plugins && this.ɵoptions.plugins.headerRenderer && this.ɵoptions.plugins.headerRenderer.instanceCallback) { this.ɵoptions.plugins.headerRenderer.instanceCallback(headerRenderer); } } //######################### protected methods ######################### /** * Invalidates visuals, redraw template */ ɵinvalidateVisuals() { const bodyRenderer = this.gridPluginsInstance['BODY_CONTENT_RENDERER']; const headerRenderer = this.gridPluginsInstance['HEADER_CONTENT_RENDERER']; if (headerRenderer.metadata != this.metadataSelector?.metadata) { headerRenderer.metadata = this.metadataSelector?.metadata(); headerRenderer.invalidateVisuals(); } if (bodyRenderer.data != this.dataLoader?.result().data || bodyRenderer.metadata != this.metadataSelector?.metadata) { bodyRenderer.data = this.dataLoader?.result().data ?? []; bodyRenderer.metadata = this.metadataSelector?.metadata(); bodyRenderer.invalidateVisuals(); } } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.1.0", ngImport: i0, type: BodyHeaderContentRendererAbstractComponent, deps: "invalid", target: i0.ɵɵFactoryTarget.Directive }); } static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.1.0", type: BodyHeaderContentRendererAbstractComponent, isStandalone: true, host: { properties: { "class": "this.cssClass" } }, ngImport: i0 }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.0", ngImport: i0, type: BodyHeaderContentRendererAbstractComponent, decorators: [{ type: Directive }], ctorParameters: () => [{ type: i0.ElementRef }, { type: undefined }, { type: undefined }, { type: undefined }], propDecorators: { cssClass: [{ type: HostBinding, args: ['class'] }] } }); //# sourceMappingURL=bodyHeaderContentRendererAbstract.component.js.map