Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion demo/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,24 @@ $(function () {
}
});

var $getId = $('#getId');
$getId.on('click', function (event) {
alert(staticReport.getId());
});

var $fullscreen = $('#fullscreen');

$fullscreen.on('click', function (event) {
staticReport.fullscreen();
});

var $reloadReport = $('#reloadReport');
$reloadReport.on('click', function (event) {
staticReport.reload()
.catch(error => { alert(error); });
});

var $printReport = $('#printReport');
$printReport.on('click', function (event) {
staticReport.print();
});
});
2 changes: 1 addition & 1 deletion demo/bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"es6-promise": "^3.2.2",
"bootstrap": "^3.3.6",
"jquery": "^3.1.0",
"powerbi-client": "2.0.0-beta.12"
"powerbi-client": "^2.2.1"
},
"devDependencies": {}
}
40 changes: 40 additions & 0 deletions demo/code-demo/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">

<link rel="stylesheet" href="/bower_components/bootstrap/dist/css/bootstrap.css" />
<link rel="stylesheet" type="text/css" href="style/style.css">
</head>

<body>
<header class="ms-font-xxl">
<div class="logo-text">
<span class="logo-text-span">Microsoft Power BI JavaScript SDK - Live Sample</span>
</div>
</header>

<div id="mainContent" class="jumbotron">
</div>

<script src="/bower_components/jquery/dist/jquery.js"></script>
<script src="/bower_components/es6-promise/es6-promise.js"></script>
<script src="/bower_components/fetch/fetch.js"></script>
<script src="/bower_components/powerbi-client/dist/powerbi.js"></script>

<script src="scripts/codesamples.js"></script>

<script src="scripts/index.js"></script>
<script src="scripts/utils.js"></script>
<script src="scripts/session_utils.js"></script>


<script src="scripts/report.js"></script>

<script src="scripts/step_authorize.js"></script>
<script src="scripts/step_embed.js"></script>
<script src="scripts/step_interact.js"></script>
</body>
</html>
31 changes: 31 additions & 0 deletions demo/code-demo/report.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<div>
<div id="steps-nav-bar">
<div class="main-title">Report Embed</div>
<div id="steps-ul-dev">
<ul id="steps-ul" class="steps-ul">
<li id="steps-auth" class="steps-li-active" onclick="OpenAuthStep();"><a href="#">Authorize</a></li>
<li id="steps-embed" onclick="OpenEmbedStepWithSample();"><a href="#">Embed</a></li>
<li id="steps-interact" onclick="OpenInteractStep();"><a href="#">Interact</a></li>
</ul>
</div>
</div>

<div id="embed-and-interact-panel">
<div id="right-pane" class="halfWidth left">
</div>

<div id="left-pane" class="halfWidth right">
<div id="embedArea">
<h3>Embedded Report Area</h3>
<h5>The following div id is <b>reportContainer</b>. In code, we embed a report to it.</h5>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to go through text scrubbing for the texts here..

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is sure.
I will do it in another increment.

<div id="reportContainer" style="width: 800px; height: 600px; background: #DDDDDD;"></div>
</div>
</div>
</div>
</div>

<script>
// Open Authorization Step after this page loads.
OpenAuthStep();
</script>
273 changes: 273 additions & 0 deletions demo/code-demo/scripts/codesamples.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,273 @@
/*
This file contains the code samples which will appear live in the web-page.
Each sample method name starts with _Report_ or _Page or _Embed depends on which section it appears.
Please keep this.
*/

// ---- Embed Code ----------------------------------------------------

function _Embed_BasicEmbed() {
var txtAccessToken = $('#txtAccessToken').val();
var txtEmbedUrl = $('#txtReportEmbed').val();
var txtEmbedReportId = $('#txtEmbedReportId').val();

var embedConfiguration = {
type: 'report',
accessToken: txtAccessToken,
embedUrl: txtEmbedUrl,
id: txtEmbedReportId,
settings: {
filterPaneEnabled: true,
navContentPaneEnabled: true
}
};

var reportContainer = document.getElementById('reportContainer');
powerbi.embed(reportContainer, embedConfiguration);
}

function _Embed_EmbedWithDefaultFilter() {
var txtAccessToken = $('#txtAccessToken').val();
var txtEmbedUrl = $('#txtReportEmbed').val();
var txtEmbedReportId = $('#txtEmbedReportId').val();

const filter = {
$schema: "http://powerbi.com/product/schema#basic",
target: {
table: "Store",
column: "Chain"
},
operator: "In",
values: ["Lindseys"]
};

var embedConfiguration = {
type: 'report',
accessToken: txtAccessToken,
embedUrl: txtEmbedUrl,
id: txtEmbedReportId,
settings: {
filterPaneEnabled: false,
navContentPaneEnabled: false
},
filters: [filter]
};

var reportContainer = document.getElementById('reportContainer');
powerbi.embed(reportContainer, embedConfiguration);
}

// ---- Report Operations ----------------------------------------------------

function _Report_GetId() {
report = powerbi.embeds[0];
$('#result').html(report.getId());

@noanu Noa (noanu) Nov 14, 2016 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is"report" always defined? is there a chance for referencing a null here? (and same comment for the below code thar references the report object without checking if it is defined.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually report can be null if there is no embeds.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the code will not be that clear.
this is a sample code for developers, they should add the check after copying.

}

function _Report_UpdateSettings() {
const newSettings = {
navContentPaneEnabled: true,
filterPaneEnabled: false
};

report = powerbi.embeds[0];
report.updateSettings(newSettings)
.then(function (result) {
$("#result").html(result);
})
.catch(function (error) {
$("#result").html(error);
});
}

function _Report_GetPages() {
report = powerbi.embeds[0];

report.getPages()
.then(function (pages) {
var result = "";
var index = 1;
pages.forEach(function(page) {
result = result + index + ") " + page.name + "(displayName: " + page.displayName + ")" + "<br/>";
index++;
});

$("#result").html("Done. <br/>" + result);
})
.catch(function (errors) {
$("#result").html("Error. <br/>" + JSON.stringify(errors));
});
}

function _Report_SetPage() {
report = powerbi.embeds[0];
report.setPage("ReportSection2")
.then(function (result) {
$("#result").html("Done. <br/>" + JSON.stringify(result));
})
.catch(function (errors) {
$("#result").html("Error. <br/>" + JSON.stringify(errors));
});
}

function _Report_GetFilters() {
report = powerbi.embeds[0];

report.getFilters()
.then(function (filters) {
$("#result").html("Done. <br/>" + JSON.stringify(filters, null, " "));
})
.catch(function (errors) {
$("#result").html("Error. <br/>" + JSON.stringify(errors));
});
}

function _Report_SetFilters() {
const filter = {
$schema: "http://powerbi.com/product/schema#basic",
target: {
table: "Store",
column: "Chain"
},
operator: "In",
values: ["Lindseys"]
};

report = powerbi.embeds[0];
report.setFilters([filter])
.then(function (result) {
$("#result").html("Done. <br/>" + JSON.stringify(result));
})
.catch(function (errors) {
$("#result").html("Error. <br/>" + JSON.stringify(errors));
});
}

function _Report_RemoveFilters() {
report = powerbi.embeds[0];
report.removeFilters()
.then(function (result) {
$("#result").html("Done. <br/>" + JSON.stringify(result));
})
.catch(function (errors) {
$("#result").html("Error. <br/>" + JSON.stringify(errors));
});
}

function _Report_PrintCurrentReport() {
report = powerbi.embeds[0];
report.print()
.then(function (result) {
$("#result").html("Done. <br/>" + JSON.stringify(result));
})
.catch(function (errors) {
$("#result").html("Error. <br/>" + JSON.stringify(errors));
});
}

function _Report_Reload() {
report = powerbi.embeds[0];
report.reload()
.then(function (result) {
$("#result").html("Done. <br/>" + JSON.stringify(result));
})
.catch(function (errors) {
$("#result").html("Error. <br/>" + JSON.stringify(errors));
});
}

function _Report_FullScreen() {
report = powerbi.embeds[0];
report.fullscreen();

$("#result").html("Done!");
}

function _Report_ExitFullScreen() {
report = powerbi.embeds[0];
report.exitFullscreen();

$("#result").html("Done!");
}

// ---- Page Operations ----------------------------------------------------

function _Page_SetActive() {
report = powerbi.embeds[0];

// Set the second page active
report.getPages()
.then(function (pages) {
pages[1].setActive().then(function (result) {
$("#result").html("Done. <br/>" + result)
});
})
.catch(function (errors) {
$("#result").html("getPages Error. " + errors);
});
}

function _Page_GetFilters() {
report = powerbi.embeds[0];

// Get Filters of first page
report.getPages()
.then(function (pages) {
pages[1].getFilters()
.then(function (filters) {
$("#result").html("Done. <br/>" + JSON.stringify(filters, null, " "))
})
.catch(function (errors) {
$("#result").html("Error. <br/>" + JSON.stringify(errors));
});
})
.catch(function (errors) {
$("#result").html("getPages Error. " + errors);
});
}

function _Page_SetFilters() {
const filter = {
$schema: "http://powerbi.com/product/schema#basic",
target: {
table: "Store",
column: "Chain"
},
operator: "In",
values: ["Lindseys"]
};

report = powerbi.embeds[0];
report.getPages()
.then(function (pages) {
pages[1].setFilters([filter])
.then(function (result) {
$("#result").html("Done. <br/>" + JSON.stringify(result));
})
.catch(function (errors) {
$("#result").html("Error. <br/>" + JSON.stringify(errors));
});
})
.catch(function (errors) {
$("#result").html("Error. <br/>" + JSON.stringify(errors));
});
}

function _Page_RemoveFilters() {
report = powerbi.embeds[0];

// Get Filters of first page
report.getPages()
.then(function (pages) {
pages[1].removeFilters()
.then(function (result) {
$("#result").html("Done. <br/>" + JSON.stringify(result));
})
.catch(function (errors) {
$("#result").html("Error. <br/>" + JSON.stringify(errors));
});
})
.catch(function (errors) {
$("#result").html("getPages Error. " + errors);
});
}
4 changes: 4 additions & 0 deletions demo/code-demo/scripts/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
$(function() {
// Open Report Sample.
$("#mainContent").load("report.html");
});
Loading