@anglr/grid
Version:
Angular module displaying grid
126 lines • 6.48 kB
JavaScript
import { Inject, Component, ChangeDetectionStrategy, ElementRef, ChangeDetectorRef, Optional, signal, computed } from '@angular/core';
import { CommonModule } from '@angular/common';
import { LocalizePipe } from '@anglr/common';
import { extend } from '@jscrpt/common/extend';
import { DataLoaderState, GridPluginType } from '../../../misc/enums';
import { GRID_PLUGIN_INSTANCES, NO_DATA_RENDERER_OPTIONS } from '../../../misc/tokens';
import * as i0 from "@angular/core";
import * as i1 from "@angular/common";
/**
* Default options for no data renderer
*/
const defaultOptions = {
template: null,
texts: {
loading: 'Loading ...',
noData: 'No data available.',
notLoaded: 'No data loaded yet'
},
cssClasses: {
wrapperContainer: 'no-data-container',
textElement: 'no-data-text',
}
};
/**
* Component for basic simple no data renderer
*/
export class SimpleNoDataRendererComponent {
//######################### public properties - implementation of NoDataRenderer #########################
/**
* @inheritdoc
*/
get options() {
return this.optionsValue();
}
set options(options) {
this.optionsValue.update(opts => extend(true, opts, options));
}
//######################### constructor #########################
constructor(pluginElement, changeDetector, gridPlugins, options) {
this.pluginElement = pluginElement;
this.changeDetector = changeDetector;
this.gridPlugins = gridPlugins;
//######################### protected properties - template bindings #########################
/**
* Currently displayed text
*/
this.text = signal('').asReadonly();
this.optionsValue = signal(extend(true, {}, defaultOptions, options));
}
//######################### public methods - implementation of NoDataRenderer #########################
/**
* @inheritdoc
*/
initialize(force) {
if (!this.gridPlugins) {
throw new Error('SimpleNoDataRendererComponent: missing gridPlugins!');
}
const dataLoader = this.gridPlugins[GridPluginType.DataLoader];
//data loader obtained and its different instance
if (force || (this.dataLoader && this.dataLoader != dataLoader)) {
this.dataLoader = null;
}
//no data loader obtained
if (!this.dataLoader) {
this.dataLoader = dataLoader;
this.text = computed(() => {
if (!this.dataLoader) {
return '';
}
const state = this.dataLoader.state();
switch (state) {
case DataLoaderState.NoDataLoading:
{
return this.optionsValue().texts.loading;
}
case DataLoaderState.NoData:
{
return this.optionsValue().texts.noData;
}
case DataLoaderState.NotLoadedYet:
{
return this.optionsValue().texts.notLoaded;
}
default:
//case DataLoaderState.Loaded:
//case DataLoaderState.DataLoading:
{
return '';
}
}
});
}
this.invalidateVisuals();
}
/**
* @inheritdoc
*/
initOptions() {
}
/**
* @inheritdoc
*/
invalidateVisuals() {
this.changeDetector.detectChanges();
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.1.0", ngImport: i0, type: SimpleNoDataRendererComponent, deps: [{ token: i0.ElementRef }, { token: i0.ChangeDetectorRef }, { token: GRID_PLUGIN_INSTANCES, optional: true }, { token: NO_DATA_RENDERER_OPTIONS, optional: true }], target: i0.ɵɵFactoryTarget.Component }); }
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.1.0", type: SimpleNoDataRendererComponent, isStandalone: true, selector: "ng-simple-no-data", ngImport: i0, template: "@if(text())\r\n{\r\n <div [ngClass]=\"optionsValue().cssClasses.wrapperContainer\">\r\n @if(!optionsValue().template)\r\n {\r\n <span [ngClass]=\"optionsValue().cssClasses.textElement\">{{text() | localize}}</span>\r\n }\r\n @else\r\n {\r\n <ng-container *ngTemplateOutlet=\"optionsValue().template\"></ng-container>\r\n }\r\n </div>\r\n}", dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i1.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "pipe", type: LocalizePipe, name: "localize" }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.0", ngImport: i0, type: SimpleNoDataRendererComponent, decorators: [{
type: Component,
args: [{ selector: 'ng-simple-no-data', imports: [
CommonModule,
LocalizePipe,
], changeDetection: ChangeDetectionStrategy.OnPush, template: "@if(text())\r\n{\r\n <div [ngClass]=\"optionsValue().cssClasses.wrapperContainer\">\r\n @if(!optionsValue().template)\r\n {\r\n <span [ngClass]=\"optionsValue().cssClasses.textElement\">{{text() | localize}}</span>\r\n }\r\n @else\r\n {\r\n <ng-container *ngTemplateOutlet=\"optionsValue().template\"></ng-container>\r\n }\r\n </div>\r\n}" }]
}], ctorParameters: () => [{ type: i0.ElementRef }, { type: i0.ChangeDetectorRef }, { type: undefined, decorators: [{
type: Inject,
args: [GRID_PLUGIN_INSTANCES]
}, {
type: Optional
}] }, { type: undefined, decorators: [{
type: Inject,
args: [NO_DATA_RENDERER_OPTIONS]
}, {
type: Optional
}] }] });
//# sourceMappingURL=simpleNoDataRenderer.component.js.map