Skip to content

Commit 3acf0f1

Browse files
committed
Merged PR 3694: Embed Single Visual in live demo
Embed Single Visual in live demo
1 parent 4efb122 commit 3acf0f1

10 files changed

+237
-80
lines changed

demo/v2-demo/images/info.png

3.04 KB
Loading

demo/v2-demo/report.html

+6-5
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
<div class="editorTitle">
1414
<div class="editorTitleText">Embedded view</div>
1515
</div>
16-
<div id="embedContainer"></div>
17-
<div id="dashboardContainer"></div>
18-
<div id="tileContainer"></div>
19-
<div id="qnaContainer"></div>
16+
<div id="embedContainer" class="embedContainer"></div>
17+
<div id="dashboardContainer" class="embedContainer"></div>
18+
<div id="visualContainer" class="embedContainer"></div>
19+
<div id="tileContainer" class="embedContainer"></div>
20+
<div id="qnaContainer" class="embedContainer"></div>
2021
</div>
2122
</div>
2223
</div>
@@ -26,7 +27,7 @@
2627
$("#authorize-step-wrapper").load("step_authorize.html");
2728

2829
LoadLogWindow("#logWindow");
29-
30+
3031
var modeUrlParam = GetParameterByName("mode");
3132
var mode = modeUrlParam ? modeUrlParam : "view";
3233

demo/v2-demo/scripts/codesamples.js

+77-20
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function _Embed_BasicEmbed() {
5858

5959
report.on("error", function(event) {
6060
Log.log(event.detail);
61-
61+
6262
report.off("error");
6363
});
6464

@@ -71,6 +71,63 @@ function _Embed_BasicEmbed() {
7171
});
7272
}
7373

74+
function _Embed_VisualEmbed() {
75+
// Read embed application token from textbox
76+
var txtAccessToken = $('#txtAccessToken').val();
77+
78+
// Read embed URL from textbox
79+
var txtEmbedUrl = $('#txtReportEmbed').val();
80+
81+
// Read report Id from textbox
82+
var txtReportId = $('#txtEmbedReportId').val();
83+
84+
// Read page name from textbox
85+
var txtPageName = $('#txtPageName').val();
86+
87+
// Read visual name from textbox
88+
var txtVisualName = $('#txtVisualName').val();
89+
90+
// Read embed type from radio
91+
var tokenType = $('input:radio[name=tokenType]:checked').val();
92+
93+
// Get models. models contains enums that can be used.
94+
var models = window['powerbi-client'].models;
95+
96+
// Embed configuration used to describe the what and how to embed.
97+
// This object is used when calling powerbi.embed.
98+
// This also includes settings and options such as filters.
99+
// You can find more information at https://github.com/Microsoft/PowerBI-JavaScript/wiki/Embed-Configuration-Details.
100+
var config= {
101+
type: 'visual',
102+
tokenType: tokenType == '0' ? models.TokenType.Aad : models.TokenType.Embed,
103+
accessToken: txtAccessToken,
104+
embedUrl: txtEmbedUrl,
105+
id: txtReportId,
106+
pageName: txtPageName,
107+
visualName: txtVisualName
108+
};
109+
110+
// Get a reference to the embedded report HTML element
111+
var embedContainer = $('#visualContainer')[0];
112+
113+
// Embed the report and display it within the div container.
114+
var report = powerbi.embed(embedContainer, config);
115+
116+
// Report.off removes a given event handler if it exists.
117+
report.off("loaded");
118+
119+
// Report.on will add an event handler which prints to Log window.
120+
report.on("loaded", function() {
121+
Log.logText("Loaded");
122+
});
123+
124+
report.on("error", function(event) {
125+
Log.log(event.detail);
126+
127+
report.off("error");
128+
});
129+
}
130+
74131
function _Embed_DashboardEmbed() {
75132
// Read embed application token from textbox
76133
var txtAccessToken = $('#txtAccessToken').val();
@@ -115,7 +172,7 @@ function _Embed_DashboardEmbed() {
115172

116173
dashboard.on("error", function(event) {
117174
Log.log(event.detail);
118-
175+
119176
dashboard.off("error");
120177
});
121178

@@ -269,7 +326,7 @@ function _Embed_EmbedWithDefaultFilter() {
269326
var txtAccessToken = $('#txtAccessToken').val();
270327
var txtEmbedUrl = $('#txtReportEmbed').val();
271328
var txtEmbedReportId = $('#txtEmbedReportId').val();
272-
329+
273330
// Get models. models contains enums that can be used.
274331
var models = window['powerbi-client'].models;
275332

@@ -282,7 +339,7 @@ function _Embed_EmbedWithDefaultFilter() {
282339
operator: "In",
283340
values: ["Lindseys"]
284341
};
285-
342+
286343
var embedConfiguration = {
287344
type: 'report',
288345
tokenType: models.TokenType.Embed,
@@ -295,7 +352,7 @@ function _Embed_EmbedWithDefaultFilter() {
295352
},
296353
filters: [filter]
297354
};
298-
355+
299356
var embedContainer = document.getElementById('embedContainer');
300357
powerbi.embed(embedContainer, embedConfiguration);
301358
}
@@ -368,7 +425,7 @@ function _Embed_Create() {
368425

369426
// Read embed type from radio
370427
var tokenType = $('input:radio[name=tokenType]:checked').val();
371-
428+
372429
// Get models. models contains enums that can be used.
373430
var models = window['powerbi-client'].models;
374431

@@ -380,7 +437,7 @@ function _Embed_Create() {
380437
embedUrl: txtEmbedUrl,
381438
datasetId: txtEmbedDatasetId,
382439
};
383-
440+
384441
// Grab the reference to the div HTML element that will host the report
385442
var embedContainer = $('#embedContainer')[0];
386443

@@ -420,7 +477,7 @@ function _Mock_Embed_Create() {
420477

421478
// Read embed type from radio
422479
var tokenType = $('input:radio[name=tokenType]:checked').val();
423-
480+
424481
// Get models. models contains enums that can be used.
425482
var models = window['powerbi-client'].models;
426483

@@ -435,7 +492,7 @@ function _Mock_Embed_Create() {
435492
useCustomSaveAsDialog: true
436493
}
437494
};
438-
495+
439496
// Grab the reference to the div HTML element that will host the report
440497
var embedContainer = $('#embedContainer')[0];
441498

@@ -554,7 +611,7 @@ function _Report_GetPages() {
554611
// Get a reference to the embedded report.
555612
report = powerbi.get(embedContainer);
556613

557-
// Retrieve the page collection and loop through to collect the
614+
// Retrieve the page collection and loop through to collect the
558615
// page name and display name of each page and display the value.
559616
report.getPages()
560617
.then(function (pages) {
@@ -588,7 +645,7 @@ function _Report_SetPage() {
588645
// Report.off removes a given event handler if it exists.
589646
report.off("pageChanged");
590647

591-
// Report.on will add an event handler which prints page
648+
// Report.on will add an event handler which prints page
592649
// name and display name to Log window.
593650
report.on("pageChanged", function(event) {
594651
var page = event.detail.newPage;
@@ -602,7 +659,7 @@ function _Report_GetFilters() {
602659

603660
// Get a reference to the embedded report.
604661
report = powerbi.get(embedContainer);
605-
662+
606663
// Get the filters applied to the report.
607664
report.getFilters()
608665
.then(function (filters) {
@@ -631,7 +688,7 @@ function _Report_SetFilters() {
631688

632689
// Get a reference to the embedded report.
633690
report = powerbi.get(embedContainer);
634-
691+
635692
// Set the filter for the report.
636693
// Pay attention that setFilters receives an array.
637694
report.setFilters([filter])
@@ -776,7 +833,7 @@ function _Report_saveAs() {
776833

777834
// Get a reference to the embedded report.
778835
report = powerbi.get(embedContainer);
779-
836+
780837
var saveAsParameters = {
781838
name: "newReport"
782839
};
@@ -892,7 +949,7 @@ function _Page_SetActive() {
892949

893950
// Get a reference to the embedded report.
894951
report = powerbi.get(embedContainer);
895-
952+
896953
// Retrieve the page collection, and then set the second page to be active.
897954
report.getPages()
898955
.then(function (pages) {
@@ -911,7 +968,7 @@ function _Page_GetFilters() {
911968

912969
// Get a reference to the embedded report.
913970
report = powerbi.get(embedContainer);
914-
971+
915972
// Retrieve the page collection and get the filters for the first page.
916973
report.getPages()
917974
.then(function (pages) {
@@ -976,7 +1033,7 @@ function _Page_SetFilters() {
9761033
// Get a reference to the embedded report.
9771034
report = powerbi.get(embedContainer);
9781035

979-
// Build the filter you want to use. For more information, see Constructing
1036+
// Build the filter you want to use. For more information, see Constructing
9801037
// Filters in https://github.com/Microsoft/PowerBI-JavaScript/wiki/Filters.
9811038
const filter = {
9821039
$schema: "http://powerbi.com/product/schema#basic",
@@ -1016,7 +1073,7 @@ function _Page_RemoveFilters() {
10161073

10171074
// Get a reference to the embedded report.
10181075
report = powerbi.get(embedContainer);
1019-
1076+
10201077
// Retrieve the page collection and remove the filters for the first page.
10211078
report.getPages()
10221079
.then(function (pages) {
@@ -1165,7 +1222,7 @@ function _DashboardEvents_TileClicked() {
11651222
function _Qna_SetQuestion() {
11661223
// Get a reference to the embedded Q&A HTML element
11671224
var qnaContainer = $('#qnaContainer')[0];
1168-
1225+
11691226
// Get a reference to the embedded Q&A.
11701227
qna = powerbi.get(qnaContainer);
11711228

@@ -1181,7 +1238,7 @@ function _Qna_SetQuestion() {
11811238
function _Qna_QuestionChanged() {
11821239
// Get a reference to the embedded Q&A HTML element
11831240
var qnaContainer = $('#qnaContainer')[0];
1184-
1241+
11851242
// Get a reference to the embedded Q&A.
11861243
qna = powerbi.get(qnaContainer);
11871244

0 commit comments

Comments
 (0)