Thursday, April 24, 2014

Hide Done Column On TFS Web Portal Task Boards

Working with TFS's kanbon board layout can be difficult as the number of tasks grow and the number of tasks in your done column ever increase. If the done column is hidden, it becomes easier to scroll to find things that are still in play. Below is a script that I use to accomplish that.

This script handles custom setups where the Done column is not in it's default location.
// ==UserScript==
// @name        TFS Boards Hide Done Column
// @namespace   net.intellectualponderings.TFSBoardsHideDoneColumn
// @include     http://*:8080/tfs/*/_boards*
// @require     http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js
// @version     1
// @grant       GM_addStyle
// @grant       unsafeWindow
// ==/UserScript==

// Default easy method, doesn't work on customized layouts.
//GM_addStyle('#taskboard-table_s3, td[axis="taskboard-table_s3"] { display: none ! important; }');

var ob = (function () {
    var MutationObserver = window.MutationObserver || window.WebKitMutationObserver,
    eventListenerSupported = window.addEventListener;
    return function (obj, callback) {
        if (MutationObserver) {
            var obs = new MutationObserver(function (mutations, observer) {
                if (mutations[0].addedNodes.length || mutations[0].removedNodes.length)
                callback();
            });
            obs.observe(obj, {
                childList: true,
                subtree: true
            });
        } else if (eventListenerSupported) {
            obj.addEventListener('DOMNodeInserted', callback, false);
            obj.addEventListener('DOMNodeRemoved', callback, false);
        }
    }
}) ();
ob(document.getElementById('taskboard'), function () {
    var dth = $('.taskboard-row th:contains("Done")');
    if (dth) {
        var col = dth[0].id;
        // Hide the column
        GM_addStyle('#' + col + ', td[axis="' + col + '"] { display: none ! important; }');
        var numColumns = $('th.taskboard-cell:not(.taskboard-parent):visible').length
        if (numColumns > 0) {
            var newColumnWidth = 100 / numColumns;
            GM_addStyle('th.taskboard-cell:not(.taskboard-parent) { width: ' + newColumnWidth + '% !important; }');
        }
    }
});