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 / auth-guard.service.ts
Created June 10, 2018 05:35
Example for auth-guard in Angular 6
canActivate() {
if ( this.authService.isLoggedIn() ) {
return true;
}
this.router.navigate(['/']);
return false;
}
@krishnaanaril
krishnaanaril / EmbedConfig.cs
Created October 5, 2018 06:39
EmbedConfig is the class that is used to store the details of Power BI reports/dashboard that is to be embedded.
public class EmbedConfig
{
public string Id { get; set; }
public string EmbedUrl { get; set; }
public EmbedToken EmbedToken { get; set; }
public int MinutesToExpiration
{
@krishnaanaril
krishnaanaril / TileEmbedConfig.cs
Last active October 5, 2018 08:09
Class for storing the token details of Power BI tiles. It inherits the 'EmbedConfig' class
public class TileEmbedConfig : EmbedConfig
{
public string dashboardId { get; set; }
}
@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)
);
}
@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 / 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 / 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 / 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 / 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 / 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 {