Last active
August 29, 2015 13:55
-
-
Save p4ul/8764256 to your computer and use it in GitHub Desktop.
Adds "Stories finished this week" to top right of jira rapidboards
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Jira Points | |
// @version 0.1.5 | |
// @description adds issues done this week | |
// @match https://*.atlassian.net/secure/RapidBoard.jspa* | |
// ==/UserScript== | |
// a function that loads jQuery and calls a callback function when jQuery has finished loading | |
function addJQuery(callback) { | |
var script = document.createElement("script"); | |
script.setAttribute("src", "//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"); | |
script.addEventListener('load', function() { | |
var script = document.createElement("script"); | |
script.textContent = "window.jQ=jQuery.noConflict(true);(" + callback.toString() + ")();"; | |
document.body.appendChild(script); | |
}, false); | |
document.body.appendChild(script); | |
} | |
// the guts of this userscript | |
function main() { | |
// Note, jQ replaces $ to avoid conflicts. | |
var $ = jQ; | |
$(document).ready(function(){ | |
//copy from here to end of ready function and paste into console on a jiraboard to test | |
function calculateStoryData() { | |
var days = [], | |
completedStories = 0, | |
message = "", | |
currentDayOfWeek = new Date().getDay(), | |
goal = 16, | |
daysSinceStartOfSprint = currentDayOfWeek; | |
$('.ghx-swimlane:last li.ghx-column:last .ghx-issue .ghx-days').each(function(){ | |
var daysInDone = $(this).attr('title').split(" days")[0]; | |
if( days[daysInDone] === undefined){ | |
days[daysInDone] = 0; | |
} | |
days[daysInDone] ++; | |
if(daysInDone <= daysSinceStartOfSprint) { | |
completedStories ++; | |
} | |
}); | |
console.log(days, "days in done breakdown [number of days:number of issues]"); | |
message = 'Stories finished this week ' + completedStories; | |
//show the number of finished stories in the done coloumn this week up top right | |
if($('.finishedIssues').size() !== 0) { | |
$('.finishedIssues').html(message); | |
} else { | |
$('#ghx-modes-tools').prepend($('<h1>').css('display', 'inline').addClass('finishedIssues').html(message)); | |
} | |
} | |
//run once on page load | |
calculateStoryData(); | |
// bind to changes in the last colomn / bottom swimlane | |
$(".ghx-swimlane:last li.ghx-column:last").bind("DOMSubtreeModified", calculateStoryData); | |
}); | |
} | |
// load jQuery and execute the main function | |
addJQuery(main); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment