forked from mozilla-necko/necko-triage
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathutils.js
More file actions
164 lines (137 loc) · 3.72 KB
/
utils.js
File metadata and controls
164 lines (137 loc) · 3.72 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
function SortByID(a, b) {
return a["id"] - b["id"];
}
function SortBySeverity(a, b) {
const SeverityMap = [
"blocker",
"critical",
"major",
"normal",
"minor",
"trivial",
"enhancement"
];
const NewSeverityMap = [
"S1",
"S2",
"S3",
"S4",
"S5",
"--",
"N/A",
];
let aSev = SeverityMap.indexOf(a["severity"]);
if (aSev == -1) {
aSev = NewSeverityMap.indexOf(a["severity"]);
}
let bSev = SeverityMap.indexOf(b["severity"]);
if (bSev == -1) {
bSev = NewSeverityMap.indexOf(b["severity"]);
}
return aSev - bSev;
}
function GetNIHelper(dataRow) {
let lastNI = undefined;
for (let flag of dataRow["flags"]) {
if (flag["name"] == "needinfo") {
lastNI = flag["modification_date"];
}
}
return lastNI;
}
function SortByNI(a, b) {
let aNI = GetNIHelper(a);
let bNI = GetNIHelper(b);
if (a === undefined || b === undefined) {
// Use our default sort instead
return SortBySeverity(a, b);
}
let aDate = new Date(aNI);
let bDate = new Date(bNI);
// We want the oldest ones first
if (aDate < bDate) {
return -1;
}
if (bDate < aDate) {
return 1;
}
// Fall back to the default sort
return SortBySeverity(a, b);
}
function GetNI(dataRow) {
let lastNI = GetNIHelper(dataRow);
if ($.type(lastNI) == "string") {
let relativeLastNI = moment(lastNI).fromNow();
let span = $("<span />", {title: lastNI, text: relativeLastNI});
span.tooltip();
lastNI = span;
} else {
lastNI = "unknown";
}
return lastNI;
}
function MakeSelect(name, options, selected, valueGetter) {
let select = $("<select />", {name: name});
for (let i = 0; i < options.length; i++) {
let option;
if (valueGetter !== undefined) {
option = valueGetter(options[i]);
} else {
option = options[i];
}
let item;
if (option == selected) {
item = $("<option />", {"value": option, "text": option, "selected": true});
} else {
item = $("<option />", {"value": option, "text": option});
}
select.append(item);
}
return select;
}
function MakeLabel(node, label) {
let nodeName;
if (typeof node == "string") {
nodeName = node;
} else {
nodeName = node.attr("name");
}
return $("<label />", {"for": nodeName, "text": label});
}
function MakeCheckbox(name, label) {
let w = $("<span />", {"class": "checkbox-wrapper"});
w.append($("<input />", {"type": "checkbox", "name": name}));
w.append($("<label />", {"for": name, "text": label}));
return w;
}
function MakeTextbox(name, label, value) {
let w = $("<span />", {"class": "textbox-wrapper"});
w.append($("<label />", {"for": name, "text": label}));
let t = $("<input />", {"type": "text", "name": name});
if (value !== undefined) {
t.attr("value", value);
}
w.append(t);
return w;
}
function FormatDate(dateString) {
let d = new Date(dateString);
return d.toLocaleString();
}
function GetAlias(datarow) {
return datarow["alias"] || "";
}
function GetPriority(datarow) {
return datarow["priority"] || "";
}
function GetFailureCount(datarow) {
return datarow["failure_count"] || 0;
}
function SortFailures(a, b) {
return b["failure_count"] - a["failure_count"];
}
function SortPriority(a, b) {
let priorityA = a["priority"] === "--" ? 1 : parseInt(a["priority"].slice(1));
let priorityB = b["priority"] === "--" ? 1 : parseInt(b["priority"].slice(1));
return priorityA > priorityB;
}