1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-29 18:22:41 +01:00

Use real Dashboard Panels to render the default hard-coded homepage, not hacky fake panels

Summary:
Ref T13272. Currently, the hard-coded default homepage looks like a dashboard but is actually rendered completely manually.

This means that various panel rendering improvements we'd like to make (including better "Show More" behavior and better handling of overheated queries) won't work on the home page naturally: we'd have to make these changes twice, once for dashboards and once for the home page.

Instead, build the home page out of real panels. This turns out to be significantly simpler (I think the backend part of panels/dashboards is mostly on solid footing, the frontend just needs some work).

Test Plan:
Loaded the default home page, saw a thing which looked the same as the old thing. Changes I know about / expect:

  - The headers for these panels are no longer linked, but they weren't colorized before so the links were hard to find. I plan to improve panel behavior for "find/more" in a followup.
  - I've removed the "follow us on twitter" default NUX if feed is empty, since this seems like unnecessary incidental complexity.
  - (Internal exception behavior should be better, now.)

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13272

Differential Revision: https://secure.phabricator.com/D20333
This commit is contained in:
epriestley 2019-03-27 08:07:32 -07:00
parent 3e1ffda85d
commit a68b6cfe65

View file

@ -77,149 +77,76 @@ final class PHUIHomeView
return $view; 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() { private function buildRevisionPanel() {
$viewer = $this->getViewer(); $viewer = $this->getViewer();
if (!$viewer->isLoggedIn()) { if (!$viewer->isLoggedIn()) {
return null; return null;
} }
$engine = new DifferentialRevisionSearchEngine(); $panel = $this->newQueryPanel()
$engine->setViewer($viewer); ->setName(pht('Active Revisions'))
$saved = $engine->buildSavedQueryFromBuiltin('active'); ->setProperty('class', 'DifferentialRevisionSearchEngine')
$query = $engine->buildQueryFromSavedQuery($saved); ->setProperty('key', 'active');
$pager = $engine->newPagerForSavedQuery($saved);
$pager->setPageSize(15);
$results = $engine->executeQuery($query, $pager);
$view = $engine->renderResults($results, $saved);
$title = pht('Active Revisions'); return $this->renderPanel($panel);
$href = '/differential/query/active/';
return $this->buildHomepagePanel($title, $href, $view);
} }
private function buildTasksPanel() { private function buildTasksPanel() {
$viewer = $this->getViewer(); $viewer = $this->getViewer();
$query = 'assigned'; if ($viewer->isLoggedIn()) {
$title = pht('Assigned Tasks'); $name = pht('Assigned Tasks');
$href = '/maniphest/query/assigned/'; $query = 'assigned';
if (!$viewer->isLoggedIn()) { } else {
$name = pht('Open Tasks');
$query = 'open'; $query = 'open';
$title = pht('Open Tasks');
$href = '/maniphest/query/open/';
} }
$engine = new ManiphestTaskSearchEngine(); $panel = $this->newQueryPanel()
$engine->setViewer($viewer); ->setName($name)
$saved = $engine->buildSavedQueryFromBuiltin($query); ->setProperty('class', 'ManiphestTaskSearchEngine')
$query = $engine->buildQueryFromSavedQuery($saved); ->setProperty('key', $query)
$pager = $engine->newPagerForSavedQuery($saved); ->setProperty('limit', 15);
$pager->setPageSize(15);
$results = $engine->executeQuery($query, $pager);
$view = $engine->renderResults($results, $saved);
return $this->buildHomepagePanel($title, $href, $view); return $this->renderPanel($panel);
} }
public function buildFeedPanel() { 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(); return $this->renderPanel($panel);
$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(<<<EOT
Welcome to Phabricator, here are some links to get you started:
- [[ /config/ | Configure Phabricator ]]
- [[ /guides/ | Quick Start Guide ]]
- [[ /diffusion/ | Create a Repository ]]
- [[ /people/invite/send/ | Invite People ]]
- [[ https://twitter.com/phabricator/ | Follow us on Twitter ]]
EOT
);
} else {
$content = pht(<<<EOT
Welcome to Phabricator, here are some links to get you started:
- [[ /guides/ | Quick Start Guide ]]
- [[ /diffusion/ | Create a Repository ]]
- [[ https://twitter.com/phabricator/ | Follow us on Twitter ]]
EOT
);
}
if ($results) {
$list = new PHUIObjectItemListView();
$view = new PhabricatorApplicationSearchResultView();
$view->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);
} }
public function buildRepositoryPanel() { 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(); $viewer = $this->getViewer();
$engine = new PhabricatorRepositorySearchEngine(); return id(new PhabricatorDashboardPanelRenderingEngine())
$engine->setViewer($viewer); ->setViewer($viewer)
$saved = $engine->buildSavedQueryFromBuiltin('active'); ->setPanel($panel)
$query = $engine->buildQueryFromSavedQuery($saved); ->setParentPanelPHIDs(array())
$pager = $engine->newPagerForSavedQuery($saved); ->renderPanel();
$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);
} }
} }