Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Place your settings in this file to overwrite default and user settings.
{
"editor.tabSize": 4,
"editor.insertSpaces": true

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unrelated but I noticed half of the files are using 2 spaces and others using 4. Going to reformat everything to 2 space after the code review is complete, but didn't want to do it now since it introduces lot of white-space change noise in the review.

}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
},
"dependencies": {
"http-post-message": "^0.2.0",
"powerbi-models": "^0.5.0",
"powerbi-models": "^0.7.2",
"powerbi-router": "^0.1.2",
"window-post-message-proxy": "^0.2.1"
},
Expand Down
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const config = {
version: '2.0.0-beta.7',
version: '2.0.0-beta.8',
type: 'js'
};

Expand Down
11 changes: 9 additions & 2 deletions src/embed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ export abstract class Embed {
* navContentPaneEnabled: false
* },
* pageName: "DefaultPage",
* filte: "DefaultReportFilter"
* filters: [
* {
* ... DefaultReportFilter ...
* }
* ]
* })
* .catch(error => { ... });
* ```
Expand All @@ -109,7 +113,10 @@ export abstract class Embed {
}

return this.service.hpm.post<void>('/report/load', config, { uid: this.config.uniqueId }, this.iframe.contentWindow)
.catch(response => {
.then(response => {
return response.body;
},
response => {
throw response.body;
});
}
Expand Down
7 changes: 7 additions & 0 deletions src/ifilterable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as models from 'powerbi-models';

export interface IFilterable {
getFilters(): Promise<(models.IBasicFilter | models.IAdvancedFilter)[]>;
setFilters(filters: (models.IBasicFilter | models.IAdvancedFilter)[]): Promise<void>;
removeFilters(): Promise<void>;
}
121 changes: 121 additions & 0 deletions src/page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import { IFilterable } from './ifilterable';
import { IReportNode } from './report';
import { Visual } from './visual';
import * as models from 'powerbi-models';

export interface IPageNode {
report: IReportNode;
name: string;
}

export class Page implements IPageNode, IFilterable {
report: IReportNode;
name: string;
// This can be undefined in cases where page is created manually
displayName: string;

constructor(report: IReportNode, name: string, displayName?: string) {
this.report = report;
this.name = name;
this.displayName = displayName;
}

/**
* Gets all page level filters within report
*
* ```javascript
* page.getFilters()
* .then(pages => { ... });
* ```
*/
getFilters() {
return this.report.service.hpm.get<models.IFilter[]>(`/report/pages/${this.name}/filters`, { uid: this.report.config.uniqueId }, this.report.iframe.contentWindow)
.then(response => response.body,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or is this supposed to be a catch block?

response => {
throw response.body;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming these throw statements will be replace once we have implementations for them on the WFE.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not understanding the relationship with WFE code. For both fulfilled and rejected responses from the server we want to return the body of the response instead of just the response. For the fulfill case the body should be a list of filters, and for the rejected case it should be an error object. The throw is needed to preserve rejected state for the chain.

});
}

/**
* Gets all the visuals on the page.
*
* ```javascript
* page.getVisuals()
* .then(visuals => { ... });
* ```
*/
getVisuals(): Promise<Visual[]> {
return this.report.service.hpm.get<models.IVisual[]>(`/report/pages/${this.name}/visuals`, { uid: this.report.config.uniqueId }, this.report.iframe.contentWindow)
.then(response => {
return response.body
.map(visual => {
return new Visual(this, visual.name);
});
}, response => {
throw response.body;
});
}

/**
* Remove all filters on this page within the report
*
* ```javascript
* page.removeFilters();
* ```
*/
removeFilters() {
return this.setFilters([]);
}

/**
* Make the current page the active page of the report.
*
* ```javascripot
* page.setActive();
* ```
*/
setActive() {
const page: models.IPage = {
name: this.name,
displayName: null
};

return this.report.service.hpm.put<models.IError[]>('/report/pages/active', page, { uid: this.report.config.uniqueId }, this.report.iframe.contentWindow)
.catch(response => {
throw response.body;
});
}

/**
* Sets all filters on the current page.
*
* ```javascript
* page.setFilters(filters);
* .catch(errors => { ... });
* ```
*/
setFilters(filters: (models.IBasicFilter | models.IAdvancedFilter)[]) {
return this.report.service.hpm.put<models.IError[]>(`/report/pages/${this.name}/filters`, filters, { uid: this.report.config.uniqueId }, this.report.iframe.contentWindow)
.catch(response => {
throw response.body;
});
}

/**
* Creates new Visual object given a name of the visual.
*
* Normally you would get Visual objects by calling `page.getVisuals()` but in the case
* that the visual name is known and you want to perform an action on a visaul such as setting a filters
* without having to retrieve it first you can create it directly.
*
* Note: Since you are creating the visual manually there is no guarantee that the visual actually exists in the report and the subsequence requests could fail.
*
* ```javascript
* const visual = report.page('ReportSection1').visual('BarChart1');
* visual.setFilters(filters);
* ```
*/
visual(name: string): Visual {
return new Visual(this, name);
}
}
Loading