UNPKG

@nibo-ai/ngx-powerbi

Version:

TypeScript library for embedding Power BI assets (reports/dashboards/tiles) in your application. This TypeScript library is built on top of the official powerbi-client library provided by Microsoft.

591 lines (584 loc) 22.9 kB
import { Injectable, Optional, ɵɵdefineInjectable, EventEmitter, Component, Input, Output, ViewChild, NgModule } from '@angular/core'; import { service, factories } from 'powerbi-client'; import { TokenType as TokenType$1 } from 'powerbi-models'; /** * @fileoverview added by tsickle * Generated from: lib/ngx-powerbi.service.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @return {?} */ function powerBiServiceFactory() { return new service.Service(factories.hpmFactory, factories.wpmpFactory, factories.routerFactory); } var NgxPowerBiService = /** @class */ (function () { function NgxPowerBiService(service$1) { this.service = service$1; if (!service$1) { this.powerBiCoreService = new service.Service(factories.hpmFactory, factories.wpmpFactory, factories.routerFactory); } else { this.powerBiCoreService = service$1; } } /** * Creates new report * @param HTMLElement Parent HTML element * @param IEmbedConfiguration Embed configuration * @returns Embed Embedded object */ /** * Creates new report * @param {?} element * @param {?} config * @return {?} Embed Embedded object */ NgxPowerBiService.prototype.createReport = /** * Creates new report * @param {?} element * @param {?} config * @return {?} Embed Embedded object */ function (element, config) { return this.powerBiCoreService.createReport(element, config); }; /** * Given a configuration based on an HTML element, * if the component has already been created and attached to the element, reuses the component instance and existing iframe, * otherwise creates a new component instance. * * @param HTMLElement Parent HTML element * @param IEmbedConfiguration Embed configuration * @returns Embed Embedded object */ /** * Given a configuration based on an HTML element, * if the component has already been created and attached to the element, reuses the component instance and existing iframe, * otherwise creates a new component instance. * * @param {?} element * @param {?} config * @return {?} Embed Embedded object */ NgxPowerBiService.prototype.embed = /** * Given a configuration based on an HTML element, * if the component has already been created and attached to the element, reuses the component instance and existing iframe, * otherwise creates a new component instance. * * @param {?} element * @param {?} config * @return {?} Embed Embedded object */ function (element, config) { return this.powerBiCoreService.embed(element, config); }; /** * Given a configuration based on an HTML element, * if the component has already been created and attached to the element, reuses the component instance and existing iframe, * otherwise creates a new component instance. * This is used for the phased embedding API, once element is loaded successfully, one can call 'render' on it. * * @param HTMLElement} Parent HTML element * @param IEmbedConfiguration Embed configuration * @returns Embed Embedded object */ /** * Given a configuration based on an HTML element, * if the component has already been created and attached to the element, reuses the component instance and existing iframe, * otherwise creates a new component instance. * This is used for the phased embedding API, once element is loaded successfully, one can call 'render' on it. * * @param {?} element * @param {?} config * @return {?} Embed Embedded object */ NgxPowerBiService.prototype.load = /** * Given a configuration based on an HTML element, * if the component has already been created and attached to the element, reuses the component instance and existing iframe, * otherwise creates a new component instance. * This is used for the phased embedding API, once element is loaded successfully, one can call 'render' on it. * * @param {?} element * @param {?} config * @return {?} Embed Embedded object */ function (element, config) { return this.powerBiCoreService.load(element, config); }; /** * Adds an event handler for DOMContentLoaded, which searches the DOM for elements that have the 'powerbi-embed-url' attribute, * and automatically attempts to embed a Power BI component based on information from other powerbi-* attributes. * * Note: Only runs if `config.autoEmbedOnContentLoaded` is true when the service is created. * This handler is typically useful only for applications that are rendered on the server so that all * required data is available when the handler is called. */ /** * Adds an event handler for DOMContentLoaded, which searches the DOM for elements that have the 'powerbi-embed-url' attribute, * and automatically attempts to embed a Power BI component based on information from other powerbi-* attributes. * * Note: Only runs if `config.autoEmbedOnContentLoaded` is true when the service is created. * This handler is typically useful only for applications that are rendered on the server so that all * required data is available when the handler is called. * @return {?} */ NgxPowerBiService.prototype.enableAutoEmbed = /** * Adds an event handler for DOMContentLoaded, which searches the DOM for elements that have the 'powerbi-embed-url' attribute, * and automatically attempts to embed a Power BI component based on information from other powerbi-* attributes. * * Note: Only runs if `config.autoEmbedOnContentLoaded` is true when the service is created. * This handler is typically useful only for applications that are rendered on the server so that all * required data is available when the handler is called. * @return {?} */ function () { return this.powerBiCoreService.enableAutoEmbed(); }; /** * Returns an instance of the component associated with the element. * * @param HTMLElement Parent HTML element * @returns (Report | Tile) Embedded report/tile object */ /** * Returns an instance of the component associated with the element. * * @param {?} element * @return {?} (Report | Tile) Embedded report/tile object */ NgxPowerBiService.prototype.get = /** * Returns an instance of the component associated with the element. * * @param {?} element * @return {?} (Report | Tile) Embedded report/tile object */ function (element) { return this.powerBiCoreService.get(element); }; /** * Finds an embed instance by the name or unique ID that is provided. * * @param string} uniqueId or name of the report/tile * @returns (Report | Tile) Embedded report/tile object */ /** * Finds an embed instance by the name or unique ID that is provided. * * @param {?} uniqueId * @return {?} (Report | Tile) Embedded report/tile object */ NgxPowerBiService.prototype.findById = /** * Finds an embed instance by the name or unique ID that is provided. * * @param {?} uniqueId * @return {?} (Report | Tile) Embedded report/tile object */ function (uniqueId) { return this.powerBiCoreService.find(uniqueId); }; /** * Given an HTML element that has a component embedded within it, * removes the component from the list of embedded components, * removes the association between the element and the component, and removes the iframe. * * @param HTMLElement Parent HTML element * @returns void */ /** * Given an HTML element that has a component embedded within it, * removes the component from the list of embedded components, * removes the association between the element and the component, and removes the iframe. * * @param {?} element * @return {?} void */ NgxPowerBiService.prototype.reset = /** * Given an HTML element that has a component embedded within it, * removes the component from the list of embedded components, * removes the association between the element and the component, and removes the iframe. * * @param {?} element * @return {?} void */ function (element) { return this.powerBiCoreService.reset(element); }; /** * handles tile events * * @param IEvent<any> event */ /** * handles tile events * * @param {?} event * @return {?} */ NgxPowerBiService.prototype.handleTileEvents = /** * handles tile events * * @param {?} event * @return {?} */ function (event) { return this.powerBiCoreService.handleTileEvents(event); }; /** * API for warm starting Power BI embedded endpoints. * Use this API to preload Power BI Embedded in the background. * * @param embed.IEmbedConfiguration Embed configuration * @param HTMLElement [element=undefined] */ /** * API for warm starting Power BI embedded endpoints. * Use this API to preload Power BI Embedded in the background. * * @param {?} config * @param {?} element * @return {?} */ NgxPowerBiService.prototype.preload = /** * API for warm starting Power BI embedded endpoints. * Use this API to preload Power BI Embedded in the background. * * @param {?} config * @param {?} element * @return {?} */ function (config, element) { return this.powerBiCoreService.preload(config, element); }; NgxPowerBiService.decorators = [ { type: Injectable, args: [{ providedIn: 'root', useFactory: powerBiServiceFactory },] } ]; /** @nocollapse */ NgxPowerBiService.ctorParameters = function () { return [ { type: service.Service, decorators: [{ type: Optional }] } ]; }; /** @nocollapse */ NgxPowerBiService.ɵprov = ɵɵdefineInjectable({ factory: powerBiServiceFactory, token: NgxPowerBiService, providedIn: "root" }); return NgxPowerBiService; }()); if (false) { /** * @type {?} * @private */ NgxPowerBiService.prototype.powerBiCoreService; /** * @type {?} * @private */ NgxPowerBiService.prototype.service; } /** * @fileoverview added by tsickle * Generated from: lib/ngx-powerbi.component.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @enum {string} */ var TokenType = { Aad: "Aad", Embed: "Embed", }; /** @enum {string} */ var ReportType = { Dashboard: "Dashboard", Report: "Report", Tile: "Tile", }; var NgxPowerBiComponent = /** @class */ (function () { function NgxPowerBiComponent(ngxPowerBiService) { this.ngxPowerBiService = ngxPowerBiService; this.embedded = new EventEmitter(); this.powerBiService = ngxPowerBiService; } /** * @return {?} */ NgxPowerBiComponent.prototype.ngAfterViewInit = /** * @return {?} */ function () { // Embed the report inside the view child that we have fetched from the DOM if (this.ngxPowerBiIFrameRef.nativeElement && this.validateRequiredAttributes()) { this.embed(this.ngxPowerBiIFrameRef.nativeElement, this.getConfig()); } }; /** * @param {?} changes * @return {?} */ NgxPowerBiComponent.prototype.ngOnChanges = /** * @param {?} changes * @return {?} */ function (changes) { if (!this.ngxPowerBiIFrameRef) { return; } var accessToken = changes.accessToken, tokenType = changes.tokenType, embedUrl = changes.embedUrl, id = changes.id, type = changes.type, name = changes.name, options = changes.options; // TODO: Validate these conditions /*if ( (accessToken.previousValue !== undefined || accessToken.previousValue === accessToken.currentValue) && embedUrl.previousValue === embedUrl.currentValue ) { return; }*/ if (this.validateRequiredAttributes()) { /** @type {?} */ var config = this.getConfig(accessToken && accessToken.currentValue, tokenType && tokenType.currentValue, embedUrl && embedUrl.currentValue, id && id.currentValue, type && type.currentValue, name && name.currentValue, options && options.currentValue); this.embed(this.ngxPowerBiIFrameRef.nativeElement, config); } else if (this.component) { this.reset(this.ngxPowerBiIFrameRef.nativeElement); } }; /** * @return {?} */ NgxPowerBiComponent.prototype.ngOnDestroy = /** * @return {?} */ function () { if (this.component) { this.reset(this.ngxPowerBiIFrameRef.nativeElement); } }; /** * Ensure required attributes (embedUrl and accessToken are valid before attempting to embed) */ /** * Ensure required attributes (embedUrl and accessToken are valid before attempting to embed) * @private * @return {?} */ NgxPowerBiComponent.prototype.validateRequiredAttributes = /** * Ensure required attributes (embedUrl and accessToken are valid before attempting to embed) * @private * @return {?} */ function () { return (typeof this.embedUrl === 'string' && this.embedUrl.length > 0 && (typeof this.accessToken === 'string' && this.accessToken.length > 0)); }; /** * Get the model class compatible token enum from our token type enum * @param tokenType - Token type in our custom enum format * @returns Token type in powerbi-models.TokenType enum format */ /** * Get the model class compatible token enum from our token type enum * @private * @param {?} tokenType - Token type in our custom enum format * @return {?} Token type in powerbi-models.TokenType enum format */ NgxPowerBiComponent.prototype.getTokenType = /** * Get the model class compatible token enum from our token type enum * @private * @param {?} tokenType - Token type in our custom enum format * @return {?} Token type in powerbi-models.TokenType enum format */ function (tokenType) { if (tokenType) { switch (tokenType) { case "Aad" /* Aad */: return TokenType$1.Aad; case "Embed" /* Embed */: return TokenType$1.Embed; default: return TokenType$1.Aad; } } else { // default is AAD return TokenType$1.Aad; } }; /** * Returns an embed configuration object. * @param accessToken - Access token required to embed a component * @param tokenType - type of accessToken: Aad or Embed * @param embedUrl - Embed URL obtained through Power BI REST API or Portal * @param id - component/element GUID * @param type - type of embedded component e.g. 'dashboard, report or tile' * @param name - name of the embedded component * @param options - Embed configuration options * @returns Embed configuration object */ /** * Returns an embed configuration object. * @private * @param {?=} accessToken - Access token required to embed a component * @param {?=} tokenType - type of accessToken: Aad or Embed * @param {?=} embedUrl - Embed URL obtained through Power BI REST API or Portal * @param {?=} id - component/element GUID * @param {?=} type - type of embedded component e.g. 'dashboard, report or tile' * @param {?=} name - name of the embedded component * @param {?=} options - Embed configuration options * @return {?} Embed configuration object */ NgxPowerBiComponent.prototype.getConfig = /** * Returns an embed configuration object. * @private * @param {?=} accessToken - Access token required to embed a component * @param {?=} tokenType - type of accessToken: Aad or Embed * @param {?=} embedUrl - Embed URL obtained through Power BI REST API or Portal * @param {?=} id - component/element GUID * @param {?=} type - type of embedded component e.g. 'dashboard, report or tile' * @param {?=} name - name of the embedded component * @param {?=} options - Embed configuration options * @return {?} Embed configuration object */ function (accessToken, tokenType, embedUrl, id, type, name, options) { // For null arguments - use the initial value // For specified arguments - use the current value return { type: type ? type : this.type ? this.type : "Report" /* Report */, embedUrl: embedUrl ? embedUrl : this.embedUrl, accessToken: accessToken ? accessToken : this.accessToken, tokenType: tokenType ? this.getTokenType(tokenType) : this.getTokenType(this.tokenType), id: id ? id : this.id, uniqueId: name ? name : this.name, settings: options ? options : this.options }; }; /** * Given an HTMLElement, construct an embed configuration based on attributes and pass to service. * @param element - native element where the embedding needs to be done * @param config - configuration to be embedded */ /** * Given an HTMLElement, construct an embed configuration based on attributes and pass to service. * @private * @param {?} element - native element where the embedding needs to be done * @param {?} config - configuration to be embedded * @return {?} */ NgxPowerBiComponent.prototype.embed = /** * Given an HTMLElement, construct an embed configuration based on attributes and pass to service. * @private * @param {?} element - native element where the embedding needs to be done * @param {?} config - configuration to be embedded * @return {?} */ function (element, config) { /*if (this.options) { const newConfig = { config, ...this.options }; }*/ this.component = this.powerBiService.embed(element, config); this.embedded.emit((/** @type {?} */ (this.component))); }; /** * Reset the component that has been removed from DOM. * @param element - native element where the embedded was made */ /** * Reset the component that has been removed from DOM. * @param {?} element - native element where the embedded was made * @return {?} */ NgxPowerBiComponent.prototype.reset = /** * Reset the component that has been removed from DOM. * @param {?} element - native element where the embedded was made * @return {?} */ function (element) { this.powerBiService.reset(element); this.component = null; }; NgxPowerBiComponent.decorators = [ { type: Component, args: [{ selector: 'ngx-powerbi-component', template: '<div #ngxPowerBiIFrame style="height:100%; width: 100%;"></div>' }] } ]; /** @nocollapse */ NgxPowerBiComponent.ctorParameters = function () { return [ { type: NgxPowerBiService } ]; }; NgxPowerBiComponent.propDecorators = { accessToken: [{ type: Input }], tokenType: [{ type: Input }], embedUrl: [{ type: Input }], id: [{ type: Input }], type: [{ type: Input }], name: [{ type: Input }], options: [{ type: Input }], embedded: [{ type: Output }], ngxPowerBiIFrameRef: [{ type: ViewChild, args: ['ngxPowerBiIFrame', { static: true },] }] }; return NgxPowerBiComponent; }()); if (false) { /** @type {?} */ NgxPowerBiComponent.prototype.accessToken; /** @type {?} */ NgxPowerBiComponent.prototype.tokenType; /** @type {?} */ NgxPowerBiComponent.prototype.embedUrl; /** @type {?} */ NgxPowerBiComponent.prototype.id; /** @type {?} */ NgxPowerBiComponent.prototype.type; /** @type {?} */ NgxPowerBiComponent.prototype.name; /** @type {?} */ NgxPowerBiComponent.prototype.options; /** @type {?} */ NgxPowerBiComponent.prototype.embedded; /** @type {?} */ NgxPowerBiComponent.prototype.ngxPowerBiIFrameRef; /** * @type {?} * @private */ NgxPowerBiComponent.prototype.component; /** * @type {?} * @private */ NgxPowerBiComponent.prototype.powerBiService; /** * @type {?} * @private */ NgxPowerBiComponent.prototype.ngxPowerBiService; } /** * @fileoverview added by tsickle * Generated from: lib/ngx-powerbi.module.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var NgxPowerBiModule = /** @class */ (function () { function NgxPowerBiModule() { } NgxPowerBiModule.decorators = [ { type: NgModule, args: [{ imports: [], declarations: [NgxPowerBiComponent], exports: [NgxPowerBiComponent] },] } ]; return NgxPowerBiModule; }()); /** * @fileoverview added by tsickle * Generated from: public-api.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @fileoverview added by tsickle * Generated from: nibo-ai-ngx-powerbi.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ export { NgxPowerBiComponent, NgxPowerBiModule, NgxPowerBiService, powerBiServiceFactory }; //# sourceMappingURL=nibo-ai-ngx-powerbi.js.map