UNPKG

@progress/kendo-angular-pivotgrid

Version:
189 lines (188 loc) 7.09 kB
/**----------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the project root for more information *-------------------------------------------------------------------------------------------*/ import { Directive, Input, NgZone } from '@angular/core'; import { PivotGridDataService } from './pivotgrid-data.service'; import { addKPI, buildKPIMeasures, createDataState, fetchData, fetchDiscover } from '@progress/kendo-pivotgrid-common'; import { anyChanged } from '@progress/kendo-angular-common'; import { PivotBaseBindingDirective } from './base-binding-directive'; import { clone } from '../util'; import * as i0 from "@angular/core"; import * as i1 from "./pivotgrid-data.service"; /** * A directive which binds the PivotGrid to data using an Online Analytical Processing (OLAP) service ([see example]({% slug directives_databinding_remote_pivotgrid %})). */ export class PivotOLAPBindingDirective extends PivotBaseBindingDirective { /** * The OLAP service endpoint where the data is processed and retrieved to render the pivot table. */ url; /** * The cube name that is used to retrieve data for the pivot table rendering. */ cube; /** * The database name that is used to retrieve the data from the specified connection string. */ catalog; type = 'olap'; constructor(dataService, zone) { super(dataService, zone); } ngOnChanges(changes) { if (anyChanged(['url', 'cube', 'catalog', 'columnAxes', 'rowAxes', 'measureAxes'], changes)) { this.loadData(this.dataService.state); this.loadFields(); } } loadData(state) { const { columnAxes, rowAxes, measureAxes, sort, filter } = state; this.dataService.loading.next(true); const options = { connection: { catalog: this.catalog, cube: this.cube }, columnAxes, rowAxes, measureAxes, sort, filter }; fetchData({ url: this.url }, clone(options)) .then(createDataState) .then(newDataState => { this.dataState = newDataState; this.updateDataServiceFields(); this.dataService.loading.next(false); }); } loadFields() { const options = { connection: { catalog: this.catalog, cube: this.cube }, restrictions: { catalogName: this.catalog, cubeName: this.cube }, command: 'schemaDimensions' }; fetchDiscover({ url: this.url }, options) .then((newFields) => { addKPI(newFields); this.configuratorFields = newFields; this.updateConfiguratorFields(); }); } async updateFields(event, fields) { const newFields = fields.slice(); const field = this.getField(newFields, event); if (field && field.uniqueName === '[KPIs]') { const KPIs = this.normalizeKPIs(await this.loadKPIs()); field.children = KPIs; } else if (field && field.type === 'kpi') { field.children = buildKPIMeasures(field); } else if (field && !field.children) { const additionalFields = await this.loadAvailableFields(field); field.children = additionalFields; } return field?.children; } /** * @hidden */ fetchChildren(event, fields) { return this.updateFields(event, fields); } normalizeKPIs(data) { for (let idx = 0, length = data.length; idx < length; idx++) { data[idx].uniqueName = data[idx].name; data[idx].type = 'kpi'; } return data; } getField(nodes = [], target) { for (let i = 0; i < nodes.length; i++) { const node = nodes[i]; if (node.uniqueName === target.uniqueName) { return node; } const result = this.getField(node.children, target); if (result !== null) { return result; } } return null; } async loadKPIs() { const options = { connection: { catalog: this.catalog, cube: this.cube }, restrictions: { catalogName: this.catalog, cubeName: this.cube }, command: 'schemaKPIs' }; return fetchDiscover({ url: this.url }, options); } async loadAvailableFields(field) { let command; let dimensionUniqueName; let hierarchyUniqueName; let levelUniqueName; let memberUniqueName; let treeOp; if (field.type === 2) { command = 'schemaMeasures'; } else if (field.dimensionUniqueName) { command = 'schemaLevels'; hierarchyUniqueName = field.uniqueName; } else { command = 'schemaHierarchies'; dimensionUniqueName = field.uniqueName; } const options = { connection: { catalog: this.catalog, cube: this.cube }, restrictions: { catalogName: this.catalog, cubeName: this.cube, hierarchyUniqueName, dimensionUniqueName, levelUniqueName, memberUniqueName, treeOp }, command }; return fetchDiscover({ url: this.url }, options); } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: PivotOLAPBindingDirective, deps: [{ token: i1.PivotGridDataService }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Directive }); static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.12", type: PivotOLAPBindingDirective, isStandalone: true, selector: "[kendoPivotOLAPBinding]", inputs: { url: "url", cube: "cube", catalog: "catalog" }, exportAs: ["kendoPivotOLAPBinding"], usesInheritance: true, usesOnChanges: true, ngImport: i0 }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: PivotOLAPBindingDirective, decorators: [{ type: Directive, args: [{ selector: '[kendoPivotOLAPBinding]', exportAs: 'kendoPivotOLAPBinding', standalone: true }] }], ctorParameters: function () { return [{ type: i1.PivotGridDataService }, { type: i0.NgZone }]; }, propDecorators: { url: [{ type: Input }], cube: [{ type: Input }], catalog: [{ type: Input }] } });