|
1 | 1 | <?php
|
2 | 2 |
|
3 |
| -final class ReleephProjectViewController extends ReleephProjectController { |
| 3 | +final class ReleephProjectViewController extends ReleephProjectController |
| 4 | + implements PhabricatorApplicationSearchResultsControllerInterface { |
| 5 | + |
| 6 | + private $queryKey; |
| 7 | + |
| 8 | + public function shouldAllowPublic() { |
| 9 | + return true; |
| 10 | + } |
| 11 | + |
| 12 | + public function willProcessRequest(array $data) { |
| 13 | + parent::willProcessRequest($data); |
| 14 | + $this->queryKey = idx($data, 'queryKey'); |
| 15 | + } |
4 | 16 |
|
5 | 17 | public function processRequest() {
|
6 |
| - // Load all branches |
7 |
| - $releeph_project = $this->getReleephProject(); |
8 |
| - $releeph_branches = id(new ReleephBranch()) |
9 |
| - ->loadAllWhere('releephProjectID = %d', |
10 |
| - $releeph_project->getID()); |
11 |
| - |
12 |
| - $path = $this->getRequest()->getRequestURI()->getPath(); |
13 |
| - $is_open_branches = strpos($path, 'closedbranches/') === false; |
14 |
| - |
15 |
| - $view = id(new ReleephProjectView()) |
16 |
| - ->setShowOpenBranches($is_open_branches) |
17 |
| - ->setUser($this->getRequest()->getUser()) |
18 |
| - ->setReleephProject($releeph_project) |
19 |
| - ->setBranches($releeph_branches); |
20 |
| - |
21 |
| - $crumbs = $this->buildApplicationCrumbs() |
22 |
| - ->addCrumb( |
23 |
| - id(new PhabricatorCrumbView()) |
24 |
| - ->setName($releeph_project->getName()) |
25 |
| - ->setHref($releeph_project->getURI())); |
26 |
| - |
27 |
| - if ($releeph_project->getIsActive()) { |
28 |
| - $crumbs->addAction( |
| 18 | + $request = $this->getRequest(); |
| 19 | + $controller = id(new PhabricatorApplicationSearchController($request)) |
| 20 | + ->setQueryKey($this->queryKey) |
| 21 | + ->setSearchEngine( |
| 22 | + id(new ReleephBranchSearchEngine()) |
| 23 | + ->setProjectID($this->getReleephProject()->getID())) |
| 24 | + ->setNavigation($this->buildSideNavView()); |
| 25 | + |
| 26 | + return $this->delegateToController($controller); |
| 27 | + } |
| 28 | + |
| 29 | + public function renderResultsList( |
| 30 | + array $branches, |
| 31 | + PhabricatorSavedQuery $saved) { |
| 32 | + assert_instances_of($branches, 'ReleephBranch'); |
| 33 | + |
| 34 | + $viewer = $this->getRequest()->getUser(); |
| 35 | + |
| 36 | + $projects = mpull($branches, 'getProject'); |
| 37 | + $repo_phids = mpull($projects, 'getRepositoryPHID'); |
| 38 | + |
| 39 | + $repos = id(new PhabricatorRepositoryQuery()) |
| 40 | + ->setViewer($viewer) |
| 41 | + ->withPHIDs($repo_phids) |
| 42 | + ->execute(); |
| 43 | + $repos = mpull($repos, null, 'getPHID'); |
| 44 | + |
| 45 | + $phids = mpull($branches, 'getCreatedByUserPHID'); |
| 46 | + $this->loadHandles($phids); |
| 47 | + |
| 48 | + $requests = array(); |
| 49 | + if ($branches) { |
| 50 | + $requests = id(new ReleephRequestQuery()) |
| 51 | + ->setViewer($viewer) |
| 52 | + ->withBranchIDs(mpull($branches, 'getID')) |
| 53 | + ->withStatus(ReleephRequestQuery::STATUS_OPEN) |
| 54 | + ->execute(); |
| 55 | + $requests = mgroup($requests, 'getBranchID'); |
| 56 | + } |
| 57 | + |
| 58 | + $list = id(new PhabricatorObjectItemListView()) |
| 59 | + ->setUser($viewer); |
| 60 | + foreach ($branches as $branch) { |
| 61 | + $diffusion_href = null; |
| 62 | + $repo = idx($repos, $branch->getProject()->getRepositoryPHID()); |
| 63 | + if ($repo) { |
| 64 | + $drequest = DiffusionRequest::newFromDictionary( |
| 65 | + array( |
| 66 | + 'user' => $viewer, |
| 67 | + 'repository' => $repo, |
| 68 | + )); |
| 69 | + |
| 70 | + $diffusion_href = $drequest->generateURI( |
| 71 | + array( |
| 72 | + 'action' => 'branch', |
| 73 | + 'branch' => $branch->getName(), |
| 74 | + )); |
| 75 | + } |
| 76 | + |
| 77 | + $branch_link = $branch->getName(); |
| 78 | + if ($diffusion_href) { |
| 79 | + $branch_link = phutil_tag( |
| 80 | + 'a', |
| 81 | + array( |
| 82 | + 'href' => $diffusion_href, |
| 83 | + ), |
| 84 | + $branch_link); |
| 85 | + } |
| 86 | + |
| 87 | + $item = id(new PhabricatorObjectItemView()) |
| 88 | + ->setHeader($branch->getDisplayName()) |
| 89 | + ->setHref($branch->getURI()) |
| 90 | + ->addAttribute($branch_link); |
| 91 | + |
| 92 | + $item->addAction( |
29 | 93 | id(new PHUIListItemView())
|
30 |
| - ->setHref($releeph_project->getURI('cutbranch')) |
31 |
| - ->setName(pht('Cut New Branch')) |
32 |
| - ->setIcon('create')); |
| 94 | + ->setIcon('edit') |
| 95 | + ->setHref($branch->getURI('edit/'))); |
| 96 | + |
| 97 | + if ($branch->getIsActive()) { |
| 98 | + $item->setBarColor('blue'); |
| 99 | + $item->addAction( |
| 100 | + id(new PHUIListItemView()) |
| 101 | + ->setIcon('delete') |
| 102 | + ->setWorkflow(true) |
| 103 | + ->setHref($branch->getURI('close/'))); |
| 104 | + } else { |
| 105 | + $item->setDisabled(true); |
| 106 | + $item->addAction( |
| 107 | + id(new PHUIListItemView()) |
| 108 | + ->setIcon('enable') |
| 109 | + ->setWorkflow(true) |
| 110 | + ->setHref($branch->getURI('re-open/'))); |
| 111 | + } |
| 112 | + |
| 113 | + $commit = $branch->getCutPointCommit(); |
| 114 | + if ($commit) { |
| 115 | + $item->addIcon( |
| 116 | + 'none', |
| 117 | + phabricator_datetime($commit->getEpoch(), $viewer)); |
| 118 | + } |
| 119 | + |
| 120 | + $open_count = count(idx($requests, $branch->getID(), array())); |
| 121 | + if ($open_count) { |
| 122 | + $item->setBarColor('orange'); |
| 123 | + $item->addIcon( |
| 124 | + 'fork', |
| 125 | + pht('%d Open Pull Request(s)', new PhutilNumber($open_count))); |
| 126 | + } |
| 127 | + |
| 128 | + $list->addItem($item); |
| 129 | + } |
| 130 | + |
| 131 | + return $list; |
| 132 | + } |
| 133 | + |
| 134 | + public function buildSideNavView($for_app = false) { |
| 135 | + $user = $this->getRequest()->getUser(); |
| 136 | + |
| 137 | + $nav = new AphrontSideNavFilterView(); |
| 138 | + $nav->setBaseURI(new PhutilURI($this->getApplicationURI())); |
| 139 | + |
| 140 | + if ($for_app) { |
| 141 | + $nav->addFilter('project/create/', pht('Create Project')); |
33 | 142 | }
|
34 | 143 |
|
35 |
| - return $this->buildStandardPageResponse( |
36 |
| - array( |
37 |
| - $crumbs, |
38 |
| - $view, |
39 |
| - ), |
40 |
| - array( |
41 |
| - 'title' => $releeph_project->getName() |
42 |
| - )); |
| 144 | + id(new ReleephBranchSearchEngine()) |
| 145 | + ->setProjectID($this->getReleephProject()->getID()) |
| 146 | + ->setViewer($user) |
| 147 | + ->addNavigationItems($nav->getMenu()); |
| 148 | + |
| 149 | + $nav->selectFilter(null); |
| 150 | + |
| 151 | + return $nav; |
| 152 | + } |
| 153 | + |
| 154 | + public function buildApplicationCrumbs() { |
| 155 | + $crumbs = parent::buildApplicationCrumbs(); |
| 156 | + |
| 157 | + $project = $this->getReleephProject(); |
| 158 | + |
| 159 | + $crumbs->addCrumb( |
| 160 | + id(new PhabricatorCrumbView()) |
| 161 | + ->setName($project->getName())); |
| 162 | + |
| 163 | + $crumbs->addAction( |
| 164 | + id(new PHUIListItemView()) |
| 165 | + ->setHref($project->getURI('cutbranch')) |
| 166 | + ->setName(pht('Cut New Branch')) |
| 167 | + ->setIcon('create')); |
| 168 | + |
| 169 | + return $crumbs; |
43 | 170 | }
|
44 | 171 |
|
45 | 172 | }
|
0 commit comments