Differential D18161 Diff 43739 src/applications/diffusion/controller/DiffusionRepositoryController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/controller/DiffusionRepositoryController.php
| Show First 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | if ($page_has_content) { | ||||
| $content = $this->buildNormalContent($drequest); | $content = $this->buildNormalContent($drequest); | ||||
| } else { | } else { | ||||
| $content = id(new PHUIInfoView()) | $content = id(new PHUIInfoView()) | ||||
| ->setTitle($empty_title) | ->setTitle($empty_title) | ||||
| ->setSeverity(PHUIInfoView::SEVERITY_WARNING) | ->setSeverity(PHUIInfoView::SEVERITY_WARNING) | ||||
| ->setErrors(array($empty_message)); | ->setErrors(array($empty_message)); | ||||
| } | } | ||||
| $tabs = $this->buildTabsView('home'); | |||||
| $view = id(new PHUITwoColumnView()) | $view = id(new PHUITwoColumnView()) | ||||
| ->setHeader($header) | ->setHeader($header) | ||||
| ->setCurtain($curtain) | ->setCurtain($curtain) | ||||
| ->setTabs($tabs) | |||||
| ->setMainColumn(array( | ->setMainColumn(array( | ||||
| $property_table, | $property_table, | ||||
| $description, | $description, | ||||
| $locate_file, | $locate_file, | ||||
| )) | )) | ||||
| ->setFooter($content); | ->setFooter($content); | ||||
| return $this->newPage() | return $this->newPage() | ||||
| Show All 31 Lines | private function buildNormalContent(DiffusionRequest $drequest) { | ||||
| $this->browseFuture = $this->callConduitMethod( | $this->browseFuture = $this->callConduitMethod( | ||||
| 'diffusion.browsequery', | 'diffusion.browsequery', | ||||
| array( | array( | ||||
| 'commit' => $commit, | 'commit' => $commit, | ||||
| 'path' => $path, | 'path' => $path, | ||||
| 'limit' => $browse_pager->getPageSize() + 1, | 'limit' => $browse_pager->getPageSize() + 1, | ||||
| )); | )); | ||||
| if ($this->needTagFuture()) { | |||||
| $tag_limit = $this->getTagLimit(); | |||||
| $this->tagFuture = $this->callConduitMethod( | |||||
| 'diffusion.tagsquery', | |||||
| array( | |||||
| // On the home page, we want to find tags on any branch. | |||||
| 'commit' => null, | |||||
| 'limit' => $tag_limit + 1, | |||||
| )); | |||||
| } | |||||
| if ($this->needBranchFuture()) { | |||||
| $branch_limit = $this->getBranchLimit(); | |||||
| $this->branchFuture = $this->callConduitMethod( | |||||
| 'diffusion.branchquery', | |||||
| array( | |||||
| 'closed' => false, | |||||
| 'limit' => $branch_limit + 1, | |||||
| )); | |||||
| } | |||||
| $futures = array( | $futures = array( | ||||
| $this->historyFuture, | $this->historyFuture, | ||||
| $this->browseFuture, | $this->browseFuture, | ||||
| $this->tagFuture, | |||||
| $this->branchFuture, | |||||
| ); | ); | ||||
| $futures = array_filter($futures); | $futures = array_filter($futures); | ||||
| $futures = new FutureIterator($futures); | $futures = new FutureIterator($futures); | ||||
| foreach ($futures as $future) { | foreach ($futures as $future) { | ||||
| // Just resolve all the futures before continuing. | // Just resolve all the futures before continuing. | ||||
| } | } | ||||
| $phids = array(); | $phids = array(); | ||||
| ▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | $content[] = $this->buildBrowseTable( | ||||
| $handles, | $handles, | ||||
| $browse_pager); | $browse_pager); | ||||
| $content[] = $this->buildHistoryTable( | $content[] = $this->buildHistoryTable( | ||||
| $history_results, | $history_results, | ||||
| $history, | $history, | ||||
| $history_exception); | $history_exception); | ||||
| try { | |||||
| $content[] = $this->buildTagListTable($drequest); | |||||
| } catch (Exception $ex) { | |||||
| if (!$repository->isImporting()) { | |||||
| $content[] = $this->renderStatusMessage( | |||||
| pht('Unable to Load Tags'), | |||||
| $ex->getMessage()); | |||||
| } | |||||
| } | |||||
| try { | |||||
| $content[] = $this->buildBranchListTable($drequest); | |||||
| } catch (Exception $ex) { | |||||
| if (!$repository->isImporting()) { | |||||
| $content[] = $this->renderStatusMessage( | |||||
| pht('Unable to Load Branches'), | |||||
| $ex->getMessage()); | |||||
| } | |||||
| } | |||||
| if ($readme) { | if ($readme) { | ||||
| $content[] = $readme; | $content[] = $readme; | ||||
| } | } | ||||
| return $content; | return $content; | ||||
| } | } | ||||
| private function buildHeaderView(PhabricatorRepository $repository) { | private function buildHeaderView(PhabricatorRepository $repository) { | ||||
| ▲ Show 20 Lines • Show All 89 Lines • ▼ Show 20 Lines | foreach ($uris as $uri) { | ||||
| $label = phutil_tag_div('diffusion-clone-label', pht('Clone')); | $label = phutil_tag_div('diffusion-clone-label', pht('Clone')); | ||||
| } | } | ||||
| $view->addProperty( | $view->addProperty( | ||||
| $label, | $label, | ||||
| $this->renderCloneURI($repository, $uri)); | $this->renderCloneURI($repository, $uri)); | ||||
| } | } | ||||
| if (!$view->hasAnyProperties()) { | |||||
| $view = id(new PHUIInfoView()) | |||||
| ->setSeverity(PHUIInfoView::SEVERITY_NOTICE) | |||||
| ->appendChild(pht('Repository has no URIs set.')); | |||||
| } | |||||
| $box = id(new PHUIObjectBoxView()) | $box = id(new PHUIObjectBoxView()) | ||||
| ->setHeaderText(pht('Details')) | ->setHeaderText(pht('Details')) | ||||
| ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) | ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) | ||||
| ->appendChild($view); | ->appendChild($view); | ||||
| $info = null; | $info = null; | ||||
| $drequest = $this->getDiffusionRequest(); | $drequest = $this->getDiffusionRequest(); | ||||
| Show All 30 Lines | if ($alternatives) { | ||||
| $box->setInfoView($info); | $box->setInfoView($info); | ||||
| } | } | ||||
| return $box; | return $box; | ||||
| } | } | ||||
| private function buildBranchListTable(DiffusionRequest $drequest) { | |||||
| $viewer = $this->getViewer(); | |||||
| if (!$this->needBranchFuture()) { | |||||
| return null; | |||||
| } | |||||
| $branches = $this->branchFuture->resolve(); | |||||
| if (!$branches) { | |||||
| return null; | |||||
| } | |||||
| $limit = $this->getBranchLimit(); | |||||
| $more_branches = (count($branches) > $limit); | |||||
| $branches = array_slice($branches, 0, $limit); | |||||
| $branches = DiffusionRepositoryRef::loadAllFromDictionaries($branches); | |||||
| $commits = id(new DiffusionCommitQuery()) | |||||
| ->setViewer($viewer) | |||||
| ->withIdentifiers(mpull($branches, 'getCommitIdentifier')) | |||||
| ->withRepository($drequest->getRepository()) | |||||
| ->execute(); | |||||
| $table = id(new DiffusionBranchTableView()) | |||||
| ->setUser($viewer) | |||||
| ->setDiffusionRequest($drequest) | |||||
| ->setBranches($branches) | |||||
| ->setCommits($commits); | |||||
| $panel = id(new PHUIObjectBoxView()) | |||||
| ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY); | |||||
| $header = new PHUIHeaderView(); | |||||
| $header->setHeader(pht('Branches')); | |||||
| if ($more_branches) { | |||||
| $header->setSubheader(pht('Showing %d branches.', $limit)); | |||||
| } | |||||
| $button = id(new PHUIButtonView()) | |||||
| ->setText(pht('Show All')) | |||||
| ->setTag('a') | |||||
| ->setIcon('fa-code-fork') | |||||
| ->setHref($drequest->generateURI( | |||||
| array( | |||||
| 'action' => 'branches', | |||||
| ))); | |||||
| $header->addActionLink($button); | |||||
| $panel->setHeader($header); | |||||
| $panel->setTable($table); | |||||
| return $panel; | |||||
| } | |||||
| private function buildTagListTable(DiffusionRequest $drequest) { | |||||
| $viewer = $this->getViewer(); | |||||
| $repository = $drequest->getRepository(); | |||||
| if (!$this->needTagFuture()) { | |||||
| return null; | |||||
| } | |||||
| $tags = $this->tagFuture->resolve(); | |||||
| $tags = DiffusionRepositoryTag::newFromConduit($tags); | |||||
| if (!$tags) { | |||||
| return null; | |||||
| } | |||||
| $tag_limit = $this->getTagLimit(); | |||||
| $more_tags = (count($tags) > $tag_limit); | |||||
| $tags = array_slice($tags, 0, $tag_limit); | |||||
| $commits = id(new DiffusionCommitQuery()) | |||||
| ->setViewer($viewer) | |||||
| ->withIdentifiers(mpull($tags, 'getCommitIdentifier')) | |||||
| ->withRepository($repository) | |||||
| ->needCommitData(true) | |||||
| ->execute(); | |||||
| $view = id(new DiffusionTagTableView()) | |||||
| ->setUser($viewer) | |||||
| ->setDiffusionRequest($drequest) | |||||
| ->setTags($tags) | |||||
| ->setCommits($commits); | |||||
| $phids = $view->getRequiredHandlePHIDs(); | |||||
| $handles = $this->loadViewerHandles($phids); | |||||
| $view->setHandles($handles); | |||||
| $panel = new PHUIObjectBoxView(); | |||||
| $header = new PHUIHeaderView(); | |||||
| $header->setHeader(pht('Tags')); | |||||
| if ($more_tags) { | |||||
| $header->setSubheader( | |||||
| pht('Showing the %d most recent tags.', $tag_limit)); | |||||
| } | |||||
| $button = id(new PHUIButtonView()) | |||||
| ->setText(pht('Show All Tags')) | |||||
| ->setTag('a') | |||||
| ->setIcon('fa-tag') | |||||
| ->setHref($drequest->generateURI( | |||||
| array( | |||||
| 'action' => 'tags', | |||||
| ))); | |||||
| $header->addActionLink($button); | |||||
| $panel->setHeader($header); | |||||
| $panel->setTable($view); | |||||
| $panel->setBackground(PHUIObjectBoxView::BLUE_PROPERTY); | |||||
| return $panel; | |||||
| } | |||||
| private function buildHistoryTable( | private function buildHistoryTable( | ||||
| $history_results, | $history_results, | ||||
| $history, | $history, | ||||
| $history_exception) { | $history_exception) { | ||||
| $request = $this->getRequest(); | $request = $this->getRequest(); | ||||
| $viewer = $request->getUser(); | $viewer = $request->getUser(); | ||||
| $drequest = $this->getDiffusionRequest(); | $drequest = $this->getDiffusionRequest(); | ||||
| Show All 22 Lines | private function buildHistoryTable( | ||||
| $history_table->loadRevisions(); | $history_table->loadRevisions(); | ||||
| if ($history_results) { | if ($history_results) { | ||||
| $history_table->setParents($history_results['parents']); | $history_table->setParents($history_results['parents']); | ||||
| } | } | ||||
| $history_table->setIsHead(true); | $history_table->setIsHead(true); | ||||
| $history = id(new PHUIButtonView()) | |||||
| ->setText(pht('History')) | |||||
| ->setHref($drequest->generateURI( | |||||
| array( | |||||
| 'action' => 'history', | |||||
| ))) | |||||
| ->setTag('a') | |||||
| ->setIcon('fa-history'); | |||||
| $graph = id(new PHUIButtonView()) | |||||
| ->setText(pht('Graph')) | |||||
| ->setHref($drequest->generateURI( | |||||
| array( | |||||
| 'action' => 'graph', | |||||
| ))) | |||||
| ->setTag('a') | |||||
| ->setIcon('fa-code-fork'); | |||||
| $panel = id(new PHUIObjectBoxView()) | $panel = id(new PHUIObjectBoxView()) | ||||
| ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY); | ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY); | ||||
| $header = id(new PHUIHeaderView()) | $header = id(new PHUIHeaderView()) | ||||
| ->setHeader(pht('Recent Commits')) | ->setHeader(pht('Recent Commits')); | ||||
| ->addActionLink($graph) | |||||
| ->addActionLink($history); | |||||
| $panel->setHeader($header); | $panel->setHeader($header); | ||||
| $panel->setTable($history_table); | $panel->setTable($history_table); | ||||
| return $panel; | return $panel; | ||||
| } | } | ||||
| private function buildLocateFile() { | private function buildLocateFile() { | ||||
| $request = $this->getRequest(); | $request = $this->getRequest(); | ||||
| ▲ Show 20 Lines • Show All 114 Lines • ▼ Show 20 Lines | private function renderCloneURI( | ||||
| return id(new DiffusionCloneURIView()) | return id(new DiffusionCloneURIView()) | ||||
| ->setViewer($viewer) | ->setViewer($viewer) | ||||
| ->setRepository($repository) | ->setRepository($repository) | ||||
| ->setRepositoryURI($uri) | ->setRepositoryURI($uri) | ||||
| ->setDisplayURI($display); | ->setDisplayURI($display); | ||||
| } | } | ||||
| private function needTagFuture() { | |||||
| $drequest = $this->getDiffusionRequest(); | |||||
| $repository = $drequest->getRepository(); | |||||
| switch ($repository->getVersionControlSystem()) { | |||||
| case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN: | |||||
| // No tags in SVN. | |||||
| return false; | |||||
| } | |||||
| return true; | |||||
| } | |||||
| private function getTagLimit() { | private function getTagLimit() { | ||||
| return 15; | return 15; | ||||
| } | } | ||||
| private function needBranchFuture() { | |||||
| $drequest = $this->getDiffusionRequest(); | |||||
| if ($drequest->getBranch() === null) { | |||||
| return false; | |||||
| } | |||||
| return true; | |||||
| } | |||||
| private function getBranchLimit() { | |||||
| return 15; | |||||
| } | |||||
| } | } | ||||