diff options
-rw-r--r-- | extensions/MozReview/Extension.pm | 8 | ||||
-rw-r--r-- | extensions/MozReview/template/en/default/moz_review/table.html.tmpl | 33 | ||||
-rw-r--r-- | extensions/MozReview/web/js/mozreview.js | 69 | ||||
-rw-r--r-- | template/en/default/bug/show-header.html.tmpl | 1 |
4 files changed, 59 insertions, 52 deletions
diff --git a/extensions/MozReview/Extension.pm b/extensions/MozReview/Extension.pm index 296240b49..1f2758f9f 100644 --- a/extensions/MozReview/Extension.pm +++ b/extensions/MozReview/Extension.pm @@ -36,19 +36,19 @@ sub template_before_process { $vars->{'mozreview_enabled'} = 1; } } else { - my @rrids; + my $has_mozreview = 0; my $attachments = Bugzilla::Attachment->get_attachments_by_bug($bug); foreach my $attachment (@$attachments) { if ($attachment->contenttype eq 'text/x-review-board-request' && !$attachment->isobsolete) { - push @rrids, ($attachment->data =~ m#/r/(\d+)/?$#); + $has_mozreview = 1; + last; } } - if (scalar @rrids) { + if ($has_mozreview) { $vars->{'mozreview'} = 1; - $vars->{'review_request_ids'} = \@rrids; } } } diff --git a/extensions/MozReview/template/en/default/moz_review/table.html.tmpl b/extensions/MozReview/template/en/default/moz_review/table.html.tmpl index d167a9651..1a40cf7db 100644 --- a/extensions/MozReview/template/en/default/moz_review/table.html.tmpl +++ b/extensions/MozReview/template/en/default/moz_review/table.html.tmpl @@ -8,23 +8,20 @@ <table class="mozreview-requests" data-mozreview-url="[% Bugzilla.params.mozreview_base_url FILTER html %]"> <thead> - <th>Commit</th> - <th>Status</th> - <th>Open Issues</th> - <th>Last Updated</th> + <tr> + <th>Commit</th> + <th>Status</th> + <th>Open Issues</th> + <th>Last Updated</th> + </tr> </thead> - [% FOREACH rrid IN review_request_ids %] - [%# rrid is guaranteed to be an integer %] - <tbody class="mozreview-request" - data-rrid="[% rrid FILTER none %]"> - <tr class="mozreview-loading-row"> - <td colspan="4">Loading...</td> - </tr> - <tr class="mozreview-loading-error-row bz_default_hidden"> - <td colspan="4">Error loading review - request <span class="mozreview-load-error-rrid"></span>: - <span class="mozreview-load-error-string"></span></td> - </tr> - </tbody> - [% END %] + <tbody class="mozreview-request"> + <tr class="mozreview-loading-row"> + <td colspan="4">Loading...</td> + </tr> + <tr class="mozreview-loading-error-row bz_default_hidden"> + <td colspan="4">Error loading review requests: + <span class="mozreview-load-error-string"></span></td> + </tr> + </tbody> </table> diff --git a/extensions/MozReview/web/js/mozreview.js b/extensions/MozReview/web/js/mozreview.js index 2d5fdb0fa..2b9575292 100644 --- a/extensions/MozReview/web/js/mozreview.js +++ b/extensions/MozReview/web/js/mozreview.js @@ -50,8 +50,9 @@ MozReview.getReviewRequest = function() { var tr = $('<tr/>'); var td = $('<td/>'); - var rrApiBaseUrl = hostUrl + - 'api/extensions/mozreview.extension.MozReviewExtension/summary/'; + var rrSummaryApiUrl = hostUrl + + 'api/extensions/mozreview.extension.MozReviewExtension/summary/?bug=' + + BUGZILLA.bug_id; var rrUiBaseUrl = hostUrl + 'r/'; function rrUrl(rrId) { @@ -104,35 +105,43 @@ MozReview.getReviewRequest = function() { } }); - $('.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'; + var tbody = $('tbody.mozreview-request'); + + function displayLoadError(errStr) { + var errRow = tbody.find('.mozreview-loading-error-row'); + errRow.find('.mozreview-load-error-string').text(errStr); + errRow.removeClass('bz_default_hidden'); + } + + $.getJSON(rrSummaryApiUrl, function(data) { + var family, parent, i, j; + + if (data.review_request_summaries.length === 0) { + displayLoadError('none returned from server'); + } else { + for (i = 0; i < data.review_request_summaries.length; i++) { + family = data.review_request_summaries[i]; + parent = family.parent; + tbody.append(rrRow(parent, true)); + for (j = 0; j < family.children.length; j++) { + tbody.append(rrRow(family.children[j], false)); + } } - errRow.find('.mozreview-load-error-string').text(errStr); - errRow.removeClass('bz_default_hidden'); - }); + } + + tbody.find('.mozreview-loading-row').addClass('bz_default_hidden'); + }).fail(function(jqXHR, textStatus, errorThrown) { + 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'; + } + displayLoadError(errStr); + tbody.find('.mozreview-loading-row').addClass('bz_default_hidden'); }); }; diff --git a/template/en/default/bug/show-header.html.tmpl b/template/en/default/bug/show-header.html.tmpl index 4fc1ebe0f..6170d7a45 100644 --- a/template/en/default/bug/show-header.html.tmpl +++ b/template/en/default/bug/show-header.html.tmpl @@ -72,6 +72,7 @@ YAHOO.bugzilla.bugUserLastVisit.update([ [% bug.bug_id FILTER none %] ]); [% END %] }); + BUGZILLA.bug_id = [% bug.id FILTER none %]; [% javascript FILTER none %] [% END %] [% END %] |