-
Notifications
You must be signed in to change notification settings - Fork 1
/
jira-sprintboard-info.user.js
139 lines (122 loc) · 5.08 KB
/
jira-sprintboard-info.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// ==UserScript==
// @name JIRA Sprintboad quick info
// @namespace https://github.com/m-rk/jira-tamper
// @version 0.5
// @description Adds SP and Release Version to sprint board
// @author Alan Seymour https://github.com/alan-seymour
// @match https://navitasltd.atlassian.net/secure/RapidBoard.jspa?rapidView=1*
// @grant none
// @require https://code.jquery.com/jquery-3.1.1.min.js
// @run-at document-start
// ==/UserScript==
var tickets = [];
function loadExtraInfo(node) {
tickets.push(jQ(node).find('div').first().data('issue-key'));
if (tickets.length == jQ('.ghx-swimlane').length) {
//found all tickets
fetchIssues(tickets);
tickets = [];
}
}
function fetchIssues(issues) {
var filteredIssues = issues.filter((e) => { return e != '' && e != undefined && e != null; });
var issueString = filteredIssues.join(', ');
jQ.get('https://navitasltd.atlassian.net/rest/api/2/search/', {"jql": "issue in ("+issueString+")"}, function(data){displayData(data);});
}
function displayData(data) {
// clear old info
jQ('.jira-tamper-sbi').remove();
// display new info
data.issues.forEach(function(issue){renderIssueDetails(issue);});
}
function renderIssueDetails(issue) {
if(issue.fields.fixVersions.length > 0) {
jQ('.ghx-swimlane-header[data-issue-key="' + issue.key + '"]').find('.ghx-info').append('<span class="jira-tamper-sbi aui-label ghx-label-version ghx-label ghx-label-double" style="margin-left: 5px;">'+issue.fields.fixVersions[0].name+'</span>');
}
jQ('.ghx-swimlane-header[data-issue-key="' + issue.key + '"]').find('.ghx-heading').prepend('<span class="jira-tamper-sbi aui-badge ghx-statistic-badge" style="margin-right:5px;">'+issue.fields.customfield_10004+'</span>');
}
window.jQ = $.noConflict(true);
waitForKeyElements('.ghx-swimlane', loadExtraInfo, false);
/*--- waitForKeyElements(): A utility function, for Greasemonkey scripts,
that detects and handles AJAXed content.
Usage example:
waitForKeyElements (
"div.comments"
, commentCallbackFunction
);
//--- Page-specific function to do what we want when the node is found.
function commentCallbackFunction (jNode) {
jNode.text ("This comment changed by waitForKeyElements().");
}
IMPORTANT: This function requires your script to have loaded jQuery.
*/
function waitForKeyElements (
selectorTxt, /* Required: The jQuery selector string that
specifies the desired element(s).
*/
actionFunction, /* Required: The code to run when elements are
found. It is passed a jNode to the matched
element.
*/
bWaitOnce, /* Optional: If false, will continue to scan for
new elements even after the first match is
found.
*/
iframeSelector /* Optional: If set, identifies the iframe to
search.
*/
) {
var targetNodes, btargetsFound;
if (typeof iframeSelector == "undefined")
targetNodes = jQ(selectorTxt);
else
targetNodes = jQ(iframeSelector).contents ()
.find (selectorTxt);
if (targetNodes && targetNodes.length > 0) {
btargetsFound = true;
/*--- Found target node(s). Go through each and act if they
are new.
*/
targetNodes.each ( function () {
var jThis = jQ(this);
var alreadyFound = jThis.data ('alreadyFound') || false;
if (!alreadyFound) {
//--- Call the payload function.
var cancelFound = actionFunction (jThis);
if (cancelFound)
btargetsFound = false;
else
jThis.data ('alreadyFound', true);
}
} );
}
else {
btargetsFound = false;
}
//--- Get the timer-control variable for this selector.
var controlObj = waitForKeyElements.controlObj || {};
var controlKey = selectorTxt.replace (/[^\w]/g, "_");
var timeControl = controlObj [controlKey];
//--- Now set or clear the timer as appropriate.
if (btargetsFound && bWaitOnce && timeControl) {
//--- The only condition where we need to clear the timer.
clearInterval (timeControl);
delete controlObj [controlKey]
}
else {
//--- Set a timer, if needed.
if ( ! timeControl) {
timeControl = setInterval ( function () {
waitForKeyElements ( selectorTxt,
actionFunction,
bWaitOnce,
iframeSelector
);
},
300
);
controlObj [controlKey] = timeControl;
}
}
waitForKeyElements.controlObj = controlObj;
}