-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
393 lines (340 loc) · 13.3 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
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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap" rel="stylesheet">
<title>SSSIP - Self-Service Software Installation Portal</title>
<style>
body {
font-family: 'Roboto', sans-serif;
background-color: #f4f4f7;
margin: 0;
padding: 20px;
color: #333;
}
.logo-container {
display: flex;
justify-content: center;
margin: 30px 0;
}
.logo-container img {
max-width: 200px;
height: auto;
}
h1 {
color: #2c3e50;
font-weight: 600;
text-align: center;
margin-bottom: 10px;
font-size: 2em;
}
h2 {
color: #34495e;
font-weight: 500;
text-align: left;
margin: 20px 0;
}
p {
line-height: 1.6;
margin-bottom: 15px;
}
#apps, #devices {
background-color: #ffffff;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
padding: 15px;
margin-bottom: 30px;
border-radius: 8px;
}
button {
background-color: #3498db;
color: white;
padding: 12px 25px;
font-size: 1rem;
border-radius: 6px;
cursor: pointer;
transition: background-color 0.3s;
box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
button:hover {
background-color: #2980b9;
}
.app-info {
padding: 10px;
border-bottom: 1px solid #ececec;
margin-bottom: 5px;
}
.loading-overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
display: none;
align-items: center;
justify-content: center;
z-index: 1000;
}
.loading-spinner {
border: 4px solid rgba(255, 255, 255, 0.3);
border-radius: 50%;
border-top: 4px solid #ffffff;
width: 40px;
height: 40px;
animation: spin 2s linear infinite;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.notification {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
padding: 20px;
background-color: #ffffff;
border-radius: 6px;
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
z-index: 1001;
display: none;
}
.notification p {
margin-bottom: 20px;
}
.notification button {
background-color: #4CAF50;
color: white;
padding: 10px 20px;
margin: 4px 2px;
cursor: pointer;
border-radius: 4px;
}
</style>
</head>
<body>
<!--
<div class="logo-container">
<img src="logo.png" alt="SSSIP Logo">
</div>
-->
<div id="user-info">Loading user info...</div>
<h2>SSSIP - Self-Service Software Installation Portal</h2>
<h3>Your Devices</h3>
<p>Select the device on which you want to install the software:</p>
<select id="devices" onchange="loadAppsForSelectedDevice()">
<!-- Device options will be loaded here -->
</select>
<h2>Available Software</h2>
<p>Select the software you want to install:</p>
<div id="apps"></div>
<button onclick="installSoftware()">Install</button>
<div id="notification" class="notification">
<p id="notification-message"></p>
<button onclick="closeNotification()">OK</button>
</div>
<script>
async function loadApps() {
try {
const response = await fetch('/api/apps');
if (!response.ok) throw new Error('Network response was not ok.');
const apps = await response.json();
console.log("Apps loaded with versions:", apps.map(app => ({ name: app.displayName, version: app.packageVersion })));
const appsContainer = document.getElementById('apps');
appsContainer.innerHTML = ''; // Clear existing apps
apps.forEach(app => {
const appElement = document.createElement('div');
appElement.className = 'app-info';
const radio = document.createElement('input');
radio.type = 'radio';
radio.name = 'app';
radio.value = app.id;
const label = document.createElement('label');
label.appendChild(radio);
// Create strong element for display name
const displayName = document.createElement('strong');
displayName.textContent = app.displayName;
label.appendChild(displayName);
// Add version info
const versionInfo = document.createElement('div');
versionInfo.textContent = `Version: ${app.packageVersion || 'N/A'}`;
label.appendChild(versionInfo);
// Add description
const description = document.createElement('div');
description.textContent = `Description: ${app.description || 'No description available.'}`;
label.appendChild(description);
// Add size info
const sizeInfo = document.createElement('div');
sizeInfo.textContent = `Size: ${app.size || 'Unknown'}`;
label.appendChild(sizeInfo);
// Append the label to the app element
appElement.appendChild(label);
// Append the app element to the apps container
appsContainer.appendChild(appElement);
});
} catch (error) {
console.error('Error fetching applications:', error);
}
}
// This function is called whenever the selected device changes
async function loadAppsForSelectedDevice() {
try {
const devicesSelect = document.getElementById('devices');
const selectedDeviceOS = devicesSelect.options[devicesSelect.selectedIndex].getAttribute('data-os');
const encodedOS = encodeURIComponent(selectedDeviceOS); // Encode the OS for use in the URL
const response = await fetch(`/api/apps?os=${encodedOS}`);
if (!response.ok) throw new Error('Network response was not ok.');
const apps = await response.json();
console.log("Apps loaded:", apps); // Debug: log the apps data
const appsContainer = document.getElementById('apps');
appsContainer.innerHTML = ''; // Clear existing apps
apps.forEach(app => {
// Check if settings array exists and has at least one entry
const version = app.settings && app.settings.length > 0 && app.settings[0].packageVersion
? app.settings[0].packageVersion
: 'N/A';
console.log("Rendering app:", app.displayName, "Version:", version); // Debug: log the app being rendered
const appElement = document.createElement('div');
appElement.className = 'app-info';
const radio = document.createElement('input');
radio.type = 'radio';
radio.name = 'app';
radio.value = app.id;
const label = document.createElement('label');
label.appendChild(radio);
// Create strong element for display name
const displayName = document.createElement('strong');
displayName.textContent = app.displayName;
label.appendChild(displayName);
// Add version info
const versionInfo = document.createElement('div');
versionInfo.textContent = `Version: ${version}`;
label.appendChild(versionInfo);
// Add description
//const description = document.createElement('div');
//description.textContent = `Description: ${app.description || 'No description available.'}`;
//label.appendChild(description);
// Add size info
//const sizeInfo = document.createElement('div');
//sizeInfo.textContent = `Size: ${app.size || 'Unknown'}`;
//label.appendChild(sizeInfo);
// Append the label to the app element
appElement.appendChild(label);
// Append the app element to the apps container
appsContainer.appendChild(appElement);
});
} catch (error) {
console.error('Error fetching apps for selected device:', error);
}
}
async function loadDevices() {
try {
const response = await fetch('/api/devices');
if (!response.ok) throw new Error('Network response was not ok.');
const devices = await response.json();
const devicesSelect = document.getElementById('devices');
devicesSelect.innerHTML = ''; // Clear existing options
devices.forEach(device => {
// Format the lastContact date and determine the active status
const lastContactFormatted = device.lastContact === 'Never' ? 'Never' : new Date(device.lastContact).toLocaleString();
const isActive = device.active ? 'Active' : 'Inactive';
// Create the option element with detailed text
const option = document.createElement('option');
option.value = device.id;
option.textContent = `${device.name} - OS: ${device.os}, Arch: ${device.arch || 'Unknown'}) - Last contact: ${lastContactFormatted} - Status: ${isActive}`;
// Set data attributes for further details if needed
option.setAttribute('data-os', device.os);
option.setAttribute('data-os-version', device.osVersion);
option.setAttribute('data-arch', device.arch);
option.setAttribute('data-hostname', device.hostname);
option.setAttribute('data-last-contact', device.lastContact);
option.setAttribute('data-active', device.active);
devicesSelect.appendChild(option);
});
// After loading devices, load apps for the selected device
loadAppsForSelectedDevice();
} catch (error) {
console.error('Error fetching devices:', error);
}
}
// Add an event listener to the device select box to load apps when the device changes
document.getElementById('devices').addEventListener('change', loadAppsForSelectedDevice);
async function loadUserInfo() {
try {
const response = await fetch('/api/user-info');
if (!response.ok) {
throw new Error('Failed to load user info');
}
const userInfo = await response.json();
document.getElementById('user-info').textContent = `Welcome, ${userInfo.name || 'User'}!`;
} catch (error) {
console.error('Error loading user info:', error);
document.getElementById('user-info').textContent = 'Welcome, User!';
}
}
function showLoading() {
document.getElementById('loading').style.display = 'flex';
}
function hideLoading() {
document.getElementById('loading').style.display = 'none';
}
function showNotification(message, isError=false) {
const notification = document.getElementById('notification');
const messageElement = document.getElementById('notification-message');
messageElement.textContent = message;
notification.style.backgroundColor = isError ? '#f44336' : '#4CAF50';
notification.style.display = 'block'; // Show notification when this function is called
}
function closeNotification() {
document.getElementById('notification').style.display = 'none';
}
async function installSoftware() {
const selectedApp = document.querySelector('#apps input[type="radio"]:checked');
const selectedDevice = document.getElementById('devices').value;
if (!selectedApp) {
showNotification('Please select a software application.', true);
return;
}
if (!selectedDevice) {
showNotification('Please select a device.', true);
return;
}
showLoading();
try {
const response = await fetch('/api/install', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
appId: selectedApp.value,
deviceId: selectedDevice
})
});
// If the response is not OK and there is a message in the response body, use it.
if (!response.ok) {
const errorBody = await response.json();
throw new Error(errorBody.message || 'Failed to initiate installation');
}
const data = await response.json();
showNotification(`Installation ${data.status}`);
} catch (error) {
console.error('Error initiating installation:', error);
showNotification(error.message || 'Error initiating installation', true);
} finally {
hideLoading();
}
}
window.onload = async function() {
showLoading(); // Show the loading overlay
await loadUserInfo();
await loadDevices(); // This will automatically call loadAppsForSelectedDevice
hideLoading(); // Hide the loading overlay
closeNotification(); // Hide the notification on initial load
};
</script>
<div id="loading" class="loading-overlay">
<div class="loading-spinner"></div>
</div>
</body>
</html>