Skip to content

Commit 68d4655

Browse files
author
Amit Shuster
committed
Merged PR 9034: Report embed front load
Report embed front load, Sends iframe uid on the embed url, handles 'ready' message and send the config to the iframe for front load calls
1 parent 022dd3e commit 68d4655

File tree

5 files changed

+74
-9
lines changed

5 files changed

+74
-9
lines changed

dist/powerbi-client.d.ts

+4
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,10 @@ declare module "embed" {
394394
* @returns {string}
395395
*/
396396
static findGroupIdFromEmbedUrl(url: string): string;
397+
/**
398+
* Sends the config for front load calls, after 'ready' message is received from the iframe
399+
*/
400+
private frontLoadSendConfig(config);
397401
}
398402
}
399403
declare module "ifilterable" {

dist/powerbi.js

+32-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/powerbi.min.js

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/embed.ts

+21-2
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ export abstract class Embed {
535535
private setIframe(isLoad: boolean, phasedRender?: boolean): void {
536536
if(!this.iframe) {
537537
var iframeContent = document.createElement("iframe");
538-
var embedUrl = this.config.embedUrl;
538+
var embedUrl = this.config.uniqueId ? utils.addParamToUrl(this.config.embedUrl, 'uid', this.config.uniqueId) : this.config.embedUrl;
539539
iframeContent.setAttribute("style", "width:100%;height:100%;");
540540
iframeContent.setAttribute("src", embedUrl);
541541
iframeContent.setAttribute("scrolling", "no");
@@ -548,8 +548,10 @@ export abstract class Embed {
548548
this.iframe = <HTMLIFrameElement>node.firstChild;
549549
}
550550

551-
if(isLoad){
551+
if (isLoad) {
552552
this.iframe.addEventListener('load', () => this.load(this.config, phasedRender), false);
553+
// 'ready' event is fired by the embedded element (not by the iframe)
554+
this.element.addEventListener('ready', () => this.frontLoadSendConfig(this.config), false);
553555
} else {
554556
this.iframe.addEventListener('load', () => this.createReport(this.createConfig), false);
555557
}
@@ -574,4 +576,21 @@ export abstract class Embed {
574576

575577
return groupId;
576578
}
579+
580+
/**
581+
* Sends the config for front load calls, after 'ready' message is received from the iframe
582+
*/
583+
private frontLoadSendConfig(config: IEmbedConfigurationBase): Promise<void> {
584+
const errors = this.validate(config);
585+
if (errors) {
586+
throw errors;
587+
}
588+
589+
return this.service.hpm.post<void>("/frontload/config", config, { uid: this.config.uniqueId }, this.iframe.contentWindow).then(response => {
590+
return response.body;
591+
},
592+
response => {
593+
throw response.body;
594+
});
595+
}
577596
}

src/service.ts

+14
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,20 @@ export class Service implements IService {
192192
this.handleEvent(event);
193193
});
194194

195+
/**
196+
* Adds handler for front load 'ready' message.
197+
*/
198+
this.router.post(`/ready/:uniqueId`, (req, res) => {
199+
const event: IEvent<any> = {
200+
type: 'report',
201+
id: req.params.uniqueId,
202+
name: 'ready',
203+
value: req.body
204+
};
205+
206+
this.handleEvent(event);
207+
});
208+
195209
this.embeds = [];
196210

197211
// TODO: Change when Object.assign is available.

0 commit comments

Comments
 (0)