/
dashboard.js
1345 lines (1097 loc) · 63.3 KB
/
dashboard.js
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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
const pingFrequency = 5000; // milliseconds
const logFrequency = 250; // milliseconds
const statusFrequency = 5000; // milliseconds
const checkUpdateFrequency = 1 * 3600 * 1000; // 1hr in milliseconds
const logLinesPerRequest = 100; // lines to retrieve per log request
const maxLogEntriesPerLevel = 1000; // max entries for each log level
const lostConnectionSec = 15; // consider connection down after 15s no contact
// For logging output
const specialCategory = ""; // "Server: ";
const highlightMarker = "** ";
const criticalMarker = "*** ";
let apiServiceProtocol = window.location.protocol;
if (!apiServiceProtocol || apiServiceProtocol === "file:")
apiServiceProtocol = "http:"; // Needed if you launch this file from Finder
const apiServiceHostname = window.location.hostname || "localhost";
const apiServicePort = window.location.port === "" ? "" : ":" + (window.location.port || 32168);
const apiServiceUrl = `${apiServiceProtocol}//${apiServiceHostname}${apiServicePort}`;
let _usingGPU = false; // Is the server reporting that we're we using a GPU?
let _lastLogId = 0; // Allows us to fetch only new log entries
let _serverIsOnline = false; // Anyone home?
let _version = null; // Currently installed version of the server
let _darkMode = true; // TODO: Need to store this in a cookie
let _delayFetchCallUntil = null; // No fetch calls until this time. Allows us to delay after fetch errors
let _fetchErrorDelaySec = 0; // The number of seconds to delay until the next fetch if there's a fetch error
let _logVerbosityLevel = "information";
let _displayDirty = false;
let _installNotice = null; // Human readable text about current install/uninstalls
let _requestIdMap = new Map();
let _logEntries = new Map();
// Status: ping, version =====================================================
/**
* Makes a call to the status API of the server
* @param method - the name of the method to call: ping, version, updates etc
*/
async function callStatus(method, callback) {
if (isFetchDelayInEffect())
return;
let urlElm = document.getElementById('serviceUrl');
let url = urlElm.value.trim() + '/v1/status/' + method;
try {
await fetch(url, {
method: "GET",
cache: "no-cache"
})
.then(response => {
clearFetchError();
if (!response.ok) {
setServerStatus('Error', "danger");
}
else {
response.json()
.then(data => callback(data))
.catch(error => {
setServerStatus('Error', "danger");
addLogEntry(null, new Date(), "error", null, "Bad data returned from server: " + error);
});
}
})
.catch(error => {
if (error.name === 'AbortError')
setServerStatus('Timeout', "warning");
else {
setFetchError();
}
});
}
catch
{
setFetchError();
}
}
/**
* Pings the server to check we're still online
*/
async function ping() {
await callStatus('ping', function (data) {
if (_serverIsOnline == data.success)
return;
_serverIsOnline = data.success;
if (_serverIsOnline)
setServerStatus('Online', "success");
});
}
/**
* Gets the current version of the server
*/
async function getVersion() {
await callStatus('version', function (data) {
_version = data.version;
let version = document.getElementById("version");
version.innerHTML = data.message;
});
}
/**
* Checks to see if there is a new version available
* @param showResult - if true then a result is shown even if no update is available.
*/
async function checkForUpdates(showResult) {
let update = document.getElementById("update");
update.innerHTML = "Checking for updates";
await callStatus('updateavailable', function (data) {
if (data && data.version) {
if (data.updateAvailable) {
update.style.display = '';
let message = data.message + " <a href='" + data.version.file + "'>Download<a>";
if (data.version.releaseNotes)
message += "<div class='mt-2 text-white-50'>" + data.version.releaseNotes + "</div>";
update.innerHTML = message;
update.style.display = '';
}
else if (showResult) {
update.style.display = '';
update.innerHTML = "You have the latest version of CodeProject.AI";
}
}
else {
updateError.innerHTML = "Unable to check for updates";
let element = document.getElementById("updateToast");
let toastPopup = new bootstrap.Toast(element);
toastPopup.show();
}
});
}
// Settings: Change server and module Status (eg disable module, enable GPU) ==
async function callSettings(moduleId, key, value) {
if (isFetchDelayInEffect())
return;
let urlElm = document.getElementById('serviceUrl');
let url = urlElm.value.trim() + '/v1/settings/' + moduleId;
let formData = new FormData();
formData.append("name", key);
formData.append("value", value);
try {
await fetch(url, {
method: "POST",
body: formData
})
.then(response => {
// if (response.ok)
// ... all good
// else
// ... an issue
})
.catch(error => {
setFetchError();
});
}
catch
{
setFetchError();
}
}
/**
* Calls the settings API to update a setting with the given value for the
* given module
* @param event - the click event
* @param moduleId - The ID of the module to update
* @param setting - the setting to change
* @param value - the value to assign to the setting
*/
function updateSetting(event, moduleId, setting, value) {
event.preventDefault();
callSettings(moduleId, setting, value.toString());
}
// Server status: server and analysis modules status and stats ================
/**
* Gets the system utilitisation (CPU and GPU use + RAM)
*/
async function getSystemStatus() {
if (isFetchDelayInEffect())
return;
let urlElm = document.getElementById('serviceUrl');
let url = urlElm.value.trim() + '/v1/status/system-status';
try {
fetch(url, {
method: "GET",
cache: "no-cache"
})
.then(response => {
if (response.ok) {
response.json().then(result => {
let systemMemUsage = (result.data.systemMemUsage / 1000 / 1000 / 1000).toFixed(2) + " GB";
let gpuMemUsage = (result.data.gpuMemUsage / 1000 / 1000 / 1000).toFixed(2) + " GB";
let cpuUsage = result.data.cpuUsage.toFixed(0) + " %";
let gpuUsage = result.data.gpuUsage.toFixed(0) + " %";
let gpu = `<span class="alert-success p-1 rounded" title="RAM Used / Processor Utilization">GPU</span> ${gpuMemUsage} / ${gpuUsage }`;
let system = `<span class="alert-info ms-3 p-1 rounded" title="RAM Used / Processor Utilization">System</span> ${ systemMemUsage } / ${ cpuUsage }`;
let gpuMemUsed = document.getElementById('gpuMemUsed');
gpuMemUsed.innerHTML = (result.data.gpuMemUsage ? gpu : "") + system;
let serverStatus = document.getElementById('serverStatusVerbose');
serverStatus.innerHTML = result.data.serverStatus.replace(/[\n\r]+/g, "<br>");
});
}
})
.catch(error => {
setFetchError();
});
}
catch
{
setFetchError();
}
}
/**
* Query the server for a list of services that are installed, and their status.
* The results of this will be used to populate the serviceStatus table
*/
async function getModulesStatuses() {
if (isFetchDelayInEffect())
return;
// In the future we will ask for "logs since log ID 'x'" so we have
// a full history. For now, a simple "last 10".
let urlElm = document.getElementById('serviceUrl');
let url = urlElm.value.trim() + '/v1/status/analysis/list?random=' + new Date().getTime();
let statusTable = document.getElementById('serviceStatus');
try {
fetch(url, {
method: "GET",
cache: "no-cache"
})
.then(response => {
clearFetchError();
if (response.ok) {
response.json().then(data => {
if (data && data.statuses) {
_usingGPU = false;
data.statuses.sort((a, b) => a.name.localeCompare(b.name));
for (let i = 0; i < data.statuses.length; i++) {
let moduleInfo = data.statuses[i];
let moduleId = moduleInfo.moduleId;
let moduleName = moduleInfo.name;
let status = moduleInfo.status;
let lastSeen = moduleInfo.lastSeen? new Date(moduleInfo.lastSeen) : null;
let processedCount = moduleInfo.processed;
let hardwareType = moduleInfo.hardwareType;
let executionProvider = moduleInfo.executionProvider;
let queue = moduleInfo.queue;
let canUseGPU = moduleInfo.canUseGPU;
var numberFormat = Intl.NumberFormat();
processedCount = numberFormat.format(parseInt(processedCount));
// Have we lost contact with a module that should be running?
if (status === "Started" && lastSeen && (new Date() - lastSeen)/1000 > lostConnectionSec)
status = "LostContact";
let className = status.toLowerCase();
let statusDesc = "Unknown";
switch (status) {
case "Enabled":
statusDesc = "Enabled";
className = "alert-info"
break;
case "NotEnabled":
statusDesc = "Not Enabled";
className = "alert-light"
break;
case "Starting":
statusDesc = "Starting";
className = "alert-info"
break;
case "Started":
statusDesc = "Started";
className = "alert-success"
break;
case "NotStarted":
statusDesc = "Not Started";
className = "alert-light"
break;
case "NotAvailable":
statusDesc = "Not Available";
className = "alert-light"
break;
case "FailedStart":
statusDesc = "Failed to Start";
className = "alert-danger"
break;
case "Crashed":
statusDesc = "Crashed";
className = "alert-danger"
break;
case "Stopping":
statusDesc = "Stopping";
className = "alert-warning"
break;
case "Uninstalling":
statusDesc = "Uninstalling";
className = "alert-warning"
break;
case "Stopped":
statusDesc = "Stopped";
className = "alert-light"
break;
case "LostContact":
statusDesc = "Lost Contact";
className = "bg-dark text-muted"
break;
}
let hardware = (!hardwareType || hardwareType.toLowerCase() === "cpu") ? "CPU" : "GPU";
if (executionProvider)
hardware += ` (${executionProvider})`;
if (!_usingGPU && hardware == "GPU")
_usingGPU = true;
let currentSummary = moduleInfo.summary.replace(/[\n\r]+/g, "<br>");
let startupSummary = moduleInfo.startupSummary.replace(/[\n\r]+/g, "<br>");
let installSummary = moduleInfo.installSummary;
if (installSummary) {
installSummary = installSummary.replace(/[\n\r]+/g, "<br>");
installSummary = convertXtermToCss(installSummary);
installSummary = "<br><br><b>Installation Log</b><br>" + installSummary;
}
let rowClass = `d-flex justify-content-between status-row ${className}`;
let row = document.getElementById('module-info-' + moduleId);
if (!row) {
row = document.createElement("div");
statusTable.appendChild(row);
let rowHtml =
`<div id='module-info-${moduleId}' class='${rowClass}'>`
+ `<div class='module-name me-auto'><b>${moduleName}</b> <span class="ms-1 text-muted">${moduleInfo.version}</span></div>`
+ `<div class='status me-1'>${statusDesc}</div>`
+ `<div class='hardware text-end me-1'>${hardware}</div>`
+ `<div class='dropdown ms-2' style='width:3rem'>`
+ `<button class='btn dropdown-toggle p-1' type='button' id='dropdownMenuInfo${i}' data-bs-toggle='dropdown'>Info</button>`
+ `<ul class='dropdown-menu' aria-labelledby="dropdownMenuInfo${i}"><li>`
+ `<div style="float:right;cursor: pointer;position:relative;z-index:100" onclick="copyToClipboard('module-summary-${moduleId}')" title="Copy to clipboard">`
+ '<svg stroke="currentColor" fill="none" stroke-width="2" viewBox="0 0 24 24" stroke-linecap="round" '
+ ' stroke-linejoin="round" class="h-4 w-4" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg">'
+ '<path d="M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2"></path>'
+ '<rect x="8" y="2" width="8" height="4" rx="1" ry="1"></rect>'
+ '</svg>'
+ '</div>'
+ `<div id='module-summary-${moduleId}'>`
+ `<div class='startup-summary'>${startupSummary}</div>`
+ `<div class='current-summary'>${currentSummary}</div>`
+ `<div class='install-summary'>${installSummary}</div>`
+ `</div>`
+ `</li></ul>`
+ `</div>`
if (status == "NotAvailable") {
rowHtml +=
"<div class='ms-2' style='width:9.7rem'></div>";
}
else {
rowHtml +=
`<div class='proc-count text-end text-nowrap me-1' style='width:3rem'>${processedCount}</div>`
+ `<div class='ms-2 text-nowrap' style='width:4em'>`
+ `<a class='me-1' href='#' title='Restart' onclick=\"updateSetting(event, '${moduleId}', 'Restart', 'now')">`
+ `<svg xmlns="http://www.w3.org/2000/svg" width="16px" height="16px" viewBox="0 0 512 512"><title>Restart</title>`
+ `<g transform="matrix(27.423195, 0, 0, 27.423195, -73.373978, -90.935013)">`
+ `<path class="action-path" d="M 9.203 17.507 C 8.914 17.507 8.687 17.272 8.687 16.972 L 8.687 9.351 C 8.687 9.051 8.914 8.816 9.203 8.816 C 9.302 8.816 9.398 8.843 9.483 8.893 L 16.081 12.703 C 16.253 12.803 16.356 12.975 16.356 13.162 C 16.356 13.348 16.254 13.522 16.081 13.62 L 9.483 17.431 C 9.398 17.48 9.302 17.507 9.203 17.507 L 9.203 17.507 Z"/>`
+ `<path class="action-path" d="M 18.268 3.559 C 18.549 3.675 18.731 3.948 18.731 4.252 L 18.731 8.494 C 18.731 8.909 18.396 9.244 17.981 9.244 L 13.739 9.244 C 13.435 9.244 13.162 9.062 13.046 8.781 C 12.93 8.501 12.994 8.179 13.208 7.964 L 14.811 6.361 C 12.178 5.26 9.027 5.781 6.884 7.924 C 4.053 10.755 4.053 15.346 6.884 18.177 C 9.716 21.008 14.306 21.008 17.137 18.177 C 18.783 16.531 19.473 14.291 19.204 12.144 C 19.153 11.733 19.444 11.358 19.855 11.307 C 20.266 11.255 20.641 11.547 20.693 11.958 C 21.016 14.544 20.185 17.25 18.198 19.238 C 14.781 22.655 9.241 22.655 5.824 19.238 C 2.407 15.821 2.407 10.28 5.824 6.863 C 8.562 4.125 12.662 3.582 15.942 5.231 L 17.451 3.721 C 17.666 3.507 17.988 3.443 18.268 3.559 Z"/>`
+ `</g></svg>`
+ `</a>`
+ `<a class='me-1' href='#' title='Stop' onclick="updateSetting(event, '${moduleId}', 'AutoStart', false)">`
+ `<?xml version="1.0" encoding="utf-8"?>`
+ `<svg width="24px" height="24px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">`
+ `<title>Stop</title><path class="action-path" d="M7 7H17V17H7V7Z" />`
+ `</svg>`
+ `</a>`
// + `<a class='me-1' href='#' title='Pause' onclick="updateSetting(event, '${moduleId}', 'AutoStart', false)">`
// + `<svg xmlns="http://www.w3.org/2000/svg" width="14px" height="14px" viewBox="0 0 512 512"><title>Pause</title>`
// + `<path class="action-path" d="M395,512a73.14,73.14,0,0,1-73.14-73.14V73.14a73.14,73.14,0,1,1,146.29,0V438.86A73.14,73.14,0,0,1,395,512Z"/>`
// + `<path class="action-path" d="M117,512a73.14,73.14,0,0,1-73.14-73.14V73.14a73.14,73.14,0,1,1,146.29,0V438.86A73.14,73.14,0,0,1,117,512Z"/></svg>`
// + `</a>`
+ `<a class='me-1' href='#' title='Start' onclick="updateSetting(event, '${moduleId}', 'AutoStart', true)">`
+ `<svg xmlns="http://www.w3.org/2000/svg" width="14px" height="14px" viewBox="0 0 512 512"><title>Start</title>`
+ `<path class="action-path" d="M60.54,512c-17.06,0-30.43-13.86-30.43-31.56V31.55C30.12,13.86,43.48,0,60.55,0A32.94,32.94,0,0,1,77,4.52L465.7,229c10.13,5.85,16.18,16,16.18,27s-6,21.2-16.18,27L77,507.48A32.92,32.92,0,0,1,60.55,512Z"/></svg>`
+ `</a>`
+ '</div>';
// Dropdown menu
let dropDown = ``;
// Start / Stop / Restart
// + `<li><a class='dropdown-item small' href='#' onclick=\"updateSetting(event, '${moduleId}', 'Restart', 'now')\">Restart</a></li>`
// + `<li><a class='dropdown-item small' href='#' onclick=\"updateSetting(event, '${moduleId}', 'AutoStart', false)\">Stop</a></li>`
// + `<li><a class='dropdown-item small' href='#' onclick=\"updateSetting(event, '${moduleId}', 'AutoStart', true)\">Start</a></li>`;
// Toggle GPU support
if (canUseGPU) {
dropDown +=
`<li><a class='dropdown-item small' href='#' onclick=\"updateSetting(event, '${moduleId}', 'SupportGPU', false)\">Disable GPU</a></li>`
+ `<li><a class='dropdown-item small' href='#' onclick=\"updateSetting(event, '${moduleId}', 'SupportGPU', true)\">Enable GPU</a></li>`;
}
// Half-precision (PyTorch only)
if (moduleId == "ObjectDetectionYolo" || moduleId == "YOLOv5-3.1" || moduleId == "FaceProcessing") {
dropDown +=
"<li><a class='dropdown-item small' href='#'>Half Precision »</a>"
+ " <ul class='submenu dropdown-menu dropdown-menu-right'>"
+ ` <li><a class='dropdown-item small' href='#' onclick=\"updateSetting(event, '${moduleId}', 'CPAI_HALF_PRECISION', 'force')\">Force on</a></li>`
+ ` <li><a class='dropdown-item small' href='#' onclick=\"updateSetting(event, '${moduleId}', 'CPAI_HALF_PRECISION', 'enable')\">Use Default</a></li>`
+ ` <li><a class='dropdown-item small' href='#' onclick=\"updateSetting(event, '${moduleId}', 'CPAI_HALF_PRECISION', 'disable')\">Disable</a></li>`
+ " </ul>"
+ "</li>";
}
// Model size (Object detection only)
if (queue == "objectdetection_queue") {
dropDown +=
"<li><a class='dropdown-item small' href='#'>Model Size »</a>"
+ " <ul class='submenu dropdown-menu dropdown-menu-right'>"
+ ` <li><a class='dropdown-item small' href='#' onclick=\"updateSetting(event, '${moduleId}', 'MODEL_SIZE', 'tiny')\">Tiny</a></li>`
+ ` <li><a class='dropdown-item small' href='#' onclick=\"updateSetting(event, '${moduleId}', 'MODEL_SIZE', 'small')\">Small</a></li>`
+ ` <li><a class='dropdown-item small' href='#' onclick=\"updateSetting(event, '${moduleId}', 'MODEL_SIZE', 'medium')\">Medium</a></li>`
+ ` <li><a class='dropdown-item small' href='#' onclick=\"updateSetting(event, '${moduleId}', 'MODEL_SIZE', 'large')\">Large</a></li>`
+ " </ul>"
+ "</li>";
}
if (dropDown) {
rowHtml +=
"<div class='dropdown ms-0 me-3' style='width:1.4rem'>"
+ `<button class='btn dropdown-toggle p-1' type='button' id='dropdownMenu${i}' data-bs-toggle='dropdown'>`
+ "<svg xmlns='http://www.w3.org/2000/svg' width='24px' height='24px' version='1.1' x='0px' y='0px' viewBox='0 0 100 100' xml:space='preserve'>"
+ "<path class='action-path-on' d='M60.1,88.7c-0.1,0-0.3,0-0.4,0c-2.1-0.4-4-1.8-5-3.7c-0.1-0.1-0.1-0.2-0.2-0.3c-0.1-0.2-0.9-1.7-3.2-1.8c0,0-0.1,0-0.1,0 c-0.8,0-1.5,0-2.3,0c0,0-0.1,0-0.1,0c-2.4,0-3.2,1.7-3.2,1.8c-0.1,0.1-0.1,0.2-0.2,0.3c-1,1.9-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2,2c0,0.1-0.1,0.1-0.1,0.2c-2,3.2-5,3.6-6.1,3.6c-0.1,0-0.3,0-0.4,0c-1.1-0.1-2.1,0.3-2.9,1.1 c-0.3,1.4-0.6,2.8-0.7,4.1c0.5,1,1.3,1.7,2.4,2c0.1,0,0.3,0.1,0.4,0.2c1.5,0.6,3.8,2.2,4.5,5.5c0,0,0,0.1,0,0.1c0,0.1,0,0.1,0,0.2 c0.1,0.8,0.2,1.5,0.4,2.3c0,0,0,0.1,0,0.1c0,0,0,0.1,0,0.1c0.5,3.3-1.1,5.6-2.4,6.7c-0.1,0.1-0.2,0.2-0.3,0.3 c-0.9,0.6-1.4,1.6-1.5,2.6c0.7,1.3,1.4,2.6,2.2,3.8c0.9,0.4,2,0.4,3-0.1c0.1-0.1,0.3-0.1,0.4-0.1c0.5-0.2,1.3-0.4,2.3-0.4 c1.7,0,3.3,0.6,4.7,1.7c0,0,0,0,0.1,0c0.1,0,0.1,0.1,0.2,0.1c0.5,0.5,1.1,1,1.8,1.5c0,0,0.1,0.1,0.1,0.1c0,0,0.1,0.1,0.1,0.1 c2.5,2.2,2.8,5.1,2.5,6.7c0,0.1,0,0.3-0.1,0.4C35,81.5,35.2,82.5,35.7,83.4z M50,70.2c-10.8,0-19.5-8.8-19.5-19.5S39.2,31.1,50,31.1 s19.5,8.8,19.5,19.5S60.8,70.2,50,70.2z M50,34.8c-8.7,0-15.9,7.1-15.9,15.9S41.3,66.5,50,66.5s15.9-7.1,15.9-15.9 S58.7,34.8,50,34.8z' /></svg>"
+ "</button>"
+ `<ul class='dropdown-menu dropdown-menu-right' aria-labelledby="dropdownMenu${i}">`
+ dropDown
+ `</ul>`
+ "</div>";
}
else {
rowHtml +=
"<div class='ms-2' style='width:1.8rem'></div>"
}
}
rowHtml +=
"</div>";
row.outerHTML = rowHtml;
}
else {
row.className = rowClass;
row.querySelector("div.status").innerHTML = statusDesc;
row.querySelector("div.hardware").innerHTML = hardware;
let procCount = row.querySelector("div.proc-count");
if (procCount) procCount.innerHTML = processedCount;
row.querySelector("div.current-summary").innerHTML = currentSummary;
row.querySelector("div.startup-summary").innerHTML = startupSummary;
row.querySelector("div.install-summary").innerHTML = installSummary;
}
}
// Now check for rows that need to be removed.
const statusRows = statusTable.querySelectorAll(".status-row");
statusRows.forEach((row) => {
let foundModuleForRow = false;
for (let i = 0; !foundModuleForRow && i < data.statuses.length; i++) {
let moduleInfo = data.statuses[i];
if (row.id == 'module-info-' + moduleInfo.moduleId)
foundModuleForRow = true;
}
if (!foundModuleForRow)
row.remove();
});
}
})
}
})
.catch(error => {
setFetchError();
});
}
catch
{
setFetchError();
}
}
// Logs =======================================================================
function purgeMarkerIndices() {
let now = new Date().getTime();
_requestIdMap.forEach((value, key, map) => {
if (now - value.time > 60000) {
// console.log(`Purging for entry ${key}`);
map.delete(key);
}
});
}
var lastIndex = 0;
function addLogEntry(id, date, logLevel, label, entry, refreshDisplay = true) {
logLevel = logLevel.toLowerCase();
// Get the bucket of entries for this log level, and abort if we have already stored this entry
let entry_bucket = _logEntries.get(logLevel) || [];
if (id && entry_bucket.some((entry) => entry.id == id))
return;
let className = "";
let dateText = date.toLocaleTimeString('en-US', { hour12: false });
let idText = "<span class='text-muted me-2'>" + (id || "") + "</span>";
let logText = entry.replace(/[\n\r]+/g, "<br>"); // newlines to BR tags
idText = ""; // comment this out for debugging
// Processing special "critical message" marker ("***")
if (logText.startsWith(specialCategory + criticalMarker)) {
logText = specialCategory + logText.substring(specialCategory.length + criticalMarker.length);
className = "critical";
}
// Processing special "highligh me" marker ("**")
if (logText.startsWith(specialCategory + highlightMarker)) {
logText = specialCategory + logText.substring(specialCategory.length + highlightMarker.length);
className = "highlight";
}
// Extract request ID and colour code logs by that ID
let markerIndex = 0;
let reqId = null;
let match = /\(\#reqid ([a-z0-9-]+)\)/g.exec(logText); // ["fee ", index: 0, input: "fee fi fo fum"]
if (match && match.length > 1 && match[1]) {
let fullMatch = match[0];
reqId = match[1];
logText = logText.replace(fullMatch, `(...${reqId.substring(reqId.length - 6)})`);
if (_requestIdMap.has(reqId)) {
markerIndex = _requestIdMap.get(reqId).index;
}
else {
markerIndex = Math.floor(Math.random() * 15) + 1;
if (markerIndex == lastIndex) markerIndex = (markerIndex+1) % 14 + 1;
lastIndex = markerIndex;
_requestIdMap.set(reqId, { index: markerIndex, time: new Date().getTime()});
}
}
let requestIdMarker;
if (reqId)
requestIdMarker = `<span class='dot dot-${markerIndex}' title='Request ID ${reqId}'></span>`;
else
requestIdMarker = `<span class='dot dot-${markerIndex}' title='No Request ID'></span>`;
let logMessage = entry.message || '';
// Strip the "spin" animation chars
const re = /(\||\-|\\|\/|\s)/g;
// May need to use this if editors or Git complain about the literal control char above.
// const re = new RegExp('(\||\-|\\|\/|\s)[\b]', 'g'); // \b = wordbreak in regex, but [\b] = backspace
logText = logText.replace(re, ""); // strip 'spin' characters |,/,-,\,<space> + backspace
// Transform xterm colour escapes into HTML.
logText = convertXtermToCss(logText);
const html = id
? `<div id='log${id}' class='${logLevel} ${label} ${className}'>${idText}${dateText}:${requestIdMarker}${logText}${logMessage}</div>`
: `<div class='${logLevel} ${label} ${className}'>${dateText}:${requestIdMarker}${logText}${logMessage}</div>`;
// Store entry in the bucket for this log level. Note we're limiting the size of each bucket
if (entry_bucket.length >= maxLogEntriesPerLevel)
entry_bucket.splice(0, entry_bucket.length - maxLogEntriesPerLevel + 1)
entry_bucket.push({ date: date, id: id, html: html});
_logEntries.set(logLevel, entry_bucket);
_displayDirty = true;
if (refreshDisplay)
displayLogs();
}
function displayLogs() {
if (!_displayDirty)
return;
_displayDirty = false;
// Combine all entries into one sorted array, but filter out by log verbosity
let allEntries = [];
for (let [logLevel, entries] of _logEntries) {
if (_logVerbosityLevel == "critical") {
if (logLevel != "critical") continue;
}
else if (_logVerbosityLevel == "error") {
if (logLevel != "critical" && logLevel != "error") continue;
}
else if (_logVerbosityLevel == "warning") {
if (logLevel != "critical" && logLevel != "error" && logLevel != "warning") continue;
}
else if (_logVerbosityLevel == "information") {
if (logLevel != "critical" && logLevel != "error" && logLevel != "warning" &&
logLevel != "information") continue;
}
else if (_logVerbosityLevel == "debug") {
if (logLevel != "critical" && logLevel != "error" && logLevel != "warning" &&
logLevel != "information" && logLevel != "debug") continue;
}
else if (_logVerbosityLevel == "trace") {
if (logLevel != "critical" && logLevel != "error" && logLevel != "warning" &&
logLevel != "information" && logLevel != "debug" && logLevel != "trace") continue;
}
allEntries.push(...entries);
}
allEntries.sort((a,b) => a.date - b.date);
// Create a single chunk of sorted HTML entries
// Create a single chunk of sorted HTML entries
var html = '';
for (let entry of allEntries)
html += entry.html;
let logsBrief = document.getElementById('logs');
let logsFull = document.getElementById('logsMain');
/*
if (html.length > maxLogStorage) {
html = html.substring(html.length - maxLogStorage);
let indexOfEndDiv = html.indexOf("<div");
if (indexOfEndDiv)
html = html.substring(indexOfEndDiv);
}
*/
logsBrief.innerHTML = html;
logsFull.innerHTML = html;
// logsBrief.parentNode.scrollTop = logsBrief.offsetHeight - logsBrief.parentNode.offsetHeight;
// TODO: We should suppress the scroll into view if the user has
// scrolled up. If we detect a scroll up, set "autoscroll" to false
// and if they then scroll to the bottom, turn autoscroll back on
logsBrief.scroll({ top: logsBrief.scrollHeight, behaviour: 'smooth' });
logsFull.scroll({ top: logsFull.scrollHeight, behaviour: 'smooth' });
}
/**
* Gets and displays the server logs.
*/
async function getLogs() {
if (isFetchDelayInEffect())
return;
let urlElm = document.getElementById('serviceUrl');
let url = urlElm.value.trim() + '/v1/log/list?count=' + logLinesPerRequest + '&last_id=' + _lastLogId;
try {
fetch(url, {
method: "GET"
})
.then(response => {
clearFetchError();
if (response.ok) {
response.json().then(data => {
if (data && data.entries) {
let lastEntryWasTimeout = false;
for (let i = 0; i < data.entries.length; i++) {
let logEntry = data.entries[i];
_lastLogId = logEntry.id;
// Ignore repeated timeout warnings. They just clog up the logs
if (logEntry.entry.indexOf("[TimeoutError]") >= 0 ||
logEntry.entry.indexOf("Pausing on error") >= 0)
{
if (lastEntryWasTimeout) continue;
lastEntryWasTimeout = true;
}
else
lastEntryWasTimeout = false;
addLogEntry(logEntry.id, new Date(logEntry.timestamp), logEntry.level,
logEntry.label, logEntry.entry, false)
if (logEntry.label == "command timing")
document.getElementById('latestTiming').innerText = logEntry.entry;
}
displayLogs();
}
})
}
})
.catch(error => {
setFetchError();
});
}
catch
{
setFetchError();
}
}
// Modules ====================================================================
/**
* Query the server for a list of modules that can be installed. The results of
* this will be used to populate the availableModules table
*/
async function getDownloadableModules() {
if (isFetchDelayInEffect())
return;
let urlElm = document.getElementById('serviceUrl');
let url = urlElm.value.trim() + '/v1/module/list/?random=' + new Date().getTime();
try {
fetch(url, {
method: "GET",
cache: "no-cache"
})
.then(response => {
clearFetchError();
if (response.ok) {
response.json().then(data => {
if (data && data.modules) {
_installNotice = null;
data.modules.sort((a, b) => a.name.localeCompare(b.name||''));
for (let i = 0; i < data.modules.length; i++) {
let moduleInfo = data.modules[i];
let moduleId = moduleInfo.moduleId;
let moduleName = moduleInfo.name;
let currentVersion = moduleInfo.version || '';
let latestVersion = moduleInfo.latestRelease.moduleVersion || '';
let latestReleased = moduleInfo.latestRelease.releaseDate;
let importance = moduleInfo.latestRelease.importance || '';
let status = moduleInfo.status;
let license = moduleInfo.licenseUrl && moduleInfo.license
? `<a href='${moduleInfo.licenseUrl}'>${moduleInfo.license}</a>` : '';
let downloadable = moduleInfo.isDownloadable? ''
: '<div title="This module is not downloadable" class="text-light me-2">Private</div>';
let updateDesc = '';
if (currentVersion && currentVersion != latestVersion) {
status = 'UpdateAvailable';
updateDesc = 'New version available';
if (importance)
updateDesc += ` (${importance})`;
updateDesc += `: ${latestVersion} released ${latestReleased}`;
if (moduleInfo.latestRelease.releaseNotes)
updateDesc += ". " + moduleInfo.latestRelease.releaseNotes;
importance = importance.toLowerCase();
if (importance == "minor")
updateDesc = `<span class='text-muted'>${updateDesc}</span>`;
else if (importance == "major" || importance == "critical")
updateDesc = `<span class='text-danger'>${updateDesc}</span>`;
}
let btnClassName = "d-none";
let statClassName = '';
let statusDesc = status;
let action = "";
if (status === "Installing")
_installNotice = `Installing ${moduleName}...`;
else if (status === "Uninstalling")
_installNotice = `Uninstalling ${moduleName}...`;
switch (status) {
case "Available":
statusDesc = "Available";
btnClassName = "btn-success";
statClassName = "";
action = "Install";
break;
case "Downloading":
statusDesc = "Downloading";
btnClassName = "d-none";
statClassName = "text-info";
action = "";
break;
case "Installing":
statusDesc = "Installing";
btnClassName = "d-none";
statClassName = "text-info";
action = "";
break;
case "Installed":
statusDesc = "Installed";
btnClassName = "btn-outline-danger";
statClassName = "text-success";
action = "Uninstall";
break;
case "UpdateAvailable":
statusDesc = `Update to ${latestVersion}`;
btnClassName = "btn-success";
statClassName = "text-info";
action = "Update";
break;
case "Stopping":
statusDesc = "Stopping";
btnClassName = "d-none";
statClassName = "text-warning";
action = "";
break;
case "Uninstalling":
statusDesc = "Uninstalling";
btnClassName = "d-none";
statClassName = "text-info";
action = "";
break;
case "UninstallFailed":
statusDesc = "Uninstall Failed";
btnClassName = "btn-warning";
statClassName = "text-warning";
action = "Uninstall";
break;
case "NotAvailable":
statusDesc = "Not Available";
btnClassName = "d-none";
action = "";
statClassName = "text-muted";
break;
}
let statusClass = `status me-1 ${statClassName}`;
let buttonClass = `btn action ${btnClassName} py-0 mx-2`;
let moduleIdKey = moduleId.replace(/[^a-zA-Z0-9\-]+/g, "");
let row = document.getElementById('module-download-' + moduleIdKey);
if (!row) {
row = document.createElement("div");
let modulesTable = document.getElementById('availableModules');
modulesTable.appendChild(row);
let rowHtml =
`<div id='module-download-${moduleIdKey}' class='status-row py-2'>`
+ `<div class='d-flex justify-content-between'>`
+ `<div class='me-auto'><b>${moduleName}</b></div>${downloadable}`
+ `<div class='me-3 version'>${currentVersion}</div>`
+ `<div class='me-3 text-muted'>${latestReleased}</div>`
+ `<div style='width:8rem' class='${statusClass}'>${statusDesc}</div>`
+ `<div style='width:7rem'><button class='${buttonClass}' type='button'`
+ ` id='installModule${i}' onclick='doModuleAction(this)' data-module-id='${moduleId}'`
+ ` data-action='${action}' data-available-version='${latestVersion}'`
+ ` data-downloadable='${moduleInfo.isDownloadable}'>${action}</button></div>`
+ `</div>`;
if (updateDesc)
rowHtml +=
`<div class='text-info small update-available-${moduleIdKey}' style='margin-top:-0.5rem'>${updateDesc}</div>`;
rowHtml +=
`<div class='text-muted small'>${license} ${moduleInfo.description || ''}</div>`
+ `</div>`;
row.outerHTML = rowHtml;
}
else {
let statusElm = row.querySelector("div.status");
statusElm.innerHTML = statusDesc;
statusElm.className = statusClass;
let actionElm = row.querySelector("button.action");
actionElm.className = buttonClass;
actionElm.innerHTML = action;
actionElm.dataset.action = action;
actionElm.dataset.latestVersion = latestVersion;
let versionElm = row.querySelector("div.version");
versionElm.innerHTML = currentVersion;
let updateAvailableElm = row.querySelector(`div.update-available-${moduleIdKey}`);
if (updateAvailableElm)
updateAvailableElm.innerHTML = updateDesc;
}
}
let installNotice = document.getElementById('installNotice');
if (_installNotice) {
installNotice.innerHTML = `<div class='status-row alert-info rounded'>${_installNotice}`
+ '<div class="spinner-border ms-1 p-1 spinner-border-sm text-light" role="status">'
+ '</div></div>';
}
else
installNotice.innerHTML = '';
}
})
}
})
.catch(error => {
setFetchError();
});
}
catch
{
setFetchError();
}
}
function doModuleAction(elm) {
modifyModule(elm.dataset.moduleId, elm.dataset.latestVersion, elm.dataset.action, elm.dataset.downloadable);
}
/**
* Modifies a module (installs or uninstalls).
*/
async function modifyModule(moduleId, version, action, downloadable) {