// ==UserScript==
// @name TFS Helper
// @namespace http://jonas.ninja
// @version 1.8.0
// @description Adds styles and moves things around so that oft-used functions are easier
// @author @_jnblog
// @match http://*/tfs/DefaultCollection/*/_backlogs*
// @match http://*/tfs/DefaultCollection/*/_versionControl*
// @match http://*/tfs/DefaultCollection/*/_workitems*
// @grant GM_addStyle
// @downloadURL none
// ==/UserScript==
/* jshint -W097 */
/* global GM_addStyle */
/* jshint asi: true, multistr: true */
var $ = unsafeWindow.jQuery;
var topClass = "makeTfsNotAwful"
$('body').addClass(topClass)
waitForKeyElements("div.tab-page[rawtitle=Links]", doEverything, false)
$(document).on('click', 'input.task-identifier', copyId)
.on('dblclick', 'input.task-identifier', copyMessage)
function doEverything(linksPane) {
if ($(linksPane).data('moved')) {
return
}
showLinksPane(linksPane)
stackAllTabs($(linksPane))
addBlockedButton(linksPane)
window.setTimeout(function() {
addTaskIdCopyUtilities(linksPane)
changeDialogBorderColor(linksPane)
}, 250)
refreshNowAndLater();
}
function showLinksPane(linksPane) {
$(linksPane).data('moved', true)
.addClass('linksPanel')
.prepend($("
").addClass('linksPanelHeader')
.text($(linksPane).attr('rawtitle')))
var link = $('a[rawtitle=Links]')
link.closest('td').parent().closest('td').prev().css({'width': '35%' /*, 'padding-right': '12px'*/})
link.closest('td').prepend(linksPane)
link.parent().remove()
}
function changeDialogBorderColor(linksPane) {
// depending on the type of this work item, color the border differently
var dialog = $(linksPane).closest('.workitem-dialog')
var caption = dialog.find('a.caption').text()
if (caption.indexOf('Product Backlog Item ') !== -1) {
dialog.css('border-color', '#009CCC') // blue
} else if (caption.indexOf('Bug ') !== -1) {
dialog.css('border-color', '#CC293D') // red
} else if (caption.indexOf('Feature ') !== -1) {
dialog.css('border-color', '#773B93') // purple
} else { // Task
dialog.css('border-color', '#E0C252') // yellow
}
}
function stackAllTabs($linksPane) {
var column2 = $linksPane.closest('table.content').parent('.column')
var column1 = column2.prev()
var modalRect = $linksPane.closest('.work-item-view')[0].getBoundingClientRect()
var editorContainer = column1.find('.richeditor-editarea')
if (Math.max(window.innerWidth, document.documentElement.clientWidth) >= 1600) {
// not stackable
var editorRect = editorContainer[0].getBoundingClientRect()
var newheight = modalRect.bottom - editorRect.bottom + editorRect.height - 10
var col2height = column2.height() - 52
editorContainer.css('min-height', Math.max(newheight, col2height))
.children('iframe').css('height', Math.max(newheight, col2height))
} else {
// stackable
column2.add(column1).css({width: '100%', display: 'block'})
var contentHeight = $linksPane.closest('.work-item-view').children('.witform-layout')[0].getBoundingClientRect().bottom
var newHeight = editorContainer.height() + modalRect.bottom - contentHeight
editorContainer.css('min-height', Math.max(editorContainer.height(), newHeight))
.children('iframe').css('height', Math.max(editorContainer.height(), newHeight))
}
}
function addTaskIdCopyUtilities(linksPane) {
$('.workitem-info-bar').find('.info-text-wrapper').each(function() {
var $header = $(this)
if ($header.hasClass('added')) {
return
}
$header.addClass('added')
var id = $header.find('a.caption').text().match(/\d+/)[0]
var $container = $('
').css('display', 'inline-block')
$container.append($('').addClass('task-identifier'))
$container.append($('').addClass('copy-message'))
$header.find('span.info-text').after($container)
});
}
function addBlockedButton(linksPane) {
var blockedInput = linksPane.find('[aria-label=Blocked]');
blockedInput.closest('.control-cell').css({width: 'calc(100% - 60px)', 'min-width': '50px'})
}
function copyId(e) {
displayResult(copy(this), $(this).next('span.copy-message'), $(this).parent())
}
function copyMessage(e) {
var optMessage = makeMessage(this)
displayResult(copy(this, optMessage), $(this).next('span.copy-message'), $(this).parent(), true)
}
function copy(elToCopy, optMessage) {
var $fakeElem = $('