diff --git a/src/applications/home/view/PHUIHomeView.php b/src/applications/home/view/PHUIHomeView.php index d6c3794854..45750f5a93 100644 --- a/src/applications/home/view/PHUIHomeView.php +++ b/src/applications/home/view/PHUIHomeView.php @@ -77,149 +77,76 @@ final class PHUIHomeView return $view; } - private function buildHomepagePanel($title, $href, $view) { - $title = phutil_tag( - 'a', - array( - 'href' => $href, - ), - $title); - - $icon = id(new PHUIIconView()) - ->setIcon('fa-search') - ->setHref($href); - - $header = id(new PHUIHeaderView()) - ->setHeader($title) - ->addActionItem($icon); - - $box = id(new PHUIObjectBoxView()) - ->setHeader($header); - - if ($view->getObjectList()) { - $box->setObjectList($view->getObjectList()); - } - if ($view->getContent()) { - $box->appendChild($view->getContent()); - } - - return $box; - } - private function buildRevisionPanel() { $viewer = $this->getViewer(); if (!$viewer->isLoggedIn()) { return null; } - $engine = new DifferentialRevisionSearchEngine(); - $engine->setViewer($viewer); - $saved = $engine->buildSavedQueryFromBuiltin('active'); - $query = $engine->buildQueryFromSavedQuery($saved); - $pager = $engine->newPagerForSavedQuery($saved); - $pager->setPageSize(15); - $results = $engine->executeQuery($query, $pager); - $view = $engine->renderResults($results, $saved); + $panel = $this->newQueryPanel() + ->setName(pht('Active Revisions')) + ->setProperty('class', 'DifferentialRevisionSearchEngine') + ->setProperty('key', 'active'); - $title = pht('Active Revisions'); - $href = '/differential/query/active/'; - - return $this->buildHomepagePanel($title, $href, $view); + return $this->renderPanel($panel); } private function buildTasksPanel() { $viewer = $this->getViewer(); - $query = 'assigned'; - $title = pht('Assigned Tasks'); - $href = '/maniphest/query/assigned/'; - if (!$viewer->isLoggedIn()) { + if ($viewer->isLoggedIn()) { + $name = pht('Assigned Tasks'); + $query = 'assigned'; + } else { + $name = pht('Open Tasks'); $query = 'open'; - $title = pht('Open Tasks'); - $href = '/maniphest/query/open/'; } - $engine = new ManiphestTaskSearchEngine(); - $engine->setViewer($viewer); - $saved = $engine->buildSavedQueryFromBuiltin($query); - $query = $engine->buildQueryFromSavedQuery($saved); - $pager = $engine->newPagerForSavedQuery($saved); - $pager->setPageSize(15); - $results = $engine->executeQuery($query, $pager); - $view = $engine->renderResults($results, $saved); + $panel = $this->newQueryPanel() + ->setName($name) + ->setProperty('class', 'ManiphestTaskSearchEngine') + ->setProperty('key', $query) + ->setProperty('limit', 15); - return $this->buildHomepagePanel($title, $href, $view); + return $this->renderPanel($panel); } public function buildFeedPanel() { - $viewer = $this->getViewer(); + $panel = $this->newQueryPanel() + ->setName(pht('Recent Activity')) + ->setProperty('class', 'PhabricatorFeedSearchEngine') + ->setProperty('key', 'all') + ->setProperty('limit', 40); - $engine = new PhabricatorFeedSearchEngine(); - $engine->setViewer($viewer); - $saved = $engine->buildSavedQueryFromBuiltin('all'); - $query = $engine->buildQueryFromSavedQuery($saved); - $pager = $engine->newPagerForSavedQuery($saved); - $pager->setPageSize(40); - $results = $engine->executeQuery($query, $pager); - $view = $engine->renderResults($results, $saved); - // Low tech NUX. - if (!$results && ($viewer->getIsAdmin() == 1)) { - $instance = PhabricatorEnv::getEnvConfig('cluster.instance'); - if (!$instance) { - $content = pht(<<setObjectList($list); - } else { - $content = id(new PHUIBoxView()) - ->appendChild(new PHUIRemarkupView($viewer, $content)) - ->addClass('mlt mlb msr msl'); - $view = new PhabricatorApplicationSearchResultView(); - $view->setContent($content); - } - } - - $title = pht('Recent Activity'); - $href = '/feed/'; - - return $this->buildHomepagePanel($title, $href, $view); + return $this->renderPanel($panel); } public function buildRepositoryPanel() { + $panel = $this->newQueryPanel() + ->setName(pht('Active Repositories')) + ->setProperty('class', 'PhabricatorRepositorySearchEngine') + ->setProperty('key', 'active') + ->setProperty('limit', 5); + + return $this->renderPanel($panel); + } + + private function newQueryPanel() { + $panel_type = id(new PhabricatorDashboardQueryPanelType()) + ->getPanelTypeKey(); + + return id(new PhabricatorDashboardPanel()) + ->setPanelType($panel_type); + } + + private function renderPanel(PhabricatorDashboardPanel $panel) { $viewer = $this->getViewer(); - $engine = new PhabricatorRepositorySearchEngine(); - $engine->setViewer($viewer); - $saved = $engine->buildSavedQueryFromBuiltin('active'); - $query = $engine->buildQueryFromSavedQuery($saved); - $pager = $engine->newPagerForSavedQuery($saved); - $pager->setPageSize(5); - $results = $engine->executeQuery($query, $pager); - $view = $engine->renderResults($results, $saved); - - $title = pht('Active Repositories'); - $href = '/diffusion/'; - - return $this->buildHomepagePanel($title, $href, $view); + return id(new PhabricatorDashboardPanelRenderingEngine()) + ->setViewer($viewer) + ->setPanel($panel) + ->setParentPanelPHIDs(array()) + ->renderPanel(); } }