forked from microsoft/PowerBI-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsession_utils.js
More file actions
76 lines (67 loc) · 2.08 KB
/
Copy pathsession_utils.js
File metadata and controls
76 lines (67 loc) · 2.08 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
var _session = {};
const SessionKeys = {
AccessToken : "accessToken",
EmbedUrl : "embedUrl",
EmbedId : "embedId",
GroupId : "groupId",
IsSampleReport: "isSampleReport",
QnaQuestion: "qnaQuestion",
EntityIsAlreadyEmbedded: "EntityIsAlreadyEmbedded",
};
function GetParameterByName(name, url) {
if (!url) {
url = window.location.href;
}
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
function SetSession(key, value) {
// This is a temporal solution for session (which is cleared on reload). Should be replaced with a real session.
_session[key] = value;
}
function GetSession(key) {
// This is a temporal solution for session (which is cleared on reload). Should be replaced with a real session.
return _session[key];
}
function UpdateSession(button, sessionKey) {
var value = $(button).val();
if (value)
{
SetSession(sessionKey, value);
}
}
function SetTextBoxesFromSessionOrUrlParam(accessTokenSelector, embedUrlSelector, embedIdSelector) {
var accessToken = GetParameterByName(SessionKeys.AccessToken);
if (!accessToken)
{
accessToken = GetSession(SessionKeys.AccessToken);
}
var embedUrl = GetParameterByName(SessionKeys.EmbedUrl);
if (!embedUrl)
{
embedUrl = GetSession(SessionKeys.EmbedUrl);
} else {
var groupId = GetParameterByName(SessionKeys.GroupId);
if(groupId)
{
if (embedUrl.indexOf("?") != -1)
{
embedUrl += "&groupId=" + groupId;
} else {
embedUrl += "?groupId=" + groupId;
}
}
}
var embedId = GetParameterByName(SessionKeys.EmbedId);
if (!embedId)
{
embedId = GetSession(SessionKeys.EmbedId);
}
$(accessTokenSelector).val(accessToken);
$(embedUrlSelector).val(embedUrl);
$(embedIdSelector).val(embedId);
}