diff --git a/dist/powerbi-client.d.ts b/dist/powerbi-client.d.ts index ea861e7c..c8d667ac 100644 --- a/dist/powerbi-client.d.ts +++ b/dist/powerbi-client.d.ts @@ -1,4 +1,4 @@ -/*! powerbi-client v2.6.7 | (c) 2016 Microsoft Corporation MIT */ +/*! powerbi-client v2.6.8 | (c) 2016 Microsoft Corporation MIT */ declare module "util" { /** * Raises a custom event with event data on the specified HTML element. @@ -110,6 +110,7 @@ declare module "embed" { dashboardId?: string; height?: number; width?: number; + theme?: models.IReportTheme; } export interface IVisualEmbedConfiguration extends IEmbedConfiguration { visualName: string; @@ -933,6 +934,23 @@ declare module "report" { * ``` */ refresh(): Promise; + /** + * Apply a theme to the report + * + * ```javascript + * report.applyTheme(theme); + * ``` + */ + applyTheme(theme: models.IReportTheme): Promise; + /** + * Reset and apply the default theme of the report + * + * ```javascript + * report.resetTheme(); + * ``` + */ + resetTheme(): Promise; + private applyThemeInternal(theme); private viewModeToString(viewMode); } } diff --git a/dist/powerbi.js b/dist/powerbi.js index 510520ff..976dd40a 100644 --- a/dist/powerbi.js +++ b/dist/powerbi.js @@ -1,4 +1,4 @@ -/*! powerbi-client v2.6.7 | (c) 2016 Microsoft Corporation MIT */ +/*! powerbi-client v2.6.8 | (c) 2016 Microsoft Corporation MIT */ (function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(); @@ -4600,6 +4600,35 @@ return /******/ (function(modules) { // webpackBootstrap throw response.body; }); }; + /** + * Apply a theme to the report + * + * ```javascript + * report.applyTheme(theme); + * ``` + */ + Report.prototype.applyTheme = function (theme) { + return this.applyThemeInternal(theme); + }; + /** + * Reset and apply the default theme of the report + * + * ```javascript + * report.resetTheme(); + * ``` + */ + Report.prototype.resetTheme = function () { + return this.applyThemeInternal({}); + }; + Report.prototype.applyThemeInternal = function (theme) { + return this.service.hpm.put('/report/theme', theme, { uid: this.config.uniqueId }, this.iframe.contentWindow) + .then(function (response) { + return response.body; + }) + .catch(function (response) { + throw response.body; + }); + }; Report.prototype.viewModeToString = function (viewMode) { var mode; switch (viewMode) { @@ -5066,11 +5095,12 @@ return /******/ (function(modules) { // webpackBootstrap this.config = utils.assign({ settings: settings }, baseConfig); var config = this.config; this.createConfig = { - datasetId: config.datasetId || this.getId(), accessToken: config.accessToken, - tokenType: config.tokenType, + datasetId: config.datasetId || this.getId(), + groupId: config.groupId, settings: settings, - groupId: config.groupId + tokenType: config.tokenType, + theme: config.theme }; }; /** @@ -5562,7 +5592,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ (function(module, exports) { var config = { - version: '2.6.7', + version: '2.6.8', type: 'js' }; Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/dist/powerbi.min.js b/dist/powerbi.min.js index b630ab9d..8d47636e 100644 --- a/dist/powerbi.min.js +++ b/dist/powerbi.min.js @@ -1,8 +1,8 @@ -/*! powerbi-client v2.6.7 | (c) 2016 Microsoft Corporation MIT */ +/*! powerbi-client v2.6.8 | (c) 2016 Microsoft Corporation MIT */ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["powerbi-client"]=e():t["powerbi-client"]=e()}(this,function(){return function(t){function e(a){if(r[a])return r[a].exports;var i=r[a]={exports:{},id:a,loaded:!1};return t[a].call(i.exports,i,i.exports,e),i.loaded=!0,i.exports}var r={};return e.m=t,e.c=r,e.p="",e(0)}([function(t,e,r){var a=r(1);e.service=a;var i=r(15);e.factories=i;var o=r(4);e.models=o;var n=r(5);e.Report=n.Report;var l=r(11);e.Dashboard=l.Dashboard;var s=r(12);e.Tile=s.Tile;var d=r(2);e.Embed=d.Embed;var u=r(6);e.Page=u.Page;var p=r(13);e.Qna=p.Qna;var c=r(14);e.Visual=c.Visual;var f=r(7);e.VisualDescriptor=f.VisualDescriptor;var h=new a.Service(i.hpmFactory,i.wpmpFactory,i.routerFactory);window.powerbi=h},function(t,e,r){var a=r(2),i=r(5),o=r(10),n=r(11),l=r(12),s=r(6),d=r(13),u=r(14),p=r(3),c=function(){function t(e,r,a,i){var o=this;void 0===i&&(i={}),this.wpmp=r(i.wpmpName,i.logMessages),this.hpm=e(this.wpmp,null,i.version,i.type),this.router=a(this.wpmp),this.uniqueSessionId=p.generateUUID(),this.router.post("/reports/:uniqueId/events/:eventName",function(t,e){var r={type:"report",id:t.params.uniqueId,name:t.params.eventName,value:t.body};o.handleEvent(r)}),this.router.post("/reports/:uniqueId/pages/:pageName/events/:eventName",function(t,e){var r={type:"report",id:t.params.uniqueId,name:t.params.eventName,value:t.body};o.handleEvent(r)}),this.router.post("/reports/:uniqueId/pages/:pageName/visuals/:visualName/events/:eventName",function(t,e){var r={type:"report",id:t.params.uniqueId,name:t.params.eventName,value:t.body};o.handleEvent(r)}),this.router.post("/dashboards/:uniqueId/events/:eventName",function(t,e){var r={type:"dashboard",id:t.params.uniqueId,name:t.params.eventName,value:t.body};o.handleEvent(r)}),this.router.post("/tile/:uniqueId/events/:eventName",function(t,e){var r={type:"tile",id:t.params.uniqueId,name:t.params.eventName,value:t.body};o.handleEvent(r)}),this.router.post("/qna/:uniqueId/events/:eventName",function(t,e){var r={type:"qna",id:t.params.uniqueId,name:t.params.eventName,value:t.body};o.handleEvent(r)}),this.router.post("/ready/:uniqueId",function(t,e){var r={type:"report",id:t.params.uniqueId,name:"ready",value:t.body};o.handleEvent(r)}),this.embeds=[],this.config=p.assign({},t.defaultConfig,i),this.config.autoEmbedOnContentLoaded&&this.enableAutoEmbed()}return t.prototype.createReport=function(t,e){e.type="create";var r=t,a=new o.Create(this,r,e);return r.powerBiEmbed=a,this.addOrOverwriteEmbed(a,t),a},t.prototype.init=function(t,e){var r=this;void 0===e&&(e=void 0),t=t&&t instanceof HTMLElement?t:document.body;var i=Array.prototype.slice.call(t.querySelectorAll("["+a.Embed.embedUrlAttribute+"]"));return i.map(function(t){return r.embed(t,e)})},t.prototype.embed=function(t,e){return void 0===e&&(e={}),this.embedInternal(t,e)},t.prototype.load=function(t,e){return void 0===e&&(e={}),this.embedInternal(t,e,!0)},t.prototype.embedInternal=function(t,e,r){void 0===e&&(e={});var a,i=t;return a=i.powerBiEmbed?this.embedExisting(i,e,r):this.embedNew(i,e,r)},t.prototype.getNumberOfComponents=function(){return this.embeds?this.embeds.length:0},t.prototype.getSdkSessionId=function(){return this.uniqueSessionId},t.prototype.embedNew=function(e,r,o){var n=r.type||e.getAttribute(a.Embed.typeAttribute);if(!n)throw new Error("Attempted to embed using config "+JSON.stringify(r)+" on element "+e.outerHTML+", but could not determine what type of component to embed. You must specify a type in the configuration or as an attribute such as '"+a.Embed.typeAttribute+'="'+i.Report.type.toLowerCase()+"\"'.");r.type=n;var l=p.find(function(t){return n===t.type.toLowerCase()},t.components);if(!l)throw new Error("Attempted to embed component of type: "+n+" but did not find any matching component. Please verify the type you specified is intended.");var s=new l(this,e,r,o);return e.powerBiEmbed=s,this.addOrOverwriteEmbed(s,e),s},t.prototype.embedExisting=function(t,e,r){var a=p.find(function(e){return e.element===t},this.embeds);if(!a)throw new Error("Attempted to embed using config "+JSON.stringify(e)+" on element "+t.outerHTML+" which already has embedded comopnent associated, but could not find the existing comopnent in the list of active components. This could indicate the embeds list is out of sync with the DOM, or the component is referencing the incorrect HTML element.");if(e.type&&"qna"===e.type.toLowerCase())return this.embedNew(t,e);if("string"==typeof e.type&&e.type!==a.config.type){if("report"===e.type&&"create"===a.config.type){var o=new i.Report(this,t,e,(!1),t.powerBiEmbed.iframe);return o.load(e),t.powerBiEmbed=o,this.addOrOverwriteEmbed(a,t),o}throw new Error("Embedding on an existing element with a different type than the previous embed object is not supported. Attempted to embed using config "+JSON.stringify(e)+" on element "+t.outerHTML+", but the existing element contains an embed of type: "+this.config.type+" which does not match the new type: "+e.type)}return a.load(e,r),a},t.prototype.enableAutoEmbed=function(){var t=this;window.addEventListener("DOMContentLoaded",function(e){return t.init(document.body)},!1)},t.prototype.get=function(t){var e=t;if(!e.powerBiEmbed)throw new Error("You attempted to get an instance of powerbi component associated with element: "+t.outerHTML+" but there was no associated instance.");return e.powerBiEmbed},t.prototype.find=function(t){return p.find(function(e){return e.config.uniqueId===t},this.embeds)},t.prototype.addOrOverwriteEmbed=function(t,e){this.embeds=this.embeds.filter(function(t){return t.element.id!==e.id}),this.embeds.push(t)},t.prototype.reset=function(t){var e=t;if(e.powerBiEmbed){var r=e.powerBiEmbed;r.frontLoadHandler&&r.element.removeEventListener("ready",r.frontLoadHandler,!1),p.remove(function(t){return t===e.powerBiEmbed},this.embeds),delete e.powerBiEmbed;var a=t.querySelector("iframe");a&&(void 0!==a.remove?a.remove():a.parentElement.removeChild(a))}},t.prototype.handleTileEvents=function(t){"tile"===t.type&&this.handleEvent(t)},t.prototype.handleEvent=function(t){var e=p.find(function(e){return e.config.uniqueId===t.id},this.embeds);if(e){var r=t.value;if("pageChanged"===t.name){var a="newPage",i=r[a];if(!i)throw new Error("Page model not found at 'event.value."+a+"'.");r[a]=new s.Page(e,i.name,i.displayName,(!0))}p.raiseCustomEvent(e.element,t.name,r)}},t.prototype.preload=function(t,e){var r=document.createElement("iframe");r.setAttribute("style","display:none;"),r.setAttribute("src",t.embedUrl),r.setAttribute("scrolling","no"),r.setAttribute("allowfullscreen","false");var a=e;return a||(a=document.getElementsByTagName("body")[0]),a.appendChild(r),r.onload=function(){p.raiseCustomEvent(r,"preloaded",{})},r},t.components=[l.Tile,i.Report,n.Dashboard,d.Qna,u.Visual],t.defaultConfig={autoEmbedOnContentLoaded:!1,onError:function(){for(var t=[],e=0;e>=4,r.toString(16)})}function d(t,e,r){var a=t.indexOf("?")>0?"&":"?";return t+=a+e+"="+r}e.raiseCustomEvent=r,e.findIndex=a,e.find=i,e.remove=o,e.assign=n,e.createRandomString=l,e.generateUUID=s,e.addParamToUrl=d},function(t,e,r){/*! powerbi-models v1.1.0 | (c) 2016 Microsoft Corporation MIT */ -!function(e,r){t.exports=r()}(this,function(){return function(t){function e(a){if(r[a])return r[a].exports;var i=r[a]={exports:{},id:a,loaded:!1};return t[a].call(i.exports,i,i.exports,e),i.loaded=!0,i.exports}var r={};return e.m=t,e.c=r,e.p="",e(0)}([function(t,e,r){function a(t){return l(t)&&!!t.keys}function i(t){return o(t)===Y.Basic&&!!t.keyValues}function o(t){if(t.filterType)return t.filterType;var e=t,r=t;return"string"==typeof e.operator&&Array.isArray(e.values)?Y.Basic:"string"==typeof r.logicalOperator&&Array.isArray(r.conditions)?Y.Advanced:Y.Unknown}function n(t){return void 0!==t.table&&void 0!==t.measure}function l(t){return void 0!==t.table&&void 0!==t.column}function s(t){return void 0!==t.table&&void 0!==t.hierarchy&&void 0!==t.hierarchyLevel}function d(t){var e=t.message;return e||(e=t.path+" is invalid. Not meeting "+t.keyword+" constraint"),{message:e}}function u(t){var r=e.Validators.visualSelectorValidator.validate(t);return r?r.map(d):void 0}function p(t){var r=e.Validators.slicerValidator.validate(t);return r?r.map(d):void 0}function c(t){var r=e.Validators.slicerStateValidator.validate(t);return r?r.map(d):void 0}function f(t){var r=e.Validators.playBookmarkRequestValidator.validate(t);return r?r.map(d):void 0}function h(t){var r=e.Validators.addBookmarkRequestValidator.validate(t);return r?r.map(d):void 0}function v(t){var r=e.Validators.applyBookmarkByNameRequestValidator.validate(t);return r?r.map(d):void 0}function y(t){var r=e.Validators.applyBookmarkStateRequestValidator.validate(t);return r?r.map(d):void 0}function m(t){var r=e.Validators.settingsValidator.validate(t);return r?r.map(d):void 0}function V(t){var r=e.Validators.customPageSizeValidator.validate(t);return r?r.map(d):void 0}function g(t){var r=e.Validators.extensionValidator.validate(t);return r?r.map(d):void 0}function w(t){var r=e.Validators.reportLoadValidator.validate(t);return r?r.map(d):void 0}function b(t){var r=e.Validators.reportCreateValidator.validate(t);return r?r.map(d):void 0}function O(t){var r=e.Validators.dashboardLoadValidator.validate(t);return r?r.map(d):void 0}function S(t){var r=e.Validators.tileLoadValidator.validate(t);return r?r.map(d):void 0}function T(t){var r=e.Validators.pageValidator.validate(t);return r?r.map(d):void 0}function E(t){var r=e.Validators.filtersValidator.validate(t);return r?r.map(d):void 0}function _(t){var r=e.Validators.saveAsParametersValidator.validate(t);return r?r.map(d):void 0}function P(t){var r=e.Validators.loadQnaValidator.validate(t);return r?r.map(d):void 0}function x(t){var r=e.Validators.qnaInterpretInputDataValidator.validate(t);return r?r.map(d):void 0}function A(t){var r=e.Validators.exportDataRequestValidator.validate(t);return r?r.map(d):void 0}function k(t){var r=e.Validators.visualHeaderValidator.validate(t);return r?r.map(d):void 0}function F(t){var r=e.Validators.visualSettingsValidator.validate(t);return r?r.map(d):void 0}function C(t){var r=e.Validators.commandsSettingsValidator.validate(t);return r?r.map(d):void 0}function R(t){var r=e.Validators.customThemeValidator.validate(t);return r?r.map(d):void 0}var M=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])};return function(e,r){function a(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(a.prototype=r.prototype,new a)}}();Object.defineProperty(e,"__esModule",{value:!0}),e.Validators=r(1).Validators;var q;!function(t){t[t.Information=0]="Information",t[t.Verbose=1]="Verbose",t[t.Warning=2]="Warning",t[t.Error=3]="Error",t[t.ExpectedError=4]="ExpectedError",t[t.UnexpectedError=5]="UnexpectedError",t[t.Fatal=6]="Fatal"}(q=e.TraceType||(e.TraceType={}));var I;!function(t){t[t.Widescreen=0]="Widescreen",t[t.Standard=1]="Standard",t[t.Cortana=2]="Cortana",t[t.Letter=3]="Letter",t[t.Custom=4]="Custom"}(I=e.PageSizeType||(e.PageSizeType={}));var j;!function(t){t[t.FitToPage=0]="FitToPage",t[t.FitToWidth=1]="FitToWidth",t[t.ActualSize=2]="ActualSize"}(j=e.DisplayOption||(e.DisplayOption={}));var N;!function(t){t[t.Default=0]="Default",t[t.Transparent=1]="Transparent"}(N=e.BackgroundType||(e.BackgroundType={}));var L;!function(t){t[t.Visible=0]="Visible",t[t.Hidden=1]="Hidden"}(L=e.VisualContainerDisplayMode||(e.VisualContainerDisplayMode={}));var U;!function(t){t[t.Master=0]="Master",t[t.Custom=1]="Custom",t[t.MobilePortrait=2]="MobilePortrait",t[t.MobileLandscape=3]="MobileLandscape"}(U=e.LayoutType||(e.LayoutType={}));var D;!function(t){t[t.AlwaysVisible=0]="AlwaysVisible",t[t.HiddenInViewMode=1]="HiddenInViewMode"}(D=e.SectionVisibility||(e.SectionVisibility={}));var W;!function(t){t[t.Read=0]="Read",t[t.ReadWrite=1]="ReadWrite",t[t.Copy=2]="Copy",t[t.Create=4]="Create",t[t.All=7]="All"}(W=e.Permissions||(e.Permissions={}));var B;!function(t){t[t.View=0]="View",t[t.Edit=1]="Edit"}(B=e.ViewMode||(e.ViewMode={}));var H;!function(t){t[t.Aad=0]="Aad",t[t.Embed=1]="Embed"}(H=e.TokenType||(e.TokenType={}));var z;!function(t){t[t.Bottom=0]="Bottom",t[t.Top=1]="Top"}(z=e.MenuLocation||(e.MenuLocation={}));var J;!function(t){t[t.Report=0]="Report",t[t.Page=1]="Page",t[t.Visual=2]="Visual"}(J=e.FiltersLevel||(e.FiltersLevel={}));var Y;!function(t){t[t.Advanced=0]="Advanced",t[t.Basic=1]="Basic",t[t.Unknown=2]="Unknown",t[t.IncludeExclude=3]="IncludeExclude",t[t.RelativeDate=4]="RelativeDate",t[t.TopN=5]="TopN",t[t.Tuple=6]="Tuple"}(Y=e.FilterType||(e.FilterType={}));var Q;!function(t){t[t.Days=0]="Days",t[t.Weeks=1]="Weeks",t[t.CalendarWeeks=2]="CalendarWeeks",t[t.Months=3]="Months",t[t.CalendarMonths=4]="CalendarMonths",t[t.Years=5]="Years",t[t.CalendarYears=6]="CalendarYears"}(Q=e.RelativeDateFilterTimeUnit||(e.RelativeDateFilterTimeUnit={}));var G;!function(t){t[t.InLast=0]="InLast",t[t.InThis=1]="InThis",t[t.InNext=2]="InNext"}(G=e.RelativeDateOperators||(e.RelativeDateOperators={}));var $=function(){function t(t,e){this.target=t,this.filterType=e}return t.prototype.toJSON=function(){return{$schema:this.schemaUrl,target:this.target,filterType:this.filterType}},t}();e.Filter=$;var K=function(t){function e(r,a,i){var o=t.call(this,r,Y.Unknown)||this;return o.message=a,o.notSupportedTypeName=i,o.schemaUrl=e.schemaUrl,o}return M(e,t),e.prototype.toJSON=function(){var e=t.prototype.toJSON.call(this);return e.message=this.message,e.notSupportedTypeName=this.notSupportedTypeName,e},e.schemaUrl="http://powerbi.com/product/schema#notSupported",e}($);e.NotSupportedFilter=K;var X=function(t){function e(r,a,i){var o=t.call(this,r,Y.IncludeExclude)||this;return o.values=i,o.isExclude=a,o.schemaUrl=e.schemaUrl,o}return M(e,t),e.prototype.toJSON=function(){var e=t.prototype.toJSON.call(this);return e.isExclude=this.isExclude,e.values=this.values,e},e.schemaUrl="http://powerbi.com/product/schema#includeExclude",e}($);e.IncludeExcludeFilter=X;var Z=function(t){function e(r,a,i){var o=t.call(this,r,Y.TopN)||this;return o.operator=a,o.itemCount=i,o.schemaUrl=e.schemaUrl,o}return M(e,t),e.prototype.toJSON=function(){var e=t.prototype.toJSON.call(this);return e.operator=this.operator,e.itemCount=this.itemCount,e},e.schemaUrl="http://powerbi.com/product/schema#topN",e}($);e.TopNFilter=Z;var tt=function(t){function e(r,a,i,o,n){var l=t.call(this,r,Y.RelativeDate)||this;return l.operator=a,l.timeUnitsCount=i,l.timeUnitType=o,l.includeToday=n,l.schemaUrl=e.schemaUrl,l}return M(e,t),e.prototype.toJSON=function(){var e=t.prototype.toJSON.call(this);return e.operator=this.operator,e.timeUnitsCount=this.timeUnitsCount,e.timeUnitType=this.timeUnitType,e.includeToday=this.includeToday,e},e.schemaUrl="http://powerbi.com/product/schema#relativeDate",e}($);e.RelativeDateFilter=tt;var et=function(t){function e(r,a){for(var i=[],o=2;o0&&!i)throw new Error("You should pass the values to be filtered for each key. You passed: no values and "+n+" keys");if(0===n&&i&&i.length>0)throw new Error("You passed key values but your target object doesn't contain the keys to be filtered");for(var l=0;l2)throw new Error("AdvancedFilters may not have more than two conditions. You passed: "+i.length);if(1===l.length&&"And"!==a)throw new Error('Logical Operator must be "And" when there is only one condition provided');return n.conditions=l,n}return M(e,t),e.prototype.toJSON=function(){var e=t.prototype.toJSON.call(this);return e.logicalOperator=this.logicalOperator,e.conditions=this.conditions,e},e.schemaUrl="http://powerbi.com/product/schema#advanced",e}($);e.AdvancedFilter=it,e.isFilterKeyColumnsTarget=a,e.isBasicFilterWithKeys=i,e.getFilterType=o,e.isMeasure=n,e.isColumn=l,e.isHierarchy=s;var ot;!function(t){t[t.Interactive=0]="Interactive",t[t.ResultOnly=1]="ResultOnly"}(ot=e.QnaMode||(e.QnaMode={}));var nt;!function(t){t[t.Summarized=0]="Summarized",t[t.Underlying=1]="Underlying"}(nt=e.ExportDataType||(e.ExportDataType={}));var lt;!function(t){t[t.Off=0]="Off",t[t.Presentation=1]="Presentation"}(lt=e.BookmarksPlayMode||(e.BookmarksPlayMode={})),e.CommonErrorCodes={TokenExpired:"TokenExpired",NotFound:"PowerBIEntityNotFound",InvalidParameters:"Invalid parameters",LoadReportFailed:"LoadReportFailed",NotAuthorized:"PowerBINotAuthorizedException",FailedToLoadModel:"ExplorationContainer_FailedToLoadModel_DefaultDetails"};var st=function(){function t(t){this.$schema=t}return t.prototype.toJSON=function(){return{$schema:this.$schema}},t}();e.Selector=st;var dt=function(t){function e(r){var a=t.call(this,e.schemaUrl)||this;return a.pageName=r,a}return M(e,t),e.prototype.toJSON=function(){var e=t.prototype.toJSON.call(this);return e.pageName=this.pageName,e},e.schemaUrl="http://powerbi.com/product/schema#pageSelector",e}(st);e.PageSelector=dt;var ut=function(t){function e(r){var a=t.call(this,e.schemaUrl)||this;return a.visualName=r,a}return M(e,t),e.prototype.toJSON=function(){var e=t.prototype.toJSON.call(this);return e.visualName=this.visualName,e},e.schemaUrl="http://powerbi.com/product/schema#visualSelector",e}(st);e.VisualSelector=ut;var pt=function(t){function e(e){var r=t.call(this,ut.schemaUrl)||this;return r.visualType=e,r}return M(e,t),e.prototype.toJSON=function(){var e=t.prototype.toJSON.call(this);return e.visualType=this.visualType,e},e.schemaUrl="http://powerbi.com/product/schema#visualTypeSelector",e}(st);e.VisualTypeSelector=pt;var ct=function(t){function e(e){var r=t.call(this,ut.schemaUrl)||this;return r.target=e,r}return M(e,t),e.prototype.toJSON=function(){var e=t.prototype.toJSON.call(this);return e.target=this.target,e},e.schemaUrl="http://powerbi.com/product/schema#slicerTargetSelector",e}(st);e.SlicerTargetSelector=ct;var ft;!function(t){t[t.Enabled=0]="Enabled",t[t.Disabled=1]="Disabled",t[t.Hidden=2]="Hidden"}(ft=e.CommandDisplayOption||(e.CommandDisplayOption={})),e.validateVisualSelector=u,e.validateSlicer=p,e.validateSlicerState=c,e.validatePlayBookmarkRequest=f,e.validateAddBookmarkRequest=h,e.validateApplyBookmarkByNameRequest=v,e.validateApplyBookmarkStateRequest=y,e.validateSettings=m,e.validateCustomPageSize=V,e.validateExtension=g,e.validateReportLoad=w,e.validateCreateReport=b,e.validateDashboardLoad=O,e.validateTileLoad=S,e.validatePage=T,e.validateFilter=E,e.validateSaveAsParameters=_,e.validateLoadQnaConfiguration=P,e.validateQnaInterpretInputData=x,e.validateExportDataRequest=A,e.validateVisualHeader=k,e.validateVisualSettings=F,e.validateCommandsSettings=C,e.validateCustomTheme=R},function(t,e,r){Object.defineProperty(e,"__esModule",{value:!0});var a=r(2),i=r(3),o=r(5),n=r(6),l=r(7),s=r(8),d=r(9),u=r(10),p=r(11),c=r(12),f=r(13),h=r(14),v=r(15),y=r(16),m=r(17),V=r(18),g=r(19),w=r(20),b=r(21),O=r(22),S=r(23),T=r(24);e.Validators={addBookmarkRequestValidator:new n.AddBookmarkRequestValidator,advancedFilterTypeValidator:new a.EnumValidator([0]),advancedFilterValidator:new l.AdvancedFilterValidator,anyArrayValidator:new a.ArrayValidator([new d.AnyOfValidator([new a.StringValidator,new a.NumberValidator,new a.BooleanValidator])]),anyFilterValidator:new d.AnyOfValidator([new l.BasicFilterValidator,new l.AdvancedFilterValidator,new l.IncludeExcludeFilterValidator,new l.NotSupportedFilterValidator,new l.RelativeDateFilterValidator,new l.TopNFilterValidator]),anyValueValidator:new d.AnyOfValidator([new a.StringValidator,new a.NumberValidator,new a.BooleanValidator]),applyBookmarkByNameRequestValidator:new n.ApplyBookmarkByNameRequestValidator,applyBookmarkStateRequestValidator:new n.ApplyBookmarkStateRequestValidator,applyBookmarkValidator:new d.AnyOfValidator([new n.ApplyBookmarkByNameRequestValidator,new n.ApplyBookmarkStateRequestValidator]),backgroundValidator:new a.EnumValidator([0,1]),basicFilterTypeValidator:new a.EnumValidator([1]),basicFilterValidator:new l.BasicFilterValidator,booleanArrayValidator:new a.BooleanArrayValidator,booleanValidator:new a.BooleanValidator,commandDisplayOptionValidator:new a.EnumValidator([0,1,2]),commandExtensionSelectorValidator:new d.AnyOfValidator([new w.VisualSelectorValidator,new w.VisualTypeSelectorValidator]),commandExtensionValidator:new i.CommandExtensionValidator,commandsSettingsArrayValidator:new a.ArrayValidator([new S.CommandsSettingsValidator]),commandsSettingsValidator:new S.CommandsSettingsValidator,conditionItemValidator:new l.ConditionItemValidator,customLayoutDisplayOptionValidator:new a.EnumValidator([0,1,2]),customLayoutValidator:new V.CustomLayoutValidator,customPageSizeValidator:new h.CustomPageSizeValidator,customThemeValidator:new T.CustomThemeValidator,dashboardLoadValidator:new c.DashboardLoadValidator,displayStateModeValidator:new a.EnumValidator([0,1]),displayStateValidator:new V.DisplayStateValidator,exportDataRequestValidator:new g.ExportDataRequestValidator,extensionArrayValidator:new a.ArrayValidator([new i.ExtensionValidator]),extensionPointsValidator:new i.ExtensionPointsValidator,extensionValidator:new i.ExtensionValidator,fieldRequiredValidator:new s.FieldRequiredValidator,filterColumnTargetValidator:new l.FilterColumnTargetValidator,filterConditionsValidator:new a.ArrayValidator([new l.ConditionItemValidator]),filterHierarchyTargetValidator:new l.FilterHierarchyTargetValidator,filterMeasureTargetValidator:new l.FilterMeasureTargetValidator,filterTargetValidator:new d.AnyOfValidator([new l.FilterColumnTargetValidator,new l.FilterHierarchyTargetValidator,new l.FilterMeasureTargetValidator]),filtersArrayValidator:new a.ArrayValidator([new d.AnyOfValidator([new l.BasicFilterValidator,new l.AdvancedFilterValidator,new l.RelativeDateFilterValidator])]),filtersValidator:new l.FilterValidator,includeExcludeFilterValidator:new l.IncludeExcludeFilterValidator,includeExludeFilterTypeValidator:new a.EnumValidator([3]),layoutTypeValidator:new a.EnumValidator([0,1,2,3]),loadQnaValidator:new v.LoadQnaValidator,menuExtensionValidator:new i.MenuExtensionValidator,menuLocationValidator:new a.EnumValidator([0,1]),notSupportedFilterTypeValidator:new a.EnumValidator([2]),notSupportedFilterValidator:new l.NotSupportedFilterValidator,numberArrayValidator:new a.NumberArrayValidator,numberValidator:new a.NumberValidator,pageLayoutValidator:new m.MapValidator([new a.StringValidator],[new V.VisualLayoutValidator]),pageSizeTypeValidator:new a.EnumValidator([0,1,2,3,4,5]),pageSizeValidator:new h.PageSizeValidator,pageValidator:new h.PageValidator,pageViewFieldValidator:new h.PageViewFieldValidator,pagesLayoutValidator:new m.MapValidator([new a.StringValidator],[new V.PageLayoutValidator]),permissionsValidator:new a.EnumValidator([0,1,2,4,7]),playBookmarkRequestValidator:new n.PlayBookmarkRequestValidator,qnaInterpretInputDataValidator:new v.QnaInterpretInputDataValidator,qnaSettingValidator:new v.QnaSettingsValidator,relativeDateFilterOperatorValidator:new a.EnumValidator([0,1,2]),relativeDateFilterTimeUnitTypeValidator:new a.EnumValidator([0,1,2,3,4,5,6]),relativeDateFilterTypeValidator:new a.EnumValidator([4]),relativeDateFilterValidator:new l.RelativeDateFilterValidator,reportCreateValidator:new p.ReportCreateValidator,reportLoadValidator:new u.ReportLoadValidator,saveAsParametersValidator:new y.SaveAsParametersValidator,settingsValidator:new o.SettingsValidator,singleCommandSettingsValidator:new S.SingleCommandSettingsValidator,slicerSelectorValidator:new d.AnyOfValidator([new w.VisualSelectorValidator,new w.SlicerTargetSelectorValidator]),slicerStateValidator:new b.SlicerStateValidator,slicerTargetValidator:new d.AnyOfValidator([new l.FilterColumnTargetValidator,new l.FilterHierarchyTargetValidator,new l.FilterMeasureTargetValidator,new l.FilterKeyColumnsTargetValidator,new l.FilterKeyHierarchyTargetValidator]),slicerValidator:new b.SlicerValidator,stringArrayValidator:new a.StringArrayValidator,stringValidator:new a.StringValidator,tileLoadValidator:new f.TileLoadValidator,tokenTypeValidator:new a.EnumValidator([0,1]),topNFilterTypeValidator:new a.EnumValidator([5]),topNFilterValidator:new l.TopNFilterValidator,viewModeValidator:new a.EnumValidator([0,1]),visualCommandSelectorValidator:new d.AnyOfValidator([new w.VisualSelectorValidator,new w.VisualTypeSelectorValidator]),visualHeaderSelectorValidator:new d.AnyOfValidator([new w.VisualSelectorValidator,new w.VisualTypeSelectorValidator]),visualHeaderSettingsValidator:new O.VisualHeaderSettingsValidator,visualHeaderValidator:new O.VisualHeaderValidator,visualHeadersValidator:new a.ArrayValidator([new O.VisualHeaderValidator]),visualLayoutValidator:new V.VisualLayoutValidator,visualSelectorValidator:new w.VisualSelectorValidator,visualSettingsValidator:new O.VisualSettingsValidator,visualTypeSelectorValidator:new w.VisualTypeSelectorValidator}},function(t,e){var r=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])};return function(e,r){function a(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(a.prototype=r.prototype,new a)}}();Object.defineProperty(e,"__esModule",{value:!0});var a=function(){function t(){}return t.prototype.validate=function(t,e,r){return null==t?null:"object"!=typeof t||Array.isArray(t)?[{message:void 0!==r?r+" must be an object":"input must be an object",path:e,keyword:"type"}]:null},t}();e.ObjectValidator=a;var i=function(){function t(t){this.itemValidators=t}return t.prototype.validate=function(t,e,r){if(null==t)return null;if(!Array.isArray(t))return[{message:r+" property is invalid",path:(e?e+".":"")+r,keyword:"type"}];for(var a=0;a0&&!i)throw new Error("You should pass the values to be filtered for each key. You passed: no values and "+n+" keys");if(0===n&&i&&i.length>0)throw new Error("You passed key values but your target object doesn't contain the keys to be filtered");for(var l=0;l2)throw new Error("AdvancedFilters may not have more than two conditions. You passed: "+i.length);if(1===l.length&&"And"!==a)throw new Error('Logical Operator must be "And" when there is only one condition provided');return n.conditions=l,n}return q(e,t),e.prototype.toJSON=function(){var e=t.prototype.toJSON.call(this);return e.logicalOperator=this.logicalOperator,e.conditions=this.conditions,e},e.schemaUrl="http://powerbi.com/product/schema#advanced",e}($);e.AdvancedFilter=it,e.isFilterKeyColumnsTarget=a,e.isBasicFilterWithKeys=i,e.getFilterType=o,e.isMeasure=n,e.isColumn=l,e.isHierarchy=s;var ot;!function(t){t[t.Interactive=0]="Interactive",t[t.ResultOnly=1]="ResultOnly"}(ot=e.QnaMode||(e.QnaMode={}));var nt;!function(t){t[t.Summarized=0]="Summarized",t[t.Underlying=1]="Underlying"}(nt=e.ExportDataType||(e.ExportDataType={}));var lt;!function(t){t[t.Off=0]="Off",t[t.Presentation=1]="Presentation"}(lt=e.BookmarksPlayMode||(e.BookmarksPlayMode={})),e.CommonErrorCodes={TokenExpired:"TokenExpired",NotFound:"PowerBIEntityNotFound",InvalidParameters:"Invalid parameters",LoadReportFailed:"LoadReportFailed",NotAuthorized:"PowerBINotAuthorizedException",FailedToLoadModel:"ExplorationContainer_FailedToLoadModel_DefaultDetails"};var st=function(){function t(t){this.$schema=t}return t.prototype.toJSON=function(){return{$schema:this.$schema}},t}();e.Selector=st;var dt=function(t){function e(r){var a=t.call(this,e.schemaUrl)||this;return a.pageName=r,a}return q(e,t),e.prototype.toJSON=function(){var e=t.prototype.toJSON.call(this);return e.pageName=this.pageName,e},e.schemaUrl="http://powerbi.com/product/schema#pageSelector",e}(st);e.PageSelector=dt;var ut=function(t){function e(r){var a=t.call(this,e.schemaUrl)||this;return a.visualName=r,a}return q(e,t),e.prototype.toJSON=function(){var e=t.prototype.toJSON.call(this);return e.visualName=this.visualName,e},e.schemaUrl="http://powerbi.com/product/schema#visualSelector",e}(st);e.VisualSelector=ut;var pt=function(t){function e(e){var r=t.call(this,ut.schemaUrl)||this;return r.visualType=e,r}return q(e,t),e.prototype.toJSON=function(){var e=t.prototype.toJSON.call(this);return e.visualType=this.visualType,e},e.schemaUrl="http://powerbi.com/product/schema#visualTypeSelector",e}(st);e.VisualTypeSelector=pt;var ct=function(t){function e(e){var r=t.call(this,ut.schemaUrl)||this;return r.target=e,r}return q(e,t),e.prototype.toJSON=function(){var e=t.prototype.toJSON.call(this);return e.target=this.target,e},e.schemaUrl="http://powerbi.com/product/schema#slicerTargetSelector",e}(st);e.SlicerTargetSelector=ct;var ft;!function(t){t[t.Enabled=0]="Enabled",t[t.Disabled=1]="Disabled",t[t.Hidden=2]="Hidden"}(ft=e.CommandDisplayOption||(e.CommandDisplayOption={})),e.validateVisualSelector=u,e.validateSlicer=p,e.validateSlicerState=c,e.validatePlayBookmarkRequest=f,e.validateAddBookmarkRequest=h,e.validateApplyBookmarkByNameRequest=v,e.validateApplyBookmarkStateRequest=y,e.validateSettings=m,e.validateCustomPageSize=V,e.validateExtension=g,e.validateReportLoad=w,e.validateCreateReport=b,e.validateDashboardLoad=O,e.validateTileLoad=S,e.validatePage=T,e.validateFilter=E,e.validateSaveAsParameters=_,e.validateLoadQnaConfiguration=P,e.validateQnaInterpretInputData=x,e.validateExportDataRequest=A,e.validateVisualHeader=k,e.validateVisualSettings=F,e.validateCommandsSettings=C,e.validateCustomTheme=R},function(t,e,r){Object.defineProperty(e,"__esModule",{value:!0});var a=r(2),i=r(3),o=r(5),n=r(6),l=r(7),s=r(8),d=r(9),u=r(10),p=r(11),c=r(12),f=r(13),h=r(14),v=r(15),y=r(16),m=r(17),V=r(18),g=r(19),w=r(20),b=r(21),O=r(22),S=r(23),T=r(24);e.Validators={addBookmarkRequestValidator:new n.AddBookmarkRequestValidator,advancedFilterTypeValidator:new a.EnumValidator([0]),advancedFilterValidator:new l.AdvancedFilterValidator,anyArrayValidator:new a.ArrayValidator([new d.AnyOfValidator([new a.StringValidator,new a.NumberValidator,new a.BooleanValidator])]),anyFilterValidator:new d.AnyOfValidator([new l.BasicFilterValidator,new l.AdvancedFilterValidator,new l.IncludeExcludeFilterValidator,new l.NotSupportedFilterValidator,new l.RelativeDateFilterValidator,new l.TopNFilterValidator]),anyValueValidator:new d.AnyOfValidator([new a.StringValidator,new a.NumberValidator,new a.BooleanValidator]),applyBookmarkByNameRequestValidator:new n.ApplyBookmarkByNameRequestValidator,applyBookmarkStateRequestValidator:new n.ApplyBookmarkStateRequestValidator,applyBookmarkValidator:new d.AnyOfValidator([new n.ApplyBookmarkByNameRequestValidator,new n.ApplyBookmarkStateRequestValidator]),backgroundValidator:new a.EnumValidator([0,1]),basicFilterTypeValidator:new a.EnumValidator([1]),basicFilterValidator:new l.BasicFilterValidator,booleanArrayValidator:new a.BooleanArrayValidator,booleanValidator:new a.BooleanValidator,commandDisplayOptionValidator:new a.EnumValidator([0,1,2]),commandExtensionSelectorValidator:new d.AnyOfValidator([new w.VisualSelectorValidator,new w.VisualTypeSelectorValidator]),commandExtensionValidator:new i.CommandExtensionValidator,commandsSettingsArrayValidator:new a.ArrayValidator([new S.CommandsSettingsValidator]),commandsSettingsValidator:new S.CommandsSettingsValidator,conditionItemValidator:new l.ConditionItemValidator,customLayoutDisplayOptionValidator:new a.EnumValidator([0,1,2]),customLayoutValidator:new V.CustomLayoutValidator,customPageSizeValidator:new h.CustomPageSizeValidator,customThemeValidator:new T.CustomThemeValidator,dashboardLoadValidator:new c.DashboardLoadValidator,displayStateModeValidator:new a.EnumValidator([0,1]),displayStateValidator:new V.DisplayStateValidator,exportDataRequestValidator:new g.ExportDataRequestValidator,extensionArrayValidator:new a.ArrayValidator([new i.ExtensionValidator]),extensionPointsValidator:new i.ExtensionPointsValidator,extensionValidator:new i.ExtensionValidator,fieldRequiredValidator:new s.FieldRequiredValidator,filterColumnTargetValidator:new l.FilterColumnTargetValidator,filterConditionsValidator:new a.ArrayValidator([new l.ConditionItemValidator]),filterHierarchyTargetValidator:new l.FilterHierarchyTargetValidator,filterMeasureTargetValidator:new l.FilterMeasureTargetValidator,filterTargetValidator:new d.AnyOfValidator([new l.FilterColumnTargetValidator,new l.FilterHierarchyTargetValidator,new l.FilterMeasureTargetValidator]),filtersArrayValidator:new a.ArrayValidator([new d.AnyOfValidator([new l.BasicFilterValidator,new l.AdvancedFilterValidator,new l.RelativeDateFilterValidator])]),filtersValidator:new l.FilterValidator,includeExcludeFilterValidator:new l.IncludeExcludeFilterValidator,includeExludeFilterTypeValidator:new a.EnumValidator([3]),layoutTypeValidator:new a.EnumValidator([0,1,2,3]),loadQnaValidator:new v.LoadQnaValidator,menuExtensionValidator:new i.MenuExtensionValidator,menuLocationValidator:new a.EnumValidator([0,1]),notSupportedFilterTypeValidator:new a.EnumValidator([2]),notSupportedFilterValidator:new l.NotSupportedFilterValidator,numberArrayValidator:new a.NumberArrayValidator,numberValidator:new a.NumberValidator,pageLayoutValidator:new m.MapValidator([new a.StringValidator],[new V.VisualLayoutValidator]),pageSizeTypeValidator:new a.EnumValidator([0,1,2,3,4,5]),pageSizeValidator:new h.PageSizeValidator,pageValidator:new h.PageValidator,pageViewFieldValidator:new h.PageViewFieldValidator,pagesLayoutValidator:new m.MapValidator([new a.StringValidator],[new V.PageLayoutValidator]),permissionsValidator:new a.EnumValidator([0,1,2,4,7]),playBookmarkRequestValidator:new n.PlayBookmarkRequestValidator,qnaInterpretInputDataValidator:new v.QnaInterpretInputDataValidator,qnaSettingValidator:new v.QnaSettingsValidator,relativeDateFilterOperatorValidator:new a.EnumValidator([0,1,2]),relativeDateFilterTimeUnitTypeValidator:new a.EnumValidator([0,1,2,3,4,5,6]),relativeDateFilterTypeValidator:new a.EnumValidator([4]),relativeDateFilterValidator:new l.RelativeDateFilterValidator,reportCreateValidator:new p.ReportCreateValidator,reportLoadValidator:new u.ReportLoadValidator,saveAsParametersValidator:new y.SaveAsParametersValidator,settingsValidator:new o.SettingsValidator,singleCommandSettingsValidator:new S.SingleCommandSettingsValidator,slicerSelectorValidator:new d.AnyOfValidator([new w.VisualSelectorValidator,new w.SlicerTargetSelectorValidator]),slicerStateValidator:new b.SlicerStateValidator,slicerTargetValidator:new d.AnyOfValidator([new l.FilterColumnTargetValidator,new l.FilterHierarchyTargetValidator,new l.FilterMeasureTargetValidator,new l.FilterKeyColumnsTargetValidator,new l.FilterKeyHierarchyTargetValidator]),slicerValidator:new b.SlicerValidator,stringArrayValidator:new a.StringArrayValidator,stringValidator:new a.StringValidator,tileLoadValidator:new f.TileLoadValidator,tokenTypeValidator:new a.EnumValidator([0,1]),topNFilterTypeValidator:new a.EnumValidator([5]),topNFilterValidator:new l.TopNFilterValidator,viewModeValidator:new a.EnumValidator([0,1]),visualCommandSelectorValidator:new d.AnyOfValidator([new w.VisualSelectorValidator,new w.VisualTypeSelectorValidator]),visualHeaderSelectorValidator:new d.AnyOfValidator([new w.VisualSelectorValidator,new w.VisualTypeSelectorValidator]),visualHeaderSettingsValidator:new O.VisualHeaderSettingsValidator,visualHeaderValidator:new O.VisualHeaderValidator,visualHeadersValidator:new a.ArrayValidator([new O.VisualHeaderValidator]),visualLayoutValidator:new V.VisualLayoutValidator,visualSelectorValidator:new w.VisualSelectorValidator,visualSettingsValidator:new O.VisualSettingsValidator,visualTypeSelectorValidator:new w.VisualTypeSelectorValidator}},function(t,e){var r=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])};return function(e,r){function a(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(a.prototype=r.prototype,new a)}}();Object.defineProperty(e,"__esModule",{value:!0});var a=function(){function t(){}return t.prototype.validate=function(t,e,r){return null==t?null:"object"!=typeof t||Array.isArray(t)?[{message:void 0!==r?r+" must be an object":"input must be an object",path:e,keyword:"type"}]:null},t}();e.ObjectValidator=a;var i=function(){function t(t){this.itemValidators=t}return t.prototype.validate=function(t,e,r){if(null==t)return null;if(!Array.isArray(t))return[{message:r+" property is invalid",path:(e?e+".":"")+r,keyword:"type"}];for(var a=0;a2&&"[]"===n.slice(l-2)&&(s=!0,n=n.slice(0,l-2),r[n]||(r[n]=[])),i=o[1]?w(o[1]):""),s?r[n].push(i):r[n]=i}return r},recognize:function(t){var e,r,a,i=[this.rootState],o={},n=!1;if(a=t.indexOf("?"),a!==-1){var l=t.substr(a+1,t.length);t=t.substr(0,a),o=this.parseQueryString(l)}for(t=decodeURI(t),"/"!==t.charAt(0)&&(t="/"+t),e=t.length,e>1&&"/"===t.charAt(e-1)&&(t=t.substr(0,e-1),n=!0),r=0;rthis.config; this.createConfig = { - datasetId: config.datasetId || this.getId(), accessToken: config.accessToken, - tokenType: config.tokenType, + datasetId: config.datasetId || this.getId(), + groupId: config.groupId, settings: settings, - groupId: config.groupId + tokenType: config.tokenType, + theme: config.theme } } diff --git a/src/embed.ts b/src/embed.ts index f5c1ce1b..0f41863b 100644 --- a/src/embed.ts +++ b/src/embed.ts @@ -58,6 +58,7 @@ export interface IEmbedConfiguration extends IEmbedConfigurationBase { dashboardId?: string; height?: number; width?: number; + theme?: models.IReportTheme; } export interface IVisualEmbedConfiguration extends IEmbedConfiguration { diff --git a/src/report.ts b/src/report.ts index e2aa7902..488ac645 100644 --- a/src/report.ts +++ b/src/report.ts @@ -365,6 +365,38 @@ export class Report extends embed.Embed implements IReportNode, IFilterable { }); } + /** + * Apply a theme to the report + * + * ```javascript + * report.applyTheme(theme); + * ``` + */ + applyTheme(theme: models.IReportTheme): Promise { + return this.applyThemeInternal(theme); + } + + /** + * Reset and apply the default theme of the report + * + * ```javascript + * report.resetTheme(); + * ``` + */ + resetTheme(): Promise { + return this.applyThemeInternal({}); + } + + private applyThemeInternal(theme: models.IReportTheme): Promise { + return this.service.hpm.put('/report/theme', theme, { uid: this.config.uniqueId }, this.iframe.contentWindow) + .then(response => { + return response.body; + }) + .catch(response => { + throw response.body; + }); + } + private viewModeToString(viewMode: models.ViewMode): string { let mode: string; switch (viewMode) { diff --git a/test/test.spec.ts b/test/test.spec.ts index e6b7d043..86041a4c 100644 --- a/test/test.spec.ts +++ b/test/test.spec.ts @@ -639,6 +639,40 @@ describe('service', function () { // Assert expect(report.createConfig.datasetId).toEqual(testDatasetId); }); + + it('theme should be in create config if exists is embedConfig', function () { + // Arrange + + const testDatasetId = "ABC123"; + const accessToken = 'ABC123'; + const theme = {themeJson: {name: "Theme ABC 123"}}; + const embedUrl = `https://app.powerbi.com/reportEmbed?datasetId=${testDatasetId}`; + const $reportContainer = $(`
`) + .appendTo('#powerbi-fixture'); + + // Act + const report = powerbi.createReport($reportContainer[0], { embedUrl: embedUrl, accessToken: accessToken, theme: theme }); + + // Assert + expect(report.createConfig.theme).toEqual(theme); + }); + + it('theme should be undefined in create config if not exists is embedConfig', function () { + // Arrange + + const testDatasetId = "ABC123"; + const accessToken = 'ABC123'; + const theme = {themeJson: {name: "Theme ABC 123"}}; + const embedUrl = `https://app.powerbi.com/reportEmbed?datasetId=${testDatasetId}`; + const $reportContainer = $(`
`) + .appendTo('#powerbi-fixture'); + + // Act + const report = powerbi.createReport($reportContainer[0], { embedUrl: embedUrl, accessToken: accessToken }); + + // Assert + expect(report.createConfig.theme).toBeUndefined(); + }); }); describe('reports', function () { @@ -725,6 +759,40 @@ describe('service', function () { // Assert expect((report.config).id).toEqual(testReportId); }); + + it('theme should be in report config if exists is embedConfig', function () { + // Arrange + const testReportId = "ABC123"; + const embedUrl = `https://app.powerbi.com/reportEmbed?reportId=${testReportId}`; + const $reportContainer = $(`
`) + .appendTo('#powerbi-fixture'); + + const theme = {themeJson: {name: "Theme ABC 123"}}; + const configuration: embed.IEmbedConfiguration = { theme: theme }; + + // Act + const report = powerbi.embed($reportContainer[0], configuration); + + // Assert + expect((report.config).theme).toEqual(theme); + }); + + it('theme should be undefined in report config if not exists is embedConfig', function () { + // Arrange + const testReportId = "ABC123"; + const embedUrl = `https://app.powerbi.com/reportEmbed?reportId=${testReportId}`; + const $reportContainer = $(`
`) + .appendTo('#powerbi-fixture'); + + const theme = {themeJson: {name: "Theme ABC 123"}}; + const configuration: embed.IEmbedConfiguration = {}; + + // Act + const report = powerbi.embed($reportContainer[0], configuration); + + // Assert + expect((report.config).theme).toBeUndefined(); + }); }); xdescribe('tiles', function () { @@ -3795,6 +3863,53 @@ describe('SDK-to-HPM', function () { }); }); }); + + describe('theme', function () { + it('report.applyTheme(theme) sends PUT /report/theme with theme in body', function () { + // Arrange + const testData = { + theme: { + themeJson: { + name: "Theme ABC 123" + } + }, + response: { + body: null + } + }; + + spyHpm.post.and.returnValue(Promise.resolve(testData.response)); + report.applyTheme(testData.theme) + .then(() => { + spyHpm.post.calls.reset(); + + // Act + report.reload(); + + // Assert + expect(spyHpm.post).toHaveBeenCalledWith('/report/load', jasmine.objectContaining(testData.theme), { uid: uniqueId, sdkSessionId: sdkSessionId }, iframe.contentWindow); + }); + }); + + it('report.resetTheme() sends PUT /report/theme with empty object as theme in body', function () { + // Arrange + const response = { + body: null + }; + + spyHpm.post.and.returnValue(Promise.resolve(response)); + report.resetTheme() + .then(() => { + spyHpm.post.calls.reset(); + + // Act + report.reload(); + + // Assert + expect(spyHpm.post).toHaveBeenCalledWith('/report/load', jasmine.objectContaining({}), { uid: uniqueId, sdkSessionId: sdkSessionId }, iframe.contentWindow); + }); + }); + }); }); describe('SDK-to-Router (Event subscription)', function () {