forked from microsoft/PowerBI-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction_mapping.js
More file actions
75 lines (63 loc) · 2.5 KB
/
Copy pathfunction_mapping.js
File metadata and controls
75 lines (63 loc) · 2.5 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
const mockDict = {
_Report_GetPages: datasetNotSupported,
_Report_SetPage: datasetNotSupported,
_Report_SetFilters: datasetNotSupported,
_Report_GetFilters: datasetNotSupported,
_Report_RemoveFilters: datasetNotSupported,
_Report_PrintCurrentReport: datasetNotSupported,
_Report_UpdateSettings: datasetNotSupported,
_Report_Reload: datasetNotSupported,
_Page_SetActive: datasetNotSupported,
_Page_SetFilters: datasetNotSupported,
_Page_GetFilters: datasetNotSupported,
_Page_RemoveFilters: datasetNotSupported,
_Report_switchModeEdit: datasetNotSupported,
_Report_switchModeView: datasetNotSupported,
_Embed_BasicEmbed: _Mock_Embed_BasicEmbed_ViewMode,
_Embed_BasicEmbed_EditMode: _Mock_Embed_BasicEmbed_EditMode,
_Report_save: _Mock_Report_save,
_Report_saveAs: _Mock_Report_save,
_Embed_Create: _Mock_Embed_Create
};
function datasetNotSupported() {
Log.logText('Operation not supported for dataset')
}
function IsSaveMock(funcName) {
return ((funcName === '_Report_save' || funcName === '_Report_saveAs') && (
_session.embedId === 'c52af8ab-0468-4165-92af-dc39858d66ad' /*Sample Report*/ ||
_session.embedId === '1ee0b264-b280-43f1-bbb7-9d8bd2d03a78' /*Sample dataset*/ ));
}
function IsBasicMock(funcName) {
return ((funcName === '_Embed_BasicEmbed' || funcName === '_Embed_BasicEmbed_EditMode') && _session.embedId === 'c52af8ab-0468-4165-92af-dc39858d66ad');
}
function IsCreateMock(funcName) {
return (funcName === '_Embed_Create' && _session.embedId === '1ee0b264-b280-43f1-bbb7-9d8bd2d03a78');
}
function IsNotSupported(funcName) {
if (powerbi.embeds.length === 0) {
return false
}
// Get a reference to the embedded element
var embed = powerbi.get($('#reportContainer')[0]);
if (embed.config.type !== 'create') {
return false;
}
var runFunc = mockDict[funcName];
return (runFunc && runFunc === datasetNotSupported) ? true : false;
}
function IsMock(funcName) {
return (IsBasicMock(funcName) || IsSaveMock(funcName) || IsCreateMock(funcName) || IsNotSupported(funcName));
}
function mapFunc(func) {
var funcName = getFuncName(func);
return IsMock(funcName) ? mockDict[funcName] : func;
}
function getFuncName(func) {
var funcName = func.name;
if (!funcName)
{
// in IE, func.name is invalid method. so, function name should be extracted manually.
funcName = func.toString().match(/^function\s*([^\s(]+)/)[1];
}
return funcName;
}