Skip to content

Commit e5466c7

Browse files
author
Omri Armstrong
committed
CR fixes
1 parent 3c30261 commit e5466c7

15 files changed

Lines changed: 296 additions & 190 deletions

‎demo/code-demo/scripts/codesamples.js‎

Lines changed: 121 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ function _Embed_BasicEmbed() {
1616
// Read report Id from textbox
1717
var txtEmbedReportId = $('#txtEmbedReportId').val();
1818

19+
// Get viewMode
20+
var checkd = $('#viewMode:checked').val();
21+
var viewMode = checkd ? 1 : 0;
22+
1923
// Embed configuration used to describe the what and how to embed.
2024
// This object is used when calling powerbi.embed.
2125
// This also includes settings and options such as filters.
@@ -26,6 +30,7 @@ function _Embed_BasicEmbed() {
2630
embedUrl: txtEmbedUrl,
2731
id: txtEmbedReportId,
2832
permissions: 3/*All*/,
33+
viewMode: viewMode,
2934
settings: {
3035
filterPaneEnabled: true,
3136
navContentPaneEnabled: true
@@ -114,8 +119,12 @@ function _Embed_Create() {
114119
// ---- Report Operations ----------------------------------------------------
115120

116121
function _Report_GetId() {
122+
123+
// Grab the reference to the div HTML element that will host the report.
124+
var reportContainer = $('#reportContainer')[0];
125+
117126
// Get a reference to the embedded report.
118-
report = powerbi.embeds[0];
127+
report = powerbi.get(reportContainer);
119128

120129
// Retrieve the report id.
121130
var reportId = report.getId();
@@ -130,8 +139,11 @@ function _Report_UpdateSettings() {
130139
filterPaneEnabled: false
131140
};
132141

142+
// Grab the reference to the div HTML element that will host the report.
143+
var reportContainer = $('#reportContainer')[0];
144+
133145
// Get a reference to the embedded report.
134-
report = powerbi.embeds[0];
146+
report = powerbi.get(reportContainer);
135147

136148
// Update the settings by passing in the new settings you have configured.
137149
report.updateSettings(newSettings)
@@ -144,8 +156,11 @@ function _Report_UpdateSettings() {
144156
}
145157

146158
function _Report_GetPages() {
159+
// Grab the reference to the div HTML element that will host the report.
160+
var reportContainer = $('#reportContainer')[0];
161+
147162
// Get a reference to the embedded report.
148-
report = powerbi.embeds[0];
163+
report = powerbi.get(reportContainer);
149164

150165
// Retrieve the page collection and loop through to collect the
151166
// page name and display name of each page and display the value.
@@ -162,8 +177,11 @@ function _Report_GetPages() {
162177
}
163178

164179
function _Report_SetPage() {
180+
// Grab the reference to the div HTML element that will host the report.
181+
var reportContainer = $('#reportContainer')[0];
182+
165183
// Get a reference to the embedded report.
166-
report = powerbi.embeds[0];
184+
report = powerbi.get(reportContainer);
167185

168186
// setPage will change the selected view to the page you indicate.
169187
// This is the actual page name not the display name.
@@ -187,8 +205,11 @@ function _Report_SetPage() {
187205
}
188206

189207
function _Report_GetFilters() {
208+
// Grab the reference to the div HTML element that will host the report.
209+
var reportContainer = $('#reportContainer')[0];
210+
190211
// Get a reference to the embedded report.
191-
report = powerbi.embeds[0];
212+
report = powerbi.get(reportContainer);
192213

193214
// Get the filters applied to the report.
194215
report.getFilters()
@@ -213,8 +234,11 @@ function _Report_SetFilters() {
213234
values: ["Lindseys"]
214235
};
215236

237+
// Grab the reference to the div HTML element that will host the report.
238+
var reportContainer = $('#reportContainer')[0];
239+
216240
// Get a reference to the embedded report.
217-
report = powerbi.embeds[0];
241+
report = powerbi.get(reportContainer);
218242

219243
// Set the filter for the report.
220244
// Pay attention that setFilters receives an array.
@@ -228,8 +252,11 @@ function _Report_SetFilters() {
228252
}
229253

230254
function _Report_RemoveFilters() {
255+
// Grab the reference to the div HTML element that will host the report.
256+
var reportContainer = $('#reportContainer')[0];
257+
231258
// Get a reference to the embedded report.
232-
report = powerbi.embeds[0];
259+
report = powerbi.get(reportContainer);
233260

234261
// Remove the filters currently applied to the report.
235262
report.removeFilters()
@@ -242,8 +269,11 @@ function _Report_RemoveFilters() {
242269
}
243270

244271
function _Report_PrintCurrentReport() {
272+
// Grab the reference to the div HTML element that will host the report.
273+
var reportContainer = $('#reportContainer')[0];
274+
245275
// Get a reference to the embedded report.
246-
report = powerbi.embeds[0];
276+
report = powerbi.get(reportContainer);
247277

248278
// Trigger the print dialog for your browser.
249279
report.print()
@@ -256,8 +286,11 @@ function _Report_PrintCurrentReport() {
256286
}
257287

258288
function _Report_Reload() {
289+
// Grab the reference to the div HTML element that will host the report.
290+
var reportContainer = $('#reportContainer')[0];
291+
259292
// Get a reference to the embedded report.
260-
report = powerbi.embeds[0];
293+
report = powerbi.get(reportContainer);
261294

262295
// Reload the displayed report
263296
report.reload()
@@ -270,40 +303,55 @@ function _Report_Reload() {
270303
}
271304

272305
function _Report_FullScreen() {
306+
// Grab the reference to the div HTML element that will host the report.
307+
var reportContainer = $('#reportContainer')[0];
308+
273309
// Get a reference to the embedded report.
274-
report = powerbi.embeds[0];
310+
report = powerbi.get(reportContainer);
275311

276312
// Displays the report in full screen mode.
277313
report.fullscreen();
278314
}
279315

280316
function _Report_ExitFullScreen() {
317+
// Grab the reference to the div HTML element that will host the report.
318+
var reportContainer = $('#reportContainer')[0];
319+
281320
// Get a reference to the embedded report.
282-
report = powerbi.embeds[0];
321+
report = powerbi.get(reportContainer);
283322

284323
// Exits full screen mode.
285324
report.exitFullscreen();
286325
}
287326

288327
function _Report_switchModeEdit() {
328+
// Grab the reference to the div HTML element that will host the report.
329+
var reportContainer = $('#reportContainer')[0];
330+
289331
// Get a reference to the embedded report.
290-
report = powerbi.embeds[0];
332+
report = powerbi.get(reportContainer);
291333

292334
// Switch to edit mode.
293335
report.switchMode("edit");
294336
}
295337

296338
function _Report_switchModeView() {
339+
// Grab the reference to the div HTML element that will host the report.
340+
var reportContainer = $('#reportContainer')[0];
341+
297342
// Get a reference to the embedded report.
298-
report = powerbi.embeds[0];
343+
report = powerbi.get(reportContainer);
299344

300345
// Switch to view mode.
301346
report.switchMode("view");
302347
}
303348

304349
function _Report_save() {
305-
// Get a reference to report.
306-
report = powerbi.embeds[0];
350+
// Grab the reference to the div HTML element that will host the report.
351+
var reportContainer = $('#reportContainer')[0];
352+
353+
// Get a reference to the embedded report.
354+
report = powerbi.get(reportContainer);
307355

308356
// Save report
309357
report.save();
@@ -315,14 +363,19 @@ function _Report_save() {
315363
report.on("saved", function() {
316364
var reportObjectId = event.detail.reportObjectId;
317365
var isSaveAs = event.detail.saveAs;
366+
var name = event.detail.reportName;
367+
Log.logText("Report name " + name);
318368
Log.logText("Save Report Completed, reportObjectId: " + reportObjectId);
319369
Log.logText("Is saveAs: " + isSaveAs.toString());
320370
});
321371
}
322372

323373
function _Report_saveAs() {
324-
// Get a reference to report.
325-
report = powerbi.embeds[0];
374+
// Grab the reference to the div HTML element that will host the report.
375+
var reportContainer = $('#reportContainer')[0];
376+
377+
// Get a reference to the embedded report.
378+
report = powerbi.get(reportContainer);
326379

327380
var saveAsParameters = {
328381
name: "newReport"
@@ -346,8 +399,11 @@ function _Report_saveAs() {
346399
}
347400

348401
function _Report_setAccessToken() {
349-
// Get a reference to report.
350-
report = powerbi.embeds[0];
402+
// Grab the reference to the div HTML element that will host the report.
403+
var reportContainer = $('#reportContainer')[0];
404+
405+
// Get a reference to the embedded report.
406+
report = powerbi.get(reportContainer);
351407

352408
// New AccessToken
353409
var newAccessToken = "newAccessToken";
@@ -364,8 +420,11 @@ function _Report_setAccessToken() {
364420
// ---- Page Operations ----------------------------------------------------
365421

366422
function _Page_SetActive() {
423+
// Grab the reference to the div HTML element that will host the report.
424+
var reportContainer = $('#reportContainer')[0];
425+
367426
// Get a reference to the embedded report.
368-
report = powerbi.embeds[0];
427+
report = powerbi.get(reportContainer);
369428

370429
// Retrieve the page collection, and then set the second page to be active.
371430
report.getPages()
@@ -380,8 +439,11 @@ function _Page_SetActive() {
380439
}
381440

382441
function _Page_GetFilters() {
442+
// Grab the reference to the div HTML element that will host the report.
443+
var reportContainer = $('#reportContainer')[0];
444+
383445
// Get a reference to the embedded report.
384-
report = powerbi.embeds[0];
446+
report = powerbi.get(reportContainer);
385447

386448
// Retrieve the page collection and get the filters for the first page.
387449
report.getPages()
@@ -400,8 +462,11 @@ function _Page_GetFilters() {
400462
}
401463

402464
function _Page_SetFilters() {
465+
// Grab the reference to the div HTML element that will host the report.
466+
var reportContainer = $('#reportContainer')[0];
467+
403468
// Get a reference to the embedded report.
404-
report = powerbi.embeds[0];
469+
report = powerbi.get(reportContainer);
405470

406471
// Build the filter you want to use. For more information, see Constructing
407472
// Filters in https://github.com/Microsoft/PowerBI-JavaScript/wiki/Filters.
@@ -433,8 +498,11 @@ function _Page_SetFilters() {
433498
}
434499

435500
function _Page_RemoveFilters() {
501+
// Grab the reference to the div HTML element that will host the report.
502+
var reportContainer = $('#reportContainer')[0];
503+
436504
// Get a reference to the embedded report.
437-
report = powerbi.embeds[0];
505+
report = powerbi.get(reportContainer);
438506

439507
// Retrieve the page collection and remove the filters for the first page.
440508
report.getPages()
@@ -455,8 +523,11 @@ function _Page_RemoveFilters() {
455523
// ---- Event Listener ----------------------------------------------------
456524

457525
function _Events_PageChanged() {
526+
// Grab the reference to the div HTML element that will host the report.
527+
var reportContainer = $('#reportContainer')[0];
528+
458529
// Get a reference to the embedded report.
459-
report = powerbi.embeds[0];
530+
report = powerbi.get(reportContainer);
460531

461532
// Report.off removes a given event listener if it exists.
462533
report.off("pageChanged");
@@ -474,8 +545,11 @@ function _Events_PageChanged() {
474545
}
475546

476547
function _Events_DataSelected() {
548+
// Grab the reference to the div HTML element that will host the report.
549+
var reportContainer = $('#reportContainer')[0];
550+
477551
// Get a reference to the embedded report.
478-
report = powerbi.embeds[0];
552+
report = powerbi.get(reportContainer);
479553

480554
// Report.off removes a given event listener if it exists.
481555
report.off("dataSelected");
@@ -490,4 +564,26 @@ function _Events_DataSelected() {
490564
// For example, a bar in a bar chart. You should see an entry in the Log window.
491565

492566
Log.logText("Select data to see events in Log window.");
567+
}
568+
569+
function _Events_SaveAsTriggered() {
570+
// Grab the reference to the div HTML element that will host the report.
571+
var reportContainer = $('#reportContainer')[0];
572+
573+
// Get a reference to the embedded report.
574+
report = powerbi.get(reportContainer);
575+
576+
// Report.off removes a given event listener if it exists.
577+
report.off("saveAsTriggered");
578+
579+
// Report.on will add an event listener.
580+
report.on("saveAsTriggered", function(event) {
581+
var eventType = event.type;
582+
Log.logText("Event Triggered: " + eventType);
583+
});
584+
585+
// Select Run and change to a different page.
586+
// You should see an entry in the Log window.
587+
588+
Log.logText("Run SaveAs to see events in Log window.");
493589
}

‎demo/code-demo/scripts/step_embed.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ function Events_DataSelected() {
7171
SetCode(_Events_DataSelected);
7272
}
7373

74+
function Events_SaveAsTriggered() {
75+
SetCode(_Events_SaveAsTriggered);
76+
}
77+
7478
// ---- Edit and Save Operations ----------------------------------------------------
7579

7680
function Report_switchModeEdit() {

‎demo/code-demo/settings_create.html‎

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,21 @@
1111
</ul>
1212
</div>
1313

14-
<div class="pageTitle">
15-
<h4>Create Report</h4>
16-
<h8>Fill in the fields below to get the code to create your report.</h8>
17-
<div class="spacer" />
18-
</div>
19-
<div class="inputLine">
20-
<h8>Embed App Token</h8>
21-
<div><input type="text" id="txtAccessToken" onchange="UpdateSession(this, SessionKeys.AccessToken);" /></div>
22-
</div>
23-
<div class="inputLine">
24-
<h8>Embed URL</h8>
25-
<div><input type="text" id="txtReportEmbed" onchange="UpdateSession(this, SessionKeys.EmbedUrl);" value="https://embedded.powerbi.com/appTokenReportEmbed"/></div>
26-
</div>
27-
<div class="inputLine">
28-
<h8>Dataset Id</h8>
29-
<div><input type="text" id="txtEmbedDatasetId" onchange="UpdateSession(this, SessionKeys.EmbedId);"/></div>
30-
</div>
14+
<div class="pageTitle">
15+
<h4>Create Report</h4>
16+
<h8>Fill in the fields below to get the code to create your report.</h8>
17+
<div class="spacer" />
18+
</div>
19+
<div class="inputLine">
20+
<h8>Embed App Token</h8>
21+
<div><input type="text" id="txtAccessToken" onchange="UpdateSession(this, SessionKeys.AccessToken);" /></div>
22+
</div>
23+
<div class="inputLine">
24+
<h8>Embed URL</h8>
25+
<div><input type="text" id="txtReportEmbed" onchange="UpdateSession(this, SessionKeys.EmbedUrl);" value="https://embedded.powerbi.com/appTokenReportEmbed"/></div>
26+
</div>
27+
<div class="inputLine">
28+
<h8>Dataset Id</h8>
29+
<div><input type="text" id="txtEmbedDatasetId" onchange="UpdateSession(this, SessionKeys.EmbedId);"/></div>
30+
</div>
3131
</div>

0 commit comments

Comments
 (0)