Project

General

Profile

Highlight my backlog » History » Version 12

Tom Clegg, 12/11/2017 09:59 PM
updated for redmine 3.4.2

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
// ==UserScript==
41
// @name         Highlight my redmine backlog
42 1 Tom Clegg
// @namespace    https://dev.arvados.org/projects/arvados/wiki/Highlight_my_backlog
43 12 Tom Clegg
// @version      0.2
44 3 Nancy Ouyang
// @description  Highlights issues assigned to you in redmine Backlogs view and
45
//               puts in parens the total point count you have for each sprint.
46 6 Abram Connelly
// @author       Tom Clegg, Abram Connelly
47 8 Tom Clegg
// @match        https://dev.arvados.org/rb/master_backlog/*
48 3 Nancy Ouyang
// @grant        none
49 1 Tom Clegg
// ==/UserScript==
50 3 Nancy Ouyang
51 12 Tom Clegg
$.ajax('/my/api_key', {success: function(data, _, _) {
52
    var key = $('div.box pre',data).text();
53
    var url = '/issues.json?set_filter=1&f[]=assigned_to_id&op[assigned_to_id]=%3d&v[assigned_to_id][]=me&limit=100';
54 3 Nancy Ouyang
    var ajaxopts = {
55 1 Tom Clegg
        dataType: 'json',
56
        headers: {'X-Redmine-API-Key': key},
57 12 Tom Clegg
        success: dopage,
58 3 Nancy Ouyang
    };
59
    $.ajax(url, ajaxopts);
60
    function dopage(data, _, _) {
61 12 Tom Clegg
62 3 Nancy Ouyang
        var my_sprint_info = {};
63 12 Tom Clegg
64 3 Nancy Ouyang
        for (var i=0; i<data.issues.length; i++) {
65 12 Tom Clegg
66 3 Nancy Ouyang
            if ("fixed_version" in data.issues[i]) {
67 1 Tom Clegg
              var sprint_id = data.issues[i].fixed_version.id;
68
              var sprint_name = data.issues[i].fixed_version.name;
69 3 Nancy Ouyang
              if (!(sprint_id in my_sprint_info)) {
70
                  my_sprint_info[sprint_id]={"story_points" : 0, "sprint_id" : sprint_id, "sprint_name" : sprint_name };
71
              }
72
              if ("story_points" in data.issues[i]) {
73
                my_sprint_info[sprint_id].story_points += data.issues[i].story_points;
74
              }
75
            }
76 12 Tom Clegg
77 3 Nancy Ouyang
            $('#story_'+data.issues[i].id).css({
78 12 Tom Clegg
                color:'#fff',
79
                background:'#444',
80
                'font-weight':'bold',
81 3 Nancy Ouyang
            });
82
        }
83 12 Tom Clegg
84 3 Nancy Ouyang
        if (data.total_count > data.offset + data.limit) {
85
            $.ajax(url + '&offset=' + (data.offset + data.limit), ajaxopts);
86
        }
87 12 Tom Clegg
88 3 Nancy Ouyang
        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
</code></pre>
96
97 9 Nancy Ouyang
h1. color each user a different color 
98
99
The user ids are hardcoded in.
100
Thanks to Abram and http://stackoverflow.com/questions/13977046/using-anonymous-function-in-javascript-for-loops .
101
102 11 Nancy Ouyang
!https://dev.arvados.org/attachments/download/806/Screenshot%20from%202015-09-11%2017_17_22.png! 
103 10 Nancy Ouyang
104 9 Nancy Ouyang
<pre><code class="javascript">
105
// ==UserScript==
106
// @name         Highlight my redmine backlog
107
// @namespace    https://arvados.org/projects/arvados/wiki/Highlight_my_backlog
108 11 Nancy Ouyang
// @version      0.1c
109
// @description  Highlights issues assigned to hardcoded set of  users in redmine Backlogs view and
110
//               puts in parens the total point count everyone have for each sprint. (point ct runs off screen right now)
111 9 Nancy Ouyang
// @author       Tom Clegg, Abram Connelly, Nancy Ouyang
112
// @match        https://dev.arvados.org/rb/master_backlog/*
113
// @grant        none
114
// ==/UserScript==
115
116
$.ajax('/my/account', {success: function(data, _, _) {
117
    //    var sguthrie = 184;
118
    //    var nouyang = 235;
119
    //    var jli = 303;
120
    //    var aconnelly = 99;
121
    //    var azaranek = 8;
122
    //    var szaranek = 326;
123
    //ROYGBV
124
    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)'};
125
126
    for ( var usercolor in usercolors ) {
127
        (function(usercolor) {
128
            //console.log(usercolors[usercolor]);
129
            var key = $('#api-access-key',data).text();
130
            var url = '/issues.json?assigned_to_id=' + usercolor + '&limit=50';
131
            var ajaxopts = {
132
                dataType: 'json',
133
                headers: {'X-Redmine-API-Key': key},
134
                success: dopage
135
            };
136
            $.ajax(url, ajaxopts);
137
138
            function dopage(data, _, _) {
139
                //console.log(usercolor, usercolors[usercolor]);
140
                var my_sprint_info = {};
141
142
                for (var i=0; i<data.issues.length; i++) {
143
144
                    if ("fixed_version" in data.issues[i]) {
145
                        var sprint_id = data.issues[i].fixed_version.id;
146
                        var sprint_name = data.issues[i].fixed_version.name;
147
                        if (!(sprint_id in my_sprint_info)) {
148
                            my_sprint_info[sprint_id]={"story_points" : 0, "sprint_id" : sprint_id, "sprint_name" : sprint_name };
149
                        }
150
                        if ("story_points" in data.issues[i]) {
151
                            my_sprint_info[sprint_id].story_points += data.issues[i].story_points;
152
                        }
153
                    }
154
155
                    $('#story_'+data.issues[i].id).css({
156
                        //'background':'#F49C54', //orange
157
                        'background':usercolors[usercolor],
158
                        'font-family':'URW Bookman L, serif',
159
                        'font-size':'1.2em',
160
                    });
161
                }
162
163
                if (data.total_count > data.offset + data.limit) {
164
                    $.ajax(url + '&offset=' + (data.offset + data.limit), ajaxopts);
165
                }
166
167
                for (var sprint_id in my_sprint_info) {
168
                    var cur_pnt = $("#sprint_" + sprint_id).children(".fff-right").children(".velocity").text();
169
                    cur_pnt += " (" + my_sprint_info[sprint_id].story_points +")";
170
                    $("#sprint_" + sprint_id).children(".fff-right").children(".velocity").text(cur_pnt);
171
                }
172
            }
173
        } )(usercolor);
174
    }
175
}});
176
177
</code></pre>
178
179 5 Nancy Ouyang
h1. Useful stuff
180 1 Tom Clegg
181 5 Nancy Ouyang
h2. Links
182
183 8 Tom Clegg
* Test it out on a backlog page: https://dev.arvados.org/rb/master_backlog/arvados
184
* The tooltips on the backlog page are loaded dynamically on mouseover: https://dev.arvados.org/rb/story/6394/tooltip?project_id=39
185 4 Nancy Ouyang
* Redmine Backlog, github page: https://github.com/backlogs/redmine_backlogs/
186 1 Tom Clegg
* The Redmine REST API: http://www.redmine.org/projects/redmine/wiki/Rest_api
187 5 Nancy Ouyang
188
h2. Example of changing the background color and the font (in short, use 'font-family' not 'font')
189
190
                'background':'#F49C54', //orange
191
                'font-family':'URW Bookman L, serif',
192
                'font-size':'1.2em',
193 7 Abram Connelly
194
h2. Possible extensions
195
196
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.
197
198
Here is an API call that can get the process started:
199
200
<pre><code class="javascript">
201
function dopage(data) { console.log(data); }
202
var ajaxopts = { dataType: 'json', headers: {'X-Redmine-API-Key' : key}, success: dopage };
203
var url0 = "/issues.json?project_id=39&limit=100&offset=0";
204
var url1 = "/issues.json?project_id=39&limit=100&offset=100";
205
$.ajax(url0,ajaxopts);
206
$.ajax(url1,ajaxopts);
207
</code></pre>
208
209
(39 is the lightning project id).
210
211
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.