1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-26 00:32:42 +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;
}
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(<<<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);
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();
}
}