-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard-builder.html
More file actions
231 lines (204 loc) · 7.92 KB
/
dashboard-builder.html
File metadata and controls
231 lines (204 loc) · 7.92 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Dashboard Builder</title>
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css"
rel="stylesheet"
/>
<link
href="https://fonts.googleapis.com/icon?family=Material+Icons"
rel="stylesheet"
/>
<script src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js"></script>
<script src="https://unpkg.com/dayjs@1.8.21/dayjs.min.js"></script>
<script src="https://dl.revealbi.io/reveal/libs/1.7.1/infragistics.reveal.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@revealbi/dom/index.umd.min.js"></script>
<style>
body {
font-family: "Roboto", sans-serif;
height: 97vh;
margin: 0;
}
.container-fluid {
height: 100%;
}
.row {
height: 100%;
}
.list-container {
height: 450px;
overflow-y: auto;
border-bottom: 1px solid #ddd;
}
.single-viz-container {
height: 50%;
padding-top: 1rem;
border-top: 1px solid #ddd;
}
.generated-dashboard {
height: 97%;
}
.scrollable-list {
max-height: 400px;
overflow-y: auto;
}
.list-group-item {
cursor: pointer;
transition: background-color 0.2s ease;
}
.list-group-item:hover {
background-color: #f0f0f0;
}
.selected {
background-color: #e0e0e0;
}
.reveal-dash-board {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div class="container-fluid">
<div class="row">
<!-- Sidebar with list and single visualization -->
<div class="col-md-4 d-flex flex-column">
<div class="list-container">
<h5>Visualization List</h5>
<ul id="visualizationList" class="list-group scrollable-list"></ul>
</div>
<div class="single-viz-container">
<h5>Single Visualization</h5>
<div
id="revealSingleViz"
class="reveal-dash-board border rounded"
></div>
</div>
</div>
<!-- Main content for the generated dashboard -->
<div class="col-md-8 generated-dashboard">
<h5 class="mt-2">Generated Dashboard</h5>
<div
id="revealDashboard"
class="reveal-dash-board border rounded"
></div>
</div>
</div>
</div>
<script>
// ** API to get the visualizations from your dashboards
//const API_BASE_URL = "https://acmeanalyticsserver.azurewebsites.net/dashboards/visualizations";
const API_BASE_URL = "http://localhost:5111/reveal-api/dashboards/visualizations";
// ** note the /reveal-api suffix on the endpoint
$.ig.RevealSdkSettings.setBaseUrl("http://localhost:5111/reveal-api");
//$.ig.RevealSdkSettings.setBaseUrl("https://acmeanalyticsserver.azurewebsites.net");
// ** Test with server or local app
//const IMAGE_URL = 'https://acmeanalyticsserver.azurewebsites.net/images/png/';
const IMAGE_URL = "http://localhost:5111/images/png/";
let selectedItem = null;
let selectedVisualizations = [];
const sourceDocs = new Map();
async function fetchVisualizations() {
try {
const response = await fetch(API_BASE_URL);
const visualizations = await response.json();
populateVisualizationList(visualizations);
} catch (error) {
console.error("Error fetching visualizations:", error);
}
}
function populateVisualizationList(visualizations) {
const listElement = document.getElementById("visualizationList");
listElement.innerHTML = "";
visualizations.forEach((viz, index) => {
const encodedViz = encodeURIComponent(JSON.stringify(viz)); // Safely encode JSON
const listItem = document.createElement("li");
listItem.className = "list-group-item d-flex align-items-center";
listItem.innerHTML = `
<img src="${IMAGE_URL}${viz.vizChartType}.png" alt="${viz.vizTitle}" class="me-3" style="width: 40px; height: 40px;">
<div>
<div><strong>${viz.vizTitle}</strong></div>
<div class="text-muted">${viz.dashboardTitle}</div>
</div>
<i class="material-icons ms-auto text-primary" style="cursor: pointer;" onclick="addVisualization(event, '${encodedViz}')">add</i>
`;
listItem.addEventListener("click", () =>
handleVisualizationClick(viz, listItem)
);
listElement.appendChild(listItem);
if (index === 0) {
listItem.click();
}
});
}
async function handleVisualizationClick(viz, listItem) {
if (selectedItem) {
selectedItem.classList.remove("selected");
}
listItem.classList.add("selected");
selectedItem = listItem;
try {
const dashboard = await $.ig.RVDashboard.loadDashboard(
viz.dashboardFileName
);
const revealView = new $.ig.RevealView(
document.getElementById("revealSingleViz")
);
revealView.dashboard = dashboard;
revealView.singleVisualizationMode = true;
revealView.maximizedVisualization = dashboard.visualizations.getById(
viz.vizId
);
} catch (error) {
console.error("Error loading visualization:", error);
}
}
function addVisualization(event, vizJson) {
event.stopPropagation();
try {
const viz = JSON.parse(decodeURIComponent(vizJson));
if (!viz || !viz.dashboardFileName) {
console.error("Invalid Visualization: Missing dashboardFileName", viz);
return;
}
selectedVisualizations.push(viz);
generateDashboard();
} catch (error) {
console.error("Error parsing visualization JSON:", vizJson, error);
}
}
async function generateDashboard() {
try {
const dashboardDocument = new dom.RdashDocument("Generated Dashboard");
for (const viz of selectedVisualizations) {
console.log("Processing visualization:", viz);
let sourceDoc = sourceDocs.get(viz.dashboardFileName);
if (!sourceDoc) {
sourceDoc = await dom.RdashDocument.load(viz.dashboardFileName);
if (!sourceDoc) {
throw new Error(`Failed to load source document: ${viz.dashboardFileName}`);
}
sourceDocs.set(viz.dashboardFileName, sourceDoc);
}
dashboardDocument.import(sourceDoc, viz.vizId);
}
const rvDashboard = await dashboardDocument.toRVDashboard();
if (!rvDashboard) {
throw new Error("Generated dashboard is null or undefined");
}
const revealView = new $.ig.RevealView(
document.getElementById("revealDashboard")
);
revealView.dashboard = rvDashboard;
revealView.startInEditMode = true;
} catch (error) {
console.error("Error generating dashboard:", error);
}
}
fetchVisualizations();
</script>
</body>
</html>