Skip to content

Commit e1ac43e

Browse files
committed
Merged PR 3734: moving tileEmbed to communicate with iframe like all embed types
moving tileEmbed to communicate with iframe like all embed types
1 parent c867661 commit e1ac43e

File tree

8 files changed

+33
-155
lines changed

8 files changed

+33
-155
lines changed

demo/v2-demo/scripts/codesamples.js

-1
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,6 @@ function _Embed_TileEmbed() {
400400
// Tile.on will add an event handler which prints to Log window.
401401
tile.on("tileLoaded", function(event) {
402402
Log.logText("Tile loaded event");
403-
Log.log(event.detail);
404403
});
405404

406405
// Tile.off removes a given event handler if it exists.

dist/powerbi-client.d.ts

+1-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! powerbi-client v2.4.5 | (c) 2016 Microsoft Corporation MIT */
1+
/*! powerbi-client v2.4.6 | (c) 2016 Microsoft Corporation MIT */
22
declare module "config" {
33
const config: {
44
version: string;
@@ -940,13 +940,6 @@ declare module "tile" {
940940
* @returns {void}
941941
*/
942942
populateConfig(baseConfig: embed.IEmbedConfigurationBase): void;
943-
/**
944-
* Sends load configuration data for tile
945-
*
946-
* @param {models.ILoadConfiguration} config
947-
* @returns {Promise<void>}
948-
*/
949-
load(baseConfig: embed.IEmbedConfigurationBase): Promise<void>;
950943
/**
951944
* Adds the ability to get tileId from url.
952945
* By extracting the ID we can ensure that the ID is always explicitly provided as part of the load configuration.
@@ -956,12 +949,6 @@ declare module "tile" {
956949
* @returns {string}
957950
*/
958951
static findIdFromEmbedUrl(url: string): string;
959-
/**
960-
* Adds the ability to get events from iframe
961-
*
962-
* @param event: MessageEvent
963-
*/
964-
private receiveMessage(event);
965952
}
966953
}
967954
declare module "qna" {

dist/powerbi.js

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

dist/powerbi.min.js

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

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "powerbi-client",
3-
"version": "2.4.5",
3+
"version": "2.4.6",
44
"description": "JavaScript library for embedding Power BI into your apps. Provides service which makes it easy to embed different types of components and an object model which allows easy interaction with these components such as changing pages, applying filters, and responding to data selection.",
55
"main": "dist/powerbi.js",
66
"typings": "dist/powerbi-client.d.ts",

src/config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const config = {
2-
version: '2.4.5',
2+
version: '2.4.6',
33
type: 'js'
44
};
55

src/service.ts

+11
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,17 @@ export class Service implements IService {
167167
this.handleEvent(event);
168168
});
169169

170+
this.router.post(`/tile/:uniqueId/events/:eventName`, (req, res) => {
171+
const event: IEvent<any> = {
172+
type: 'tile',
173+
id: req.params.uniqueId,
174+
name: req.params.eventName,
175+
value: req.body
176+
};
177+
178+
this.handleEvent(event);
179+
});
180+
170181
/**
171182
* Adds handler for Q&A events.
172183
*/

src/tile.ts

+1-70
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,9 @@ export class Tile extends embed.Embed {
1717

1818
constructor(service: service.Service, element: HTMLElement, baseConfig: embed.IEmbedConfigurationBase, phasedRender?: boolean) {
1919
let config = <embed.IEmbedConfiguration>baseConfig;
20-
config.embedUrl = utils.addParamToUrl(config.embedUrl, 'dashboardId', config.dashboardId);
21-
config.embedUrl = utils.addParamToUrl(config.embedUrl, 'tileId', config.id);
22-
2320
super(service, element, config, /* iframe */ undefined, phasedRender);
21+
this.loadPath = "/tile/load";
2422
Array.prototype.push.apply(this.allowedEvents, Tile.allowedEvents);
25-
26-
window.addEventListener("message", this.receiveMessage.bind(this), false);
2723
}
2824

2925
/**
@@ -69,40 +65,6 @@ export class Tile extends embed.Embed {
6965
this.config = config;
7066
}
7167

72-
/**
73-
* Sends load configuration data for tile
74-
*
75-
* @param {models.ILoadConfiguration} config
76-
* @returns {Promise<void>}
77-
*/
78-
load(baseConfig: embed.IEmbedConfigurationBase): Promise<void> {
79-
let config = <embed.IEmbedConfiguration>baseConfig;
80-
const errors = this.validate(config);
81-
if (errors) {
82-
throw errors;
83-
}
84-
85-
let height = config.height ? config.height : this.iframe.offsetHeight;
86-
let width = config.width ? config.width : this.iframe.offsetWidth;
87-
let action = config.action ? config.action : 'loadTile';
88-
89-
let tileConfig = {
90-
action: action,
91-
height: height,
92-
width: width,
93-
accessToken: config.accessToken,
94-
tokenType: config.tokenType,
95-
}
96-
97-
this.iframe.contentWindow.postMessage(JSON.stringify(tileConfig), "*")
98-
99-
// In order to use this function the same way we use it in embed
100-
// we need to keep the return type the same as 'load' in embed
101-
return new Promise<void>( () => {
102-
return;
103-
});
104-
}
105-
10668
/**
10769
* Adds the ability to get tileId from url.
10870
* By extracting the ID we can ensure that the ID is always explicitly provided as part of the load configuration.
@@ -122,35 +84,4 @@ export class Tile extends embed.Embed {
12284

12385
return tileId;
12486
}
125-
126-
/**
127-
* Adds the ability to get events from iframe
128-
*
129-
* @param event: MessageEvent
130-
*/
131-
private receiveMessage(event: MessageEvent): void {
132-
if (event.data) {
133-
try {
134-
let messageData = JSON.parse(event.data);
135-
let value = {
136-
navigationUrl: messageData.navigationUrl,
137-
errors: messageData.error,
138-
openReport: messageData.openReport
139-
};
140-
141-
const tileEvent: service.IEvent<any> = {
142-
type: 'tile',
143-
id: this.config.uniqueId,
144-
name: messageData.event,
145-
value: value
146-
};
147-
148-
this.service.handleTileEvents(tileEvent);
149-
}
150-
catch (e) {
151-
console.log("invalid message data");
152-
return;
153-
}
154-
}
155-
}
15687
}

0 commit comments

Comments
 (0)