diff options
author | byron jones <byron@glob.com.au> | 2018-04-20 19:18:53 +0200 |
---|---|---|
committer | dklawren <dklawren@users.noreply.github.com> | 2018-04-20 19:18:53 +0200 |
commit | 867057e89a8f309cedcc1affbe00923fd8f8b3c2 (patch) | |
tree | 3c0a71df710e2fc96ace93b70d9bba895f36e454 /extensions/MyDashboard/web | |
parent | 5b0812a368b9e646f393ccbf62186ed1b2b535d2 (diff) | |
download | bugzilla-867057e89a8f309cedcc1affbe00923fd8f8b3c2.tar.gz bugzilla-867057e89a8f309cedcc1affbe00923fd8f8b3c2.tar.xz |
Bug 1440828 - Phabricator review requests should show up on the BMO dashboard
Diffstat (limited to 'extensions/MyDashboard/web')
-rw-r--r-- | extensions/MyDashboard/web/js/flags.js | 144 | ||||
-rw-r--r-- | extensions/MyDashboard/web/js/query.js | 7 | ||||
-rw-r--r-- | extensions/MyDashboard/web/styles/mydashboard.css | 5 |
3 files changed, 132 insertions, 24 deletions
diff --git a/extensions/MyDashboard/web/js/flags.js b/extensions/MyDashboard/web/js/flags.js index 95b256708..b56559ae3 100644 --- a/extensions/MyDashboard/web/js/flags.js +++ b/extensions/MyDashboard/web/js/flags.js @@ -16,15 +16,18 @@ $(function () { // Common var counter = 0; var dataSource = { + reviews: null, requestee: null, requester: null }; var dataTable = { + reviews: null, requestee: null, requester: null }; + var hasReviews = !!document.getElementById('reviews_container'); - var updateFlagTable = function(type) { + var updateRequestsTable = function(type) { if (!type) return; counter = counter + 1; @@ -32,32 +35,40 @@ $(function () { var callback = { success: function(e) { if (e.response) { + Y.one('#' + type + '_loading').addClass('bz_default_hidden'); Y.one('#' + type + '_count_refresh').removeClass('bz_default_hidden'); Y.one("#" + type + "_flags_found").setHTML( - e.response.results.length + ' flags found'); + e.response.results.length + + ' request' + (e.response.results.length == 1 ? '' : 's') + + ' found'); dataTable[type].set('data', e.response.results); } }, failure: function(o) { - if (o.error) { - alert("Failed to load flag list from Bugzilla:\n\n" + o.error.message); + Y.one('#' + type + '_loading').addClass('bz_default_hidden'); + Y.one('#' + type + '_count_refresh').removeClass('bz_default_hidden'); + if (o.error && o.error.message) { + alert("Failed to load requests:\n\n" + o.error.message); } else { - alert("Failed to load flag list from Bugzilla."); + alert("Failed to load requests."); } } }; + var method = type === 'reviews' ? 'PhabBugz.needs_review' : 'MyDashboard.run_flag_query'; var json_object = { version: "1.1", - method: "MyDashboard.run_flag_query", + method: method, id: counter, - params: { type : type, - Bugzilla_api_token : (BUGZILLA.api_token ? BUGZILLA.api_token : '') + params: { + type : type, + Bugzilla_api_token : (BUGZILLA.api_token ? BUGZILLA.api_token : '') } }; var stringified = Y.JSON.stringify(json_object); + Y.one('#' + type + '_loading').removeClass('bz_default_hidden'); Y.one('#' + type + '_count_refresh').addClass('bz_default_hidden'); dataTable[type].set('data', []); @@ -86,14 +97,17 @@ $(function () { }; var bugLinkFormatter = function(o) { + if (!o.data.bug_id) { + return '-'; + } var bug_closed = ""; if (o.data.bug_status == 'RESOLVED' || o.data.bug_status == 'VERIFIED') { bug_closed = "bz_closed"; } - return '<a href="show_bug.cgi?id=' + encodeURIComponent(o.value) + + return '<a href="show_bug.cgi?id=' + encodeURIComponent(o.data.bug_id) + '" target="_blank" ' + 'title="' + Y.Escape.html(o.data.bug_status) + ' - ' + - Y.Escape.html(o.data.bug_summary) + '" class="' + Y.Escape.html(bug_closed) + - '">' + o.value + '</a>'; + Y.Escape.html(o.data.bug_summary) + '" class="' + bug_closed + + '">' + o.data.bug_id + '</a>'; }; var updatedFormatter = function(o) { @@ -124,6 +138,85 @@ $(function () { } }; + var phabAuthorFormatter = function(o) { + return '<span title="' + Y.Escape.html(o.data.author_email) + '">' + + Y.Escape.html(o.data.author_name) + '</span>'; + }; + + var phabRowFormatter = function(o) { + var row = o.cell.ancestor(); + + // space in the 'flags' tables is tight + // render requests as two rows - diff title on first row, columns + // on second + + row.insert( + '<tr class="' + row.getAttribute('class') + '">' + + '<td class="yui3-datatable-cell" colspan="4">' + + '<a href="' + o.data.url + '" target="_blank">' + + Y.Escape.html('D' + o.data.id + ' - ' + o.data.title) + + '</a></td></tr>', + 'before'); + + o.cell.set('text', o.data.status == 'added' ? 'pending' : o.data.status); + + return false; + }; + + // Reviews + if (hasReviews) { + dataSource.reviews = new Y.DataSource.IO({ source: 'jsonrpc.cgi' }); + dataSource.reviews.on('error', function(e) { + console.log(e); + try { + var response = Y.JSON.parse(e.data.responseText); + if (response.error) + e.error.message = response.error.message; + } catch(ex) { + // ignore + } + }); + dataTable.reviews = new Y.DataTable({ + columns: [ + { key: 'author_email', label: 'Requester', sortable: true, + formattter: phabAuthorFormatter, allowHTML: true }, + { key: 'id', label: 'Status', sortable: true, + nodeFormatter: phabRowFormatter, allowHTML: true }, + { key: 'bug_id', label: 'Bug', sortable: true, + formatter: bugLinkFormatter, allowHTML: true }, + { key: 'updated', label: 'Updated', sortable: true, + formatter: updatedFormatter, allowHTML: true } + ], + strings: { + emptyMessage: 'No review requests.', + } + }); + + dataTable.reviews.plug(Y.Plugin.DataTableSort); + + dataTable.reviews.plug(Y.Plugin.DataTableDataSource, { + datasource: dataSource.reviews + }); + + dataSource.reviews.plug(Y.Plugin.DataSourceJSONSchema, { + schema: { + resultListLocator: 'result.result', + resultFields: [ 'author_email', 'author_name', 'bug_id', + 'bug_status', 'bug_summary', 'id', 'status', 'title', + 'updated', 'updated_fancy', 'url' ] + } + }); + + dataTable.reviews.render("#reviews_table"); + + Y.one('#reviews_refresh').on('click', function(e) { + updateRequestsTable('reviews'); + }); + Y.one('#reviews_buglist').on('click', function(e) { + loadBugList('reviews'); + }); + } + // Requestee dataSource.requestee = new Y.DataSource.IO({ source: 'jsonrpc.cgi' }); dataSource.requestee.on('error', function(e) { @@ -146,7 +239,7 @@ $(function () { formatter: updatedFormatter, allowHTML: true } ], strings: { - emptyMessage: 'No flag data found.', + emptyMessage: 'No flags requested of you.', } }); @@ -167,7 +260,7 @@ $(function () { dataTable.requestee.render("#requestee_table"); Y.one('#requestee_refresh').on('click', function(e) { - updateFlagTable('requestee'); + updateRequestsTable('requestee'); }); Y.one('#requestee_buglist').on('click', function(e) { loadBugList('requestee'); @@ -196,7 +289,7 @@ $(function () { formatter: updatedFormatter, allowHTML: true } ], strings: { - emptyMessage: 'No flag data found.', + emptyMessage: 'No requested flags found.', } }); @@ -214,19 +307,24 @@ $(function () { } }); - // Initial load - Y.on("contentready", function (e) { - updateFlagTable("requestee"); - }, "#requestee_table"); - Y.on("contentready", function (e) { - updateFlagTable("requester"); - }, "#requester_table"); - Y.one('#requester_refresh').on('click', function(e) { - updateFlagTable('requester'); + updateRequestsTable('requester'); }); Y.one('#requester_buglist').on('click', function(e) { loadBugList('requester'); }); + + // Initial load + if (hasReviews) { + Y.on("contentready", function (e) { + updateRequestsTable('reviews'); + }, "#reviews_table"); + } + Y.on("contentready", function (e) { + updateRequestsTable("requestee"); + }, "#requestee_table"); + Y.on("contentready", function (e) { + updateRequestsTable("requester"); + }, "#requester_table"); }); }); diff --git a/extensions/MyDashboard/web/js/query.js b/extensions/MyDashboard/web/js/query.js index a95c0be61..e5e0979a1 100644 --- a/extensions/MyDashboard/web/js/query.js +++ b/extensions/MyDashboard/web/js/query.js @@ -77,6 +77,7 @@ $(function() { var bugQueryCallback = { success: function(e) { if (e.response) { + Y.one('#query_loading').addClass('bz_default_hidden'); Y.one('#query_count_refresh').removeClass('bz_default_hidden'); Y.one("#query_container .query_description").setHTML(e.response.meta.description); Y.one("#query_container .query_heading").setHTML(e.response.meta.heading); @@ -100,6 +101,8 @@ $(function() { } }, failure: function(o) { + Y.one('#query_loading').addClass('bz_default_hidden'); + Y.one('#query_count_refresh').removeClass('bz_default_hidden'); if (o.error) { alert("Failed to load bug list from Bugzilla:\n\n" + o.error.message); } else { @@ -114,6 +117,7 @@ $(function() { counter = counter + 1; lastChangesCache = {}; + Y.one('#query_loading').removeClass('bz_default_hidden'); Y.one('#query_count_refresh').addClass('bz_default_hidden'); bugQueryTable.set('data', []); bugQueryTable.render("#query_table"); @@ -173,6 +177,9 @@ $(function() { { key: "bug_status", label: "Status", sortable: true }, { key: "short_desc", label: "Summary", sortable: true }, ], + strings: { + emptyMessage: 'Zarro Boogs found' + } }); var last_changes_source = Y.one('#last-changes-template').getHTML(), diff --git a/extensions/MyDashboard/web/styles/mydashboard.css b/extensions/MyDashboard/web/styles/mydashboard.css index 1011a9143..ef34bb100 100644 --- a/extensions/MyDashboard/web/styles/mydashboard.css +++ b/extensions/MyDashboard/web/styles/mydashboard.css @@ -18,10 +18,13 @@ white-space: nowrap; } +#mydashboard .requests { + margin-bottom: 2em; +} + .query_heading { font-size: 18px; font-weight: 600; - margin: 5px 0; color: rgb(72, 72, 72); } |