Repository navigation
Expand file tree
/
Copy pathfunction_mapping.js
More file actions
86 lines (73 loc) · 2.81 KB
/
Copy pathfunction_mapping.js
File metadata and controls
86 lines (73 loc) · 2.81 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
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,
_Page_GetVisuals: 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) {
const sampleId = GetSession(SessionKeys.SampleId);
const isSample = sampleId && (_session.embedId === sampleId);
return ((funcName === '_Report_save' || funcName === '_Report_saveAs') && isSample);
}
function IsBasicMock(funcName) {
const sampleId = GetSession(SessionKeys.SampleId);
const isSample = sampleId && (_session.embedId === sampleId);
return ((funcName === '_Embed_BasicEmbed' || funcName === '_Embed_BasicEmbed_EditMode') && isSample);
}
function IsCreateMock(funcName) {
const sampleId = GetSession(SessionKeys.SampleId);
const isSample = sampleId && (_session.embedId === sampleId);
return (funcName === '_Embed_Create' && isSample);
}
function IsNotSupported(funcName) {
if (powerbi.embeds.length === 0) {
return false
}
const notReportMatch = funcName.match(/Dashboard|Tile|Qna|Visual|Mobile|PaginatedReport/);
if (notReportMatch) {
return false;
}
// Get a reference to the embedded element
const container = '#embedContainer';
let embed = powerbi.get($(container)[0]);
if (embed.config.type !== 'create') {
return false;
}
const runFunc = mockDict[funcName];
return (runFunc && runFunc === datasetNotSupported) ? true : false;
}
function IsMock(funcName) {
return (IsBasicMock(funcName) || IsSaveMock(funcName) || IsCreateMock(funcName) || IsNotSupported(funcName));
}
function mapFunc(func) {
const funcName = getFuncName(func);
return IsMock(funcName) ? mockDict[funcName] : func;
}
function getFuncName(func) {
let 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;
}