-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
147 lines (128 loc) · 5.29 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Hello World!</title>
<!-- Import the webpage's javascript file -->
<link rel="stylesheet" href="https://qlikcloud-jwt-proxy.qlik.repl.co/resources/autogenerated/qlik-styles.css" />
<script src="https://qlikcloud-jwt-proxy.qlik.repl.co/resources/assets/external/requirejs/require.js"></script>
<script
crossorigin="anonymous"
type="application/javascript"
src="https://cdn.jsdelivr.net/npm/@qlik/embed-web-components"
data-host="https://qlikcloud-jwt-proxy.qlik.repl.co"
></script>
<style>
.viz {
position: relative;
width: 600px;
height: 600px;
padding: 16px;
border: 1px solid #bbb;
border-radius: 3px;
box-shadow: 1px 1px 10px rgba(0, 0, 0, 0.2);
}
</style>
<script defer>
document.addEventListener("DOMContentLoaded", (event) => {
console.log("DOM fully loaded and parsed");
renderIframe(config)
});
const config = {
host: "qlikcloud-jwt-proxy.qlik.repl.co",
port: 443,
prefix: "/",
isSecure: true,
};
const appId = "e1024b45-efa3-421f-b0c0-44d7d1222c7d";
require.config({
baseUrl: `https://${config.host}/resources`,
});
const openWebSocket = async () => {
console.log("open the websocket");
const backendWebSocket = new WebSocket(`wss://${config.host}:443/app/${appId}?somefakeparam=somefakevalue`);
renderSheet(config)
}
function createGrid(querySelector, columns, rows) {
const gridContainer = document.querySelector(querySelector);
gridContainer.style.display = 'grid';
gridContainer.style.gridTemplateRows = `repeat(${rows}, minmax(0, 1fr)`;
gridContainer.style.gridTemplateColumns = `repeat(${columns}, minmax(0, 1fr))`;
return gridContainer;
}
function constructSheet(sheetLayout, querySelector, addClass) {
const gridContainer = createGrid(querySelector, sheetLayout.columns, sheetLayout.rows);
(sheetLayout.cells).forEach(function (object) {
const objectId = object.name;
const colStart = object.col + 1;
const rowStart = object.row + 1;
const colSpan = object.colspan;
const rowSpan = object.rowspan;
const objectDiv = document.createElement('div');
objectDiv.id = objectId;
objectDiv.style["grid-column"] = `${colStart} / span ${colSpan}`;
objectDiv.style["grid-row"] = `${rowStart} / span ${rowSpan}`;
objectDiv.style.border = '2px solid #0000';
objectDiv.style.margin = '5px';
objectDiv.classList.add(addClass);
gridContainer.appendChild(objectDiv);
})
return true;
}
function renderSheet(config) {
const qlikConfig = {
appId: "e1024b45-efa3-421f-b0c0-44d7d1222c7d",
sheetId: "a8bdb8b2-525e-486e-91d1-7318d362acee"
}
requirejs(["js/qlik"], (qlik) => {
qlik.theme.apply('breeze')
const app = qlik.openApp(qlikConfig.appId, config);
const sheetObject = app.getObject(qlikConfig.sheetId)
.then((sheetObject) => {
const sheetLayout = sheetObject.getLayout()
.then((sheetLayout) => {
constructSheet(sheetLayout, "#sheet", "qlikObject");
$(`.qlikObject`).each(function () {
var chartId = $(this).attr("id");
app.getObject(this, chartId);
});
})
})
})
}
function renderIframe(config) {
//embed chart using single API iframe
const qlikConfig = {
appId: "e1024b45-efa3-421f-b0c0-44d7d1222c7d",
sheetId: "05743d07-2e17-4c5b-8f81-625c4ee0931b"
}
console.log("begin render iframe")
let iframeSrc = `https://${config.host}/single/?appid=${qlikConfig.appId}&sheet=${qlikConfig.sheetId}&theme=breeze&opt=ctxmenu,currsel`;
let iframe = document.createElement("iframe");
iframe.src = iframeSrc;
iframe.style = "border:none;width:100%;height:100%;"
document.querySelector("#iframe").appendChild(iframe);
console.log('render an iframe');
}
if (!document.cookie) {
window.location = '/#'
} else {
openWebSocket();
}
</script>
</head>
<body>
<div id="sheet" style="height:800px;position:relative;"></div>
<br />
<div id="iframe" style="height:800px;position:relative"></div>
<div width="100%" style="height:800px;position:relative">
<div class="viz" style="float:left;">
<qlik-embed
ui="object"
app-id="b1b79fcd-e500-491c-b6e9-2ceaa109214c"
object-id="ZxDKp"
></qlik-embed>
</div>
</body>
</html>