Skip to content

Commit e6f1d6e

Browse files
maurerleskorpy2009
authored andcommitted
sort firmware versions by name if same count exists
1 parent eef3e16 commit e6f1d6e

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

lib/proportions.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { GenericNodeFilter } from "./filters/genericnode.js";
66
import * as helper from "./utils/helper.js";
77
import { _ } from "./utils/language.js";
88
import { Node } from "./utils/node.js";
9+
import { compare } from "./utils/version.js";
910

1011
type TableNode = {
1112
element: HTMLTableElement;
@@ -111,6 +112,14 @@ export const Proportions = function (filterManager: ReturnType<typeof DataDistri
111112
return null;
112113
}
113114

115+
function sortVersionCountAndName(a, b) {
116+
// descending by count
117+
if (b[1] !== a[1]) {
118+
return b[1] - a[1];
119+
}
120+
return compare(a[0], b[0]);
121+
}
122+
114123
let gatewayDict = count(nodes, ["gateway"], hostnameOfNodeID);
115124
let gateway6Dict = count(nodes, ["gateway6"], hostnameOfNodeID);
116125

@@ -154,21 +163,9 @@ export const Proportions = function (filterManager: ReturnType<typeof DataDistri
154163
}),
155164
);
156165

157-
tables.firmware = fillTable(
158-
"node.firmware",
159-
tables.firmware,
160-
fwDict.sort(function (a, b) {
161-
return b[1] - a[1];
162-
}),
163-
);
166+
tables.firmware = fillTable("node.firmware", tables.firmware, fwDict.sort(sortVersionCountAndName));
164167

165-
tables.baseversion = fillTable(
166-
"node.baseversion",
167-
tables.baseversion,
168-
baseDict.sort(function (a, b) {
169-
return b[1] - a[1];
170-
}),
171-
);
168+
tables.baseversion = fillTable("node.baseversion", tables.baseversion, baseDict.sort(sortVersionCountAndName));
172169

173170
tables.deprecationStatus = fillTable(
174171
"node.deprecationStatus",

lib/utils/version.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
type Version = { epoch: number; upstream: string; debian: string };
22

33
const Version = function (v: string) {
4+
// remove leading "v" or "V" if present
5+
if (v.startsWith("v") || v.startsWith("V")) {
6+
v = v.slice(1);
7+
}
48
let versionResult = /^[a-zA-Z]?([0-9]*(?=:))?:(.*)/.exec(v);
59
let version = versionResult && versionResult[2] ? versionResult[2] : v;
610
let versionParts = version.split("-");
@@ -21,9 +25,6 @@ Version.prototype.compare = function (b: Version) {
2125
};
2226

2327
Version.prototype.charCode = function (c: string) {
24-
// the lower the character code the lower the version.
25-
// if (c === '~') {return 0;} // tilde sort before anything
26-
// else
2728
if (/[a-zA-Z]/.test(c)) {
2829
return c.charCodeAt(0) - "A".charCodeAt(0) + 1;
2930
} else if (/[.:+-:]/.test(c)) {
@@ -90,8 +91,8 @@ Version.prototype.compareStrings = function (a: string, b: string) {
9091
return 0;
9192
};
9293

93-
export const compare = (a: any[], b: any[]) => {
94-
let va = new Version(a[0]);
95-
let vb = new Version(b[0]);
94+
export const compare = (a: string, b: string) => {
95+
let va = new Version(a);
96+
let vb = new Version(b);
9697
return vb.compare(va);
9798
};

0 commit comments

Comments
 (0)