Skip to content

Commit 2a1b8c5

Browse files
author
Omri Armstrong
committed
adding tests
1 parent 79bf79f commit 2a1b8c5

14 files changed

Lines changed: 639 additions & 103 deletions

File tree

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

Lines changed: 42 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
// ---- Embed Code ----------------------------------------------------
88

99
function _Embed_BasicEmbed() {
10+
// Get models. models contains enums that can be used.
11+
var models = window['powerbi-client'].models;
12+
1013
// Read embed application token from textbox
1114
var txtAccessToken = $('#txtAccessToken').val();
1215

@@ -16,9 +19,9 @@ function _Embed_BasicEmbed() {
1619
// Read report Id from textbox
1720
var txtEmbedReportId = $('#txtEmbedReportId').val();
1821

19-
// Get viewMode
20-
var checkd = $('#viewMode:checked').val();
21-
var viewMode = checkd ? 1 : 0;
22+
// Embed report in View mode or Edit mode based or checkbox value.
23+
var checked = $('#viewMode:checked').val();
24+
var viewMode = checked ? models.ViewMode.Edit : models.ViewMode.View;
2225

2326
// Embed configuration used to describe the what and how to embed.
2427
// This object is used when calling powerbi.embed.
@@ -29,15 +32,15 @@ function _Embed_BasicEmbed() {
2932
accessToken: txtAccessToken,
3033
embedUrl: txtEmbedUrl,
3134
id: txtEmbedReportId,
32-
permissions: 3/*All*/,
35+
permissions: 3 /*models.Permissions.All gives maximum permissions*/,
3336
viewMode: viewMode,
3437
settings: {
3538
filterPaneEnabled: true,
3639
navContentPaneEnabled: true
3740
}
3841
};
3942

40-
// Grab the reference to the div HTML element that will host the report.
43+
// Get a reference to the embedded report HTML element
4144
var reportContainer = $('#reportContainer')[0];
4245

4346
// Embed the report and display it within the div container.
@@ -107,20 +110,19 @@ function _Embed_Create() {
107110
// Create report
108111
var report = powerbi.createReport(reportContainer, embedCreateConfiguration);
109112

110-
// Report.off removes a given event handler if it exists.
111-
report.off("loaded");
113+
// // Report.off removes a given event handler if it exists.
114+
// report.off("loaded");
112115

113-
// Report.on will add an event handler which prints to Log window.
114-
report.on("loaded", function() {
115-
Log.logText("Loaded");
116-
});
116+
// // Report.on will add an event handler which prints to Log window.
117+
// report.on("loaded", function() {
118+
// Log.logText("Loaded");
119+
// });
117120
}
118121

119122
// ---- Report Operations ----------------------------------------------------
120123

121124
function _Report_GetId() {
122-
123-
// Grab the reference to the div HTML element that will host the report.
125+
// Get a reference to the embedded report HTML element
124126
var reportContainer = $('#reportContainer')[0];
125127

126128
// Get a reference to the embedded report.
@@ -139,7 +141,7 @@ function _Report_UpdateSettings() {
139141
filterPaneEnabled: false
140142
};
141143

142-
// Grab the reference to the div HTML element that will host the report.
144+
// Get a reference to the embedded report HTML element
143145
var reportContainer = $('#reportContainer')[0];
144146

145147
// Get a reference to the embedded report.
@@ -156,7 +158,7 @@ function _Report_UpdateSettings() {
156158
}
157159

158160
function _Report_GetPages() {
159-
// Grab the reference to the div HTML element that will host the report.
161+
// Get a reference to the embedded report HTML element
160162
var reportContainer = $('#reportContainer')[0];
161163

162164
// Get a reference to the embedded report.
@@ -177,7 +179,7 @@ function _Report_GetPages() {
177179
}
178180

179181
function _Report_SetPage() {
180-
// Grab the reference to the div HTML element that will host the report.
182+
// Get a reference to the embedded report HTML element
181183
var reportContainer = $('#reportContainer')[0];
182184

183185
// Get a reference to the embedded report.
@@ -205,7 +207,7 @@ function _Report_SetPage() {
205207
}
206208

207209
function _Report_GetFilters() {
208-
// Grab the reference to the div HTML element that will host the report.
210+
// Get a reference to the embedded report HTML element
209211
var reportContainer = $('#reportContainer')[0];
210212

211213
// Get a reference to the embedded report.
@@ -234,7 +236,7 @@ function _Report_SetFilters() {
234236
values: ["Lindseys"]
235237
};
236238

237-
// Grab the reference to the div HTML element that will host the report.
239+
// Get a reference to the embedded report HTML element
238240
var reportContainer = $('#reportContainer')[0];
239241

240242
// Get a reference to the embedded report.
@@ -252,7 +254,7 @@ function _Report_SetFilters() {
252254
}
253255

254256
function _Report_RemoveFilters() {
255-
// Grab the reference to the div HTML element that will host the report.
257+
// Get a reference to the embedded report HTML element
256258
var reportContainer = $('#reportContainer')[0];
257259

258260
// Get a reference to the embedded report.
@@ -269,7 +271,7 @@ function _Report_RemoveFilters() {
269271
}
270272

271273
function _Report_PrintCurrentReport() {
272-
// Grab the reference to the div HTML element that will host the report.
274+
// Get a reference to the embedded report HTML element
273275
var reportContainer = $('#reportContainer')[0];
274276

275277
// Get a reference to the embedded report.
@@ -286,7 +288,7 @@ function _Report_PrintCurrentReport() {
286288
}
287289

288290
function _Report_Reload() {
289-
// Grab the reference to the div HTML element that will host the report.
291+
// Get a reference to the embedded report HTML element
290292
var reportContainer = $('#reportContainer')[0];
291293

292294
// Get a reference to the embedded report.
@@ -303,7 +305,7 @@ function _Report_Reload() {
303305
}
304306

305307
function _Report_FullScreen() {
306-
// Grab the reference to the div HTML element that will host the report.
308+
// Get a reference to the embedded report HTML element
307309
var reportContainer = $('#reportContainer')[0];
308310

309311
// Get a reference to the embedded report.
@@ -314,7 +316,7 @@ function _Report_FullScreen() {
314316
}
315317

316318
function _Report_ExitFullScreen() {
317-
// Grab the reference to the div HTML element that will host the report.
319+
// Get a reference to the embedded report HTML element
318320
var reportContainer = $('#reportContainer')[0];
319321

320322
// Get a reference to the embedded report.
@@ -325,7 +327,7 @@ function _Report_ExitFullScreen() {
325327
}
326328

327329
function _Report_switchModeEdit() {
328-
// Grab the reference to the div HTML element that will host the report.
330+
// Get a reference to the embedded report HTML element
329331
var reportContainer = $('#reportContainer')[0];
330332

331333
// Get a reference to the embedded report.
@@ -336,7 +338,7 @@ function _Report_switchModeEdit() {
336338
}
337339

338340
function _Report_switchModeView() {
339-
// Grab the reference to the div HTML element that will host the report.
341+
// Get a reference to the embedded report HTML element
340342
var reportContainer = $('#reportContainer')[0];
341343

342344
// Get a reference to the embedded report.
@@ -347,7 +349,7 @@ function _Report_switchModeView() {
347349
}
348350

349351
function _Report_save() {
350-
// Grab the reference to the div HTML element that will host the report.
352+
// Get a reference to the embedded report HTML element
351353
var reportContainer = $('#reportContainer')[0];
352354

353355
// Get a reference to the embedded report.
@@ -360,18 +362,13 @@ function _Report_save() {
360362
report.off("saved");
361363

362364
// report.on will add an event handler which prints to Log window.
363-
report.on("saved", function() {
364-
var reportObjectId = event.detail.reportObjectId;
365-
var isSaveAs = event.detail.saveAs;
366-
var name = event.detail.reportName;
367-
Log.logText("Report name " + name);
368-
Log.logText("Save Report Completed, reportObjectId: " + reportObjectId);
369-
Log.logText("Is saveAs: " + isSaveAs.toString());
365+
report.on("saved", function(event) {
366+
Log.log(event.detail);
370367
});
371368
}
372369

373370
function _Report_saveAs() {
374-
// Grab the reference to the div HTML element that will host the report.
371+
// Get a reference to the embedded report HTML element
375372
var reportContainer = $('#reportContainer')[0];
376373

377374
// Get a reference to the embedded report.
@@ -388,39 +385,15 @@ function _Report_saveAs() {
388385
report.off("saved");
389386

390387
// report.on will add an event handler which prints to Log window.
391-
report.on("saved", function() {
392-
var reportObjectId = event.detail.reportObjectId;
393-
var isSaveAs = event.detail.saveAs;
394-
var name = event.detail.reportName;
395-
Log.logText("Report name " + name);
396-
Log.logText("Save Report Completed, new reportObjectId: " + reportObjectId);
397-
Log.logText("Is saveAs: " + isSaveAs.toString());
388+
report.on("saved", function(event) {
389+
Log.log(event.detail);
398390
});
399391
}
400392

401-
function _Report_setAccessToken() {
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);
407-
408-
// New AccessToken
409-
var newAccessToken = "newAccessToken";
410-
411-
// Set new AccessToken
412-
report.setAccessToken(newAccessToken).then(function (result) {
413-
Log.log("AccessToken set");
414-
})
415-
.catch(function (errors) {
416-
Log.log(errors);
417-
});
418-
}
419-
420393
// ---- Page Operations ----------------------------------------------------
421394

422395
function _Page_SetActive() {
423-
// Grab the reference to the div HTML element that will host the report.
396+
// Get a reference to the embedded report HTML element
424397
var reportContainer = $('#reportContainer')[0];
425398

426399
// Get a reference to the embedded report.
@@ -439,7 +412,7 @@ function _Page_SetActive() {
439412
}
440413

441414
function _Page_GetFilters() {
442-
// Grab the reference to the div HTML element that will host the report.
415+
// Get a reference to the embedded report HTML element
443416
var reportContainer = $('#reportContainer')[0];
444417

445418
// Get a reference to the embedded report.
@@ -462,7 +435,7 @@ function _Page_GetFilters() {
462435
}
463436

464437
function _Page_SetFilters() {
465-
// Grab the reference to the div HTML element that will host the report.
438+
// Get a reference to the embedded report HTML element
466439
var reportContainer = $('#reportContainer')[0];
467440

468441
// Get a reference to the embedded report.
@@ -498,7 +471,7 @@ function _Page_SetFilters() {
498471
}
499472

500473
function _Page_RemoveFilters() {
501-
// Grab the reference to the div HTML element that will host the report.
474+
// Get a reference to the embedded report HTML element
502475
var reportContainer = $('#reportContainer')[0];
503476

504477
// Get a reference to the embedded report.
@@ -523,7 +496,7 @@ function _Page_RemoveFilters() {
523496
// ---- Event Listener ----------------------------------------------------
524497

525498
function _Events_PageChanged() {
526-
// Grab the reference to the div HTML element that will host the report.
499+
// Get a reference to the embedded report HTML element
527500
var reportContainer = $('#reportContainer')[0];
528501

529502
// Get a reference to the embedded report.
@@ -545,7 +518,7 @@ function _Events_PageChanged() {
545518
}
546519

547520
function _Events_DataSelected() {
548-
// Grab the reference to the div HTML element that will host the report.
521+
// Get a reference to the embedded report HTML element
549522
var reportContainer = $('#reportContainer')[0];
550523

551524
// Get a reference to the embedded report.
@@ -567,7 +540,7 @@ function _Events_DataSelected() {
567540
}
568541

569542
function _Events_SaveAsTriggered() {
570-
// Grab the reference to the div HTML element that will host the report.
543+
// Get a reference to the embedded report HTML element
571544
var reportContainer = $('#reportContainer')[0];
572545

573546
// Get a reference to the embedded report.
@@ -578,11 +551,10 @@ function _Events_SaveAsTriggered() {
578551

579552
// Report.on will add an event listener.
580553
report.on("saveAsTriggered", function(event) {
581-
var eventType = event.type;
582-
Log.logText("Event Triggered: " + eventType);
554+
Log.log(event);
583555
});
584556

585-
// Select Run and change to a different page.
557+
// Select Run and then run SaveAs.
586558
// You should see an entry in the Log window.
587559

588560
Log.logText("Run SaveAs to see events in Log window.");

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,4 @@ function Report_save() {
9191

9292
function Report_saveAs() {
9393
SetCode(_Report_saveAs);
94-
}
95-
96-
function Report_setAccessToken() {
97-
SetCode(_Report_setAccessToken);
9894
}

‎demo/code-demo/settings_embed.html‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<div id="report-embed-table">
22

3-
<div class="tabContainer">
4-
<ul class="nav nav-tabs">
5-
<li class="active" id="steps-embed" onclick="OpenEmbedStep();">
6-
<a data-toggle="tab" href="#Embed">Embed</a>
7-
</li>
8-
<li id="steps-embed" onclick="OpenCleanEmbedStepCreate();">
9-
<a data-toggle="tab" href="#Create">Create</a>
10-
</li>
11-
</ul>
12-
</div>
3+
<div class="tabContainer">
4+
<ul class="nav nav-tabs">
5+
<li class="active" id="steps-embed" onclick="OpenEmbedStep();">
6+
<a data-toggle="tab" href="#Embed">Embed</a>
7+
</li>
8+
<li id="steps-embed" onclick="OpenCleanEmbedStepCreate();">
9+
<a data-toggle="tab" href="#Create">Create</a>
10+
</li>
11+
</ul>
12+
</div>
1313

1414
<div class="pageTitle">
1515
<h4>Embed Report</h4>
@@ -29,6 +29,6 @@ <h4>Embed Report</h4>
2929
<div><input type="text" id="txtEmbedReportId" onchange="UpdateSession(this, SessionKeys.EmbedId);"/></div>
3030
</div>
3131
<div id="report-embed-checkbox" class="checkbox">
32-
<label><input type="checkbox" id="viewMode">Embed in Edit mode</label>
32+
<label><input type="checkbox" id="viewMode">Embed in Edit mode</label>
3333
</div>
3434
</div>

‎demo/code-demo/settings_interact.html‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
<li class="" onclick="Report_switchModeView()">Enter view mode</li>
6262
<li class="" onclick="Report_save()">Save report</li>
6363
<li class="" onclick="Report_saveAs()">SaveAs report</li>
64-
<li class="" onclick="Report_setAccessToken()">Set AccessToken</li>
6564
</ul>
6665
</div>
6766
</div>

‎demo/code-demo/style/style.css‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -498,14 +498,14 @@ a {
498498
}
499499

500500
.tabContainer {
501-
margin-bottom: 5px;
502-
padding-left: 0;
501+
margin-bottom: 5px;
502+
padding-left: 0;
503503
}
504504

505505
.nav-tabs {
506-
border-bottom: 0px;
506+
border-bottom: 0px;
507507
}
508508

509509
.checkbox.input {
510-
width: auto;
510+
width: auto;
511511
}

0 commit comments

Comments
 (0)