Repository navigation
Expand file tree
/
Copy pathutils.js
More file actions
249 lines (206 loc) · 7.31 KB
/
Copy pathutils.js
File metadata and controls
249 lines (206 loc) · 7.31 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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
var currentCode = "";
const interactIndicationTimeout = 5000;
const elementClickedTimeout = 250;
const textCodeTimeout = 100;
function BodyCodeOfFunction(func) {
let lines = func.toString().split('\n');
lines = lines.slice(1, lines.length-1);
for (let i = 0; i < lines.length; ++i)
{
// remove trailing spaces.
lines[i] = lines[i].substring(4);
}
return lines.join('\n');
}
function LoadCodeArea(divSelector, initialFunctionCode) {
$(divSelector).load("code_area.html", function() {
SetCode(initialFunctionCode);
});
}
function LoadLogWindow(divSelector) {
$(divSelector).load("log_window.html");
}
function SetCode(func) {
currentCode = BodyCodeOfFunction(func);
$("#highlighter").empty();
var txtCodeElement = document.createElement("div");
txtCodeElement.setAttribute("id", "txtCode");
txtCodeElement.setAttribute("style", "display: none;");
var preElement = document.createElement("pre");
preElement.setAttribute("class", "brush: js; gutter: false;");
var codeElement = document.createTextNode(currentCode);
preElement.appendChild(codeElement);
txtCodeElement.appendChild(preElement);
$("#highlighter").append(txtCodeElement);
var scriptElement = document.createElement("script");
scriptElement.setAttribute("type", "text/javascript");
scriptElement.setAttribute("src", "syntaxHighlighter/syntaxhighlighter.js");
$("#highlighter").append(scriptElement);
setTimeout(function() {
$("#txtCode").show();
}, textCodeTimeout);
if (func != "") {
let runFunc = mapFunc(func);
let funcName = getFuncName(runFunc);
if (funcName.match(/Embed/)) {
let oldFunc = runFunc;
runFunc = function() {
oldFunc();
SetSession(SessionKeys.EntityIsAlreadyEmbedded, true);
$('#interact-tab').addClass('enableTransition');
setTimeout(function() {
$('#interact-tab').addClass('changeColor');
}, interactIndicationTimeout);
}
}
$('#btnRunCode').off('click');
$('#btnRunCode').click(function() {
showEmbedContainer();
removeIframeIfUrlIsChanged();
elementClicked('#btnRunCode');
trackEvent(TelemetryEventName.RunClick, { EmbedType: GetSession(SessionKeys.EntityType), TokenType: GetSession(SessionKeys.TokenType), ApiUsed: funcName });
runFunc();
});
// TODO: add indication to click Interact tab on first embedding
}
}
function CopyCode() {
const id = "clipboard-textarea";
let textarea = document.getElementById(id);
if (!textarea) {
textarea = document.createElement("textarea");
textarea.id = id;
document.querySelector("body").appendChild(textarea);
}
textarea.value = currentCode;
CopyTextArea('#' + id, "#btnRunCopyCode");
trackEvent(TelemetryEventName.CopyCode, {});
}
function CopyResponseWindow() {
CopyTextArea("#txtResponse", "#btnCopyResponse");
trackEvent(TelemetryEventName.CopyLog, {});
}
function CopyTextArea(textAreaSelector, buttonSelector) {
$(textAreaSelector).select();
document.execCommand('copy');
window.getSelection().removeAllRanges();
// Set focus on copy button - this will deselect text in copied area.
$(buttonSelector).focus();
}
function ClearTextArea(textAreaSelector) {
$(textAreaSelector).val("");
}
function getEmbedContainerID(entityType) {
switch (entityType) {
case EntityType.Dashboard:
return "dashboardContainer";
case EntityType.Tile:
return "tileContainer";
case EntityType.Qna:
return "qnaContainer";
case EntityType.PaginatedReport:
return "paginatedReportContainer";
default:
return "embedContainer";
}
}
function getEmbedContainerClassPrefix(entityType) {
switch (entityType) {
case EntityType.Visual:
return ".visual";
case EntityType.Dashboard:
return ".dashboard";
case EntityType.Tile:
return ".tile";
case EntityType.Qna:
return ".qna";
case EntityType.PaginatedReport:
return ".paginatedReport";
default:
return ".report";
}
}
function getActiveEmbedContainer() {
const entityType = GetSession(SessionKeys.EntityType);
const classPrefix = getEmbedContainerClassPrefix(entityType);
const activeContainer = classPrefix + ($(".desktop-view").hasClass(active_class) ? 'Container' : 'MobileContainer');
return $(activeContainer)[0];
}
function getEntityTypeFromParameter(urlParam) {
switch (urlParam) {
case "visual":
return EntityType.Visual;
case "dashboard":
return EntityType.Dashboard;
case "tile":
return EntityType.Tile;
case "qna":
return EntityType.Qna;
case "rdl":
return EntityType.PaginatedReport;
default:
return EntityType.Report;
}
}
function elementClicked(element) {
$(element).addClass('elementClicked');
setTimeout(function() {
$(element).removeClass('elementClicked');
}, elementClickedTimeout);
}
function showEmbedContainer() {
const activeContainer = getActiveEmbedContainer();
$(activeContainer).css({"visibility":"visible"});
}
function removeIframeIfUrlIsChanged() {
const activeContainer = getActiveEmbedContainer();
if (!activeContainer || !activeContainer.powerBiEmbed || !activeContainer.powerBiEmbed.iframe) {
return;
}
let existingIframeUrl = removeArgFromUrl(activeContainer.powerBiEmbed.iframe.src, "uid");
existingIframeUrl = removeArgFromUrl(existingIframeUrl, "isMobile");
let embedUrl = GetSession(SessionKeys.EmbedUrl);
if (embedUrl !== existingIframeUrl) {
// textbox has changed, delete the iframe and avoid the bootstrap.
powerbi.reset(activeContainer);
}
}
function SetAuthoringPageActive(report) {
return new Promise(function(resolve, reject) {
// Get all report pages
report.getPages().then(function (pages) {
// Find authoring page
var authoringPage = pages.filter(function (page) {
return page.name === "ReportSection6da8317ad6cbcae5b3bb";
})[0];
// If active page is not authoring page, navigate to authoring page
if (authoringPage.isActive) {
resolve(authoringPage);
} else {
authoringPage.setActive().then(function () {
Log.logText("Page was set to authoring page.");
resolve(authoringPage);
}).catch(function (errors) {
reject(errors);
});
}
}).catch(function (errors) {
reject(errors);
});
});
}
function removeArgFromUrl(url, arg) {
const argRegEx = new RegExp(arg + '="?([^&]+)"?')
const argMatch = url.match(argRegEx);
if (argMatch) {
return url.replace("&" + argMatch[0], "");
}
return url;
}
function getRandomValue() {
// window.msCrypto for IE
var cryptoObj = window.crypto || window.msCrypto;
var randomValueArray = new Uint32Array(1);
cryptoObj.getRandomValues(randomValueArray);
return randomValueArray[0];
}