diff options
author | Mark Côté <mcote@alumni.uwaterloo.ca> | 2015-03-05 17:07:27 +0100 |
---|---|---|
committer | Mark Côté <mcote@alumni.uwaterloo.ca> | 2015-03-05 17:14:46 +0100 |
commit | 7d75b6edad8cf5e312d32859f64e49538b5c79de (patch) | |
tree | 3deaa031bb7fab54c498326dc6b33503b35355a0 /extensions/MozReview/web/js | |
parent | 8d20ba6e2308484b6685c35a832033fcfff89f17 (diff) | |
download | bugzilla-7d75b6edad8cf5e312d32859f64e49538b5c79de.tar.gz bugzilla-7d75b6edad8cf5e312d32859f64e49538b5c79de.tar.xz |
Bug 1102428 - Extension to display MozReview data. r=glob
Add an extension called "MozReview" (and an addition hook to
bug/edit.html.tmpl) that displays a table of MozReview request
summaries on show_bug if there are any MozReview attachments
in the current bug.
Diffstat (limited to 'extensions/MozReview/web/js')
-rw-r--r-- | extensions/MozReview/web/js/mozreview.js | 141 |
1 files changed, 141 insertions, 0 deletions
diff --git a/extensions/MozReview/web/js/mozreview.js b/extensions/MozReview/web/js/mozreview.js new file mode 100644 index 000000000..714863a74 --- /dev/null +++ b/extensions/MozReview/web/js/mozreview.js @@ -0,0 +1,141 @@ +/* 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/. + * + * This Source Code Form is "Incompatible With Secondary Licenses", as + * defined by the Mozilla Public License, v. 2.0. + */ + +var MozReview = {}; + +MozReview.formatElapsedTime = function(s, val) { + val = Math.floor(val); + return val + ' ' + s + (val == 1 ? '' : 's') + ' ago'; +}; + +MozReview.elapsedTime = function(d) { + var ms = Date.now() - d; + + var seconds = ms / 1000; + if (seconds < 60) { + return MozReview.formatElapsedTime('second', seconds); + } + + var minutes = seconds / 60; + if (minutes < 60) { + return MozReview.formatElapsedTime('minute', minutes); + } + + var hours = minutes / 60; + if (hours < 24) { + return MozReview.formatElapsedTime('hour', hours); + } + + var days = hours / 24; + if (days < 30) { + return MozReview.formatElapsedTime("day", days); + } + + var months = days / 30; // enh fudge it + if (months < 12) { + return MozReview.formatElapsedTime("month", months); + } + + var years = months / 12; + return MozReview.formatElapsedTime("year", years); +}; + +MozReview.getReviewRequest = function() { + var hostUrl = $('.mozreview-table').data('mozreviewUrl'); + var tr = $('<tr/>'); + var td = $('<td/>'); + + var rrApiBaseUrl = hostUrl + + 'api/extensions/mozreview.extension.MozReviewExtension/summary/'; + var rrUiBaseUrl = hostUrl + 'r/'; + + function rrUrl(rrId) { + return rrUiBaseUrl + rrId + '/'; + } + + function rrRow(rr, isParent) { + var tdSummary = td.clone(); + var trCommit = tr.clone(); + var a = $('<a/>'); + + if (!isParent) { + tdSummary.addClass('mozreview-child-request-summary'); + } + + a.attr('href', rrUrl(rr.id)); + a.text(rr.summary); + tdSummary.append(a); + + if (isParent) { + tdSummary.append($('<span/>').text(' (' + rr.submitter + ')')); + } + + tdSummary.addClass('mozreview-summary'); + + trCommit.append( + tdSummary, + td.clone().text(rr.status), + td.clone().text(rr.issue_open_count) + .addClass('mozreview-open-issues'), + td.clone().text(MozReview.elapsedTime(new Date(rr.last_updated))) + ); + + if (rr.status == "discarded") { + $('.mozreview-hide-discarded-row').removeClass('bz_default_hidden'); + trCommit.addClass('bz_default_hidden mozreview-discarded-request'); + } + + return trCommit; + } + + $('.mozreview-hide-discarded-link').click(function() { + if ($('.bz_default_hidden.mozreview-discarded-request').length) { + $('.mozreview-discarded-request').removeClass('bz_default_hidden'); + $('.mozreview-discarded-action').text('Hide'); + } else { + $('.mozreview-discarded-request').addClass('bz_default_hidden'); + $('.mozreview-discarded-action').text('Show'); + } + return false; + }); + + $('.mozreview-request').each(function() { + var tbody = $(this); + var rrId = tbody.data('rrid'); + var url = rrApiBaseUrl + rrId + '/'; + var i; + + $.getJSON(url, function(data) { + var parent = data.parent; + tbody.append(rrRow(parent, true)); + for (i = 0; i < data.children.length; i++) { + tbody.append(rrRow(data.children[i], false)); + } + tbody.find('.mozreview-loading-row').addClass('bz_default_hidden'); + }).fail(function(jqXHR, textStatus, errorThrown) { + tbody.find('.mozreview-loading-row').addClass('bz_default_hidden'); + tbody.find('.mozreview-load-error-rrid').text(rrId); + var errRow = tbody.find('.mozreview-loading-error-row'); + var errStr; + if (jqXHR.responseJSON && jqXHR.responseJSON.err && + jqXHR.responseJSON.err.msg) { + errStr = jqXHR.responseJSON.err.msg; + } else if (errorThrown) { + errStr = errorThrown; + } else { + errStr = 'unknown'; + } + errRow.find('.mozreview-load-error-string').text(errStr); + errRow.removeClass('bz_default_hidden'); + }); + }); +}; + +$().ready(function() { + MozReview.getReviewRequest(); +}); |