Skip to content

Commit d295039

Browse files
committed
Merged PR 17832: add isSaved API method
add isSaved to report and create
1 parent c97e814 commit d295039

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

src/create.ts

+13
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,19 @@ export class Create extends embed.Embed {
5757
}
5858
}
5959

60+
/**
61+
* checks if the report is saved.
62+
*
63+
* ```javascript
64+
* report.isSaved()
65+
* ```
66+
*
67+
* @returns {Promise<boolean>}
68+
*/
69+
isSaved(): Promise<boolean> {
70+
return utils.isSavedInternal(this.service.hpm, this.config.uniqueId, this.iframe.contentWindow);
71+
}
72+
6073
/**
6174
* Adds the ability to get datasetId from url.
6275
* (e.g. http://embedded.powerbi.com/appTokenReportEmbed?datasetId=854846ed-2106-4dc2-bc58-eb77533bf2f1).

src/report.ts

+14-2
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,19 @@ export class Report extends embed.Embed implements IReportNode, IFilterable {
366366
}
367367

368368
/**
369-
* Apply a theme to the report
369+
* checks if the report is saved.
370+
*
371+
* ```javascript
372+
* report.isSaved()
373+
* ```
374+
*
375+
* @returns {Promise<boolean>}
376+
*/
377+
isSaved(): Promise<boolean> {
378+
return utils.isSavedInternal(this.service.hpm, this.config.uniqueId, this.iframe.contentWindow);
379+
}
380+
381+
/* Apply a theme to the report
370382
*
371383
* ```javascript
372384
* report.applyTheme(theme);
@@ -394,7 +406,7 @@ export class Report extends embed.Embed implements IReportNode, IFilterable {
394406
})
395407
.catch(response => {
396408
throw response.body;
397-
});
409+
});
398410
}
399411

400412
private viewModeToString(viewMode: models.ViewMode): string {

src/util.ts

+18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { HttpPostMessage } from 'http-post-message';
12

23
/**
34
* Raises a custom event with event data on the specified HTML element.
@@ -144,3 +145,20 @@ export function addParamToUrl(url: string, paramName: string, value: string): st
144145
url += parameterPrefix + paramName + '=' + value;
145146
return url;
146147
}
148+
149+
/**
150+
* Checks if the report is saved.
151+
*
152+
* @export
153+
* @param {HttpPostMessage} hpm
154+
* @param {string} uid
155+
* @param {Window} contentWindow
156+
* @returns {Promise<boolean>}
157+
*/
158+
export function isSavedInternal(hpm: HttpPostMessage, uid: string, contentWindow: Window): Promise<boolean> {
159+
return hpm.get<boolean>('/report/hasUnsavedChanges', { uid }, contentWindow)
160+
.then(response => !response.body,
161+
response => {
162+
throw response.body;
163+
});
164+
}

0 commit comments

Comments
 (0)