Root/
| Source at commit 7383e18dff19e7e6a1e56d55cdfbfa109e91bfb3 created 1 year 7 months ago. By Loic d'Anterroches, Fixed issue 4, with fine control over the tabs access. | |
|---|---|
| 1 | <?php |
| 2 | /* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 3 | /* |
| 4 | # ***** BEGIN LICENSE BLOCK ***** |
| 5 | # This file is part of InDefero, an open source project management application. |
| 6 | # Copyright (C) 2008 Céondo Ltd and contributors. |
| 7 | # |
| 8 | # InDefero is free software; you can redistribute it and/or modify |
| 9 | # it under the terms of the GNU General Public License as published by |
| 10 | # the Free Software Foundation; either version 2 of the License, or |
| 11 | # (at your option) any later version. |
| 12 | # |
| 13 | # InDefero is distributed in the hope that it will be useful, |
| 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | # GNU General Public License for more details. |
| 17 | # |
| 18 | # You should have received a copy of the GNU General Public License |
| 19 | # along with this program; if not, write to the Free Software |
| 20 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 21 | # |
| 22 | # ***** END LICENSE BLOCK ***** */ |
| 23 | |
| 24 | Pluf::loadFunction('Pluf_HTTP_URL_urlForView'); |
| 25 | Pluf::loadFunction('Pluf_Shortcuts_RenderToResponse'); |
| 26 | Pluf::loadFunction('Pluf_Shortcuts_GetObjectOr404'); |
| 27 | Pluf::loadFunction('Pluf_Shortcuts_GetFormForModel'); |
| 28 | |
| 29 | /** |
| 30 | * Issues' views. |
| 31 | */ |
| 32 | class IDF_Views_Issue |
| 33 | { |
| 34 | /** |
| 35 | * View list of issues for a given project. |
| 36 | */ |
| 37 | public $index_precond = array('IDF_Precondition::accessIssues'); |
| 38 | public function index($request, $match) |
| 39 | { |
| 40 | $prj = $request->project; |
| 41 | $title = sprintf(__('%s Recent Issues'), (string) $prj); |
| 42 | // Get stats about the issues |
| 43 | $open = $prj->getIssueCountByStatus('open'); |
| 44 | $closed = $prj->getIssueCountByStatus('closed'); |
| 45 | // Paginator to paginate the issues |
| 46 | $pag = new Pluf_Paginator(new IDF_Issue()); |
| 47 | $pag->class = 'recent-issues'; |
| 48 | $pag->item_extra_props = array('project_m' => $prj, |
| 49 | 'shortname' => $prj->shortname); |
| 50 | $pag->summary = __('This table shows the open recent issues.'); |
| 51 | $otags = $prj->getTagIdsByStatus('open'); |
| 52 | if (count($otags) == 0) $otags[] = 0; |
| 53 | $pag->forced_where = new Pluf_SQL('project=%s AND status IN ('.implode(', ', $otags).')', array($prj->id)); |
| 54 | $pag->action = array('IDF_Views_Issue::index', array($prj->shortname)); |
| 55 | $pag->sort_order = array('modif_dtime', 'DESC'); |
| 56 | $list_display = array( |
| 57 | 'id' => __('Id'), |
| 58 | array('summary', 'IDF_Views_Issue_SummaryAndLabels', __('Summary')), |
| 59 | array('status', 'IDF_Views_Issue_ShowStatus', __('Status')), |
| 60 | array('modif_dtime', 'Pluf_Paginator_DateAgo', __('Last Updated')), |
| 61 | ); |
| 62 | $pag->configure($list_display, array(), array('status', 'modif_dtime')); |
| 63 | $pag->items_per_page = 10; |
| 64 | $pag->no_results_text = __('No issues were found.'); |
| 65 | $pag->setFromRequest($request); |
| 66 | return Pluf_Shortcuts_RenderToResponse('issues/index.html', |
| 67 | array('project' => $prj, |
| 68 | 'page_title' => $title, |
| 69 | 'open' => $open, |
| 70 | 'closed' => $closed, |
| 71 | 'issues' => $pag, |
| 72 | ), |
| 73 | $request); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * View the issues of a given user. |
| 78 | * |
| 79 | * Only open issues are shown. |
| 80 | */ |
| 81 | public $myIssues_precond = array('IDF_Precondition::accessIssues', |
| 82 | 'Pluf_Precondition::loginRequired'); |
| 83 | public function myIssues($request, $match) |
| 84 | { |
| 85 | $prj = $request->project; |
| 86 | $otags = $prj->getTagIdsByStatus('open'); |
| 87 | if (count($otags) == 0) $otags[] = 0; |
| 88 | if ($match[2] == 'submit') { |
| 89 | $title = sprintf(__('My Submitted %s Issues'), (string) $prj); |
| 90 | $f_sql = new Pluf_SQL('project=%s AND submitter=%s AND status IN ('.implode(', ', $otags).')', array($prj->id, $request->user->id)); |
| 91 | } else { |
| 92 | $title = sprintf(__('My Working %s Issues'), (string) $prj); |
| 93 | $f_sql = new Pluf_SQL('project=%s AND owner=%s AND status IN ('.implode(', ', $otags).')', array($prj->id, $request->user->id)); |
| 94 | } |
| 95 | // Get stats about the issues |
| 96 | $sql = new Pluf_SQL('project=%s AND submitter=%s AND status IN ('.implode(', ', $otags).')', array($prj->id, $request->user->id)); |
| 97 | $nb_submit = Pluf::factory('IDF_Issue')->getCount(array('filter'=>$sql->gen())); |
| 98 | $sql = new Pluf_SQL('project=%s AND owner=%s AND status IN ('.implode(', ', $otags).')', array($prj->id, $request->user->id)); |
| 99 | $nb_owner = Pluf::factory('IDF_Issue')->getCount(array('filter'=>$sql->gen())); |
| 100 | // Paginator to paginate the issues |
| 101 | $pag = new Pluf_Paginator(new IDF_Issue()); |
| 102 | $pag->class = 'recent-issues'; |
| 103 | $pag->item_extra_props = array('project_m' => $prj, |
| 104 | 'shortname' => $prj->shortname); |
| 105 | $pag->summary = __('This table shows the open recent issues.'); |
| 106 | $pag->forced_where = $f_sql; |
| 107 | $pag->action = array('IDF_Views_Issue::myIssues', array($prj->shortname, $match[2])); |
| 108 | $pag->sort_order = array('modif_dtime', 'DESC'); |
| 109 | $list_display = array( |
| 110 | 'id' => __('Id'), |
| 111 | array('summary', 'IDF_Views_Issue_SummaryAndLabels', __('Summary')), |
| 112 | array('status', 'IDF_Views_Issue_ShowStatus', __('Status')), |
| 113 | array('modif_dtime', 'Pluf_Paginator_DateAgo', __('Last Updated')), |
| 114 | ); |
| 115 | $pag->configure($list_display, array(), array('status', 'modif_dtime')); |
| 116 | $pag->items_per_page = 10; |
| 117 | $pag->no_results_text = __('No issues were found.'); |
| 118 | $pag->setFromRequest($request); |
| 119 | return Pluf_Shortcuts_RenderToResponse('issues/my-issues.html', |
| 120 | array('project' => $prj, |
| 121 | 'page_title' => $title, |
| 122 | 'nb_submit' => $nb_submit, |
| 123 | 'nb_owner' => $nb_owner, |
| 124 | 'issues' => $pag, |
| 125 | ), |
| 126 | $request); |
| 127 | } |
| 128 | |
| 129 | public $create_precond = array('IDF_Precondition::accessIssues', |
| 130 | 'Pluf_Precondition::loginRequired'); |
| 131 | public function create($request, $match) |
| 132 | { |
| 133 | $prj = $request->project; |
| 134 | $title = __('Submit a new issue'); |
| 135 | $params = array( |
| 136 | 'project' => $prj, |
| 137 | 'user' => $request->user); |
| 138 | if ($request->method == 'POST') { |
| 139 | $form = new IDF_Form_IssueCreate($request->POST, $params); |
| 140 | if ($form->isValid()) { |
| 141 | $issue = $form->save(); |
| 142 | $url = Pluf_HTTP_URL_urlForView('IDF_Views_Issue::index', |
| 143 | array($prj->shortname)); |
| 144 | $urlissue = Pluf_HTTP_URL_urlForView('IDF_Views_Issue::view', |
| 145 | array($prj->shortname, $issue->id)); |
| 146 | $request->user->setMessage(sprintf(__('<a href="%s">Issue %d</a> has been created.'), $urlissue, $issue->id)); |
| 147 | return new Pluf_HTTP_Response_Redirect($url); |
| 148 | } |
| 149 | } else { |
| 150 | $form = new IDF_Form_IssueCreate(null, $params); |
| 151 | } |
| 152 | $arrays = self::autoCompleteArrays($prj); |
| 153 | return Pluf_Shortcuts_RenderToResponse('issues/create.html', |
| 154 | array_merge( |
| 155 | array('project' => $prj, |
| 156 | 'form' => $form, |
| 157 | 'page_title' => $title, |
| 158 | ), |
| 159 | $arrays), |
| 160 | $request); |
| 161 | } |
| 162 | |
| 163 | public $view_precond = array('IDF_Precondition::accessIssues'); |
| 164 | public function view($request, $match) |
| 165 | { |
| 166 | $prj = $request->project; |
| 167 | $issue = Pluf_Shortcuts_GetObjectOr404('IDF_Issue', $match[2]); |
| 168 | $prj->inOr404($issue); |
| 169 | $comments = $issue->get_comments_list(array('order' => 'id ASC')); |
| 170 | $url = Pluf_HTTP_URL_urlForView('IDF_Views_Issue::view', |
| 171 | array($prj->shortname, $issue->id)); |
| 172 | $title = Pluf_Template::markSafe(sprintf(__('Issue <a href="%s">%d</a>: %s'), $url, $issue->id, $issue->summary)); |
| 173 | $form = false; // The form is available only if logged in. |
| 174 | if (!$request->user->isAnonymous()) { |
| 175 | $params = array( |
| 176 | 'project' => $prj, |
| 177 | 'user' => $request->user, |
| 178 | 'issue' => $issue, |
| 179 | ); |
| 180 | if ($request->method == 'POST') { |
| 181 | $form = new IDF_Form_IssueUpdate($request->POST, $params); |
| 182 | if ($form->isValid()) { |
| 183 | $issue = $form->save(); |
| 184 | $url = Pluf_HTTP_URL_urlForView('IDF_Views_Issue::index', |
| 185 | array($prj->shortname)); |
| 186 | $urlissue = Pluf_HTTP_URL_urlForView('IDF_Views_Issue::view', |
| 187 | array($prj->shortname, $issue->id)); |
| 188 | $request->user->setMessage(sprintf(__('<a href="%s">Issue %d</a> has been updated.'), $urlissue, $issue->id)); |
| 189 | return new Pluf_HTTP_Response_Redirect($url); |
| 190 | } |
| 191 | } else { |
| 192 | $form = new IDF_Form_IssueUpdate(null, $params); |
| 193 | } |
| 194 | } |
| 195 | $arrays = self::autoCompleteArrays($prj); |
| 196 | return Pluf_Shortcuts_RenderToResponse('issues/view.html', |
| 197 | array_merge( |
| 198 | array('project' => $prj, |
| 199 | 'issue' => $issue, |
| 200 | 'comments' => $comments, |
| 201 | 'form' => $form, |
| 202 | 'page_title' => $title, |
| 203 | ), |
| 204 | $arrays), |
| 205 | $request); |
| 206 | } |
| 207 | |
| 208 | /** |
| 209 | * View list of issues for a given project with a given status. |
| 210 | */ |
| 211 | public $listStatus_precond = array('IDF_Precondition::accessIssues'); |
| 212 | public function listStatus($request, $match) |
| 213 | { |
| 214 | $prj = $request->project; |
| 215 | $status = $match[2]; |
| 216 | $title = sprintf(__('%s Closed Issues'), (string) $prj); |
| 217 | // Get stats about the issues |
| 218 | $open = $prj->getIssueCountByStatus('open'); |
| 219 | $closed = $prj->getIssueCountByStatus('closed'); |
| 220 | // Paginator to paginate the issues |
| 221 | $pag = new Pluf_Paginator(new IDF_Issue()); |
| 222 | $pag->class = 'recent-issues'; |
| 223 | $pag->item_extra_props = array('project_m' => $prj, |
| 224 | 'shortname' => $prj->shortname); |
| 225 | $pag->summary = __('This table shows the closed issues.'); |
| 226 | $otags = $prj->getTagIdsByStatus('closed'); |
| 227 | if (count($otags) == 0) $otags[] = 0; |
| 228 | $pag->forced_where = new Pluf_SQL('project=%s AND status IN ('.implode(', ', $otags).')', array($prj->id)); |
| 229 | $pag->action = array('IDF_Views_Issue::index', array($prj->shortname)); |
| 230 | $pag->sort_order = array('modif_dtime', 'DESC'); |
| 231 | $list_display = array( |
| 232 | 'id' => __('Id'), |
| 233 | array('summary', 'IDF_Views_Issue_SummaryAndLabels', __('Summary')), |
| 234 | array('status', 'IDF_Views_Issue_ShowStatus', __('Status')), |
| 235 | array('modif_dtime', 'Pluf_Paginator_DateAgo', __('Last Updated')), |
| 236 | ); |
| 237 | $pag->configure($list_display, array(), array('id', 'status', 'modif_dtime')); |
| 238 | $pag->items_per_page = 10; |
| 239 | $pag->no_results_text = __('No issues were found.'); |
| 240 | $pag->setFromRequest($request); |
| 241 | return Pluf_Shortcuts_RenderToResponse('issues/index.html', |
| 242 | array('project' => $prj, |
| 243 | 'page_title' => $title, |
| 244 | 'open' => $open, |
| 245 | 'closed' => $closed, |
| 246 | 'issues' => $pag, |
| 247 | ), |
| 248 | $request); |
| 249 | } |
| 250 | |
| 251 | /** |
| 252 | * View list of issues for a given project with a given label. |
| 253 | */ |
| 254 | public $listLabel_precond = array('IDF_Precondition::accessIssues'); |
| 255 | public function listLabel($request, $match) |
| 256 | { |
| 257 | $prj = $request->project; |
| 258 | $tag = Pluf_Shortcuts_GetObjectOr404('IDF_Tag', $match[2]); |
| 259 | $status = $match[3]; |
| 260 | if ($tag->project != $prj->id or !in_array($status, array('open', 'closed'))) { |
| 261 | throw new Pluf_HTTP_Error404(); |
| 262 | } |
| 263 | if ($status == 'open') { |
| 264 | $title = sprintf(__('%1$s Issues with Label %2$s'), (string) $prj, |
| 265 | (string) $tag); |
| 266 | } else { |
| 267 | $title = sprintf(__('%1$s Closed Issues with Label %2$s'), |
| 268 | (string) $prj, (string) $tag); |
| 269 | } |
| 270 | // Get stats about the open/closed issues having this tag. |
| 271 | $open = $prj->getIssueCountByStatus('open', $tag); |
| 272 | $closed = $prj->getIssueCountByStatus('closed', $tag); |
| 273 | // Paginator to paginate the issues |
| 274 | $pag = new Pluf_Paginator(new IDF_Issue()); |
| 275 | $pag->model_view = 'join_tags'; |
| 276 | $pag->class = 'recent-issues'; |
| 277 | $pag->item_extra_props = array('project_m' => $prj, |
| 278 | 'shortname' => $prj->shortname); |
| 279 | $pag->summary = sprintf(__('This table shows the issues with label %s.'), (string) $tag); |
| 280 | $otags = $prj->getTagIdsByStatus($status); |
| 281 | if (count($otags) == 0) $otags[] = 0; |
| 282 | $pag->forced_where = new Pluf_SQL('project=%s AND idf_tag_id=%s AND status IN ('.implode(', ', $otags).')', array($prj->id, $tag->id)); |
| 283 | $pag->action = array('IDF_Views_Issue::listLabel', array($prj->shortname, $tag->id, $status)); |
| 284 | $pag->sort_order = array('modif_dtime', 'DESC'); |
| 285 | $list_display = array( |
| 286 | 'id' => __('Id'), |
| 287 | array('summary', 'IDF_Views_Issue_SummaryAndLabels', __('Summary')), |
| 288 | array('status', 'IDF_Views_Issue_ShowStatus', __('Status')), |
| 289 | array('modif_dtime', 'Pluf_Paginator_DateAgo', __('Last Updated')), |
| 290 | ); |
| 291 | $pag->configure($list_display, array(), array('status', 'modif_dtime')); |
| 292 | $pag->items_per_page = 10; |
| 293 | $pag->no_results_text = __('No issues were found.'); |
| 294 | $pag->setFromRequest($request); |
| 295 | if (($open+$closed) > 0) { |
| 296 | $completion = sprintf('%01.0f%%', (100*$closed)/((float) $open+$closed)); |
| 297 | } else { |
| 298 | $completion = false; |
| 299 | } |
| 300 | return Pluf_Shortcuts_RenderToResponse('issues/by-label.html', |
| 301 | array('project' => $prj, |
| 302 | 'completion' => $completion, |
| 303 | 'page_title' => $title, |
| 304 | 'open' => $open, |
| 305 | 'label' => $tag, |
| 306 | 'closed' => $closed, |
| 307 | 'issues' => $pag, |
| 308 | ), |
| 309 | $request); |
| 310 | } |
| 311 | |
| 312 | /** |
| 313 | * Create the autocomplete arrays for the little AJAX stuff. |
| 314 | */ |
| 315 | public static function autoCompleteArrays($project) |
| 316 | { |
| 317 | $conf = new IDF_Conf(); |
| 318 | $conf->setProject($project); |
| 319 | $auto = array('auto_status' => '', 'auto_labels' => ''); |
| 320 | $auto_raw = array('auto_status' => '', 'auto_labels' => ''); |
| 321 | $st = $conf->getVal('labels_issue_open', IDF_Form_IssueTrackingConf::init_open); |
| 322 | $st .= "\n".$conf->getVal('labels_issue_closed', IDF_Form_IssueTrackingConf::init_closed); |
| 323 | $auto_raw['auto_status'] = $st; |
| 324 | $auto_raw['auto_labels'] = $conf->getVal('labels_issue_predefined', IDF_Form_IssueTrackingConf::init_predefined); |
| 325 | foreach ($auto_raw as $key => $st) { |
| 326 | $st = preg_split("/\015\012|\015|\012/", $st, -1, PREG_SPLIT_NO_EMPTY); |
| 327 | foreach ($st as $s) { |
| 328 | $v = ''; |
| 329 | $d = ''; |
| 330 | $_s = split('=', $s, 2); |
| 331 | if (count($_s) > 1) { |
| 332 | $v = trim($_s[0]); |
| 333 | $d = trim($_s[1]); |
| 334 | } else { |
| 335 | $v = trim($_s[0]); |
| 336 | } |
| 337 | $auto[$key] .= sprintf('{ name: "%s", to: "%s" }, ', |
| 338 | Pluf_esc($d), |
| 339 | Pluf_esc($v)); |
| 340 | } |
| 341 | $auto[$key] = substr($auto[$key], 0, -1); |
| 342 | } |
| 343 | // Get the members/owners |
| 344 | $m = $project->getMembershipData(); |
| 345 | $auto['_auto_owner'] = $m['members']; |
| 346 | $auto['auto_owner'] = ''; |
| 347 | foreach ($m['owners'] as $owner) { |
| 348 | if (!Pluf_Model_InArray($owner, $auto['_auto_owner'])) { |
| 349 | $auto['_auto_owner'][] = $owner; |
| 350 | } |
| 351 | } |
| 352 | foreach ($auto['_auto_owner'] as $owner) { |
| 353 | $auto['auto_owner'] .= sprintf('{ name: "%s", to: "%s" }, ', |
| 354 | Pluf_esc($owner), |
| 355 | Pluf_esc($owner->login)); |
| 356 | } |
| 357 | $auto['auto_owner'] = substr($auto['auto_owner'], 0, -1); |
| 358 | unset($auto['_auto_owner']); |
| 359 | return $auto; |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | /** |
| 364 | * Display the summary of an issue, then on a new line, display the |
| 365 | * list of labels with a link to a view "by label only". |
| 366 | * |
| 367 | * The summary of the issue is linking to the issue. |
| 368 | */ |
| 369 | function IDF_Views_Issue_SummaryAndLabels($field, $issue, $extra='') |
| 370 | { |
| 371 | $edit = Pluf_HTTP_URL_urlForView('IDF_Views_Issue::view', |
| 372 | array($issue->shortname, $issue->id)); |
| 373 | $tags = array(); |
| 374 | foreach ($issue->get_tags_list() as $tag) { |
| 375 | $url = Pluf_HTTP_URL_urlForView('IDF_Views_Issue::listLabel', |
| 376 | array($issue->shortname, $tag->id, 'open')); |
| 377 | $tags[] = sprintf('<a class="label" href="%s">%s</a>', $url, Pluf_esc((string) $tag)); |
| 378 | } |
| 379 | $out = ''; |
| 380 | if (count($tags)) { |
| 381 | $out = '<br /><span class="note">'.implode(', ', $tags).'</span>'; |
| 382 | } |
| 383 | return sprintf('<a href="%s">%s</a>', $edit, Pluf_esc($issue->summary)).$out; |
| 384 | } |
| 385 | |
| 386 | /** |
| 387 | * Display the status in the issue listings. |
| 388 | * |
| 389 | */ |
| 390 | function IDF_Views_Issue_ShowStatus($field, $issue, $extra='') |
| 391 | { |
| 392 | return Pluf_esc($issue->get_status()->name); |
| 393 | } |
