-
Notifications
You must be signed in to change notification settings - Fork 2
/
agile.php
261 lines (216 loc) · 5.93 KB
/
agile.php
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
<?php
require 'inc.bootstrap.php';
do_logincheck();
$boards = $user->agile_boards;
$boardId = @$_GET['board'] ?: $user->config('agile_view_id');
$baseParams = array('rapidViewId' => $boardId);
if ( !$boardId || !isset($boards[$boardId]) ) {
$_title = 'Agile';
include 'tpl.header.php';
?>
<h1>Plan</h1>
<form method="get" action="">
<p><select name="board"><?= html_options($boards, $boardId, '-- Select a board --') ?></select></p>
<p><button>Open</button></p>
</form>
<?php
exit;
}
$params = $baseParams;
$board = jira_get('/rest/greenhopper/1.0/xboard/config', $params, $error, $info);
// DEBUG //
// $board = json_decode(file_get_contents('debug-board.json'));
// echo "\n\n\n\n\n" . json_encode($board) . "\n\n\n\n\n";
// exit;
// DEBUG //
// echo '<pre>';
// print_r($board);
// var_dump($error);
// print_r($info);
// exit;
$params = $baseParams;
if ( !empty($_GET['filter']) ) {
$params += array('activeQuickFilters' => $_GET['filter']);
}
$plan = jira_get('/rest/greenhopper/1.0/xboard/plan/backlog/data', $params, $error, $info);
// DEBUG //
// $plan = json_decode(file_get_contents('debug-plan.json'));
// echo "\n\n\n\n\n" . json_encode($plan) . "\n\n\n\n\n";
// exit;
// DEBUG //
// echo '<pre>';
// print_r($plan);
// var_dump($error);
// print_r($info);
// exit;
$allSprints = array_reduce($plan->sprints, function($sprints, $sprint) {
$sprints[$sprint->id] = $sprint;
return $sprints;
}, array());
$allIssues = array_reduce($plan->issues, function($issues, $issue) {
empty($issue->hidden) and $issues[$issue->id] = $issue;
return $issues;
}, array());
$groupedIssues = array();
foreach ($plan->sprints as $sprint) {
foreach ($sprint->issuesIds as $id) {
if ( isset($allIssues[$id]) ) {
$groupedIssues[$sprint->id][] = $allIssues[$id];
unset($allIssues[$id]);
}
}
}
$groupedIssues['backlog'] = array_values($allIssues);
// echo '<pre>';
// print_r($groupedIssues);
// exit;
$_title = 'Agile';
include 'tpl.header.php';
include 'tpl.epiccolors.php';
?>
<style>
#filter {
height: 40px;
height: calc(1.4em + 20px);
}
.longdata {
width: 100%;
}
.longdata .thead th {
padding: 0;
}
.longdata .thead a {
display: block;
padding: 4px 0;
background-color: #ccc;
text-decoration: none;
border-bottom: solid 1px black;
}
.longdata .thead.hide a {
color: #c00;
}
.longdata .tbody.hide {
display: none;
}
.longdata tr {
vertical-align: top;
}
.longdata tr:nth-child(even) {
background-color: #eee;
}
.longdata th,
.longdata td {
border-bottom: solid 1px #ccc;
padding: 2px 3px;
}
.longdata .key {
border-left: solid 5px black;
overflow: hidden;
}
.longdata .key .out {
width: 5em;
position: relative;
}
.longdata .key .in {
position: absolute;
right: 0;
}
.longdata .sp {
background-color: #eee;
text-align: center;
border-left: solid 2px #ccc;
border-right: solid 1px #ccc;
}
.longdata tr:nth-child(even) .sp {
background-color: #ddd;
}
</style>
<h1>Plan</h1>
<form id="form-filter">
<p>
<select name="board"><?= html_options($boards, $boardId, '-- Select a board --') ?></select>
</p>
<p>
<select name="filter"><?= html_options(array_reduce($board->currentViewConfig->quickFilters, function($options, $option) {
return $options + array($option->id => '' . $option->name);
}, array()), @$_GET['filter'], '-- All issues --', false) ?></select>
</p>
</form>
<?php
echo '<table class="longdata">';
foreach ($groupedIssues as $sprintId => $issues) {
$sprint = @$allSprints[$sprintId];
$title = $sprint ? $sprint->name . ' (' . $sprint->state . ')' : 'BACKLOG';
$class = !$sprint || $sprint->state != 'ACTIVE' ? 'hidden hide' : 'unplanned';
echo '<tbody class="thead ' . $class . '">';
echo '<tr><th colspan="4"><a href="#">' . $title . ' -- ' . count($issues) . ' issues</a></th></tr>';
echo '</tbody>';
echo '<tbody class="tbody ' . $class . '">';
foreach ($issues as $issue) {
$priority = '';
if (@$issue->priorityUrl) {
$priority = html_icon($issue, 'priority');
}
$epic = '';
if (@$issue->epic) {
$epic = '<span class="epic ' . html(@$issue->epicField->epicColor) . '"><a href="issue.php?key=' . html($issue->epicField->epicKey) . '">' . html($issue->epicField->text) . '</a></span>';
}
echo '<tr>';
// echo '<td class="type" style="background-color: ' . $issue->color . '; color: ' . $issue->color . '">.</td>';
echo '<td class="key" style="border-left-color: ' . @$issue->color . '"><div class="out"><div class="in">' . $issue->key . '</div></div></td>';
echo '<td class="priority">' . $priority . '</td>';
echo '<td class="summary wrap"><a href="issue.php?key=' . $issue->key . '">' . ( @$issue->summary ?: '???' ) . '</a> ' . $epic . '</td>';
echo '<td class="sp">' . @$issue->estimateStatistic->statFieldValue->value . '</td>';
echo '</tr>';
}
echo '</tbody>';
}
echo '</table>' . "\n\n";
?>
<script>
// Reset SELECT
setTimeout(function() {
$('form-filter').reset();
}, 1);
// Change page after filter selection
$('form-filter').on('change', function(e) {
this.submit();
});
// Toggle issues tbody
$$('.thead a').on('click', function(e) {
e.preventDefault();
var thead = this.ancestor('tbody');
var tbody = thead.nextElementSibling;
var hidden = tbody.classList.toggle('hide'); // returns bool
console.log(hidden);
thead.toggleClass('hide', hidden);
});
</script>
<?php
if ( isset($_GET['debug']) ) {
echo '<pre>' . print_r($board, 1) . '</pre>';
echo '<pre>' . print_r($issues, 1) . '</pre>';
}
include 'tpl.footer.php';
exit;
$error = false;
$sprints = $boardId ? jira_get('/rest/greenhopper/1.0/sprintquery/' . $boardId, array(), $error, $info) : array();
if ( !$boardId || !$sprints || $error ) {
$_title = 'Agile';
include 'tpl.header.php';
echo '<p>No <strong>Greenhopper</strong> in this house...</p>';
if ( $error ) {
echo '<pre>';
var_dump($error);
print_r($info);
echo '</pre>';
}
include 'tpl.footer.php';
exit;
}
echo '<pre>';
$actives = array_filter($sprints->sprints, function($sprint) {
return $sprint->state == 'ACTIVE';
});
print_r($actives);
print_r($sprints);