Skip to content

Commit fe28e0c

Browse files
author
Matt Mazzola
committed
Add demo application
1 parent 046a2fa commit fe28e0c

4 files changed

Lines changed: 162 additions & 0 deletions

File tree

‎bower.json‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,10 @@
1919
],
2020
"devDependencies": {
2121
"jquery": "~2.2.0"
22+
},
23+
"dependencies": {
24+
"bootstrap": "^3.3.6",
25+
"fetch": "^1.0.0",
26+
"es6-promise": "^3.2.2"
2227
}
2328
}

‎demo/app/app.js‎

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
$(function () {
2+
3+
var $staticReport = $('#reportstatic');
4+
5+
var $reportsList = $('#reportslist');
6+
var $dynamicReport = $('#reportdynamic');
7+
var $customPageNavReport = $('#reportcustompagenav');
8+
var $resetButton = $('#resetButton');
9+
10+
var apiBaseUrl = 'http://powerbipaasapi.azurewebsites.net/api/reports';
11+
12+
/**
13+
* Basic Embed
14+
*/
15+
var staticReportId = '5dac7a4a-4452-46b3-99f6-a25915e0fe55';
16+
var staticReportUrl = apiBaseUrl + '/' + staticReportId;
17+
18+
fetch(staticReportUrl)
19+
.then(function (response) {
20+
return response.json();
21+
})
22+
.then(function (report) {
23+
var reportConfig = $.extend({ type: 'report' }, report);
24+
powerbi.embed($staticReport.get(0), reportConfig);
25+
});
26+
27+
/**
28+
* Dynamic Embed
29+
*/
30+
function generateReportListItem(report) {
31+
var button = $('<button>')
32+
.attr({
33+
type: 'button'
34+
})
35+
.addClass('btn btn-success')
36+
.data('report', report)
37+
.text('Embed!');
38+
39+
var reportName = $('<span />')
40+
.addClass('report-name')
41+
.text(report.name)
42+
43+
var element = $('<li>')
44+
.append(reportName)
45+
.append(button);
46+
47+
return element;
48+
}
49+
50+
var allReportsUrl = apiBaseUrl;
51+
fetch(allReportsUrl)
52+
.then(function (response) {
53+
return response.json();
54+
})
55+
.then(function (reports) {
56+
reports
57+
.map(generateReportListItem)
58+
.forEach(function (element) {
59+
$reportsList.append(element);
60+
});
61+
});
62+
63+
// When report button is clicked embed the report
64+
$reportsList.on('click', 'button', function (event) {
65+
var button = event.target;
66+
var report = $(button).data('report');
67+
var url = apiBaseUrl + '/' + report.id;
68+
69+
fetch(url)
70+
.then(function (response) {
71+
return response.json();
72+
})
73+
.then(function (reportWithToken) {
74+
var reportConfig = $.extend({ type: 'report' }, reportWithToken);
75+
powerbi.embed($dynamicReport.get(0), reportConfig);
76+
});
77+
});
78+
79+
$resetButton.on('click', function (event) {
80+
powerbi.reset($dynamicReport.get(0));
81+
});
82+
});

‎demo/index.html‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
6+
<meta http-equiv="x-ua-compatible" content="ie=edge">
7+
<title>Power BI - Sample - Client - JavaScript</title>
8+
<base path="/" />
9+
10+
<link rel="stylesheet" href="../bower_components/bootstrap/dist/css/bootstrap.css" />
11+
<link rel="stylesheet" href="styles/app.css" />
12+
</head>
13+
<body>
14+
<div class="container">
15+
<h1>Power BI - Sample - Client - Javascript</h1>
16+
<p>Demonstrate how to consume Power BI API and render using core library. <a href="https://github.com/microsoft/PowerBI-JavaScript" target="_blank">PowerBI-JavaScript</a></p>
17+
18+
<h2>Static Embed</h2>
19+
<p>Report to embed is known by the developer.</p>
20+
21+
<div id="reportstatic" class="powerbi-container"></div>
22+
23+
<h2>Dynamic Embed</h2>
24+
<p>Report to embed is chosen by the user.</p>
25+
<ol id="reportslist">
26+
</ol>
27+
<p class="text-right">
28+
<button type="button" id="resetButton" class="btn btn-danger">Reset</button>
29+
</p>
30+
31+
<div id="reportdynamic" class="powerbi-container"></div>
32+
33+
<h2>Custom Page Navigation</h2>
34+
<p>Page navigation is hidden in the embedded report and recreated by developer to allow custom branding or even automation to tell stories and navigate user.</p>
35+
36+
<div id="reportcustompagenav" class="powerbi-container"></div>
37+
</div>
38+
39+
<script src="../bower_components/jquery/dist/jquery.js"></script>
40+
<script src="../bower_components/es6-promise/es6-promise.js"></script>
41+
<script src="../bower_components/fetch/fetch.js"></script>
42+
43+
<script src="../dist/powerbi.js"></script>
44+
<script src="app/app.js"></script>
45+
</body>
46+
</html>

‎demo/styles/app.css‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
body {
2+
padding: 2em 0;
3+
}
4+
5+
.powerbi-container {
6+
height: 400px;
7+
}
8+
.powerbi-container iframe {
9+
border: none;
10+
}
11+
12+
#reportslist {
13+
margin: 0 0 1em 0;
14+
}
15+
#reportslist li {
16+
margin: 1em 0;
17+
}
18+
.reportslistdescription {
19+
margin: 1em 0 0 0;
20+
font-weight: bold;
21+
}
22+
.report-name {
23+
display: inline-block;
24+
margin: 0 1em;
25+
font-weight: bold;
26+
}
27+
.checkbox {
28+
margin-left: 1em;
29+
}

0 commit comments

Comments
 (0)