Jump to content

MediaWiki:Gadget-BugStatusUpdate.js and User:Technical 13/SandBox/Gadget-BugStatusUpdate.js: Difference between pages

From Wikipedia, the free encyclopedia
(Difference between pages)
Content deleted Content added
m space
 
Technical 13 (talk | contribs)
m Trying to fix backwards compatibility.
 
Line 1: Line 1:
/*
/*
* Bug Status Update Gadget
* Bug Status Update Gadget
* Author: Rob Moen (robm)
* Author: Donald Fortier (User:Technical_13)
* Based on original code:
** Author: Rob Moen (robm)
** Source: [[mw:User:Robmoen/bugStatusUpdate.js]]
* Description:
* Description:
* Finds and updates bug status templates on a page.
* Finds and updates bug status templates on a page.
* Makes 1 JSONP request to Bugzilla JSON RPC api.
* Makes 1 JSONP request to Bugzilla JSON RPC api.
* Source: [[mw:User:Robmoen/bugStatusUpdate.js]]
*/
*/
(function($){
(function($){
var ids = [],
var ids = [],
target = 'https://bugzilla.wikimedia.org/jsonrpc.cgi';
target = 'https://bugzilla.wikimedia.org/jsonrpc.cgi';
//ugly way to compose the request parameters. though, bugzilla is happy with it
//ugly way to compose the request parameters. though, bugzilla is happy with it
var getParams = function (ids) {
var getParams = function (ids) {
return 'method=Bug.get&id=158&params=[{ "ids": ['+ ids.join(',') +'],"include_fields":["last_change_time","status", "id", "summary"]}]';
return 'method=Bug.get&id=158&params=[{ "ids": ['+ ids.join(',') +'],"include_fields":["last_change_time","status", "id", "summary"]}]';
};
};
//get the bug id numbers on the page
//get the bug id numbers on the page
$('.mw-trackedTemplate').each(function() {
$('.mw-trackedTemplate').each(function() {
var title = $(this).find('a[title^="bugzilla:"]').attr('title');
var title = $(this).find('a[title^="bugzilla:"]').attr('title');
ids.push(title.split(':')[1]);
ids.push(title.split(':')[1]);
});
});


// Do not query if no ids were found
// Do not query if no ids were found
Line 28: Line 30:
}
}
//make jsonp
//make jsonp
$.ajax({
$.ajax({
url: target,
url: target,
dataType:'jsonp',
dataType:'jsonp',
data: getParams(ids),
data: getParams(ids),
success: function (data) {
success: function (data) {
var color = {
var color = {
"RESOLVED": "green",
"RESOLVED": "green",
"CRITICAL": "red"
"CRITICAL": "red"
},
},
statusProps = {
statusProps = {
'font-weight': 'bold',
'font-weight': 'bold',
'font-size': '1.5em',
'font-size': '1.5em',
'text-transform': 'uppercase'
'text-transform': 'uppercase'
};
};
if(data.result.bugs) {
if(data.result.bugs) {
for(var b in data.result.bugs) {
for(var b in data.result.bugs) {
//find the right bug to update
//find the right bug to update
$item = $('.mw-trackedTemplate')
var $item = $('.mw-trackedTemplate').find('a[title^="bugzilla:'+data.result.bugs[b].id+'"]');
.find('a[title^="bugzilla:'+data.result.bugs[b].id+'"]');
var title = $('.trakbug-'+data.result.bugs[b].id);
title = $('#trakbug-'+data.result.bugs[b].id)


if(title) {
if(title) {
title.text( data.result.bugs[b].summary );
title.text( data.result.bugs[b].summary );
}
}
// COMPATIBILITY SECTION TOP FOR CURRENT SETUP
var titleBACK = $('#trakbug-'+data.result.bugs[b].id);
if(titleBACK) {
titleBACK.text( data.result.bugs[b].summary );
}
// COMPATIBILITY SECTION BOTTOM FOR CURRENT SETUP

if($item) {
//find child, if exists
$status = $item
.parent()
.next('p')
.children('span');
//create the status element if it does not exist
if($status.length === 0){
$item
.parent()
.parent()
.append(
$('<p />').append(
$('<span />').css(statusProps)
.text('Status')
)
);
}
//udpate the status element
$item
.parent()
.next('p')
.children('span')
.css('color', color[data.result.bugs[b].status] || '#333333')
.text(data.result.bugs[b].status);
$status = null;
}
if($item) {
}
//find child, if exists
}
$status = $item
}
.parent()
});
.next('p')
.children('span');
//create the status element if it does not exist
if($status.length === 0){
$item
.parent()
.parent()
.append(
$('<p />').append(
$('<span />').css(statusProps)
.text('Status')
)
);
}
//udpate the status element
$item
.parent()
.next('p')
.children('span')
.css('color', color[data.result.bugs[b].status] || '#333333')
.text(data.result.bugs[b].status);
$status = null;
}
}
}
}
});
})(jQuery);
})(jQuery);

Revision as of 20:58, 18 June 2013

/*
 * 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';
 
    //ugly way to compose the request parameters. though, 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 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) {
                return;
        }
 
    //make jsonp
    $.ajax({
        url: target,
        dataType:'jsonp',
        data: getParams(ids),
        success: function (data) {
 
            var        color = {
                        "RESOLVED": "green",
                        "CRITICAL": "red"
                    },
                    statusProps = {
                        'font-weight': 'bold',
                        'font-size': '1.5em',
                        'text-transform': 'uppercase'
                    };
 
            if(data.result.bugs) {
                for(var b in data.result.bugs) {
                    //find the right bug to update
                    var $item = $('.mw-trackedTemplate').find('a[title^="bugzilla:'+data.result.bugs[b].id+'"]');
                    var title = $('.trakbug-'+data.result.bugs[b].id);

                    if(title) {
                        title.text( data.result.bugs[b].summary );
                    }
// COMPATIBILITY SECTION TOP FOR CURRENT SETUP
                    var titleBACK = $('#trakbug-'+data.result.bugs[b].id);
                    if(titleBACK) {
                        titleBACK.text( data.result.bugs[b].summary );
                    }
// COMPATIBILITY SECTION BOTTOM FOR CURRENT SETUP

                    if($item) {
                        //find child, if exists
                        $status = $item
                            .parent()
                            .next('p')
                            .children('span');
                        //create the status element if it does not exist
                        if($status.length === 0){
                            $item
                                .parent()
                                .parent()
                                .append(
                                    $('<p />').append(
                                        $('<span />').css(statusProps)
                                            .text('Status')
                                    )
                                );
                        }
                        //udpate the status element
                        $item
                            .parent()
                            .next('p')
                            .children('span')
                            .css('color', color[data.result.bugs[b].status] || '#333333')
                            .text(data.result.bugs[b].status);    
                        $status = null;
 
                    }
                }
            }
        }
    });
 
})(jQuery);