Skip to content

Instantly share code, notes, and snippets.

@rcarmo
Last active December 14, 2015 21:29
Show Gist options
  • Select an option

  • Save rcarmo/5151527 to your computer and use it in GitHub Desktop.

Select an option

Save rcarmo/5151527 to your computer and use it in GitHub Desktop.
Build a dashboard using XMLRPC calls to Trac. Relies on jQuery Masonry (http://masonry.desandro.com). And uses jQuery because that's what Trac comes bundled with.
<script src="/main/chrome/shared/js/jquery.masonry.min.js"></script>
<script>
function dashboard(container, tracs, pattern) {
var boxes = {};
// set up the container with the appropriate classes
container.empty();
container.addClass('fluid');
container.addClass('clearfix');
container.masonry({
itemSelector: '.box',
columnWidth: function(containerWidth) { return containerWidth/12; }
});
$.each(tracs, function(index, value) {
var calls = [];
// setup our Ajax calls
$.ajaxSetup({
url:'/' + value + '/login/jsonrpc',
type:'POST',
contentType: 'application/json',
"async": false,
});
calls.push({method: 'wiki.getAllPages',params:[]})
$.ajax({
data: JSON.stringify({params: calls, method: "system.multicall"}),
success: function(data){
var names = [];
$(data.result[0].result).each(function(id){
var name = data.result[0].result[id];
if(name.match(pattern)){ names.push(name) }
})
boxes[value] = names;
}, // data
error: function (request, status, error) {
console.log("Error getting pages from " + value + ": " + request.responseText);
}
}); // ajax
}); // each
$.each(tracs, function(index,value) {
var calls = [];
// setup our Ajax calls
$.ajaxSetup({
url:'/' + value + '/login/jsonrpc',
type:'POST',
contentType: 'application/json',
"async": false,
});
$(boxes[value]).each(function(id){
calls.push({
method:'wiki.getPageHTML',
params:[boxes[value][id]]
})
});
$.ajax({
data: JSON.stringify({params: calls, method: "system.multicall"}),
success: function(data){
$(data.result).each(function(id){
var box = $('<div class="box col1"/>').append(data.result[id].result);
container.append(box).masonry('appended',box);
})
}, // data
error: function (request, status, error) {
console.log("Error getting pages from " + value + ": " + request.responseText);
}
}); // ajax
}); // each
} // function
$(function() {
dashboard($('#masonry'),['changes','acls'],/^dash\//g);
})
</script>
<div id="masonry"><center><h1>Loading...</h1></div>
<br clear="all">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment