-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard.html
More file actions
264 lines (218 loc) · 7.94 KB
/
dashboard.html
File metadata and controls
264 lines (218 loc) · 7.94 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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>URL Shortener Dashboard</title>
<style>
/* Your CSS styles for the dashboard here */
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #333;
color: #fff;
animation: fade-in 0.5s;
}
@keyframes fade-in {
0% { opacity: 0; transform: translateY(-20px); }
100% { opacity: 1; transform: translateY(0); }
}
.dashboard-container {
max-width: 800px;
margin: 0 auto;
padding: 20px;
background-color: #444;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
border-radius: 5px;
}
h1 {
font-size: 24px;
margin-bottom: 20px;
}
p {
font-size: 16px;
margin-bottom: 20px;
}
.url-item {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 10px;
border: 1px solid #555;
padding: 10px;
border-radius: 5px;
animation: slide-up 0.5s;
}
@keyframes slide-up {
0% { opacity: 0; transform: translateY(10px); }
100% { opacity: 1; transform: translateY(0); }
}
.url-item select {
width: 60%;
padding: 5px;
}
.btn {
background-color: #007bff;
color: #fff;
border: none;
padding: 5px 10px;
cursor: pointer;
border-radius: 3px;
}
.btn:hover {
background-color: #0056b3;
}
#realtimeDataContainer {
margin-top: 20px;
border-top: 1px solid #555;
padding-top: 20px;
}
#usageChart {
width: 100%;
}
.url-list {
margin-top: 20px;
}
.url-list-item {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 10px;
background-color: #555;
padding: 10px;
border-radius: 5px;
animation: fade-in 0.5s;
}
.url-list-item span {
flex-grow: 1;
margin-right: 10px;
}
.url-list-item a {
color: #007bff;
text-decoration: none;
}
.url-list-item a:hover {
text-decoration: underline;
}
.export-btn {
background-color: #007bff;
color: #fff;
border: none;
padding: 5px 10px;
cursor: pointer;
border-radius: 3px;
}
.export-btn:hover {
background-color: #0056b3;
}
.button {
background-color: #4CAF50; /* Green */
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
}
/* Custom CSS for the "Back to Home" button */
.back-button {
display: inline-block;
padding: 10px 20px;
background-color: #007bff; /* Button background color */
color: #fff; /* Button text color */
text-decoration: none;
border-radius: 5px;
transition: background-color 0.3s ease; /* Smooth color transition on hover */
}
.back-button:hover {
background-color: #0056b3; /* New background color on hover */
}
</style>
</head>
<body>
<a href="/" class="back-button">Back to Home</a>
<div class="dashboard-container">
<h1>URL Shortener Dashboard</h1>
<p>Welcome to the URL Shortener Dashboard.</p>
<!-- Dark mode is always enabled -->
<!-- Display URL analytics and other features here -->
<!-- "Export as CSV" button -->
<button id="exportBtn" class="export-btn">Export as CSV</button>
<div id="realtimeDataContainer">
<h2>Real-Time Data:</h2>
<p>Total URLs: <span id="totalUrls">0</span></p>
<canvas id="usageChart" width="400" height="200"></canvas>
</div>
<!-- JavaScript code for dashboard functionality here -->
<script src="/socket.io/socket.io.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script>
// JavaScript code for dashboard functionality
const socket = io();
// Function to populate the select element with options
function populateSelect(shortUrl, originalUrl) {
const selectElement = document.createElement('select');
selectElement.id = `urlSelect_${shortUrl}`;
const option = document.createElement('option');
option.value = shortUrl;
option.textContent = originalUrl;
selectElement.appendChild(option);
return selectElement;
}
socket.on('realtimeData', (data) => {
document.getElementById('totalUrls').innerText = data.totalUrls;
// Update the usage chart
const ctx = document.getElementById('usageChart').getContext('2d');
// Destroy the previous chart to prevent errors
if (window.myChart) {
window.myChart.destroy();
}
const usageCounts = data.usageCounts;
const labels = Array.from({ length: usageCounts.length }, (_, i) => i + 1);
window.myChart = new Chart(ctx, {
type: 'line',
data: {
labels: labels,
datasets: [{
label: 'Usage Count',
data: usageCounts,
borderColor: 'rgba(75, 192, 192, 1)',
borderWidth: 1,
fill: false,
}],
},
});
});
socket.on('urlCreated', (urlData) => {
// Add a new option to the select element when a new URL is created
const urlList = document.querySelector('.url-list');
const urlItem = document.createElement('div');
urlItem.classList.add('url-item');
const selectElement = populateSelect(urlData.shortUrl, urlData.originalUrl);
const fetchButton = document.createElement('button');
fetchButton.textContent = 'Fetch Data';
fetchButton.classList.add('btn');
fetchButton.dataset.shortUrl = urlData.shortUrl;
urlItem.appendChild(selectElement);
urlItem.appendChild(fetchButton);
urlList.appendChild(urlItem);
});
document.querySelectorAll('.btn').forEach((button) => {
button.addEventListener('click', () => {
// Get the selected short URL from the button's data attribute
const shortUrl = button.getAttribute('data-shortUrl');
// Fetch and display data for the selected URL
socket.emit('getUrlData', shortUrl);
});
});
// Placeholder for exporting data as CSV (to be implemented)
const exportBtn = document.getElementById('exportBtn');
exportBtn.addEventListener('click', () => {
alert('Export as CSV feature to be implemented.');
});
</script>
</div>
</body>
</html>