Skip to content

Commit ced5998

Browse files
committed
Merged PR 21999: support configuration of locale
support configuration of locale
1 parent 1c8a6c8 commit ced5998

File tree

10 files changed

+142
-24
lines changed

10 files changed

+142
-24
lines changed

dist/powerbi-client.d.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! powerbi-client v2.3.2 | (c) 2016 Microsoft Corporation MIT */
1+
/*! powerbi-client v2.3.3 | (c) 2016 Microsoft Corporation MIT */
22
declare module "config" {
33
const config: {
44
version: string;
@@ -52,6 +52,16 @@ declare module "util" {
5252
* @returns {string}
5353
*/
5454
export function createRandomString(): string;
55+
/**
56+
* Adds a parameter to the given url
57+
*
58+
* @export
59+
* @param {string} url
60+
* @param {string} paramName
61+
* @param {string} value
62+
* @returns {string}
63+
*/
64+
export function addParamToUrl(url: string, paramName: string, value: string): string;
5565
}
5666
declare module "embed" {
5767
import * as service from "service";
@@ -78,7 +88,7 @@ declare module "embed" {
7888
uniqueId?: string;
7989
embedUrl?: string;
8090
accessToken?: string;
81-
settings?: models.ISettings;
91+
settings?: IEmbedSettings;
8292
pageName?: string;
8393
filters?: models.IFilter[];
8494
pageView?: models.PageView;
@@ -91,6 +101,13 @@ declare module "embed" {
91101
height?: number;
92102
width?: number;
93103
}
104+
export interface ILocaleSettings {
105+
language?: string;
106+
formatLocale?: string;
107+
}
108+
export interface IEmbedSettings extends models.ISettings {
109+
localeSettings?: ILocaleSettings;
110+
}
94111
export interface IInternalEmbedConfiguration extends models.IReportLoadConfiguration {
95112
uniqueId: string;
96113
type: string;
@@ -291,6 +308,13 @@ declare module "embed" {
291308
* @returns {void}
292309
*/
293310
private populateConfig(config);
311+
/**
312+
* Adds locale parameters to embedUrl
313+
*
314+
* @private
315+
* @param {IEmbedConfiguration} config
316+
*/
317+
private addLocaleToEmbedUrl(config);
294318
/**
295319
* Gets an embed url from the first available location: options, attribute.
296320
*

dist/powerbi.js

Lines changed: 39 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/powerbi.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/powerbi.min.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "powerbi-client",
3-
"version": "2.3.2",
3+
"version": "2.3.3",
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const config = {
2-
version: '2.3.2',
2+
version: '2.3.3',
33
type: 'js'
44
};
55

src/embed.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export interface IEmbedConfiguration {
3535
uniqueId?: string;
3636
embedUrl?: string;
3737
accessToken?: string;
38-
settings?: models.ISettings;
38+
settings?: IEmbedSettings;
3939
pageName?: string;
4040
filters?: models.IFilter[];
4141
pageView?: models.PageView;
@@ -49,6 +49,15 @@ export interface IEmbedConfiguration {
4949
width?: number;
5050
}
5151

52+
export interface ILocaleSettings {
53+
language?: string;
54+
formatLocale?: string;
55+
}
56+
57+
export interface IEmbedSettings extends models.ISettings {
58+
localeSettings?: ILocaleSettings;
59+
}
60+
5261
export interface IInternalEmbedConfiguration extends models.IReportLoadConfiguration {
5362
uniqueId: string;
5463
type: string;
@@ -382,7 +391,7 @@ export abstract class Embed {
382391
this.config = utils.assign({ settings }, config);
383392
this.config.uniqueId = this.getUniqueId();
384393
this.config.embedUrl = this.getEmbedUrl();
385-
394+
this.addLocaleToEmbedUrl(config);
386395
if(this.embeType === 'create') {
387396
this.createConfig = {
388397
datasetId: config.datasetId || this.getId(),
@@ -401,6 +410,24 @@ export abstract class Embed {
401410
}
402411
}
403412

413+
/**
414+
* Adds locale parameters to embedUrl
415+
*
416+
* @private
417+
* @param {IEmbedConfiguration} config
418+
*/
419+
private addLocaleToEmbedUrl(config: IEmbedConfiguration): void {
420+
if (!config.settings) {
421+
return;
422+
}
423+
let localeSettings = config.settings.localeSettings
424+
if (localeSettings && localeSettings.language) {
425+
this.config.embedUrl = utils.addParamToUrl(this.config.embedUrl, 'language', localeSettings.language);
426+
}
427+
if (localeSettings && localeSettings.formatLocale) {
428+
this.config.embedUrl = utils.addParamToUrl(this.config.embedUrl, 'formatLocale', localeSettings.formatLocale);
429+
}
430+
}
404431

405432
/**
406433
* Gets an embed url from the first available location: options, attribute.

src/tile.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,8 @@ export class Tile extends embed.Embed {
1515
static allowedEvents = ["tileClicked", "tileLoaded"];
1616

1717
constructor(service: service.Service, element: HTMLElement, config: embed.IEmbedConfiguration) {
18-
let url = config.embedUrl;
19-
const urlParamMatch = url.indexOf("?") > 0;
20-
let firstParamSign = urlParamMatch ? '&' : '?';
21-
url = url + firstParamSign + 'dashboardId=' + config.dashboardId + '&tileId=' + config.id;
22-
config.embedUrl = url;
18+
config.embedUrl = utils.addParamToUrl(config.embedUrl, 'dashboardId', config.dashboardId);
19+
config.embedUrl = utils.addParamToUrl(config.embedUrl, 'tileId', config.id);
2320

2421
super(service, element, config);
2522
Array.prototype.push.apply(this.allowedEvents, Tile.allowedEvents);

src/util.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,18 @@ export function assign(...args) {
107107
export function createRandomString(): string {
108108
return (Math.random() + 1).toString(36).substring(7);
109109
}
110+
111+
/**
112+
* Adds a parameter to the given url
113+
*
114+
* @export
115+
* @param {string} url
116+
* @param {string} paramName
117+
* @param {string} value
118+
* @returns {string}
119+
*/
120+
export function addParamToUrl(url: string, paramName: string, value: string): string {
121+
let parameterPrefix = url.indexOf('?') > 0 ? '&' : '?';
122+
url += parameterPrefix + paramName + '=' + value;
123+
return url;
124+
}

test/test.spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,29 @@ describe('service', function () {
228228
expect(component2).toBe(component3);
229229
});
230230

231+
it('Create embed url with correct locale parameters', function () {
232+
// Arrange
233+
const $reportContainer = $('<div powerbi-embed-url="https://app.powerbi.com/reportEmbed?reportId=ABC123" powerbi-type="report"></div>')
234+
.appendTo('#powerbi-fixture');
235+
236+
const testConfiguration: embed.IEmbedConfiguration = {
237+
accessToken: "fakeAccessToken",
238+
embedUrl: 'fakeUrl?reportId=1',
239+
id: 'report2',
240+
type: 'report',
241+
settings: {
242+
localeSettings: {
243+
language: 'languageName',
244+
formatLocale: 'formatName'
245+
}
246+
}
247+
};
248+
249+
powerbi.embed($reportContainer[0], testConfiguration);
250+
var iframe = $reportContainer.find('iframe');
251+
expect(iframe.attr('src')).toEqual('fakeUrl?reportId=1&language=languageName&formatLocale=formatName');
252+
});
253+
231254
it('if attempting to embed without specifying an embed url, throw error', function () {
232255
// Arrange
233256
const component = $('<div></div>')

0 commit comments

Comments
 (0)