User:Technical 13/SandBox/Gadget-BugStatusUpdate.js: Difference between revisions

Content deleted Content added
Technical 13 (talk | contribs)
Added my name to the description at the top and added first fix... Multiple uses for the same bug on a page.
Technical 13 (talk | contribs)
Strip out unneeded backwards compat and format to be easier to read.
 
(5 intermediate revisions by the same user not shown)
Line 1:
/*
* Bug Status Update Gadget
* Author: Donald Fortier (User:Technical_13)
* * Based on original code:
* ** Author: Rob Moen (robm)
* ** Source: [[mw:User:Robmoen/bugStatusUpdate.js]]
* Description:
* Finds and updates bug status templates on a page.
* Makes 1 JSONP request to Bugzilla JSON RPC api.
*/
(function($){
var ids = [], target = 'https://bugzilla.wikimedia.org/jsonrpc.cgi';
var ids = [],
target = 'https://bugzilla.wikimedia.org/jsonrpc.cgi';
//ugly // Ugly way to compose the request parameters. thoughThough, bugzilla is happy with it.
var getParams = function ( ids ) {
return 'method=Bug.get&id=158&params=[{ "ids": [' + ids.join(',') + '],"include_fields":["last_change_time","status", "id", "summary"]}]';
};
//get // Get the bug id numbers on the page
$( '.mw-trackedTemplate' ).each( function() {
var title = $( this ).find( 'a[title^="bugzilla:"]' ).attr( 'title' );
ids.push( title.split( ':' )[1] );
});
// // Do not query if no ids were found
 
if ( !ids.length ) {
// Do not query if no ids were found
return;
if (!ids.length) {
}
return;
// Make jsonp request
}
$.ajax({
url: target,
//make jsonp
dataType: 'jsonp',
$.ajax({
data: getParams( ids ),
url: target,
success: function ( data ) {
dataType:'jsonp',
var color = {
data: getParams(ids),
"RESOLVED": "green",
success: function (data) {
"CRITICAL": "red"
},
var color = {
statusProps = {
"RESOLVED": "green",
'font-weight': 'bold',
"CRITICAL": "red"
'font-size': '1.5em',
},
'text-transform': 'uppercase'
statusProps = {
};
'font-weight': 'bold',
if ( data.result.bugs ) {
'font-size': '1.5em',
for( var b in data.result.bugs ) {
'text-transform': 'uppercase'
// //find the right bug to update
};
var $item = $( '.mw-trackedTemplate' ).find( 'a[title^="bugzilla:' + data.result.bugs[b].id + '"]' );
var title = $( '.trakbug-' + if(data.result.bugs[b].id ) {;
if( title ) {
for(var b in data.result.bugs) {
title.text( data.result.bugs[b].summary );
//find the right bug to update
}
$item = $('.mw-trackedTemplate')
if( $item ) {
.find('a[title^="bugzilla:'+data.result.bugs[b].id+'"]');
// // Find child, if it exists.
title = $('.trakbug-'+data.result.bugs[b].id)
$status = $item
 
.parent()
if(title) {
.next( 'p' )
title.text( data.result.bugs[b].summary );
.children( 'span' );
}
// //create the status element if it does not exist
if( $status.length === 0 ){
$item
if($item) {
.parent()
//find child, if exists
.parent()
$status = $item
.append(
.parent()
$( '<p />' ).append(
.next('p')
$( '<span />' ).css( statusProps )
.children('span');
.text( 'Status' )
//create the status element if it does not exist
)
if($status.length === 0){
);
$item
}
.parent()
// // Udpate the status element.
.parent()
$item
.append(
.parent()
$('<p />').append(
.next( 'p' )
$('<span />').css(statusProps)
.children( 'span' )
.text('Status')
.css( 'color', color[data.result.bugs[b].status] || '#333333' )
)
.text( data.result.bugs[b].status );
);
$status = null;
}
}
//udpate the status element
}
$item
}
.parent()
}// End of success:
.next('p')
});
.children('span')
})(jQuery);
.css('color', color[data.result.bugs[b].status] || '#333333')
.text(data.result.bugs[b].status);
$status = null;
}
}
}
}
});
})(jQuery);