1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 14:00:56 +01:00

Show recent active resources on Drydock blueprint detail, with link to all

Summary:
Ref T9252. Currently, Drydock blueprint pages:

  - show all resources, even if there are a million;
  - show resources in all states, although destroyed resources are usually uninteresting;
  - have some junky `$pager` code.

Instead, show the few most recent active resources and link to a filtered resource view in ApplicationSearch.

Test Plan:
  - Viewed some blueprints.
  - Clicked "View All Resources".
  - Saw all resources.
  - Used query / crumbs / etc.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T9252

Differential Revision: https://secure.phabricator.com/D14157
This commit is contained in:
epriestley 2015-09-24 13:52:43 -07:00
parent b441e8b81e
commit 3b2f4c258f
5 changed files with 118 additions and 29 deletions

View file

@ -53,6 +53,8 @@ final class PhabricatorDrydockApplication extends PhabricatorApplication {
'' => 'DrydockBlueprintViewController',
'(?P<action>disable|enable)/' =>
'DrydockBlueprintDisableController',
'resources/(?:query/(?P<queryKey>[^/]+)/)?' =>
'DrydockResourceListController',
),
'create/' => 'DrydockBlueprintCreateController',
'edit/(?:(?P<id>[1-9]\d*)/)?' => 'DrydockBlueprintEditController',

View file

@ -30,24 +30,6 @@ final class DrydockBlueprintViewController extends DrydockBlueprintController {
$actions = $this->buildActionListView($blueprint);
$properties = $this->buildPropertyListView($blueprint, $actions);
$blueprint_uri = 'blueprint/'.$blueprint->getID().'/';
$blueprint_uri = $this->getApplicationURI($blueprint_uri);
$resources = id(new DrydockResourceQuery())
->withBlueprintPHIDs(array($blueprint->getPHID()))
->setViewer($viewer)
->execute();
$resource_list = id(new DrydockResourceListView())
->setUser($viewer)
->setResources($resources)
->render();
$resource_list->setNoDataString(pht('This blueprint has no resources.'));
$pager = new PHUIPagerView();
$pager->setURI(new PhutilURI($blueprint_uri), 'offset');
$pager->setOffset($request->getInt('offset'));
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb(pht('Blueprint %d', $blueprint->getID()));
@ -67,9 +49,7 @@ final class DrydockBlueprintViewController extends DrydockBlueprintController {
$viewer,
$properties);
$resource_box = id(new PHUIObjectBoxView())
->setHeaderText(pht('Resources'))
->setObjectList($resource_list);
$resource_box = $this->buildResourceBox($blueprint);
$timeline = $this->buildTransactionTimeline(
$blueprint,
@ -148,4 +128,43 @@ final class DrydockBlueprintViewController extends DrydockBlueprintController {
return $view;
}
private function buildResourceBox(DrydockBlueprint $blueprint) {
$viewer = $this->getViewer();
$resources = id(new DrydockResourceQuery())
->setViewer($viewer)
->withBlueprintPHIDs(array($blueprint->getPHID()))
->withStatuses(
array(
DrydockResourceStatus::STATUS_PENDING,
DrydockResourceStatus::STATUS_ACTIVE,
))
->setLimit(100)
->execute();
$resource_list = id(new DrydockResourceListView())
->setUser($viewer)
->setResources($resources)
->render()
->setNoDataString(pht('This blueprint has no active resources.'));
$id = $blueprint->getID();
$resources_uri = "blueprint/{$id}/resources/query/all/";
$resources_uri = $this->getApplicationURI($resources_uri);
$resource_header = id(new PHUIHeaderView())
->setHeader(pht('Active Resources'))
->addActionLink(
id(new PHUIButtonView())
->setTag('a')
->setHref($resources_uri)
->setIconFont('fa-search')
->setText(pht('View All Resources')));
return id(new PHUIObjectBoxView())
->setHeader($resource_header)
->setObjectList($resource_list);
}
}

View file

@ -3,12 +3,23 @@
abstract class DrydockResourceController
extends DrydockController {
private $blueprint;
public function setBlueprint($blueprint) {
$this->blueprint = $blueprint;
return $this;
}
public function getBlueprint() {
return $this->blueprint;
}
public function buildSideNavView() {
$nav = new AphrontSideNavFilterView();
$nav->setBaseURI(new PhutilURI($this->getApplicationURI()));
id(new DrydockResourceSearchEngine())
->setViewer($this->getRequest()->getUser())
->setViewer($this->getViewer())
->addNavigationItems($nav->getMenu());
$nav->selectFilter(null);
@ -18,9 +29,26 @@ abstract class DrydockResourceController
protected function buildApplicationCrumbs() {
$crumbs = parent::buildApplicationCrumbs();
$crumbs->addTextCrumb(
pht('Resources'),
$this->getApplicationURI('resource/'));
$blueprint = $this->getBlueprint();
if ($blueprint) {
$id = $blueprint->getID();
$crumbs->addTextCrumb(
pht('Blueprints'),
$this->getApplicationURI('blueprint/'));
$crumbs->addTextCrumb(
$blueprint->getBlueprintName(),
$this->getApplicationURI("blueprint/{$id}/"));
$crumbs->addTextCrumb(
pht('Resources'),
$this->getApplicationURI("blueprint/{$id}/resources/"));
} else {
$crumbs->addTextCrumb(
pht('Resources'),
$this->getApplicationURI('resource/'));
}
return $crumbs;
}

View file

@ -7,12 +7,28 @@ final class DrydockResourceListController extends DrydockResourceController {
}
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$viewer = $this->getViewer();
$engine = new DrydockResourceSearchEngine();
$id = $request->getURIData('id');
if ($id) {
$blueprint = id(new DrydockBlueprintQuery())
->setViewer($viewer)
->withIDs(array($id))
->executeOne();
if (!$blueprint) {
return new Aphront404Response();
}
$this->setBlueprint($blueprint);
$engine->setBlueprint($blueprint);
}
$querykey = $request->getURIData('queryKey');
$controller = id(new PhabricatorApplicationSearchController())
->setQueryKey($querykey)
->setSearchEngine(new DrydockResourceSearchEngine())
->setSearchEngine($engine)
->setNavigation($this->buildSideNavView());
return $this->delegateToController($controller);

View file

@ -3,6 +3,17 @@
final class DrydockResourceSearchEngine
extends PhabricatorApplicationSearchEngine {
private $blueprint;
public function setBlueprint(DrydockBlueprint $blueprint) {
$this->blueprint = $blueprint;
return $this;
}
public function getBlueprint() {
return $this->blueprint;
}
public function getResultTypeDescription() {
return pht('Drydock Resources');
}
@ -12,7 +23,14 @@ final class DrydockResourceSearchEngine
}
public function newQuery() {
return new DrydockResourceQuery();
$query = new DrydockResourceQuery();
$blueprint = $this->getBlueprint();
if ($blueprint) {
$query->withBlueprintPHIDs(array($blueprint->getPHID()));
}
return $query;
}
protected function buildQueryFromParameters(array $map) {
@ -35,7 +53,13 @@ final class DrydockResourceSearchEngine
}
protected function getURI($path) {
return '/drydock/resource/'.$path;
$blueprint = $this->getBlueprint();
if ($blueprint) {
$id = $blueprint->getID();
return "/drydock/blueprint/{$id}/resources/".$path;
} else {
return '/drydock/resource/'.$path;
}
}
protected function getBuiltinQueryNames() {