forked from microsoft/PowerBI-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpage.ts
More file actions
214 lines (197 loc) · 5.41 KB
/
page.ts
File metadata and controls
214 lines (197 loc) · 5.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
import { IFilterable } from './ifilterable';
import { IReportNode } from './report';
import { VisualDescriptor } from './visualDescriptor';
import * as models from 'powerbi-models';
import * as utils from './util';
import * as errors from './errors';
/**
* A Page node within a report hierarchy
*
* @export
* @interface IPageNode
*/
export interface IPageNode {
report: IReportNode;
name: string;
}
/**
* A Power BI report page
*
* @export
* @class Page
* @implements {IPageNode}
* @implements {IFilterable}
*/
export class Page implements IPageNode, IFilterable {
/**
* The parent Power BI report that this page is a member of
*
* @type {IReportNode}
*/
report: IReportNode;
/**
* The report page name
*
* @type {string}
*/
name: string;
/**
* The user defined display name of the report page, which is undefined if the page is created manually
*
* @type {string}
*/
displayName: string;
/**
* Is this page is the active page
*
* @type {boolean}
*/
isActive: boolean;
/**
* The visibility of the page.
* 0 - Always Visible
* 1 - Hidden in View Mode
*
* @type {models.SectionVisibility}
*/
visibility: models.SectionVisibility;
/**
* Page size as saved in the report.
* @type {models.ICustomPageSize}
*/
defaultSize: models.ICustomPageSize;
/**
* Page display options as saved in the report.
* @type {models.ICustomPageSize}
*/
defaultDisplayOption: models.DisplayOption;
/**
* Creates an instance of a Power BI report page.
*
* @param {IReportNode} report
* @param {string} name
* @param {string} [displayName]
* @param {boolean} [isActivePage]
* @param {models.SectionVisibility} [visibility]
*/
constructor(report: IReportNode, name: string, displayName?: string, isActivePage?: boolean, visibility?: models.SectionVisibility, defaultSize?: models.ICustomPageSize, defaultDisplayOption?: models.DisplayOption) {
this.report = report;
this.name = name;
this.displayName = displayName;
this.isActive = isActivePage;
this.visibility = visibility;
this.defaultSize = defaultSize;
this.defaultDisplayOption = defaultDisplayOption;
}
/**
* Gets all page level filters within the report.
*
* ```javascript
* page.getFilters()
* .then(filters => { ... });
* ```
*
* @returns {(Promise<models.IFilter[]>)}
*/
getFilters(): Promise<models.IFilter[]> {
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,
response => {
throw response.body;
});
}
/**
* Removes all filters from this page of the report.
*
* ```javascript
* page.removeFilters();
* ```
*
* @returns {Promise<void>}
*/
removeFilters(): Promise<void> {
return this.setFilters([]);
}
/**
* Makes the current page the active page of the report.
*
* ```javascripot
* page.setActive();
* ```
*
* @returns {Promise<void>}
*/
setActive(): Promise<void> {
const page: models.IPage = {
name: this.name,
displayName: null,
isActive: true
};
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 => { ... });
* ```
*
* @param {(models.IFilter[])} filters
* @returns {Promise<void>}
*/
setFilters(filters: models.IFilter[]): Promise<void> {
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;
});
}
/**
* Gets all the visuals on the page.
*
* ```javascript
* page.getVisuals()
* .then(visuals => { ... });
* ```
*
* @returns {Promise<VisualDescriptor[]>}
*/
getVisuals(): Promise<VisualDescriptor[]> {
if (utils.isRDLEmbed(this.report.config.embedUrl)) {
return Promise.reject(errors.APINotSupportedForRDLError);
}
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 VisualDescriptor(this, visual.name, visual.title, visual.type, visual.layout);
});
}, response => {
throw response.body;
});
}
/**
* Checks if page has layout.
*
* ```javascript
* page.hasLayout(layoutType)
* .then(hasLayout: boolean => { ... });
* ```
*
* @returns {(Promise<boolean>)}
*/
hasLayout(layoutType): Promise<boolean> {
if (utils.isRDLEmbed(this.report.config.embedUrl)) {
return Promise.reject(errors.APINotSupportedForRDLError);
}
let layoutTypeEnum = models.LayoutType[layoutType];
return this.report.service.hpm.get<boolean>(`/report/pages/${this.name}/layoutTypes/${layoutTypeEnum}`, { uid: this.report.config.uniqueId }, this.report.iframe.contentWindow)
.then(response => response.body,
response => {
throw response.body;
});
}
}