This repository has been archived by the owner on Jun 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
/
bugcount.js
129 lines (107 loc) · 3.27 KB
/
bugcount.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
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
var BugPuller = (function(code) {
var _locale_code = code;
var parent = $('#bugzilla');
function getURL(suffix) {
return 'https://bugzilla.mozilla.org/rest/' + suffix;
}
function getData() {
return {
'field0-0-0': 'component',
'type0-0-0': 'regexp',
'value0-0-0': '^' + _locale_code + ' / ',
'field0-0-1': 'cf_locale',
'type0-0-1': 'regexp',
'value0-0-1': '^' + _locale_code + ' / ',
'resolution': '---',
'include_fields': 'id,last_change_time'
};
}
function excuse() {
$('.loading', parent).hide();
$('.loaded', parent).hide();
$('.failed', parent).show();
}
return {
render: function(json) {
json.bugs.sort(function(l, r) {
return l.last_change_time < r.last_change_time ? 1 : -1;
});
function buglink(b, prop) {
return '<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=' +
b.id + '">' + b[prop] + '</a>';
}
var tbody = $('<tbody>');
$.each(json.bugs, function(i, bug) {
var tr = $('<tr>').addClass('treesummary');
$('<td>')
.append($(buglink(bug, 'id')))
.appendTo(tr);
$('<td>')
.text(bug.summary)
.appendTo(tr);
$('<td>')
.text(new Date(bug.last_change_time).toDateString())
.appendTo(tr);
$('<td>')
.addClass('last-col')
.text(new Date(bug.creation_time).toDateString())
.appendTo(tr);
tbody.append(tr);
});
// it's more effient to not attach this to the DOM until it's fully
// populated
tbody.appendTo($('table', parent));
$('.loading', parent).hide();
$('.table-pre-header', parent).fadeIn(300);
$('table.recent-bugs:hidden', parent).fadeIn(300);
},
pre_render: function(json) {
$('.recent-bugs', parent).hide();
// update the count inline
$('.bug-count', parent).text(json.bugs.length);
$('.loaded', parent).fadeIn(300);
if (json.bugs.length) {
$('.loading', parent).show();
json.bugs.sort(function(l, r) {
return l.last_change_time < r.last_change_time ? 1 : -1;
});
var IDs = $.map(json.bugs.slice(0, 5), function(o) {
return o.id;
});
var details = {
'bug_id': IDs.join(','),
'include_fields': 'id,summary,creation_time,last_change_time'
};
$.ajax({
url: getURL('bug'),
data: details,
dataType: 'json',
success: BugPuller.render,
error: function(jqXHR, textStatus, errorThrown) {
excuse();
}
});
} else {
// no bugs to fetch more details about
// Mozilla is using bugs in Bugzilla to track
}
},
pull: function() {
$.ajax({
url: getURL('bug'),
data: getData(),
dataType: 'json',
success: BugPuller.pre_render,
error: function(jqXHR, textStatus, errorThrown) {
excuse();
}
});
}
};
})(LOCALE_CODE);
$(function() {
BugPuller.pull();
});