Created
October 5, 2018 11:40
-
-
Save krishnaanaril/398f8e51136e649bf35e41baf8367efe to your computer and use it in GitHub Desktop.
Embed Power BI reports for organization
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
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 reports in the group | |
this.adalSrv.getReportsInGroup(environment.groupId).subscribe(res=>{ | |
// select the first report among it. | |
this.getReport(res["value"][0]["id"], res["value"][0]["embedUrl"]); | |
}); | |
}); | |
} | |
getReport(id: string, embedUrl: string) { | |
// get token | |
// this.getToken(); | |
var embedConfiguration = { | |
type: 'report', | |
id: id, | |
embedUrl: embedUrl, | |
tokenType: pbi.models.TokenType.Aad, | |
accessToken: this.adalSrv.context.getCachedToken(environment.powerBIEndpoint) | |
}; | |
// Grab the reference to the div HTML element that will host the report. | |
const reportsContainer = <HTMLElement>document.getElementById( | |
'embedReport' | |
); | |
const report = this.powerbi.embed( | |
reportsContainer, | |
embedConfiguration | |
); | |
// Report.off removes a given event handler if it exists. | |
report.off('loaded'); | |
// Report.on will add an event handler which prints to Log window. | |
report.on('loaded', (event) => { | |
console.log('report loaded...'); | |
}) | |
report.off('pageChanged'); | |
report.on('pageChanged', e => { | |
console.log(e); | |
}); | |
// Add a listener to 'error' events | |
report.on('error', (errorObject) => { | |
console.log(errorObject); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment