Last active
March 6, 2017 15:55
-
-
Save IIIEII/12fa6acb8b411e549eb8d8cc22aa5b0d to your computer and use it in GitHub Desktop.
SBT Program Board Beautifier
This file contains 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 SBT Program Board | |
// @namespace https://sbtatlas.sigma.sbrf.ru/jira/secure/ProgramBoard | |
// @version 0.1 | |
// @author Alexander Shepel | |
// @match https://sbtatlas.sigma.sbrf.ru/jira/secure/ProgramBoard* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
// Function to get/set extension enabled status | |
var isBeautified = function(val){ | |
if (val) { | |
localStorage.setItem('sbt-beautify-board-isBeautified', val); | |
} | |
return localStorage.getItem('sbt-beautify-board-isBeautified')==='true'; | |
}; | |
// Extension enabler | |
var loadExtension = function() { | |
$(".aui-sidebar").css("display", "none"); | |
$("#sbt-program-board").css("padding-left", "0"); | |
$("#program-board-header").css({ | |
"z-index": "1000", | |
"position": "fixed", | |
"top": "162px" | |
}); | |
$("#program-board-header .sbt-program-board-column").css({ | |
"background-color": "white", | |
"box-shadow": "0 0 4px rgba(0,0,0,0.5)", | |
// "padding": "10px", | |
// "box-sizing": "border-box" | |
}) | |
$("#sbt-program-board-content").css({ | |
"padding-top": "84px" | |
}); | |
$(".sbt-program-board-swimlane-container").css({ | |
"border-top": "3px solid gray", | |
"padding-top": "10px" | |
}); | |
$(".sbt-program-board-swimlane-header").css({ | |
"position": "relative", | |
"padding": "10px", | |
"box-shadow": "0 0 2px rgba(0,0,0,1)" | |
}); | |
$(".sbt-program-board-swimlane-header-button, .sbt-program-board-swimlane-header").css({ | |
"z-index": "900", | |
"background-color": "white" | |
}); | |
window.scrollTo(0, 0); | |
var epicOffset = parseInt($(".sbt-program-board-swimlane-header").css('left')); | |
$(window).scroll(function(){ | |
// position sprint names | |
var contentTop = parseInt($("#sbt-program-board-content").offset().top - $(window).scrollTop()); | |
$("#program-board-header").css({ | |
"top": Math.max(contentTop + 1, 40) + "px", | |
"margin-left": -$(window).scrollLeft() + "px" | |
}); | |
//move epic names | |
var swimlanes = $(".sbt-program-board-swimlane-container"); | |
var epicsButtons = $(".sbt-program-board-swimlane-header-button"); | |
var epicsNames = $(".sbt-program-board-swimlane-header"); | |
for (var i = 0; i < swimlanes.length; i++) { | |
var laneTop = parseInt($(swimlanes[i]).offset().top - $(window).scrollTop()); | |
var top = Math.min($(swimlanes[i]).outerHeight() - 45, Math.max(0, 110-laneTop)); | |
$(epicsButtons[i]).css({ | |
"top": top + "px", | |
"margin-left": $(window).scrollLeft() | |
}); | |
$(epicsNames[i]).css({ | |
"top": top + "px", | |
"padding-top": "10px", | |
"padding-bottom": "10px", | |
}); | |
} | |
}); | |
}; | |
// Add extension enabler button | |
$('<li><a id="sbt-beautify-board"><span class="aui-icon aui-icon-small aui-iconfont-' + (isBeautified()?'un':'') + 'watch"></span></a></li>').insertBefore('#create-menu'); | |
$('#sbt-beautify-board').click(function() { | |
if (!isBeautified()){ | |
$('#sbt-beautify-board > span').addClass('aui-iconfont-unwatch').removeClass('aui-iconfont-watch'); | |
loadExtension(); | |
isBeautified("true"); | |
} else { | |
isBeautified("false"); | |
$('#sbt-beautify-board > span').addClass('aui-iconfont-watch').removeClass('aui-iconfont-unwatch'); | |
location.reload(); | |
} | |
}); | |
if (isBeautified()) | |
loadExtension(); | |
// Gather programBoard component | |
var programBoard = null; | |
for (var num in window.AJS.$.cache) { | |
var cache = window.AJS.$.cache[num]; | |
if (cache && cache.handle && cache.handle.elem) { | |
var reactElem = cache.handle.elem[Object.keys(cache.handle.elem).find(function(key){ | |
if (key.indexOf("__react") === 0) return true; | |
})]; | |
if (reactElem) { | |
while (reactElem["_currentElement"]["_owner"]["_currentElement"]["type"].name != 'ProgramBoard') { | |
reactElem = reactElem["_hostParent"]; | |
} | |
programBoard = reactElem["_currentElement"]["_owner"]["_instance"]; | |
break; | |
} | |
} | |
} | |
// Add data refresh button | |
$('<li><a id="sbt-reload-board"><span class="aui-icon aui-icon-small aui-iconfont-build"></span></a></li>').insertBefore('#create-menu'); | |
$('#sbt-reload-board').click(function() { | |
$("body").css("cursor", "progress"); | |
if (programBoard) { | |
$.get( window.location.pathname+window.location.search, function( data ) { | |
data = JSON.parse(data.match(/var j = (\{[^\n]*\});\n/)[1]); | |
data = JIRA.SBT.PB.view.programBoardData.prepareData(data); | |
programBoard.setState({data: data}, function() { | |
$("body").css("cursor", "default"); | |
}); | |
}); | |
} | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment