Highlight my backlog » History » Version 10
Nancy Ouyang, 09/11/2015 09:21 PM
1 | 1 | Tom Clegg | h1. Highlight my backlog |
---|---|---|---|
2 | |||
3 | <pre><code class="javascript"> |
||
4 | // ==UserScript== |
||
5 | // @name Highlight my redmine backlog |
||
6 | 8 | Tom Clegg | // @namespace https://dev.arvados.org/projects/arvados/wiki/Highlight_my_backlog |
7 | 1 | Tom Clegg | // @version 0.1 |
8 | // @description Highlights issues assigned to you in redmine Backlogs view. |
||
9 | // @author Tom Clegg |
||
10 | 8 | Tom Clegg | // @match https://dev.arvados.org/rb/master_backlog/* |
11 | 1 | Tom Clegg | // @grant none |
12 | // ==/UserScript== |
||
13 | |||
14 | $.ajax('/my/account', {success: function(data, _, _) { |
||
15 | var key = $('#api-access-key',data).text(); |
||
16 | var url = '/issues.json?assigned_to_id=me&limit=100'; |
||
17 | var ajaxopts = { |
||
18 | dataType: 'json', |
||
19 | headers: {'X-Redmine-API-Key': key}, |
||
20 | success: dopage |
||
21 | }; |
||
22 | $.ajax(url, ajaxopts); |
||
23 | function dopage(data, _, _) { |
||
24 | for (var i=0; i<data.issues.length; i++) { |
||
25 | $('#story_'+data.issues[i].id).css({ |
||
26 | //background:'#faa', |
||
27 | 'font-weight':'bold' |
||
28 | }); |
||
29 | } |
||
30 | if (data.total_count > data.offset + data.limit) { |
||
31 | $.ajax(url + '&offset=' + (data.offset + data.limit), ajaxopts); |
||
32 | } |
||
33 | } |
||
34 | }}); |
||
35 | </code></pre> |
||
36 | 3 | Nancy Ouyang | |
37 | h1. puts in parens the total point count you have for each sprint |
||
38 | |||
39 | 6 | Abram Connelly | <pre><code class="javascript"> |
40 | 3 | Nancy Ouyang | |
41 | // ==UserScript== |
||
42 | // @name Highlight my redmine backlog |
||
43 | 8 | Tom Clegg | // @namespace https://dev.arvados.org/projects/arvados/wiki/Highlight_my_backlog |
44 | 3 | Nancy Ouyang | // @version 0.1b |
45 | // @description Highlights issues assigned to you in redmine Backlogs view and |
||
46 | // puts in parens the total point count you have for each sprint. |
||
47 | 6 | Abram Connelly | // @author Tom Clegg, Abram Connelly |
48 | 8 | Tom Clegg | // @match https://dev.arvados.org/rb/master_backlog/* |
49 | 3 | Nancy Ouyang | // @grant none |
50 | // ==/UserScript== |
||
51 | |||
52 | $.ajax('/my/account', {success: function(data, _, _) { |
||
53 | var key = $('#api-access-key',data).text(); |
||
54 | var url = '/issues.json?assigned_to_id=me&limit=100'; |
||
55 | var ajaxopts = { |
||
56 | dataType: 'json', |
||
57 | headers: {'X-Redmine-API-Key': key}, |
||
58 | success: dopage |
||
59 | }; |
||
60 | $.ajax(url, ajaxopts); |
||
61 | function dopage(data, _, _) { |
||
62 | |||
63 | var my_sprint_info = {}; |
||
64 | |||
65 | for (var i=0; i<data.issues.length; i++) { |
||
66 | |||
67 | if ("fixed_version" in data.issues[i]) { |
||
68 | var sprint_id = data.issues[i].fixed_version.id; |
||
69 | var sprint_name = data.issues[i].fixed_version.name; |
||
70 | if (!(sprint_id in my_sprint_info)) { |
||
71 | my_sprint_info[sprint_id]={"story_points" : 0, "sprint_id" : sprint_id, "sprint_name" : sprint_name }; |
||
72 | } |
||
73 | if ("story_points" in data.issues[i]) { |
||
74 | my_sprint_info[sprint_id].story_points += data.issues[i].story_points; |
||
75 | } |
||
76 | } |
||
77 | |||
78 | $('#story_'+data.issues[i].id).css({ |
||
79 | //background:'#faa', |
||
80 | 'font-weight':'bold' |
||
81 | }); |
||
82 | } |
||
83 | |||
84 | if (data.total_count > data.offset + data.limit) { |
||
85 | $.ajax(url + '&offset=' + (data.offset + data.limit), ajaxopts); |
||
86 | } |
||
87 | |||
88 | for (var sprint_id in my_sprint_info) { |
||
89 | var cur_pnt = $("#sprint_" + sprint_id).children(".fff-right").children(".velocity").text(); |
||
90 | cur_pnt += " (" + my_sprint_info[sprint_id].story_points +")"; |
||
91 | $("#sprint_" + sprint_id).children(".fff-right").children(".velocity").text(cur_pnt); |
||
92 | } |
||
93 | } |
||
94 | }}); |
||
95 | |||
96 | </code></pre> |
||
97 | |||
98 | 9 | Nancy Ouyang | h1. color each user a different color |
99 | |||
100 | The user ids are hardcoded in. |
||
101 | Thanks to Abram and http://stackoverflow.com/questions/13977046/using-anonymous-function-in-javascript-for-loops . |
||
102 | |||
103 | 10 | Nancy Ouyang | !Screenshot from 2015-09-11 17:17:22.png! |
104 | |||
105 | 9 | Nancy Ouyang | <pre><code class="javascript"> |
106 | // ==UserScript== |
||
107 | // @name Highlight my redmine backlog |
||
108 | // @namespace https://arvados.org/projects/arvados/wiki/Highlight_my_backlog |
||
109 | // @version 0.1b |
||
110 | // @description Highlights issues assigned to you in redmine Backlogs view and |
||
111 | // puts in parens the total point count you have for each sprint. |
||
112 | // @author Tom Clegg, Abram Connelly, Nancy Ouyang |
||
113 | // @match https://dev.arvados.org/rb/master_backlog/* |
||
114 | // @grant none |
||
115 | // ==/UserScript== |
||
116 | |||
117 | $.ajax('/my/account', {success: function(data, _, _) { |
||
118 | // var sguthrie = 184; |
||
119 | // var nouyang = 235; |
||
120 | // var jli = 303; |
||
121 | // var aconnelly = 99; |
||
122 | // var azaranek = 8; |
||
123 | // var szaranek = 326; |
||
124 | //ROYGBV |
||
125 | var usercolors = {184:'rgba(255,0,0, 0.4)', 235:'rgba(255,153,0, 0.4)', 303:'rgba(255,255,0, 0.4)', 99:'rgba(0,255,0, 0.4)', 8:'rgba(0,255,255, 0.4)', 326:'rgba(128,0,128, 0.4)'}; |
||
126 | |||
127 | for ( var usercolor in usercolors ) { |
||
128 | (function(usercolor) { |
||
129 | //console.log(usercolors[usercolor]); |
||
130 | var key = $('#api-access-key',data).text(); |
||
131 | var url = '/issues.json?assigned_to_id=' + usercolor + '&limit=50'; |
||
132 | var ajaxopts = { |
||
133 | dataType: 'json', |
||
134 | headers: {'X-Redmine-API-Key': key}, |
||
135 | success: dopage |
||
136 | }; |
||
137 | $.ajax(url, ajaxopts); |
||
138 | |||
139 | function dopage(data, _, _) { |
||
140 | //console.log(usercolor, usercolors[usercolor]); |
||
141 | var my_sprint_info = {}; |
||
142 | |||
143 | for (var i=0; i<data.issues.length; i++) { |
||
144 | |||
145 | if ("fixed_version" in data.issues[i]) { |
||
146 | var sprint_id = data.issues[i].fixed_version.id; |
||
147 | var sprint_name = data.issues[i].fixed_version.name; |
||
148 | if (!(sprint_id in my_sprint_info)) { |
||
149 | my_sprint_info[sprint_id]={"story_points" : 0, "sprint_id" : sprint_id, "sprint_name" : sprint_name }; |
||
150 | } |
||
151 | if ("story_points" in data.issues[i]) { |
||
152 | my_sprint_info[sprint_id].story_points += data.issues[i].story_points; |
||
153 | } |
||
154 | } |
||
155 | |||
156 | $('#story_'+data.issues[i].id).css({ |
||
157 | //'background':'#F49C54', //orange |
||
158 | 'background':usercolors[usercolor], |
||
159 | 'font-family':'URW Bookman L, serif', |
||
160 | 'font-size':'1.2em', |
||
161 | }); |
||
162 | } |
||
163 | |||
164 | if (data.total_count > data.offset + data.limit) { |
||
165 | $.ajax(url + '&offset=' + (data.offset + data.limit), ajaxopts); |
||
166 | } |
||
167 | |||
168 | for (var sprint_id in my_sprint_info) { |
||
169 | var cur_pnt = $("#sprint_" + sprint_id).children(".fff-right").children(".velocity").text(); |
||
170 | cur_pnt += " (" + my_sprint_info[sprint_id].story_points +")"; |
||
171 | $("#sprint_" + sprint_id).children(".fff-right").children(".velocity").text(cur_pnt); |
||
172 | } |
||
173 | } |
||
174 | } )(usercolor); |
||
175 | } |
||
176 | }}); |
||
177 | |||
178 | </code></pre> |
||
179 | |||
180 | 5 | Nancy Ouyang | h1. Useful stuff |
181 | 1 | Tom Clegg | |
182 | 5 | Nancy Ouyang | h2. Links |
183 | |||
184 | 8 | Tom Clegg | * Test it out on a backlog page: https://dev.arvados.org/rb/master_backlog/arvados |
185 | * The tooltips on the backlog page are loaded dynamically on mouseover: https://dev.arvados.org/rb/story/6394/tooltip?project_id=39 |
||
186 | 4 | Nancy Ouyang | * Redmine Backlog, github page: https://github.com/backlogs/redmine_backlogs/ |
187 | 1 | Tom Clegg | * The Redmine REST API: http://www.redmine.org/projects/redmine/wiki/Rest_api |
188 | 5 | Nancy Ouyang | |
189 | h2. Example of changing the background color and the font (in short, use 'font-family' not 'font') |
||
190 | |||
191 | 'background':'#F49C54', //orange |
||
192 | 'font-family':'URW Bookman L, serif', |
||
193 | 'font-size':'1.2em', |
||
194 | 7 | Abram Connelly | |
195 | h2. Possible extensions |
||
196 | |||
197 | It would be nice to color each element in the backlog page by who owns it. It would also be nice to be able to add up point totals per sprint for each person as this is a common task. |
||
198 | |||
199 | Here is an API call that can get the process started: |
||
200 | |||
201 | <pre><code class="javascript"> |
||
202 | function dopage(data) { console.log(data); } |
||
203 | var ajaxopts = { dataType: 'json', headers: {'X-Redmine-API-Key' : key}, success: dopage }; |
||
204 | var url0 = "/issues.json?project_id=39&limit=100&offset=0"; |
||
205 | var url1 = "/issues.json?project_id=39&limit=100&offset=100"; |
||
206 | $.ajax(url0,ajaxopts); |
||
207 | $.ajax(url1,ajaxopts); |
||
208 | </code></pre> |
||
209 | |||
210 | (39 is the lightning project id). |
||
211 | |||
212 | The idea being, collect points by sprint name/id for each person seen (stored in a hash). Color each story appropriate as referenced in the 'assigned_to' structure. Not sure where to put the point totals. |