[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhabricatorHomeMainController extends PhabricatorHomeController { 4 5 private $only; 6 private $minipanels = array(); 7 8 public function shouldAllowPublic() { 9 return true; 10 } 11 12 public function willProcessRequest(array $data) { 13 $this->only = idx($data, 'only'); 14 } 15 16 public function processRequest() { 17 $user = $this->getRequest()->getUser(); 18 19 $dashboard = PhabricatorDashboardInstall::getDashboard( 20 $user, 21 $user->getPHID(), 22 get_class($this->getCurrentApplication())); 23 24 if (!$dashboard) { 25 $dashboard = PhabricatorDashboardInstall::getDashboard( 26 $user, 27 PhabricatorHomeApplication::DASHBOARD_DEFAULT, 28 get_class($this->getCurrentApplication())); 29 } 30 31 if ($dashboard) { 32 $content = id(new PhabricatorDashboardRenderingEngine()) 33 ->setViewer($user) 34 ->setDashboard($dashboard) 35 ->renderDashboard(); 36 } else { 37 $project_query = new PhabricatorProjectQuery(); 38 $project_query->setViewer($user); 39 $project_query->withMemberPHIDs(array($user->getPHID())); 40 $projects = $project_query->execute(); 41 42 $content = $this->buildMainResponse($projects); 43 } 44 45 if (!$this->only) { 46 $nav = $this->buildNav(); 47 $nav->appendChild( 48 array( 49 $content, 50 id(new PhabricatorGlobalUploadTargetView())->setUser($user), 51 )); 52 $content = $nav; 53 } 54 55 return $this->buildApplicationPage( 56 $content, 57 array( 58 'title' => 'Phabricator', 59 )); 60 } 61 62 private function buildMainResponse(array $projects) { 63 assert_instances_of($projects, 'PhabricatorProject'); 64 $viewer = $this->getRequest()->getUser(); 65 66 $has_maniphest = PhabricatorApplication::isClassInstalledForViewer( 67 'PhabricatorManiphestApplication', 68 $viewer); 69 70 $has_audit = PhabricatorApplication::isClassInstalledForViewer( 71 'PhabricatorAuditApplication', 72 $viewer); 73 74 $has_differential = PhabricatorApplication::isClassInstalledForViewer( 75 'PhabricatorDifferentialApplication', 76 $viewer); 77 78 if ($has_maniphest) { 79 $unbreak_panel = $this->buildUnbreakNowPanel(); 80 $triage_panel = $this->buildNeedsTriagePanel($projects); 81 $tasks_panel = $this->buildTasksPanel(); 82 } else { 83 $unbreak_panel = null; 84 $triage_panel = null; 85 $tasks_panel = null; 86 } 87 88 if ($has_audit) { 89 $audit_panel = $this->buildAuditPanel(); 90 $commit_panel = $this->buildCommitPanel(); 91 } else { 92 $audit_panel = null; 93 $commit_panel = null; 94 } 95 96 if (PhabricatorEnv::getEnvConfig('welcome.html') !== null) { 97 $welcome_panel = $this->buildWelcomePanel(); 98 } else { 99 $welcome_panel = null; 100 } 101 102 if ($has_differential) { 103 $revision_panel = $this->buildRevisionPanel(); 104 } else { 105 $revision_panel = null; 106 } 107 108 return array( 109 $welcome_panel, 110 $unbreak_panel, 111 $triage_panel, 112 $revision_panel, 113 $tasks_panel, 114 $audit_panel, 115 $commit_panel, 116 $this->minipanels, 117 ); 118 } 119 120 private function buildUnbreakNowPanel() { 121 $unbreak_now = PhabricatorEnv::getEnvConfig( 122 'maniphest.priorities.unbreak-now'); 123 if (!$unbreak_now) { 124 return null; 125 } 126 127 $user = $this->getRequest()->getUser(); 128 129 $task_query = id(new ManiphestTaskQuery()) 130 ->setViewer($user) 131 ->withStatuses(ManiphestTaskStatus::getOpenStatusConstants()) 132 ->withPriorities(array($unbreak_now)) 133 ->setLimit(10); 134 135 $tasks = $task_query->execute(); 136 137 if (!$tasks) { 138 return $this->renderMiniPanel( 139 'No "Unbreak Now!" Tasks', 140 'Nothing appears to be critically broken right now.'); 141 } 142 143 $href = urisprintf( 144 '/maniphest/?statuses=%s&priorities=%s#R', 145 implode(',', ManiphestTaskStatus::getOpenStatusConstants()), 146 $unbreak_now); 147 $title = pht('Unbreak Now!'); 148 $panel = new AphrontPanelView(); 149 $panel->setHeader($this->renderSectionHeader($title, $href)); 150 $panel->appendChild($this->buildTaskListView($tasks)); 151 $panel->setNoBackground(); 152 153 return $panel; 154 } 155 156 private function buildNeedsTriagePanel(array $projects) { 157 assert_instances_of($projects, 'PhabricatorProject'); 158 159 $needs_triage = PhabricatorEnv::getEnvConfig( 160 'maniphest.priorities.needs-triage'); 161 if (!$needs_triage) { 162 return null; 163 } 164 165 $user = $this->getRequest()->getUser(); 166 if (!$user->isLoggedIn()) { 167 return null; 168 } 169 170 if ($projects) { 171 $task_query = id(new ManiphestTaskQuery()) 172 ->setViewer($user) 173 ->withStatuses(ManiphestTaskStatus::getOpenStatusConstants()) 174 ->withPriorities(array($needs_triage)) 175 ->withAnyProjects(mpull($projects, 'getPHID')) 176 ->setLimit(10); 177 $tasks = $task_query->execute(); 178 } else { 179 $tasks = array(); 180 } 181 182 if (!$tasks) { 183 return $this->renderMiniPanel( 184 'No "Needs Triage" Tasks', 185 hsprintf( 186 'No tasks in <a href="/project/">projects you are a member of</a> '. 187 'need triage.')); 188 } 189 190 $title = pht('Needs Triage'); 191 $href = urisprintf( 192 '/maniphest/?statuses=%s&priorities=%s&userProjects=%s#R', 193 implode(',', ManiphestTaskStatus::getOpenStatusConstants()), 194 $needs_triage, 195 $user->getPHID()); 196 $panel = new AphrontPanelView(); 197 $panel->setHeader($this->renderSectionHeader($title, $href)); 198 $panel->appendChild($this->buildTaskListView($tasks)); 199 $panel->setNoBackground(); 200 201 return $panel; 202 } 203 204 private function buildRevisionPanel() { 205 $user = $this->getRequest()->getUser(); 206 $user_phid = $user->getPHID(); 207 208 $revision_query = id(new DifferentialRevisionQuery()) 209 ->setViewer($user) 210 ->withStatus(DifferentialRevisionQuery::STATUS_OPEN) 211 ->withResponsibleUsers(array($user_phid)) 212 ->needRelationships(true) 213 ->needFlags(true) 214 ->needDrafts(true); 215 216 $revisions = $revision_query->execute(); 217 218 list($blocking, $active, ) = DifferentialRevisionQuery::splitResponsible( 219 $revisions, 220 array($user_phid)); 221 222 if (!$blocking && !$active) { 223 return $this->renderMiniPanel( 224 'No Waiting Revisions', 225 'No revisions are waiting on you.'); 226 } 227 228 $title = pht('Revisions Waiting on You'); 229 $href = '/differential'; 230 $panel = new AphrontPanelView(); 231 $panel->setHeader($this->renderSectionHeader($title, $href)); 232 233 $revision_view = id(new DifferentialRevisionListView()) 234 ->setHighlightAge(true) 235 ->setRevisions(array_merge($blocking, $active)) 236 ->setUser($user); 237 $phids = array_merge( 238 array($user_phid), 239 $revision_view->getRequiredHandlePHIDs()); 240 $handles = $this->loadViewerHandles($phids); 241 242 $revision_view->setHandles($handles); 243 244 $list_view = $revision_view->render(); 245 $list_view->setFlush(true); 246 247 $panel->appendChild($list_view); 248 $panel->setNoBackground(); 249 250 return $panel; 251 } 252 253 private function buildWelcomePanel() { 254 $panel = new AphrontPanelView(); 255 $panel->appendChild( 256 phutil_safe_html( 257 PhabricatorEnv::getEnvConfig('welcome.html'))); 258 $panel->setNoBackground(); 259 260 return $panel; 261 } 262 263 private function buildTasksPanel() { 264 $user = $this->getRequest()->getUser(); 265 $user_phid = $user->getPHID(); 266 267 $task_query = id(new ManiphestTaskQuery()) 268 ->setViewer($user) 269 ->withStatuses(ManiphestTaskStatus::getOpenStatusConstants()) 270 ->setGroupBy(ManiphestTaskQuery::GROUP_PRIORITY) 271 ->withOwners(array($user_phid)) 272 ->setLimit(10); 273 274 $tasks = $task_query->execute(); 275 276 277 if (!$tasks) { 278 return $this->renderMiniPanel( 279 'No Assigned Tasks', 280 'You have no assigned tasks.'); 281 } 282 283 $title = pht('Assigned Tasks'); 284 $href = '/maniphest'; 285 $panel = new AphrontPanelView(); 286 $panel->setHeader($this->renderSectionHeader($title, $href)); 287 $panel->appendChild($this->buildTaskListView($tasks)); 288 $panel->setNoBackground(); 289 290 return $panel; 291 } 292 293 private function buildTaskListView(array $tasks) { 294 assert_instances_of($tasks, 'ManiphestTask'); 295 $user = $this->getRequest()->getUser(); 296 297 $phids = array_merge( 298 array_filter(mpull($tasks, 'getOwnerPHID')), 299 array_mergev(mpull($tasks, 'getProjectPHIDs'))); 300 301 $handles = $this->loadViewerHandles($phids); 302 303 $view = new ManiphestTaskListView(); 304 $view->setTasks($tasks); 305 $view->setUser($user); 306 $view->setHandles($handles); 307 308 return $view; 309 } 310 311 private function renderSectionHeader($title, $href) { 312 $header = phutil_tag( 313 'a', 314 array( 315 'href' => $href, 316 ), 317 $title); 318 return $header; 319 } 320 321 private function renderMiniPanel($title, $body) { 322 $panel = new AphrontMiniPanelView(); 323 $panel->appendChild( 324 phutil_tag( 325 'p', 326 array( 327 ), 328 array( 329 phutil_tag('strong', array(), $title.': '), 330 $body, 331 ))); 332 $this->minipanels[] = $panel; 333 } 334 335 public function buildAuditPanel() { 336 $request = $this->getRequest(); 337 $user = $request->getUser(); 338 339 $phids = PhabricatorAuditCommentEditor::loadAuditPHIDsForUser($user); 340 341 $query = id(new DiffusionCommitQuery()) 342 ->setViewer($user) 343 ->withAuditorPHIDs($phids) 344 ->withAuditStatus(DiffusionCommitQuery::AUDIT_STATUS_OPEN) 345 ->withAuditAwaitingUser($user) 346 ->needAuditRequests(true) 347 ->needCommitData(true) 348 ->setLimit(10); 349 350 $commits = $query->execute(); 351 352 if (!$commits) { 353 return $this->renderMinipanel( 354 'No Audits', 355 'No commits are waiting for you to audit them.'); 356 } 357 358 $view = id(new PhabricatorAuditListView()) 359 ->setCommits($commits) 360 ->setUser($user); 361 362 $phids = $view->getRequiredHandlePHIDs(); 363 $handles = $this->loadViewerHandles($phids); 364 $view->setHandles($handles); 365 366 $title = pht('Audits'); 367 $href = '/audit/'; 368 $panel = new AphrontPanelView(); 369 $panel->setHeader($this->renderSectionHeader($title, $href)); 370 $panel->appendChild($view); 371 $panel->setNoBackground(); 372 373 return $panel; 374 } 375 376 public function buildCommitPanel() { 377 $request = $this->getRequest(); 378 $user = $request->getUser(); 379 380 $phids = array($user->getPHID()); 381 382 $query = id(new DiffusionCommitQuery()) 383 ->setViewer($user) 384 ->withAuthorPHIDs($phids) 385 ->withAuditStatus(DiffusionCommitQuery::AUDIT_STATUS_CONCERN) 386 ->needCommitData(true) 387 ->needAuditRequests(true) 388 ->setLimit(10); 389 390 $commits = $query->execute(); 391 392 if (!$commits) { 393 return $this->renderMinipanel( 394 'No Problem Commits', 395 'No one has raised concerns with your commits.'); 396 } 397 398 $view = id(new PhabricatorAuditListView()) 399 ->setCommits($commits) 400 ->setUser($user); 401 402 $phids = $view->getRequiredHandlePHIDs(); 403 $handles = $this->loadViewerHandles($phids); 404 $view->setHandles($handles); 405 406 $title = pht('Problem Commits'); 407 $href = '/audit/'; 408 $panel = new AphrontPanelView(); 409 $panel->setHeader($this->renderSectionHeader($title, $href)); 410 $panel->appendChild($view); 411 $panel->setNoBackground(); 412 413 return $panel; 414 } 415 416 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |