-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbasic-widget.html
More file actions
90 lines (81 loc) · 3.19 KB
/
Copy pathbasic-widget.html
File metadata and controls
90 lines (81 loc) · 3.19 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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Basic Widget</title>
<script type="text/javascript" src="https://admin.tago.io/dist/custom-widget.min.js"></script>
<style>
body {
font-family: Arial, sans-serif;
padding: 20px;
}
.error {
color: red;
padding: 10px;
border: 1px solid red;
margin: 10px 0;
}
</style>
</head>
<body>
<h1>Basic Custom Widget</h1>
<div id="loading">Loading widget...</div>
<div id="content" style="display: none">
<h3>Widget Information</h3>
<p><strong>Widget ID:</strong> <span id="widget-id">-</span></p>
<p><strong>Dashboard ID:</strong> <span id="dashboard-id">-</span></p>
<p><strong>Widget Label:</strong> <span id="widget-label">-</span></p>
<p><strong>Variables Count:</strong> <span id="variables-count">-</span></p>
<h3>Configured Variables</h3>
<ul id="variables-list"></ul>
</div>
<div id="error" class="error" style="display: none"></div>
<script>
/**
* Basic Custom Widget Example
* Demonstrates minimal setup and widget initialization
*/
// Handle widget startup
window.TagoIO.onStart(function (widget) {
console.log("Widget started:", widget);
// Show content, hide loading
document.getElementById("loading").style.display = "none";
document.getElementById("content").style.display = "block";
// Display widget information
document.getElementById("widget-id").textContent = widget.id || "N/A";
document.getElementById("dashboard-id").textContent = widget.dashboard || "N/A";
document.getElementById("widget-label").textContent = widget.label || "No label";
document.getElementById("variables-count").textContent = widget.display.variables.length;
// Display variables
const variablesList = document.getElementById("variables-list");
variablesList.textContent = "";
if (widget.display.variables.length === 0) {
const li = document.createElement("li");
li.textContent = "No variables configured";
variablesList.appendChild(li);
} else {
widget.display.variables.forEach(function (variable) {
const li = document.createElement("li");
const strong = document.createElement("strong");
strong.textContent = variable.variable;
li.appendChild(strong);
li.appendChild(document.createTextNode(` (Device: ${variable.origin.id})`));
variablesList.appendChild(li);
});
}
});
// Handle errors
window.TagoIO.onError(function (error) {
console.error("Widget error:", error);
document.getElementById("error").style.display = "block";
document.getElementById("error").textContent = "Error: " + (error.message || "Unknown error");
document.getElementById("loading").style.display = "none";
});
// Initialize widget
window.TagoIO.ready({
header: { color: "#2196F3" },
});
</script>
</body>
</html>