Use ApplicationSearch in Diffusion
Summary: Ref T2625. Switches Diffusion to ApplicationSearch. Notes: - Rendering is a bit rough, I'll clean that up next. - Ordering is a bit arbitrary, also coming shortly. Test Plan: Used `/diffusion/` to execute various searches. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T2625 Differential Revision: https://secure.phabricator.com/D6917
This commit is contained in:
		| @@ -1533,6 +1533,7 @@ phutil_register_library_map(array( | |||||||
|     'PhabricatorRepositoryPullEngine' => 'applications/repository/engine/PhabricatorRepositoryPullEngine.php', |     'PhabricatorRepositoryPullEngine' => 'applications/repository/engine/PhabricatorRepositoryPullEngine.php', | ||||||
|     'PhabricatorRepositoryPullLocalDaemon' => 'applications/repository/daemon/PhabricatorRepositoryPullLocalDaemon.php', |     'PhabricatorRepositoryPullLocalDaemon' => 'applications/repository/daemon/PhabricatorRepositoryPullLocalDaemon.php', | ||||||
|     'PhabricatorRepositoryQuery' => 'applications/repository/query/PhabricatorRepositoryQuery.php', |     'PhabricatorRepositoryQuery' => 'applications/repository/query/PhabricatorRepositoryQuery.php', | ||||||
|  |     'PhabricatorRepositorySearchEngine' => 'applications/repository/query/PhabricatorRepositorySearchEngine.php', | ||||||
|     'PhabricatorRepositoryShortcut' => 'applications/repository/storage/PhabricatorRepositoryShortcut.php', |     'PhabricatorRepositoryShortcut' => 'applications/repository/storage/PhabricatorRepositoryShortcut.php', | ||||||
|     'PhabricatorRepositorySvnCommitChangeParserWorker' => 'applications/repository/worker/commitchangeparser/PhabricatorRepositorySvnCommitChangeParserWorker.php', |     'PhabricatorRepositorySvnCommitChangeParserWorker' => 'applications/repository/worker/commitchangeparser/PhabricatorRepositorySvnCommitChangeParserWorker.php', | ||||||
|     'PhabricatorRepositorySvnCommitMessageParserWorker' => 'applications/repository/worker/commitmessageparser/PhabricatorRepositorySvnCommitMessageParserWorker.php', |     'PhabricatorRepositorySvnCommitMessageParserWorker' => 'applications/repository/worker/commitmessageparser/PhabricatorRepositorySvnCommitMessageParserWorker.php', | ||||||
| @@ -2536,7 +2537,11 @@ phutil_register_library_map(array( | |||||||
|     'DiffusionRepositoryEditBasicController' => 'DiffusionController', |     'DiffusionRepositoryEditBasicController' => 'DiffusionController', | ||||||
|     'DiffusionRepositoryEditController' => 'DiffusionController', |     'DiffusionRepositoryEditController' => 'DiffusionController', | ||||||
|     'DiffusionRepositoryEditEncodingController' => 'DiffusionController', |     'DiffusionRepositoryEditEncodingController' => 'DiffusionController', | ||||||
|     'DiffusionRepositoryListController' => 'DiffusionController', |     'DiffusionRepositoryListController' => | ||||||
|  |     array( | ||||||
|  |       0 => 'DiffusionController', | ||||||
|  |       1 => 'PhabricatorApplicationSearchResultsControllerInterface', | ||||||
|  |     ), | ||||||
|     'DiffusionSetupException' => 'AphrontUsageException', |     'DiffusionSetupException' => 'AphrontUsageException', | ||||||
|     'DiffusionStableCommitNameQuery' => 'DiffusionQuery', |     'DiffusionStableCommitNameQuery' => 'DiffusionQuery', | ||||||
|     'DiffusionSvnCommitParentsQuery' => 'DiffusionCommitParentsQuery', |     'DiffusionSvnCommitParentsQuery' => 'DiffusionCommitParentsQuery', | ||||||
| @@ -3665,6 +3670,7 @@ phutil_register_library_map(array( | |||||||
|     'PhabricatorRepositoryPullEngine' => 'PhabricatorRepositoryEngine', |     'PhabricatorRepositoryPullEngine' => 'PhabricatorRepositoryEngine', | ||||||
|     'PhabricatorRepositoryPullLocalDaemon' => 'PhabricatorDaemon', |     'PhabricatorRepositoryPullLocalDaemon' => 'PhabricatorDaemon', | ||||||
|     'PhabricatorRepositoryQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', |     'PhabricatorRepositoryQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', | ||||||
|  |     'PhabricatorRepositorySearchEngine' => 'PhabricatorApplicationSearchEngine', | ||||||
|     'PhabricatorRepositoryShortcut' => 'PhabricatorRepositoryDAO', |     'PhabricatorRepositoryShortcut' => 'PhabricatorRepositoryDAO', | ||||||
|     'PhabricatorRepositorySvnCommitChangeParserWorker' => 'PhabricatorRepositoryCommitChangeParserWorker', |     'PhabricatorRepositorySvnCommitChangeParserWorker' => 'PhabricatorRepositoryCommitChangeParserWorker', | ||||||
|     'PhabricatorRepositorySvnCommitMessageParserWorker' => 'PhabricatorRepositoryCommitMessageParserWorker', |     'PhabricatorRepositorySvnCommitMessageParserWorker' => 'PhabricatorRepositoryCommitMessageParserWorker', | ||||||
|   | |||||||
| @@ -41,7 +41,8 @@ final class PhabricatorApplicationDiffusion extends PhabricatorApplication { | |||||||
|       '/r(?P<callsign>[A-Z]+)(?P<commit>[a-z0-9]+)' |       '/r(?P<callsign>[A-Z]+)(?P<commit>[a-z0-9]+)' | ||||||
|         => 'DiffusionCommitController', |         => 'DiffusionCommitController', | ||||||
|       '/diffusion/' => array( |       '/diffusion/' => array( | ||||||
|         '' => 'DiffusionRepositoryListController', |         '(?:query/(?P<queryKey>[^/]+)/)?' | ||||||
|  |           => 'DiffusionRepositoryListController', | ||||||
|         'create/' => 'DiffusionRepositoryCreateController', |         'create/' => 'DiffusionRepositoryCreateController', | ||||||
|         '(?P<callsign>[A-Z]+)/' => array( |         '(?P<callsign>[A-Z]+)/' => array( | ||||||
|           '' => 'DiffusionRepositoryController', |           '' => 'DiffusionRepositoryController', | ||||||
|   | |||||||
| @@ -1,56 +1,35 @@ | |||||||
| <?php | <?php | ||||||
|  |  | ||||||
| final class DiffusionRepositoryListController extends DiffusionController { | final class DiffusionRepositoryListController extends DiffusionController | ||||||
|  |   implements PhabricatorApplicationSearchResultsControllerInterface { | ||||||
|  |  | ||||||
|  |   private $queryKey; | ||||||
|  |  | ||||||
|  |   public function shouldAllowPublic() { | ||||||
|  |     return true; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public function willProcessRequest(array $data) { | ||||||
|  |     $this->queryKey = idx($data, 'queryKey'); | ||||||
|  |   } | ||||||
|  |  | ||||||
|   public function processRequest() { |   public function processRequest() { | ||||||
|     $request = $this->getRequest(); |     $request = $this->getRequest(); | ||||||
|     $user = $request->getUser(); |     $controller = id(new PhabricatorApplicationSearchController($request)) | ||||||
|  |       ->setQueryKey($this->queryKey) | ||||||
|  | //      ->setPreamble($this->buildShortcuts()) | ||||||
|  |       ->setSearchEngine(new PhabricatorRepositorySearchEngine()) | ||||||
|  |       ->setNavigation($this->buildSideNavView()); | ||||||
|  |  | ||||||
|     $shortcuts = id(new PhabricatorRepositoryShortcut())->loadAll(); |     return $this->delegateToController($controller); | ||||||
|     if ($shortcuts) { |   } | ||||||
|       $shortcuts = msort($shortcuts, 'getSequence'); |  | ||||||
|  |  | ||||||
|       $rows = array(); |   public function renderResultsList( | ||||||
|       foreach ($shortcuts as $shortcut) { |     array $repositories, | ||||||
|         $rows[] = array( |     PhabricatorSavedQuery $query) { | ||||||
|           $shortcut->getName(), |     assert_instances_of($repositories, 'PhabricatorRepository'); | ||||||
|           $shortcut->getHref(), |  | ||||||
|           $shortcut->getDescription(), |  | ||||||
|         ); |  | ||||||
|       } |  | ||||||
|  |  | ||||||
|       $list = new PHUIObjectItemListView(); |     $viewer = $this->getRequest()->getUser(); | ||||||
|       $list->setCards(true); |  | ||||||
|       $list->setFlush(true); |  | ||||||
|       foreach ($rows as $row) { |  | ||||||
|         $item = id(new PHUIObjectItemView()) |  | ||||||
|             ->setHeader($row[0]) |  | ||||||
|             ->setHref($row[1]) |  | ||||||
|             ->setSubhead(($row[2] ? $row[2] : pht('No Description'))); |  | ||||||
|         $list->addItem($item); |  | ||||||
|       } |  | ||||||
|  |  | ||||||
|       $shortcut_panel = id(new AphrontPanelView()) |  | ||||||
|         ->setNoBackground(true) |  | ||||||
|         ->setHeader(pht('Shortcuts')) |  | ||||||
|         ->appendChild($list); |  | ||||||
|  |  | ||||||
|     } else { |  | ||||||
|       $shortcut_panel = null; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     $repositories = id(new PhabricatorRepositoryQuery()) |  | ||||||
|       ->setViewer($user) |  | ||||||
|       ->needCommitCounts(true) |  | ||||||
|       ->needMostRecentCommits(true) |  | ||||||
|       ->execute(); |  | ||||||
|  |  | ||||||
|     foreach ($repositories as $key => $repo) { |  | ||||||
|       if (!$repo->isTracked()) { |  | ||||||
|         unset($repositories[$key]); |  | ||||||
|       } |  | ||||||
|     } |  | ||||||
|     $repositories = msort($repositories, 'getName'); |  | ||||||
|  |  | ||||||
|     $rows = array(); |     $rows = array(); | ||||||
|     foreach ($repositories as $repository) { |     foreach ($repositories as $repository) { | ||||||
| @@ -70,8 +49,8 @@ final class DiffusionRepositoryListController extends DiffusionController { | |||||||
|       $datetime = ''; |       $datetime = ''; | ||||||
|       $most_recent_commit = $repository->getMostRecentCommit(); |       $most_recent_commit = $repository->getMostRecentCommit(); | ||||||
|       if ($most_recent_commit) { |       if ($most_recent_commit) { | ||||||
|         $date = phabricator_date($most_recent_commit->getEpoch(), $user); |         $date = phabricator_date($most_recent_commit->getEpoch(), $viewer); | ||||||
|         $time = phabricator_time($most_recent_commit->getEpoch(), $user); |         $time = phabricator_time($most_recent_commit->getEpoch(), $viewer); | ||||||
|         $datetime = $date.' '.$time; |         $datetime = $date.' '.$time; | ||||||
|       } |       } | ||||||
|  |  | ||||||
| @@ -99,7 +78,7 @@ final class DiffusionRepositoryListController extends DiffusionController { | |||||||
|       'repository tool'); |       'repository tool'); | ||||||
|     $preface = pht('This instance of Phabricator does not have any '. |     $preface = pht('This instance of Phabricator does not have any '. | ||||||
|                    'configured repositories.'); |                    'configured repositories.'); | ||||||
|     if ($user->getIsAdmin()) { |     if ($viewer->getIsAdmin()) { | ||||||
|       $no_repositories_txt = hsprintf( |       $no_repositories_txt = hsprintf( | ||||||
|         '%s %s', |         '%s %s', | ||||||
|         $preface, |         $preface, | ||||||
| @@ -117,41 +96,70 @@ final class DiffusionRepositoryListController extends DiffusionController { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     $list = new PHUIObjectItemListView(); |     $list = new PHUIObjectItemListView(); | ||||||
|     $list->setCards(true); |  | ||||||
|     $list->setFlush(true); |  | ||||||
|     foreach ($rows as $row) { |     foreach ($rows as $row) { | ||||||
|       $item = id(new PHUIObjectItemView()) |       $item = id(new PHUIObjectItemView()) | ||||||
|           ->setHeader($row[0]) |         ->setHeader($row[0]) | ||||||
|           ->setSubHead($row[4]) |         ->setSubHead($row[4]) | ||||||
|           ->setHref($row[1]) |         ->setHref($row[1]) | ||||||
|           ->addAttribute(($row[2] ? $row[2] : pht('No Information'))) |         ->addAttribute(($row[2] ? $row[2] : pht('No Information'))) | ||||||
|           ->addAttribute(($row[3] ? $row[3] : pht('0 Commits'))) |         ->addAttribute(($row[3] ? $row[3] : pht('0 Commits'))) | ||||||
|           ->addIcon('none', $row[5]); |         ->addIcon('none', $row[5]); | ||||||
|       $list->addItem($item); |       $list->addItem($item); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     $list = id(new AphrontPanelView()) |     return $list; | ||||||
|       ->setNoBackground(true) |   } | ||||||
|       ->setHeader(pht('Repositories')) |  | ||||||
|       ->appendChild($list); |   public function buildSideNavView($for_app = false) { | ||||||
|  |     $viewer = $this->getRequest()->getUser(); | ||||||
|  |  | ||||||
|  |     $nav = new AphrontSideNavFilterView(); | ||||||
|  |     $nav->setBaseURI(new PhutilURI($this->getApplicationURI())); | ||||||
|  |  | ||||||
|  |  | ||||||
|     $crumbs = $this->buildCrumbs(); |     id(new PhabricatorRepositorySearchEngine()) | ||||||
|     $crumbs->addCrumb( |       ->setViewer($viewer) | ||||||
|       id(new PhabricatorCrumbView()) |       ->addNavigationItems($nav->getMenu()); | ||||||
|         ->setName(pht('All Repositories')) |  | ||||||
|         ->setHref($this->getApplicationURI())); |  | ||||||
|  |  | ||||||
|     return $this->buildApplicationPage( |     $nav->selectFilter(null); | ||||||
|       array( |  | ||||||
|         $crumbs, |     return $nav; | ||||||
|         $shortcut_panel, |   } | ||||||
|         $list, |  | ||||||
|       ), |   private function buildShortcuts() { | ||||||
|       array( |     $shortcuts = id(new PhabricatorRepositoryShortcut())->loadAll(); | ||||||
|         'title' => pht('Diffusion'), |     if ($shortcuts) { | ||||||
|         'device' => true, |       $shortcuts = msort($shortcuts, 'getSequence'); | ||||||
|       )); |  | ||||||
|  |       $rows = array(); | ||||||
|  |       foreach ($shortcuts as $shortcut) { | ||||||
|  |         $rows[] = array( | ||||||
|  |           $shortcut->getName(), | ||||||
|  |           $shortcut->getHref(), | ||||||
|  |           $shortcut->getDescription(), | ||||||
|  |         ); | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       $list = new PHUIObjectItemListView(); | ||||||
|  |       $list->setCards(true); | ||||||
|  |       $list->setFlush(true); | ||||||
|  |       foreach ($rows as $row) { | ||||||
|  |         $item = id(new PHUIObjectItemView()) | ||||||
|  |           ->setHeader($row[0]) | ||||||
|  |           ->setHref($row[1]) | ||||||
|  |           ->setSubhead(($row[2] ? $row[2] : pht('No Description'))); | ||||||
|  |         $list->addItem($item); | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       $shortcut_panel = id(new AphrontPanelView()) | ||||||
|  |         ->setNoBackground(true) | ||||||
|  |         ->setHeader(pht('Shortcuts')) | ||||||
|  |         ->appendChild($list); | ||||||
|  |  | ||||||
|  |     } else { | ||||||
|  |       $shortcut_panel = null; | ||||||
|  |     } | ||||||
|  |     return $shortcut_panel; | ||||||
|   } |   } | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -0,0 +1,66 @@ | |||||||
|  | <?php | ||||||
|  |  | ||||||
|  | final class PhabricatorRepositorySearchEngine | ||||||
|  |   extends PhabricatorApplicationSearchEngine { | ||||||
|  |  | ||||||
|  |   public function buildSavedQueryFromRequest(AphrontRequest $request) { | ||||||
|  |     $saved = new PhabricatorSavedQuery(); | ||||||
|  |  | ||||||
|  |     $saved->setParameter('callsigns', $request->getStrList('callsigns')); | ||||||
|  |  | ||||||
|  |     return $saved; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { | ||||||
|  |     $query = id(new PhabricatorRepositoryQuery()) | ||||||
|  |       ->needCommitCounts(true) | ||||||
|  |       ->needMostRecentCommits(true); | ||||||
|  |  | ||||||
|  |     $callsigns = $saved->getParameter('callsigns'); | ||||||
|  |     if ($callsigns) { | ||||||
|  |       $query->withCallsigns($callsigns); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     return $query; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public function buildSearchForm( | ||||||
|  |     AphrontFormView $form, | ||||||
|  |     PhabricatorSavedQuery $saved_query) { | ||||||
|  |  | ||||||
|  |     $callsigns = $saved_query->getParameter('callsigns', array()); | ||||||
|  |  | ||||||
|  |     $form | ||||||
|  |       ->appendChild( | ||||||
|  |         id(new AphrontFormTextControl()) | ||||||
|  |           ->setName('callsigns') | ||||||
|  |           ->setLabel(pht('Callsigns')) | ||||||
|  |           ->setValue(implode(', ', $callsigns))); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   protected function getURI($path) { | ||||||
|  |     return '/diffusion/'.$path; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public function getBuiltinQueryNames() { | ||||||
|  |     $names = array( | ||||||
|  |       'all' => pht('All Repositories'), | ||||||
|  |     ); | ||||||
|  |  | ||||||
|  |     return $names; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public function buildSavedQueryFromBuiltin($query_key) { | ||||||
|  |  | ||||||
|  |     $query = $this->newSavedQuery(); | ||||||
|  |     $query->setQueryKey($query_key); | ||||||
|  |  | ||||||
|  |     switch ($query_key) { | ||||||
|  |       case 'all': | ||||||
|  |         return $query; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     return parent::buildSavedQueryFromBuiltin($query_key); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  | } | ||||||
		Reference in New Issue
	
	Block a user
	 epriestley
					epriestley