Repository navigation
Alihamud live code #93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
cba63db
e2b7c3c
ce5baeb
dade325
23b13fd
e72fcc1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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> |
| 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> | ||
| <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> | ||
| 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()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually report can be null if there is no embeds.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But the code will not be that clear. |
||
| } | ||
|
|
||
| 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); | ||
| }); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| $(function() { | ||
| // Open Report Sample. | ||
| $("#mainContent").load("report.html"); | ||
| }); |
There was a problem hiding this comment.
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..
There was a problem hiding this comment.
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.