From 2c09fc56051b925c0634e5a15b5246e6c756bc74 Mon Sep 17 00:00:00 2001 From: Chad Little Date: Mon, 13 Feb 2017 16:30:33 -0800 Subject: [PATCH] Make Panels slightly easier to find and use Summary: Ref T10390, turns "add existing panel" into a typeahead, and add lots more information to search. Test Plan: Add an existing panel, click the search icon, see more information (type, engine). Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin Maniphest Tasks: T10390 Differential Revision: https://secure.phabricator.com/D17348 --- ...PhabricatorDashboardAddPanelController.php | 19 +++++-------- .../PhabricatorDashboardPanelType.php | 1 + .../PhabricatorDashboardQueryPanelType.php | 4 +++ .../PhabricatorDashboardTabsPanelType.php | 4 +++ .../PhabricatorDashboardTextPanelType.php | 4 +++ .../PhabricatorDashboardPanelDatasource.php | 27 ++++++++++++++++--- 6 files changed, 42 insertions(+), 17 deletions(-) diff --git a/src/applications/dashboard/controller/PhabricatorDashboardAddPanelController.php b/src/applications/dashboard/controller/PhabricatorDashboardAddPanelController.php index f34bdd06ae..46712d79e9 100644 --- a/src/applications/dashboard/controller/PhabricatorDashboardAddPanelController.php +++ b/src/applications/dashboard/controller/PhabricatorDashboardAddPanelController.php @@ -23,7 +23,7 @@ final class PhabricatorDashboardAddPanelController $redirect_uri = $this->getApplicationURI( 'arrange/'.$dashboard->getID().'/'); - $v_panel = $request->getStr('panel'); + $v_panel = head($request->getArr('panel')); $e_panel = true; $errors = array(); if ($request->isFormPost()) { @@ -70,26 +70,19 @@ final class PhabricatorDashboardAddPanelController ->addCancelButton($redirect_uri); } - $panel_options = array(); - foreach ($panels as $panel) { - $panel_options[$panel->getID()] = pht( - '%s %s', - $panel->getMonogram(), - $panel->getName()); - } - $form = id(new AphrontFormView()) ->setUser($viewer) ->addHiddenInput('column', $request->getInt('column')) ->appendRemarkupInstructions( pht('Choose a panel to add to this dashboard:')) ->appendChild( - id(new AphrontFormSelectControl()) + id(new AphrontFormTokenizerControl()) + ->setUser($this->getViewer()) + ->setDatasource(new PhabricatorDashboardPanelDatasource()) + ->setLimit(1) ->setName('panel') ->setLabel(pht('Panel')) - ->setValue($v_panel) - ->setError($e_panel) - ->setOptions($panel_options)); + ->setValue($v_panel)); return $this->newDialog() ->setTitle(pht('Add Panel')) diff --git a/src/applications/dashboard/paneltype/PhabricatorDashboardPanelType.php b/src/applications/dashboard/paneltype/PhabricatorDashboardPanelType.php index 81e7ec80cc..34c7b1c3ee 100644 --- a/src/applications/dashboard/paneltype/PhabricatorDashboardPanelType.php +++ b/src/applications/dashboard/paneltype/PhabricatorDashboardPanelType.php @@ -6,6 +6,7 @@ abstract class PhabricatorDashboardPanelType extends Phobject { abstract public function getPanelTypeName(); abstract public function getPanelTypeDescription(); abstract public function getFieldSpecifications(); + abstract public function getIcon(); abstract public function renderPanelContent( PhabricatorUser $viewer, diff --git a/src/applications/dashboard/paneltype/PhabricatorDashboardQueryPanelType.php b/src/applications/dashboard/paneltype/PhabricatorDashboardQueryPanelType.php index 76e6e8432b..0781d71b16 100644 --- a/src/applications/dashboard/paneltype/PhabricatorDashboardQueryPanelType.php +++ b/src/applications/dashboard/paneltype/PhabricatorDashboardQueryPanelType.php @@ -11,6 +11,10 @@ final class PhabricatorDashboardQueryPanelType return pht('Query Panel'); } + public function getIcon() { + return 'fa-search'; + } + public function getPanelTypeDescription() { return pht( 'Show results of a search query, like the most recently filed tasks or '. diff --git a/src/applications/dashboard/paneltype/PhabricatorDashboardTabsPanelType.php b/src/applications/dashboard/paneltype/PhabricatorDashboardTabsPanelType.php index 3cb758a11a..292446fe55 100644 --- a/src/applications/dashboard/paneltype/PhabricatorDashboardTabsPanelType.php +++ b/src/applications/dashboard/paneltype/PhabricatorDashboardTabsPanelType.php @@ -11,6 +11,10 @@ final class PhabricatorDashboardTabsPanelType return pht('Tab Panel'); } + public function getIcon() { + return 'fa-window-maximize'; + } + public function getPanelTypeDescription() { return pht('Use tabs to switch between several other panels.'); } diff --git a/src/applications/dashboard/paneltype/PhabricatorDashboardTextPanelType.php b/src/applications/dashboard/paneltype/PhabricatorDashboardTextPanelType.php index 413d3dc856..5ecde8501f 100644 --- a/src/applications/dashboard/paneltype/PhabricatorDashboardTextPanelType.php +++ b/src/applications/dashboard/paneltype/PhabricatorDashboardTextPanelType.php @@ -11,6 +11,10 @@ final class PhabricatorDashboardTextPanelType return pht('Text Panel'); } + public function getIcon() { + return 'fa-paragraph'; + } + public function getPanelTypeDescription() { return pht( 'Add some static text to the dashboard. This can be used to '. diff --git a/src/applications/dashboard/typeahead/PhabricatorDashboardPanelDatasource.php b/src/applications/dashboard/typeahead/PhabricatorDashboardPanelDatasource.php index 35c8c5c212..958883d34e 100644 --- a/src/applications/dashboard/typeahead/PhabricatorDashboardPanelDatasource.php +++ b/src/applications/dashboard/typeahead/PhabricatorDashboardPanelDatasource.php @@ -16,9 +16,19 @@ final class PhabricatorDashboardPanelDatasource } public function loadResults() { - $query = id(new PhabricatorDashboardPanelQuery()); + $results = $this->buildResults(); + return $this->filterResultsAgainstTokens($results); + } + + protected function renderSpecialTokens(array $values) { + return $this->renderTokensFromResults($this->buildResults(), $values); + } + + public function buildResults() { + $query = id(new PhabricatorDashboardPanelQuery()); $panels = $this->executeQuery($query); + $results = array(); foreach ($panels as $panel) { $impl = $panel->getImplementation(); @@ -27,20 +37,29 @@ final class PhabricatorDashboardPanelDatasource } else { $type_text = nonempty($panel->getPanelType(), pht('Unknown Type')); } + $id = $panel->getID(); + $monogram = $panel->getMonogram(); + $properties = $panel->getProperties(); $result = id(new PhabricatorTypeaheadResult()) ->setName($panel->getName()) - ->setPHID($panel->getPHID()) + ->setDisplayName($monogram.' '.$panel->getName()) + ->setPHID($id) + ->setIcon($impl->getIcon()) ->addAttribute($type_text); + if (!empty($properties['class'])) { + $result->addAttribute($properties['class']); + } + if ($panel->getIsArchived()) { $result->setClosed(pht('Archived')); } - $results[] = $result; + $results[$id] = $result; } - return $this->filterResultsAgainstTokens($results); + return $results; } }