Use ApplicationSearch in projects
Summary: Ref T2715. I stripped a bunch of stuff from the list since it was buggy, slow, or both. Some day, we'll rebuild it.
Test Plan: {F51128}
Reviewers: btrahan, chad
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T2715
Differential Revision: https://secure.phabricator.com/D6525
This commit is contained in:
@@ -1,151 +1,54 @@
|
||||
<?php
|
||||
|
||||
final class PhabricatorProjectListController
|
||||
extends PhabricatorProjectController {
|
||||
extends PhabricatorProjectController
|
||||
implements PhabricatorApplicationSearchResultsControllerInterface {
|
||||
|
||||
private $filter;
|
||||
private $queryKey;
|
||||
|
||||
public function shouldAllowPublic() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function willProcessRequest(array $data) {
|
||||
$this->filter = idx($data, 'filter');
|
||||
$this->queryKey = idx($data, 'queryKey');
|
||||
}
|
||||
|
||||
public function processRequest() {
|
||||
$request = $this->getRequest();
|
||||
$controller = id(new PhabricatorApplicationSearchController($request))
|
||||
->setQueryKey($this->queryKey)
|
||||
->setSearchEngine(new PhabricatorProjectSearchEngine())
|
||||
->setNavigation($this->buildSideNavView());
|
||||
|
||||
$nav = $this->buildSideNavView($this->filter);
|
||||
$this->filter = $nav->selectFilter($this->filter, 'active');
|
||||
return $this->delegateToController($controller);
|
||||
}
|
||||
|
||||
$pager = new AphrontPagerView();
|
||||
$pager->setPageSize(250);
|
||||
$pager->setURI($request->getRequestURI(), 'page');
|
||||
$pager->setOffset($request->getInt('page'));
|
||||
|
||||
$query = new PhabricatorProjectQuery();
|
||||
$query->setViewer($request->getUser());
|
||||
$query->needMembers(true);
|
||||
|
||||
$view_phid = $request->getUser()->getPHID();
|
||||
|
||||
switch ($this->filter) {
|
||||
case 'active':
|
||||
$table_header = pht('Your Projects');
|
||||
$query->withMemberPHIDs(array($view_phid));
|
||||
$query->withStatus(PhabricatorProjectQuery::STATUS_ACTIVE);
|
||||
break;
|
||||
case 'allactive':
|
||||
$table_header = pht('Active Projects');
|
||||
$query->withStatus(PhabricatorProjectQuery::STATUS_ACTIVE);
|
||||
break;
|
||||
case 'all':
|
||||
$table_header = pht('All Projects');
|
||||
$query->withStatus(PhabricatorProjectQuery::STATUS_ANY);
|
||||
break;
|
||||
}
|
||||
|
||||
$projects = $query->executeWithOffsetPager($pager);
|
||||
|
||||
$project_phids = mpull($projects, 'getPHID');
|
||||
|
||||
$profiles = array();
|
||||
if ($projects) {
|
||||
$profiles = id(new PhabricatorProjectProfile())->loadAllWhere(
|
||||
'projectPHID in (%Ls)',
|
||||
$project_phids);
|
||||
$profiles = mpull($profiles, null, 'getProjectPHID');
|
||||
}
|
||||
|
||||
$tasks = array();
|
||||
$groups = array();
|
||||
if ($project_phids) {
|
||||
$query = id(new ManiphestTaskQuery())
|
||||
->withAnyProjects($project_phids)
|
||||
->withStatus(ManiphestTaskQuery::STATUS_OPEN)
|
||||
->setLimit(PHP_INT_MAX);
|
||||
|
||||
$tasks = $query->execute();
|
||||
foreach ($tasks as $task) {
|
||||
foreach ($task->getProjectPHIDs() as $phid) {
|
||||
$groups[$phid][] = $task;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$rows = array();
|
||||
foreach ($projects as $project) {
|
||||
$phid = $project->getPHID();
|
||||
|
||||
$profile = idx($profiles, $phid);
|
||||
$members = $project->getMemberPHIDs();
|
||||
|
||||
$group = idx($groups, $phid, array());
|
||||
$task_count = count($group);
|
||||
$population = count($members);
|
||||
|
||||
if ($profile) {
|
||||
$blurb = $profile->getBlurb();
|
||||
$blurb = phutil_utf8_shorten($blurb, 64);
|
||||
} else {
|
||||
$blurb = null;
|
||||
}
|
||||
|
||||
$tasks_href = pht('%d Open Task(s)', $task_count);
|
||||
|
||||
$rows[] = array(
|
||||
$project->getName(),
|
||||
'/project/view/'.$project->getID().'/',
|
||||
PhabricatorProjectStatus::getNameForStatus($project->getStatus()),
|
||||
PhabricatorProjectStatus::getIconForStatus($project->getStatus()),
|
||||
$blurb,
|
||||
pht('%d Member(s)', $population),
|
||||
phutil_tag(
|
||||
'a',
|
||||
array(
|
||||
'href' => '/maniphest/view/all/?projects='.$phid,
|
||||
),
|
||||
$tasks_href),
|
||||
'/project/edit/'.$project->getID().'/',
|
||||
);
|
||||
}
|
||||
public function renderResultsList(
|
||||
array $projects,
|
||||
PhabricatorSavedQuery $query) {
|
||||
assert_instances_of($projects, 'PhabricatorProject');
|
||||
$viewer = $this->getRequest()->getUser();
|
||||
|
||||
$list = new PhabricatorObjectItemListView();
|
||||
$list->setStackable(true);
|
||||
foreach ($rows as $row) {
|
||||
$list->setUser($viewer);
|
||||
foreach ($projects as $project) {
|
||||
$id = $project->getID();
|
||||
|
||||
$item = id(new PhabricatorObjectItemView())
|
||||
->setHeader($row[0])
|
||||
->setHref($row[1])
|
||||
->addIcon($row[3], $row[2])
|
||||
->addIcon('edit', pht('Edit Project'), array('href' => $row[7]));
|
||||
if ($row[4]) {
|
||||
$item->addAttribute($row[4]);
|
||||
->setHeader($project->getName())
|
||||
->setHref($this->getApplicationURI("view/{$id}/"));
|
||||
|
||||
if ($project->getStatus() == PhabricatorProjectStatus::STATUS_ARCHIVED) {
|
||||
$item->addIcon('delete-grey', pht('Archived'));
|
||||
$item->setDisabled(true);
|
||||
}
|
||||
$item->addAttribute($row[5]);
|
||||
$item->addAttribute($row[6]);
|
||||
|
||||
|
||||
$list->addItem($item);
|
||||
}
|
||||
|
||||
$nav->appendChild(
|
||||
array(
|
||||
$list,
|
||||
$pager,
|
||||
));
|
||||
|
||||
$crumbs = $this->buildApplicationCrumbs($this->buildSideNavView());
|
||||
$crumbs->addCrumb(
|
||||
id(new PhabricatorCrumbView())
|
||||
->setName($table_header)
|
||||
->setHref($this->getApplicationURI()));
|
||||
$nav->setCrumbs($crumbs);
|
||||
|
||||
return $this->buildApplicationPage(
|
||||
$nav,
|
||||
array(
|
||||
'title' => pht('Projects'),
|
||||
'device' => true,
|
||||
'dust' => true,
|
||||
));
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function buildApplicationMenu() {
|
||||
return $this->buildSideNavView(null, true)->getMenu();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user