This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Component, OnInit } from '@angular/core'; | |
| import * as pbi from 'powerbi-client'; | |
| @Component({ | |
| selector: 'app-dashboard', | |
| templateUrl: './dashboard.component.html', | |
| styleUrls: ['./dashboard.component.less'] | |
| }) | |
| export class DashboardComponent implements OnInit { | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| embedPowerBIReport() { | |
| this.service.getReportEmbedToken().subscribe((res) => { | |
| let response = res.json(); | |
| let Token = response.EmbedToken; | |
| const config = { | |
| type: 'report', | |
| tokenType: pbi.models.TokenType.Embed, | |
| id: response.Id, | |
| embedUrl: response.EmbedUrl, | |
| accessToken: Token.token, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| embedPowerBITile() { | |
| this.service.getTileEmbedToken().subscribe((res) => { | |
| let response = res.json(); | |
| let Token = response.EmbedToken; | |
| const config = { | |
| type: 'tile', | |
| tokenType: pbi.models.TokenType.Embed, | |
| id: response.Id, | |
| embedUrl: response.EmbedUrl, | |
| accessToken: Token.token, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Injectable } from '@angular/core'; | |
| import { HttpClient, HttpHeaders } from '@angular/common/http'; | |
| import { Observable, Subscriber, of } from 'rxjs'; | |
| import { switchMap, map } from 'rxjs/operators'; | |
| import { RequestOptions } from '@angular/http'; | |
| import { adal } from 'adal-angular'; | |
| import * as AuthenticationContext from 'adal-angular/lib/adal' | |
| import { environment } from '../../environments/environment'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public getReportsInGroup(groupId: string){ | |
| const headers = new HttpHeaders({ | |
| 'Content-Type': 'application/json', | |
| 'Authorization': `Bearer ${this._context.getCachedToken(environment.powerBIEndpoint)}` | |
| }); // this._context is the ADAL AuthenticationContext object | |
| return this.http.get(`https://api.powerbi.com/v1.0/myorg/groups/${groupId}/reports`, { headers: headers }); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!--Id of the Azure AD application--> | |
| <add key="applicationId" value="" /> | |
| <!--Id of the workspace where your reports reside--> | |
| <add key="workspaceId" value="" /> | |
| <!-- The id of the report to embed. If empty, will use the first report in group --> | |
| <add key="reportId" value="" /> | |
| <add key="authorityUrl" value="https://login.windows.net/common/oauth2/authorize/" /> | |
| <add key="resourceUrl" value="https://analysis.windows.net/powerbi/api" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const environment = { | |
| production: false, | |
| apiEndPoint: "", // api endpoint for generationg embed tokens (for app-owns-data) | |
| powerBIEndpoint: "https://analysis.windows.net/powerbi/api", | |
| groupId: "", // similar to workspace id | |
| adalConfig: { | |
| tenant: '', //tenant id of your organization | |
| clientId: '', // client id of your azure ad application | |
| cacheLocation: 'localStorage', // Default is sessionStorage | |
| redirectUri:`${window.location.origin}/` , |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public getDashboardsInGroup(groupId: string){ | |
| const headers = new HttpHeaders({ | |
| 'Content-Type': 'application/json', | |
| 'Authorization': `Bearer ${this._context.getCachedToken(environment.powerBIEndpoint)}` | |
| });// this._context is the ADAL AuthenticationContext object | |
| return this.http.get(`https://api.powerbi.com/v1.0/myorg/groups/${groupId}/dashboards`, { headers: headers }); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public getTilesInGroup(groupId: string, dashboardKey: string){ | |
| const headers = new HttpHeaders({ | |
| 'Content-Type': 'application/json', | |
| 'Authorization': `Bearer ${this._context.getCachedToken(environment.powerBIEndpoint)}` | |
| });// this._context is the ADAL AuthenticationContext object | |
| return this.http.get(`https://api.powerbi.com/v1.0/myorg/groups/${groupId}/dashboards/${dashboardKey}/tiles`, { headers: headers }); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // get access token | |
| getToken() { | |
| this.adalSrv.context.acquireToken(environment.powerBIEndpoint, (error, token) => { | |
| if (error || !token) { | |
| // TODO: Handle error obtaining access token | |
| console.error('ERROR:\n\n' + error); | |
| return; | |
| } | |
| // Get available dashboards | |
| this.adalSrv.getDashboardsInGroup(environment.groupId).subscribe(res=>{ |