import { HttpPostMessage , IHttpPostMessageResponse } from 'http-post-message' ; import { Page , VisualDescriptor } from 'powerbi-client' ; import { ICreateVisualRequest , ICreateVisualResponse , IVisual , IVisualLayout } from 'powerbi-models' ; import { Errors } from '../errors' ; import { IVisualResponse } from '../models' ; import { IPowerBIClientExtension } from './powerBIClientExtension' ; hidden export class implements IPowerBIClientExtension export class PageExtensions implements IPowerBIClientExtension { hidden private static post < T > ( page , url , body ) { const hpm = PageExtensions . hpm ( page ) ; const uid = PageExtensions . uid ( page ) ; const contentWindow = PageExtensions . contentWindow ( page ) ; return hpm . post < T > ( url , body , { uid } , contentWindow ) . then ( ( response ) => { return response . body ; } , ( response ) => { throw response . body ; } ) ; } hidden private static contentWindow ( page ) { return page . report . iframe . contentWindow ; } hidden private static uid ( page ) { return page . report . config . uniqueId ; } hidden private static hpm ( page ) { return page . report . service . hpm ; } hidden initialize ( ) { if ( Page == null ) { console . error ( Errors . PowerBIClientIsNotInitialized ) ; return ; } Page . prototype . createVisual = function ( this , visualType , layout ? , autoFocus ? ) : Promise < IVisualResponse > { const createVisualRequest = { visualType , layout , autoFocus } ; return PageExtensions . post < ICreateVisualResponse > ( this , `/report/pages/${ this . name }/createVisual` , createVisualRequest ) . then ( ( responseBody ) => { const visual = responseBody . visual ; const visualResponse = { visual : new VisualDescriptor ( this , visual . name , visual . title , visual . type , visual . layout ) } ; return visualResponse ; } , ( responseBody ) => { throw responseBody ; } ) ; } ; Page . prototype . deleteVisual = function ( this , visualName ) : Promise < void > { return PageExtensions . post < void > ( this , `/report/pages/${ this . name }/deleteVisual` , { visualName } ) ; } ; } }