-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
83 lines (65 loc) · 2.11 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
<html>
<head>
<title>My Serenytics Dashboard</title>
</head>
<body>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script type="text/javascript">
const rootUrl = 'https://app.serenytics.com/viewer';
let auth = null;
let config = null;
window.main = function (jsonConfig) {
config = JSON.parse(jsonConfig);
getAuthAndLoadDashboard();
};
function getAuthAndLoadDashboard() {
const authorization = 'Basic ' + btoa(config.username + ':' + config.password);
axios({
method: 'get',
url: 'https://api.serenytics.com/api/token',
data: {},
headers: {
Authorization: authorization
}
}).then(response => {
auth = btoa(JSON.stringify({
token: response.data.token
}));
if (config.webAppUuid) {
loadDashboard(config.webAppUuid);
} else {
myDashboards();
}
}).catch(error => {
document.getElementById('errorMessage').textContent = error;
});
// reload every 23 hours before token expiration
setTimeout(getAuthAndLoadDashboard, 1000 * 60 * 60 * 23);
}
function quit() {
const app = require('electron').remote.app;
app.quit();
}
function reloadCurrentDashboard() {
document.getElementById('dashboard').contentWindow.location.reload();
}
function myDashboards() {
document.getElementById('dashboard').src = `${rootUrl}?auth=${auth}`;
}
function loadDashboard(uuid) {
document.getElementById('dashboard').src = `${rootUrl}/webapps/${uuid}?auth=${auth}`;
}
</script>
<button onclick="quit()">Quit ⌘Q</button>
<button onclick="getAuthAndLoadDashboard()">ReAuth</button>
<button onclick="myDashboards()">My dashboards</button>
<button onclick="reloadCurrentDashboard()">Reload dashboard</button>
<div id="errorMessage"></div>
<iframe width="100%"
height="95%"
scrolling="yes"
frameBorder="0"
id="dashboard">
</iframe>
</body>
</html>