Project

General

Profile

Highlight my backlog » History » Version 9

Nancy Ouyang, 09/11/2015 09:15 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
<pre><code class="javascript">
104
// ==UserScript==
105
// @name         Highlight my redmine backlog
106
// @namespace    https://arvados.org/projects/arvados/wiki/Highlight_my_backlog
107
// @version      0.1b
108
// @description  Highlights issues assigned to you in redmine Backlogs view and
109
//               puts in parens the total point count you have for each sprint.
110
// @author       Tom Clegg, Abram Connelly, Nancy Ouyang
111
// @match        https://dev.arvados.org/rb/master_backlog/*
112
// @grant        none
113
// ==/UserScript==
114
115
$.ajax('/my/account', {success: function(data, _, _) {
116
    //    var sguthrie = 184;
117
    //    var nouyang = 235;
118
    //    var jli = 303;
119
    //    var aconnelly = 99;
120
    //    var azaranek = 8;
121
    //    var szaranek = 326;
122
    //ROYGBV
123
    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)'};
124
125
    for ( var usercolor in usercolors ) {
126
        (function(usercolor) {
127
            //console.log(usercolors[usercolor]);
128
            var key = $('#api-access-key',data).text();
129
            var url = '/issues.json?assigned_to_id=' + usercolor + '&limit=50';
130
            var ajaxopts = {
131
                dataType: 'json',
132
                headers: {'X-Redmine-API-Key': key},
133
                success: dopage
134
            };
135
            $.ajax(url, ajaxopts);
136
137
            function dopage(data, _, _) {
138
                //console.log(usercolor, usercolors[usercolor]);
139
                var my_sprint_info = {};
140
141
                for (var i=0; i<data.issues.length; i++) {
142
143
                    if ("fixed_version" in data.issues[i]) {
144
                        var sprint_id = data.issues[i].fixed_version.id;
145
                        var sprint_name = data.issues[i].fixed_version.name;
146
                        if (!(sprint_id in my_sprint_info)) {
147
                            my_sprint_info[sprint_id]={"story_points" : 0, "sprint_id" : sprint_id, "sprint_name" : sprint_name };
148
                        }
149
                        if ("story_points" in data.issues[i]) {
150
                            my_sprint_info[sprint_id].story_points += data.issues[i].story_points;
151
                        }
152
                    }
153
154
                    $('#story_'+data.issues[i].id).css({
155
                        //'background':'#F49C54', //orange
156
                        'background':usercolors[usercolor],
157
                        'font-family':'URW Bookman L, serif',
158
                        'font-size':'1.2em',
159
                    });
160
                }
161
162
                if (data.total_count > data.offset + data.limit) {
163
                    $.ajax(url + '&offset=' + (data.offset + data.limit), ajaxopts);
164
                }
165
166
                for (var sprint_id in my_sprint_info) {
167
                    var cur_pnt = $("#sprint_" + sprint_id).children(".fff-right").children(".velocity").text();
168
                    cur_pnt += " (" + my_sprint_info[sprint_id].story_points +")";
169
                    $("#sprint_" + sprint_id).children(".fff-right").children(".velocity").text(cur_pnt);
170
                }
171
            }
172
        } )(usercolor);
173
    }
174
}});
175
176
</code></pre>
177
178 5 Nancy Ouyang
h1. Useful stuff
179 1 Tom Clegg
180 5 Nancy Ouyang
h2. Links
181
182 8 Tom Clegg
* Test it out on a backlog page: https://dev.arvados.org/rb/master_backlog/arvados
183
* The tooltips on the backlog page are loaded dynamically on mouseover: https://dev.arvados.org/rb/story/6394/tooltip?project_id=39
184 4 Nancy Ouyang
* Redmine Backlog, github page: https://github.com/backlogs/redmine_backlogs/
185 1 Tom Clegg
* The Redmine REST API: http://www.redmine.org/projects/redmine/wiki/Rest_api
186 5 Nancy Ouyang
187
h2. Example of changing the background color and the font (in short, use 'font-family' not 'font')
188
189
                'background':'#F49C54', //orange
190
                'font-family':'URW Bookman L, serif',
191
                'font-size':'1.2em',
192 7 Abram Connelly
193
h2. Possible extensions
194
195
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.
196
197
Here is an API call that can get the process started:
198
199
<pre><code class="javascript">
200
function dopage(data) { console.log(data); }
201
var ajaxopts = { dataType: 'json', headers: {'X-Redmine-API-Key' : key}, success: dopage };
202
var url0 = "/issues.json?project_id=39&limit=100&offset=0";
203
var url1 = "/issues.json?project_id=39&limit=100&offset=100";
204
$.ajax(url0,ajaxopts);
205
$.ajax(url1,ajaxopts);
206
</code></pre>
207
208
(39 is the lightning project id).
209
210
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.