Skip to content

Commit 898546c

Browse files
author
Chris Maunder
committed
Corrections to module listings
1 parent fd21528 commit 898546c

File tree

5 files changed

+92
-53
lines changed

5 files changed

+92
-53
lines changed

src/server/Modules/ModuleCollection.cs

Lines changed: 49 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -985,10 +985,11 @@ public async static Task<bool> CreateModulesListing(this ModuleCollection module
985985
Directory.CreateDirectory(dir);
986986

987987
var corrections = new dynamic [] {
988-
new { OldModuleId = "ObjectDetectionNet", NewModuleId = "ObjectDetectionYOLOv5Net" },
989-
new { OldModuleId = "ObjectDetectionYolo", NewModuleId = "ObjectDetectionYOLOv5-6.2" },
990-
new { OldModuleId = "Yolov5-3.1", NewModuleId = "ObjectDetectionYOLOv5-3.1" },
991-
new { OldModuleId = "TrainingYoloV5", NewModuleId = "TrainingObjectDetectionYOLOv5" }
988+
// No longer including renamed versions
989+
// new { OldModuleId = "ObjectDetectionNet", NewModuleId = "ObjectDetectionYOLOv5Net" },
990+
// new { OldModuleId = "ObjectDetectionYolo", NewModuleId = "ObjectDetectionYOLOv5-6.2" },
991+
// new { OldModuleId = "Yolov5-3.1", NewModuleId = "ObjectDetectionYOLOv5-3.1" },
992+
// new { OldModuleId = "TrainingYoloV5", NewModuleId = "TrainingObjectDetectionYOLOv5" }
992993
};
993994

994995
var moduleList = modules.Values
@@ -1008,54 +1009,57 @@ public async static Task<bool> CreateModulesListing(this ModuleCollection module
10081009
Downloads = 0
10091010
}).ToList();
10101011

1011-
// Add renamed modules, using their new (current) names, but listing only server revisions v2.4+
1012-
foreach (var pair in corrections)
1012+
if (corrections.Length > 0)
10131013
{
1014-
ModuleConfig? module = modules.Values.Where(m => m.ModuleId == pair.NewModuleId).FirstOrDefault();
1015-
if (module is not null)
1014+
// Add renamed modules, using their new (current) names, but listing only server revisions v2.4+
1015+
foreach (var pair in corrections)
10161016
{
1017-
ModuleRelease[] post24Releases = module.InstallOptions!.ModuleReleases
1018-
.Where(r => string.IsNullOrWhiteSpace(r.ServerVersionRange?[0]) ||
1019-
VersionInfo.Compare(r.ServerVersionRange[0], "2.4") >= 0)
1020-
.ToArray();
1021-
moduleList.Add(new {
1022-
ModuleId = module.ModuleId,
1023-
Name = module.Name,
1024-
Version = module.Version,
1025-
PublishingInfo = module.PublishingInfo,
1026-
InstallOptions = new {
1027-
Platforms = module.InstallOptions.Platforms,
1028-
ModuleReleases = post24Releases
1029-
},
1030-
Downloads = 0
1031-
});
1017+
ModuleConfig? module = modules.Values.Where(m => m.ModuleId == pair.NewModuleId).FirstOrDefault();
1018+
if (module is not null)
1019+
{
1020+
ModuleRelease[] post24Releases = module.InstallOptions!.ModuleReleases
1021+
.Where(r => string.IsNullOrWhiteSpace(r.ServerVersionRange?[0]) ||
1022+
VersionInfo.Compare(r.ServerVersionRange[0], "2.4") >= 0)
1023+
.ToArray();
1024+
moduleList.Add(new {
1025+
ModuleId = module.ModuleId,
1026+
Name = module.Name,
1027+
Version = module.Version,
1028+
PublishingInfo = module.PublishingInfo,
1029+
InstallOptions = new {
1030+
Platforms = module.InstallOptions.Platforms,
1031+
ModuleReleases = post24Releases
1032+
},
1033+
Downloads = 0
1034+
});
1035+
}
10321036
}
1033-
}
10341037

1035-
// Add renamed modules, but with their old names, and only up to server v2.4
1036-
foreach (var pair in corrections)
1037-
{
1038-
ModuleConfig? module = modules.Values.Where(m => m.ModuleId == pair.NewModuleId).FirstOrDefault();
1039-
if (module is not null)
1038+
// Add renamed modules, but with their old names, and only up to server v2.4
1039+
foreach (var pair in corrections)
10401040
{
1041-
ModuleRelease[] pre24Releases = module.InstallOptions!.ModuleReleases
1042-
.Where(r => string.IsNullOrWhiteSpace(r.ServerVersionRange?[0]) ||
1043-
VersionInfo.Compare(r.ServerVersionRange[0], "2.4") < 0)
1044-
.ToArray();
1045-
moduleList.Add(new {
1046-
ModuleId = (string?)pair.OldModuleId,
1047-
Name = module.Name,
1048-
Version = module.Version,
1049-
PublishingInfo = module.PublishingInfo,
1050-
InstallOptions = new {
1051-
Platforms = module.InstallOptions.Platforms,
1052-
ModuleReleases = pre24Releases
1053-
},
1054-
Downloads = 0
1055-
});
1041+
ModuleConfig? module = modules.Values.Where(m => m.ModuleId == pair.NewModuleId).FirstOrDefault();
1042+
if (module is not null)
1043+
{
1044+
ModuleRelease[] pre24Releases = module.InstallOptions!.ModuleReleases
1045+
.Where(r => string.IsNullOrWhiteSpace(r.ServerVersionRange?[0]) ||
1046+
VersionInfo.Compare(r.ServerVersionRange[0], "2.4") < 0)
1047+
.ToArray();
1048+
moduleList.Add(new {
1049+
ModuleId = (string?)pair.OldModuleId,
1050+
Name = module.Name,
1051+
Version = module.Version,
1052+
PublishingInfo = module.PublishingInfo,
1053+
InstallOptions = new {
1054+
Platforms = module.InstallOptions.Platforms,
1055+
ModuleReleases = pre24Releases
1056+
},
1057+
Downloads = 0
1058+
});
1059+
}
10561060
}
10571061
}
1058-
1062+
10591063
var options = new JsonSerializerOptions { WriteIndented = true };
10601064
string configJson = JsonSerializer.Serialize(moduleList, options);
10611065

src/server/wwwroot/assets/dashboard.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -841,16 +841,25 @@ async function getDownloadableModules() {
841841
let basedOn = moduleInfo.publishingInfo.basedOn || '';
842842
let basedOnUrl = moduleInfo.publishingInfo.basedOnUrl || '';
843843

844-
let currentlyInstalled = moduleInfo.currentlyInstalled || '';
844+
let currentlyInstalled = moduleInfo.currentlyInstalled || '';
845845
let latestVersion = moduleInfo.latestCompatibleRelease?.moduleVersion || '';
846846
let latestReleased = moduleInfo.latestCompatibleRelease?.releaseDate || '';
847847
let importance = moduleInfo.latestCompatibleRelease?.importance || '';
848848
let updateAvailable = moduleInfo.updateAvailable;
849849
let status = moduleInfo.status;
850850

851+
// With the move from pre-chewed module listing to having to process the raw file, we
852+
// need to be more careful about checking versions (the pre-chewed would take into
853+
// account server version)
854+
updateAvailable = compareVersion(currentVersion, latestVersion) < 0;
855+
851856
let downloadable = moduleInfo.isDownloadable? ''
852857
: '<div title="This module is not downloadable" class="text-light me-2">Private</div>';
853858

859+
// Show what's available if nothing installed
860+
if (!currentlyInstalled && latestVersion)
861+
currentlyInstalled = `<span class="text-muted">${latestVersion}</span>`;
862+
854863
let updateDesc = '';
855864
if (updateAvailable && currentlyInstalled) {
856865
status = 'UpdateAvailable';
@@ -984,7 +993,8 @@ async function getDownloadableModules() {
984993
+ `<div class='me-auto'><b>${moduleName}</b></div>${downloadable}`
985994

986995
+ `<div class='me-3'>`
987-
+ `<button class='btn dropdown-toggle p-0 version' type='button' id='dropdownVersionHistory${i}' data-bs-toggle='dropdown'>${currentlyInstalled}</button>`
996+
+ `<button class='btn dropdown-toggle p-0 version' type='button' id='dropdownVersionHistory${i}'`
997+
+ ` style="vertical-align:unset" data-bs-toggle='dropdown'>${currentlyInstalled}</button>`
988998
+ `<ul class='dropdown-menu' aria-labelledby="dropdownVersionHistory${i}"><li>`
989999
+ `<div class='module-history small font-monospace p-2 overflow-auto'>${moduleHistory}</div>`
9901000
+ `</li></ul>`

src/server/wwwroot/assets/server.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,31 @@ const copyToClipboard = (elmId) => {
204204
});
205205
}
206206

207+
// Returns -1 if version1 < version2, 0 if equal, +1 if version1 > version2
208+
function compareVersion(version1, version2) {
209+
// Split the version numbers by '.' and convert them into arrays of integers
210+
const v1 = version1.split('.').map(num => parseInt(num, 10));
211+
const v2 = version2.split('.').map(num => parseInt(num, 10));
212+
213+
// Find the length of the longer version to compare all parts
214+
const length = Math.max(v1.length, v2.length);
215+
216+
// Compare each part of the version numbers
217+
for (let i = 0; i < length; i++) {
218+
const part1 = v1[i] || 0; // Default to 0 if part is missing
219+
const part2 = v2[i] || 0; // Default to 0 if part is missing
220+
221+
// If part1 is greater than part2, version1 is greater
222+
if (part1 > part2) return 1;
223+
224+
// If part2 is greater than part1, version2 is greater
225+
if (part1 < part2) return -1;
226+
}
227+
228+
// If all parts are equal, the versions are the same
229+
return 0;
230+
}
231+
207232
// API operations ==============================================================
208233

209234
/**

src/server/wwwroot/explorer.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
<link rel="icon" type="image/png" sizes="16x16" href="assets/favicon-16x16.png">
1515

1616
<link id="bootstrapCss" rel="stylesheet" type="text/css" href="assets/bootstrap-dark.min.css">
17-
<link rel="stylesheet" type="text/css" href="assets/server.css?v=2.6.1">
17+
<link rel="stylesheet" type="text/css" href="assets/server.css?v=2.9.3">
1818

19-
<script type="text/javascript" src="assets/server.js?v=2.6.1"></script>
20-
<script type="text/javascript" src="assets/explorer.js?v=2.6.1"></script>
19+
<script type="text/javascript" src="assets/server.js?v=2.9.3"></script>
20+
<script type="text/javascript" src="assets/explorer.js?v=2.9.3"></script>
2121

2222
<!-- Will only be effective if you're connected to the internet -->
2323
<link rel="preconnect" href="https://fonts.googleapis.com">

src/server/wwwroot/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
<link rel="icon" type="image/png" sizes="16x16" href="assets/favicon-16x16.png">
2222

2323
<link id="bootstrapCss" rel="stylesheet" type="text/css" href="assets/bootstrap-dark.min.css">
24-
<link rel="stylesheet" type="text/css" href="assets/server.css?v=2.5.5.0">
24+
<link rel="stylesheet" type="text/css" href="assets/server.css?v=2.9.3">
2525

26-
<script type="text/javascript" src="assets/server.js?v=2.5.5.0"></script>
27-
<script type="text/javascript" src="assets/dashboard.js?v=2.5.5.0"></script>
26+
<script type="text/javascript" src="assets/server.js?v=2.9.3"></script>
27+
<script type="text/javascript" src="assets/dashboard.js?v=2.9.3"></script>
2828
<script type="text/javascript">
2929
window.addEventListener('DOMContentLoaded', function (event) {
3030

0 commit comments

Comments
 (0)