Skip to content

Instantly share code, notes, and snippets.

View krishnaanaril's full-sized avatar
🎯
Focusing

Krishna Mohan krishnaanaril

🎯
Focusing
View GitHub Profile
@krishnaanaril
krishnaanaril / adal.service.ts
Created October 5, 2018 10:14
Azure Active Directory authentication library service
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';
@krishnaanaril
krishnaanaril / app-data-embedPowerBITile.ts
Created October 5, 2018 10:09
Method to embed Power BI Tiles
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,
@krishnaanaril
krishnaanaril / app-data-embedPowerBIReport.ts
Created October 5, 2018 10:08
Method to embed Power BI report
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,
@krishnaanaril
krishnaanaril / DashboardComponent.ts
Last active October 5, 2018 10:00
Minimal DashboardComponent file
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 {
@krishnaanaril
krishnaanaril / updateToken.ts
Created October 5, 2018 09:57
Method to update Power BI embed token for dashboard.
updateToken() {
// Generate new EmbedToken
this.service.getDashboardEmbedToken()
.subscribe((res) => {
let Token = res.json();
// Get a reference to the embedded report HTML element
var embedDashboard = <HTMLElement>document.getElementById(
'embedDashboard'
);
@krishnaanaril
krishnaanaril / setTokenExpirationListener.ts
Created October 5, 2018 09:55
Power BI embed token expiration listener method
setTokenExpirationListener(tokenExpiration,
minutesToRefresh = 2){
// get current time
var currentTime = Date.now();
var expiration = Date.parse(tokenExpiration);
var safetyInterval = minutesToRefresh * 60 * 1000;
// time until token refresh in milliseconds
var timeout = expiration - currentTime - safetyInterval;
@krishnaanaril
krishnaanaril / app-data-embedPowerBIDashboard.ts
Created October 5, 2018 09:54
Embedding Power BI Dashboard for customers
embedPowerBIDashboard() {
this.service.getDashboardEmbedToken().subscribe((res) => {
let response = res.json();
let Token = response.EmbedToken;
const config = {
type: 'dashboard',
tokenType: pbi.models.TokenType.Embed,
id: response.Id,
embedUrl: response.EmbedUrl,
accessToken: Token.token,
@krishnaanaril
krishnaanaril / getTileEmbedToken.ts
Created October 5, 2018 08:16
Call Web API to get tile embed token
getTileEmbedToken(): Observable<any> {
let apiUrl = environment.apiEndPoint + "/api/values/getTileEmbedToken";
return this.http.get(apiUrl)
.pipe(
catchError(this.handleError)
);
}
@krishnaanaril
krishnaanaril / getDashboardEmbedToken.ts
Created October 5, 2018 08:15
Call Web API to get dashboard embed token
getDashboardEmbedToken(): Observable<any> {
let apiUrl = environment.apiEndPoint + "/api/values/getDashboardEmbedToken";
return this.http.get(apiUrl)
.pipe(
catchError(this.handleError)
);
}
@krishnaanaril
krishnaanaril / getReportEmbedToken.ts
Created October 5, 2018 08:13
Call Web API to get report embed token
getReportEmbedToken(): Observable<any> {
let apiUrl = environment.apiEndPoint + "/api/values/getReportEmbedToken?username=&roles=";
return this.http.get(apiUrl)
.pipe(
catchError(this.handleError)
);
}