-
Notifications
You must be signed in to change notification settings - Fork 13
/
utils.js
127 lines (105 loc) · 2.9 KB
/
utils.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
function SortByID(a, b) {
return a["id"] - b["id"];
}
function SortBySeverity(a, b) {
const SeverityMap = [
"blocker",
"critical",
"major",
"normal",
"minor",
"trivial",
"enhancement"
];
let aSev = SeverityMap.indexOf(a["severity"]);
let bSev = SeverityMap.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();
}