Tampermonkey
v3.12.58 by Jan Biniok
Edit - Add Story Points to Jira ...
×
?
Installed userscripts
Settings
Utilities
Add Story Points to Jira Dashboard
by Jeff Wilde
Editor
Settings
Save to diskSaveEditor resetFactory resetCloseRun syntax checkUpdate URL:
https://greasyfork.org/scripts/16551-add-story-points-to-jira-dashboard/code/Add%20Story%20Points%20to%20Jira%20Dashboard.user.js
SearchReplaceJump to lineInsert constructorAuto-Indent all
sorting to columns headers.
1
//The MIT License (MIT)
2
//Copyright (c) 2016 Jeff Wilde
3
//Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
//The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
5
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
6
7
// ==UserScript==
8
// @name Add Story Points to Jira Dashboard
9
// @namespace http://vivintsolar.com/
10
// @version 0.2
11
// @description Add the story points to the "Two Dimensional Filter Statistics" dashboard gadget. You can not add custom external gadgets to Jira cloud. This works around the issue. See also
12
// https://answers.atlassian.com/questions/85876/two-dimensional-filter-statistics-summing-story-point
13
// version 0.2 adds sorting to columns headers.
14
// @author Jeff Wilde
15
// @match https://*.atlassian.net/secure/Dashboard.jspa*
16
// @grant none
17
// @downloadURL none
// ==/UserScript==
18
/* jshint -W097 */
19
/* globals $, _ */
20
/* jshint esnext: true */
21
(function () {
22
'use strict';
23
24
const getStoryPointField = () => {
25
const deferred = $.Deferred();
26
$
27
.get(window.location.origin + "/rest/api/2/field")
28
.then((data) => {
29
30
var storyPointFields = _.where(data, {
31
name: "Story Points"
32
});
33
if (storyPointFields.length === 1) {
34
deferred.resolve(storyPointFields[0]);
35
} else {
36
deferred.reject();
37
}
38
})
39
.fail(() => {
40
deferred.reject();
41
});
42
43
return deferred.promise();
44
};
45
46
var storyPointField = getStoryPointField();
47
48
const jqlSearch = (jql) => {
49
const deferred = $.Deferred();
50
51
let url = window.location.origin;
52
url += "/rest/api/2/search";
53
url += jql;
54
$.get(url, function (data) {
55
if (data && data.issues) {
56
storyPointField.then((field) => {
57
let storyPoints = data.issues.map((issue) => {
58
return issue.fields[field.id];
59
60
});
61
let storyPointSum = storyPoints.reduce((prev, curr) => prev + curr, 0);
62
deferred.resolve(storyPointSum);
63
});
64
65
}
66
});
67
return deferred.promise();
68
};
69
70
const parseJqlParameter = (url, link) => {
71
let jqlIndex = url.indexOf("?jql");
72
let jql = url.substring(jqlIndex);
73
74
jqlSearch(jql).then((points) => {
75
link.text(points);
76
});
77
};
78
79
const getStoryPoints = (td) => {
80
const links = td.find("a");
81
links.each(function () {
82
let link = $(this);
83
let href = link.attr("href");
84
85
let jqlIndex = href.indexOf("?jql");
86
let fliterIndex = href.indexOf("?filter");
87
if (jqlIndex < 0 && fliterIndex >= 0) {
88
let filter = href.substring(fliterIndex + 8);
89
let url = window.location.origin;
90
url += "/rest/api/2/filter/";
91
url += filter;
92
93
$.get(url, function (data) {
94
parseJqlParameter(data.searchUrl, link);
95
});
96
97
} else if (jqlIndex >= 0) {
98
parseJqlParameter(href, link);
99
}
100
101
});
102
103
104
};
105
106
const sortTable = (e) => {
107
108
const iconDown = $('');
109
const iconUp = $('');
110
const clicked = $(e.target).closest("th");
111
const row = clicked.closest("tr");
112
const table = row.closest("table");
113
const tbody = table.find("tbody");
114
const tbodyRows = tbody.find("tr");
115
116
let upSorted = clicked.find(".aui-iconfont-arrows-up").length !== 0;
117
let downSorted = clicked.find(".aui-iconfont-arrows-down").length !== 0;
118
119
let sortDown = true;
120
const clickedIndex = clicked.index();
121
122
row.find(".aui-icon").remove();
123
124
if (upSorted){
125
clicked.append(iconDown);
126
sortDown = true;
127
}
128
else if (downSorted){
129
clicked.append(iconUp);
130
sortDown = false;
131
}
132
else{
133
clicked.append(iconDown);
134
sortDown = true;
135
}
136
137
let rowArray = tbodyRows.toArray();
138
let totalRow = rowArray.pop();
139
140
tbodyRows.remove();
141
rowArray = _.sortBy(rowArray, (row) => {
142
let sortByTd = $(row).find( "td:nth-of-type(" + clickedIndex + ")" );
143
let value = Number(sortByTd.text());
144
return value;
145
});
146