Differential D15487 Diff 37335 src/applications/diffusion/controller/DiffusionRepositoryController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/controller/DiffusionRepositoryController.php
| Show All 10 Lines | public function handleRequest(AphrontRequest $request) { | ||||
| if ($response) { | if ($response) { | ||||
| return $response; | return $response; | ||||
| } | } | ||||
| $viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
| $drequest = $this->getDiffusionRequest(); | $drequest = $this->getDiffusionRequest(); | ||||
| $repository = $drequest->getRepository(); | $repository = $drequest->getRepository(); | ||||
| $content = array(); | |||||
| $crumbs = $this->buildCrumbs(); | $crumbs = $this->buildCrumbs(); | ||||
| $crumbs->setBorder(true); | |||||
| $content[] = $this->buildPropertiesTable($drequest->getRepository()); | $header = $this->buildHeaderView($repository); | ||||
| $curtain = $this->buildCurtain($repository); | |||||
| $property_table = $this->buildPropertiesTable($repository); | |||||
| $description = $this->buildDescriptionView($repository); | |||||
| $locate_file = $this->buildLocateFile(); | |||||
| // Before we do any work, make sure we're looking at a some content: we're | // Before we do any work, make sure we're looking at a some content: we're | ||||
| // on a valid branch, and the repository is not empty. | // on a valid branch, and the repository is not empty. | ||||
| $page_has_content = false; | $page_has_content = false; | ||||
| $empty_title = null; | $empty_title = null; | ||||
| $empty_message = null; | $empty_message = null; | ||||
| // If this VCS supports branches, check that the selected branch actually | // If this VCS supports branches, check that the selected branch actually | ||||
| Show All 31 Lines | if (!$page_has_content) { | ||||
| } | } | ||||
| } else { | } else { | ||||
| $empty_title = pht('Empty Repository'); | $empty_title = pht('Empty Repository'); | ||||
| $empty_message = pht('This repository does not have any commits yet.'); | $empty_message = pht('This repository does not have any commits yet.'); | ||||
| } | } | ||||
| } | } | ||||
| if ($page_has_content) { | 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)); | ||||
| } | } | ||||
| $view = id(new PHUITwoColumnView()) | |||||
| ->setHeader($header) | |||||
| ->setCurtain($curtain) | |||||
| ->setMainColumn(array( | |||||
| $property_table, | |||||
| $description, | |||||
| $locate_file, | |||||
| )) | |||||
| ->setFooter($content); | |||||
| return $this->newPage() | return $this->newPage() | ||||
| ->setTitle( | ->setTitle( | ||||
| array( | array( | ||||
| $repository->getName(), | $repository->getName(), | ||||
| $repository->getDisplayName(), | $repository->getDisplayName(), | ||||
| )) | )) | ||||
| ->setCrumbs($crumbs) | ->setCrumbs($crumbs) | ||||
| ->appendChild($content); | ->appendChild(array( | ||||
| $view, | |||||
| )); | |||||
| } | } | ||||
| private function buildNormalContent(DiffusionRequest $drequest) { | private function buildNormalContent(DiffusionRequest $drequest) { | ||||
| $request = $this->getRequest(); | $request = $this->getRequest(); | ||||
| $repository = $drequest->getRepository(); | $repository = $drequest->getRepository(); | ||||
| $phids = array(); | $phids = array(); | ||||
| ▲ Show 20 Lines • Show All 106 Lines • ▼ Show 20 Lines | private function buildNormalContent(DiffusionRequest $drequest) { | ||||
| if ($readme) { | if ($readme) { | ||||
| $content[] = $readme; | $content[] = $readme; | ||||
| } | } | ||||
| return $content; | return $content; | ||||
| } | } | ||||
| private function buildPropertiesTable(PhabricatorRepository $repository) { | private function buildHeaderView(PhabricatorRepository $repository) { | ||||
| $user = $this->getRequest()->getUser(); | $viewer = $this->getViewer(); | ||||
| $header = id(new PHUIHeaderView()) | $header = id(new PHUIHeaderView()) | ||||
| ->setHeader($repository->getName()) | ->setHeader($repository->getName()) | ||||
| ->setUser($user) | ->setUser($viewer) | ||||
| ->setPolicyObject($repository); | ->setPolicyObject($repository) | ||||
| ->setHeaderIcon('fa-code'); | |||||
| if (!$repository->isTracked()) { | if (!$repository->isTracked()) { | ||||
| $header->setStatus('fa-ban', 'dark', pht('Inactive')); | $header->setStatus('fa-ban', 'dark', pht('Inactive')); | ||||
| } else if ($repository->isImporting()) { | } else if ($repository->isImporting()) { | ||||
| $ratio = $repository->loadImportProgress(); | $ratio = $repository->loadImportProgress(); | ||||
| $percentage = sprintf('%.2f%%', 100 * $ratio); | $percentage = sprintf('%.2f%%', 100 * $ratio); | ||||
| $header->setStatus( | $header->setStatus( | ||||
| 'fa-clock-o', | 'fa-clock-o', | ||||
| 'indigo', | 'indigo', | ||||
| pht('Importing (%s)...', $percentage)); | pht('Importing (%s)...', $percentage)); | ||||
| } else { | } else { | ||||
| $header->setStatus('fa-check', 'bluegrey', pht('Active')); | $header->setStatus('fa-check', 'bluegrey', pht('Active')); | ||||
| } | } | ||||
| return $header; | |||||
| } | |||||
| private function buildCurtain(PhabricatorRepository $repository) { | |||||
| $viewer = $this->getViewer(); | |||||
| $edit_uri = $repository->getPathURI('edit/'); | |||||
| $curtain = $this->newCurtainView($repository); | |||||
| $can_edit = PhabricatorPolicyFilter::hasCapability( | |||||
| $viewer, | |||||
| $repository, | |||||
| PhabricatorPolicyCapability::CAN_EDIT); | |||||
| $curtain->addAction( | |||||
| id(new PhabricatorActionView()) | |||||
| ->setName(pht('Edit Repository')) | |||||
| ->setIcon('fa-pencil') | |||||
| ->setHref($edit_uri) | |||||
| ->setWorkflow(!$can_edit) | |||||
| ->setDisabled(!$can_edit)); | |||||
| if ($repository->isHosted()) { | |||||
| $push_uri = $this->getApplicationURI( | |||||
| 'pushlog/?repositories='.$repository->getMonogram()); | |||||
| $curtain->addAction( | |||||
| id(new PhabricatorActionView()) | |||||
| ->setName(pht('View Push Logs')) | |||||
| ->setIcon('fa-list-alt') | |||||
| ->setHref($push_uri)); | |||||
| } | |||||
| return $curtain; | |||||
| } | |||||
| private function buildDescriptionView(PhabricatorRepository $repository) { | |||||
| $viewer = $this->getViewer(); | |||||
| $view = id(new PHUIPropertyListView()) | |||||
| ->setUser($viewer); | |||||
| $description = $repository->getDetail('description'); | |||||
| if (strlen($description)) { | |||||
| $description = new PHUIRemarkupView($viewer, $description); | |||||
| $view->addTextContent($description); | |||||
| return id(new PHUIObjectBoxView()) | |||||
| ->setHeaderText(pht('DESCRIPTION')) | |||||
| ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) | |||||
| ->appendChild($view); | |||||
| } | |||||
| return null; | |||||
| } | |||||
| $actions = $this->buildActionList($repository); | private function buildPropertiesTable(PhabricatorRepository $repository) { | ||||
| $viewer = $this->getViewer(); | |||||
| $view = id(new PHUIPropertyListView()) | $view = id(new PHUIPropertyListView()) | ||||
| ->setObject($repository) | ->setUser($viewer); | ||||
| ->setUser($user); | |||||
| if ($repository->isHosted()) { | if ($repository->isHosted()) { | ||||
| $ssh_uri = $repository->getSSHCloneURIObject(); | $ssh_uri = $repository->getSSHCloneURIObject(); | ||||
| if ($ssh_uri) { | if ($ssh_uri) { | ||||
| $clone_uri = $this->renderCloneCommand( | $clone_uri = $this->renderCloneCommand( | ||||
| $repository, | $repository, | ||||
| $ssh_uri, | $ssh_uri, | ||||
| $repository->getServeOverSSH(), | $repository->getServeOverSSH(), | ||||
| Show All 37 Lines | if ($repository->isHosted()) { | ||||
| pht('Checkout'), | pht('Checkout'), | ||||
| $this->renderCloneCommand( | $this->renderCloneCommand( | ||||
| $repository, | $repository, | ||||
| $repository->getPublicCloneURI())); | $repository->getPublicCloneURI())); | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| $view->invokeWillRenderEvent(); | |||||
| $description = $repository->getDetail('description'); | |||||
| if (strlen($description)) { | |||||
| $description = new PHUIRemarkupView($user, $description); | |||||
| $view->addSectionHeader( | |||||
| pht('Description'), PHUIPropertyListView::ICON_SUMMARY); | |||||
| $view->addTextContent($description); | |||||
| } | |||||
| $view->setActionList($actions); | |||||
| $box = id(new PHUIObjectBoxView()) | $box = id(new PHUIObjectBoxView()) | ||||
| ->setHeader($header) | ->setHeaderText(pht('DETAILS')) | ||||
| ->addPropertyList($view); | ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) | ||||
| ->appendChild($view); | |||||
| $info = null; | $info = null; | ||||
| $drequest = $this->getDiffusionRequest(); | $drequest = $this->getDiffusionRequest(); | ||||
| // Try to load alternatives. This may fail for repositories which have not | // Try to load alternatives. This may fail for repositories which have not | ||||
| // cloned yet. If it does, just ignore it and continue. | // cloned yet. If it does, just ignore it and continue. | ||||
| try { | try { | ||||
| $alternatives = $drequest->getRefAlternatives(); | $alternatives = $drequest->getRefAlternatives(); | ||||
| Show All 27 Lines | if ($alternatives) { | ||||
| $box->setInfoView($info); | $box->setInfoView($info); | ||||
| } | } | ||||
| return $box; | return $box; | ||||
| } | } | ||||
| private function buildBranchListTable(DiffusionRequest $drequest) { | private function buildBranchListTable(DiffusionRequest $drequest) { | ||||
| $viewer = $this->getRequest()->getUser(); | $viewer = $this->getViewer(); | ||||
| if ($drequest->getBranch() === null) { | if ($drequest->getBranch() === null) { | ||||
| return null; | return null; | ||||
| } | } | ||||
| $limit = 15; | $limit = 15; | ||||
| $branches = $this->callConduitWithDiffusionRequest( | $branches = $this->callConduitWithDiffusionRequest( | ||||
| Show All 18 Lines | $commits = id(new DiffusionCommitQuery()) | ||||
| ->execute(); | ->execute(); | ||||
| $table = id(new DiffusionBranchTableView()) | $table = id(new DiffusionBranchTableView()) | ||||
| ->setUser($viewer) | ->setUser($viewer) | ||||
| ->setDiffusionRequest($drequest) | ->setDiffusionRequest($drequest) | ||||
| ->setBranches($branches) | ->setBranches($branches) | ||||
| ->setCommits($commits); | ->setCommits($commits); | ||||
| $panel = new PHUIObjectBoxView(); | $panel = id(new PHUIObjectBoxView()) | ||||
| ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY); | |||||
| $header = new PHUIHeaderView(); | $header = new PHUIHeaderView(); | ||||
| $header->setHeader(pht('Branches')); | $header->setHeader(pht('Branches')); | ||||
| if ($more_branches) { | if ($more_branches) { | ||||
| $header->setSubHeader(pht('Showing %d branches.', $limit)); | $header->setSubHeader(pht('Showing %d branches.', $limit)); | ||||
| } | } | ||||
| $button = new PHUIButtonView(); | $button = new PHUIButtonView(); | ||||
| $button->setText(pht('Show All Branches')); | $button->setText(pht('Show All')); | ||||
| $button->setTag('a'); | $button->setTag('a'); | ||||
| $button->setIcon('fa-code-fork'); | $button->setIcon('fa-code-fork'); | ||||
| $button->setHref($drequest->generateURI( | $button->setHref($drequest->generateURI( | ||||
| array( | array( | ||||
| 'action' => 'branches', | 'action' => 'branches', | ||||
| ))); | ))); | ||||
| $header->addActionLink($button); | $header->addActionLink($button); | ||||
| $panel->setHeader($header); | $panel->setHeader($header); | ||||
| $panel->setTable($table); | $panel->setTable($table); | ||||
| return $panel; | return $panel; | ||||
| } | } | ||||
| private function buildTagListTable(DiffusionRequest $drequest) { | private function buildTagListTable(DiffusionRequest $drequest) { | ||||
| $viewer = $this->getRequest()->getUser(); | $viewer = $this->getViewer(); | ||||
| $repository = $drequest->getRepository(); | $repository = $drequest->getRepository(); | ||||
| switch ($repository->getVersionControlSystem()) { | switch ($repository->getVersionControlSystem()) { | ||||
| case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN: | case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN: | ||||
| // no tags in SVN | // no tags in SVN | ||||
| return null; | return null; | ||||
| } | } | ||||
| $tag_limit = 15; | $tag_limit = 15; | ||||
| ▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | $button->setHref($drequest->generateURI( | ||||
| array( | array( | ||||
| 'action' => 'tags', | 'action' => 'tags', | ||||
| ))); | ))); | ||||
| $header->addActionLink($button); | $header->addActionLink($button); | ||||
| $panel->setHeader($header); | $panel->setHeader($header); | ||||
| $panel->setTable($view); | $panel->setTable($view); | ||||
| $panel->setBackground(PHUIObjectBoxView::BLUE_PROPERTY); | |||||
| return $panel; | return $panel; | ||||
| } | } | ||||
| private function buildActionList(PhabricatorRepository $repository) { | |||||
| $viewer = $this->getRequest()->getUser(); | |||||
| $edit_uri = $repository->getPathURI('edit/'); | |||||
| $view = id(new PhabricatorActionListView()) | |||||
| ->setUser($viewer) | |||||
| ->setObject($repository); | |||||
| $can_edit = PhabricatorPolicyFilter::hasCapability( | |||||
| $viewer, | |||||
| $repository, | |||||
| PhabricatorPolicyCapability::CAN_EDIT); | |||||
| $view->addAction( | |||||
| id(new PhabricatorActionView()) | |||||
| ->setName(pht('Edit Repository')) | |||||
| ->setIcon('fa-pencil') | |||||
| ->setHref($edit_uri) | |||||
| ->setWorkflow(!$can_edit) | |||||
| ->setDisabled(!$can_edit)); | |||||
| if ($repository->isHosted()) { | |||||
| $push_uri = $this->getApplicationURI( | |||||
| 'pushlog/?repositories='.$repository->getMonogram()); | |||||
| $view->addAction( | |||||
| id(new PhabricatorActionView()) | |||||
| ->setName(pht('View Push Logs')) | |||||
| ->setIcon('fa-list-alt') | |||||
| ->setHref($push_uri)); | |||||
| } | |||||
| return $view; | |||||
| } | |||||
| 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 26 Lines | private function buildHistoryTable( | ||||
| } | } | ||||
| $history_table->setIsHead(true); | $history_table->setIsHead(true); | ||||
| $icon = id(new PHUIIconView()) | $icon = id(new PHUIIconView()) | ||||
| ->setIcon('fa-list-alt'); | ->setIcon('fa-list-alt'); | ||||
| $button = id(new PHUIButtonView()) | $button = id(new PHUIButtonView()) | ||||
| ->setText(pht('View Full History')) | ->setText(pht('View History')) | ||||
| ->setHref($drequest->generateURI( | ->setHref($drequest->generateURI( | ||||
| array( | array( | ||||
| 'action' => 'history', | 'action' => 'history', | ||||
| ))) | ))) | ||||
| ->setTag('a') | ->setTag('a') | ||||
| ->setIcon($icon); | ->setIcon($icon); | ||||
| $panel = new PHUIObjectBoxView(); | $panel = id(new PHUIObjectBoxView()) | ||||
| ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY); | |||||
| $header = id(new PHUIHeaderView()) | $header = id(new PHUIHeaderView()) | ||||
| ->setHeader(pht('Recent Commits')) | ->setHeader(pht('Recent Commits')) | ||||
| ->addActionLink($button); | ->addActionLink($button); | ||||
| $panel->setHeader($header); | $panel->setHeader($header); | ||||
| $panel->setTable($history_table); | $panel->setTable($history_table); | ||||
| return $panel; | return $panel; | ||||
| } | } | ||||
| private function buildLocateFile() { | |||||
| $request = $this->getRequest(); | |||||
| $viewer = $request->getUser(); | |||||
| $drequest = $this->getDiffusionRequest(); | |||||
| $repository = $drequest->getRepository(); | |||||
| $locate_panel = null; | |||||
| if ($repository->canUsePathTree()) { | |||||
| Javelin::initBehavior( | |||||
| 'diffusion-locate-file', | |||||
| array( | |||||
| 'controlID' => 'locate-control', | |||||
| 'inputID' => 'locate-input', | |||||
| 'browseBaseURI' => (string)$drequest->generateURI( | |||||
| array( | |||||
| 'action' => 'browse', | |||||
| )), | |||||
| 'uri' => (string)$drequest->generateURI( | |||||
| array( | |||||
| 'action' => 'pathtree', | |||||
| )), | |||||
| )); | |||||
| $form = id(new AphrontFormView()) | |||||
| ->setUser($viewer) | |||||
| ->appendChild( | |||||
| id(new AphrontFormTypeaheadControl()) | |||||
| ->setHardpointID('locate-control') | |||||
| ->setID('locate-input') | |||||
| ->setLabel(pht('Locate File'))); | |||||
| $form_box = id(new PHUIBoxView()) | |||||
| ->appendChild($form->buildLayoutView()); | |||||
| $locate_panel = id(new PHUIObjectBoxView()) | |||||
| ->setHeaderText(pht('Locate File')) | |||||
| ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) | |||||
| ->appendChild($form_box); | |||||
| } | |||||
| return $locate_panel; | |||||
| } | |||||
| private function buildBrowseTable( | private function buildBrowseTable( | ||||
| $browse_results, | $browse_results, | ||||
| $browse_paths, | $browse_paths, | ||||
| $browse_exception, | $browse_exception, | ||||
| array $handles, | array $handles, | ||||
| PHUIPagerView $pager) { | PHUIPagerView $pager) { | ||||
| require_celerity_resource('diffusion-icons-css'); | require_celerity_resource('diffusion-icons-css'); | ||||
| Show All 21 Lines | private function buildBrowseTable( | ||||
| if ($browse_paths) { | if ($browse_paths) { | ||||
| $browse_table->setPaths($browse_paths); | $browse_table->setPaths($browse_paths); | ||||
| } else { | } else { | ||||
| $browse_table->setPaths(array()); | $browse_table->setPaths(array()); | ||||
| } | } | ||||
| $browse_uri = $drequest->generateURI(array('action' => 'browse')); | $browse_uri = $drequest->generateURI(array('action' => 'browse')); | ||||
| $browse_panel = new PHUIObjectBoxView(); | $browse_panel = id(new PHUIObjectBoxView()) | ||||
| ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY); | |||||
| $header = id(new PHUIHeaderView()) | $header = id(new PHUIHeaderView()) | ||||
| ->setHeader(pht('Repository')); | ->setHeader($repository->getName()); | ||||
| $icon = id(new PHUIIconView()) | $icon = id(new PHUIIconView()) | ||||
| ->setIcon('fa-folder-open'); | ->setIcon('fa-folder-open'); | ||||
| $button = new PHUIButtonView(); | $button = new PHUIButtonView(); | ||||
| $button->setText(pht('Browse Repository')); | $button->setText(pht('Browse Repository')); | ||||
| $button->setTag('a'); | $button->setTag('a'); | ||||
| $button->setIcon($icon); | $button->setIcon($icon); | ||||
| $button->setHref($browse_uri); | $button->setHref($browse_uri); | ||||
| $header->addActionLink($button); | $header->addActionLink($button); | ||||
| $browse_panel->setHeader($header); | $browse_panel->setHeader($header); | ||||
| $locate_panel = null; | |||||
| if ($repository->canUsePathTree()) { | |||||
| Javelin::initBehavior( | |||||
| 'diffusion-locate-file', | |||||
| array( | |||||
| 'controlID' => 'locate-control', | |||||
| 'inputID' => 'locate-input', | |||||
| 'browseBaseURI' => (string)$drequest->generateURI( | |||||
| array( | |||||
| 'action' => 'browse', | |||||
| )), | |||||
| 'uri' => (string)$drequest->generateURI( | |||||
| array( | |||||
| 'action' => 'pathtree', | |||||
| )), | |||||
| )); | |||||
| $form = id(new AphrontFormView()) | |||||
| ->setUser($viewer) | |||||
| ->appendChild( | |||||
| id(new AphrontFormTypeaheadControl()) | |||||
| ->setHardpointID('locate-control') | |||||
| ->setID('locate-input') | |||||
| ->setLabel(pht('Locate File'))); | |||||
| $form_box = id(new PHUIBoxView()) | |||||
| ->appendChild($form->buildLayoutView()); | |||||
| $locate_panel = id(new PHUIObjectBoxView()) | |||||
| ->setHeaderText('Locate File') | |||||
| ->appendChild($form_box); | |||||
| } | |||||
| $browse_panel->setTable($browse_table); | $browse_panel->setTable($browse_table); | ||||
| $pager->setURI($browse_uri, 'offset'); | $pager->setURI($browse_uri, 'offset'); | ||||
| if ($pager->willShowPagingControls()) { | if ($pager->willShowPagingControls()) { | ||||
| $pager_box = $this->renderTablePagerBox($pager); | $pager_box = $this->renderTablePagerBox($pager); | ||||
| } else { | } else { | ||||
| $pager_box = null; | $pager_box = null; | ||||
| } | } | ||||
| return array( | return array( | ||||
| $locate_panel, | |||||
| $browse_panel, | $browse_panel, | ||||
| $pager_box, | $pager_box, | ||||
| ); | ); | ||||
| } | } | ||||
| private function renderCloneCommand( | private function renderCloneCommand( | ||||
| PhabricatorRepository $repository, | PhabricatorRepository $repository, | ||||
| $uri, | $uri, | ||||
| ▲ Show 20 Lines • Show All 74 Lines • Show Last 20 Lines | |||||