1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 14:52:41 +01:00

Add a branch selector to Diffusion

Summary: Fixes T12931. Adds a branch selector that's always visible if the repo has commits.

Test Plan:
Test a plain hg, svn, git repository. Test setting a bad default branch. Test a good default branch. Test on desktop, mobile layouts.

{F5058061}

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Maniphest Tasks: T12931

Differential Revision: https://secure.phabricator.com/D18267
This commit is contained in:
Chad Little 2017-07-24 13:27:19 -07:00
parent 0d8f4170f4
commit 69a7d57c3f
4 changed files with 147 additions and 16 deletions

View file

@ -9,7 +9,7 @@ return array(
'names' => array(
'conpherence.pkg.css' => 'e68cf1fa',
'conpherence.pkg.js' => 'b5b51108',
'core.pkg.css' => 'f1c7630f',
'core.pkg.css' => 'c0a7ecfd',
'core.pkg.js' => '5d80e0db',
'darkconsole.pkg.js' => '1f9a31bc',
'differential.pkg.css' => '45951e9e',
@ -75,7 +75,7 @@ return array(
'rsrc/css/application/diffusion/diffusion-readme.css' => '419dd5b6',
'rsrc/css/application/diffusion/diffusion-repository.css' => 'ee6f20ec',
'rsrc/css/application/diffusion/diffusion-source.css' => '750add59',
'rsrc/css/application/diffusion/diffusion.css' => '8d01932f',
'rsrc/css/application/diffusion/diffusion.css' => '67bd971b',
'rsrc/css/application/feed/feed.css' => 'ecd4ec57',
'rsrc/css/application/files/global-drag-and-drop.css' => 'b556a948',
'rsrc/css/application/flag/flag.css' => 'bba8f811',
@ -127,7 +127,7 @@ return array(
'rsrc/css/layout/phabricator-source-code-view.css' => 'aea41829',
'rsrc/css/phui/button/phui-button-bar.css' => 'f1ff5494',
'rsrc/css/phui/button/phui-button-simple.css' => '8e1baf68',
'rsrc/css/phui/button/phui-button.css' => '022581b4',
'rsrc/css/phui/button/phui-button.css' => '3a744520',
'rsrc/css/phui/calendar/phui-calendar-day.css' => '572b1893',
'rsrc/css/phui/calendar/phui-calendar-list.css' => '576be600',
'rsrc/css/phui/calendar/phui-calendar-month.css' => '21154caf',
@ -571,7 +571,7 @@ return array(
'differential-revision-history-css' => '0e8eb855',
'differential-revision-list-css' => 'f3c47d33',
'differential-table-of-contents-css' => 'ae4b7a55',
'diffusion-css' => '8d01932f',
'diffusion-css' => '67bd971b',
'diffusion-icons-css' => '0c15255e',
'diffusion-readme-css' => '419dd5b6',
'diffusion-repository-css' => 'ee6f20ec',
@ -825,7 +825,7 @@ return array(
'phui-big-info-view-css' => 'd13afcde',
'phui-box-css' => '745e881d',
'phui-button-bar-css' => 'f1ff5494',
'phui-button-css' => '022581b4',
'phui-button-css' => '3a744520',
'phui-button-simple-css' => '8e1baf68',
'phui-calendar-css' => 'f1ddf11c',
'phui-calendar-day-css' => '572b1893',

View file

@ -4,7 +4,7 @@ final class DiffusionRepositoryController extends DiffusionController {
private $historyFuture;
private $browseFuture;
private $tagFuture;
private $branchButton = null;
private $branchFuture;
public function shouldAllowPublic() {
@ -53,15 +53,25 @@ final class DiffusionRepositoryController extends DiffusionController {
// This is a valid branch, so we necessarily have some content.
$page_has_content = true;
} else {
$default = $repository->getDefaultBranch();
if ($default != $drequest->getBranch()) {
$empty_title = pht('No Such Branch');
$empty_message = pht(
'There is no branch named "%s" in this repository.',
$drequest->getBranch());
} else {
$empty_title = pht('No Default Branch');
$empty_message = pht(
'This repository is configured with default branch "%s" but '.
'there is no branch with that name in this repository.',
$default);
}
}
}
// If we didn't find any branches, check if there are any commits at all.
// This can tailor the message for empty repositories.
$any_commit = null;
if (!$page_has_content) {
$any_commit = id(new DiffusionCommitQuery())
->setViewer($viewer)
@ -81,6 +91,9 @@ final class DiffusionRepositoryController extends DiffusionController {
if ($page_has_content) {
$content = $this->buildNormalContent($drequest);
} else {
// If we have a commit somewhere, find branches.
// TODO: Evan will replace
// $this->buildNormalContent($drequest);
$content = id(new PHUIInfoView())
->setTitle($empty_title)
->setSeverity(PHUIInfoView::SEVERITY_WARNING)
@ -110,7 +123,7 @@ final class DiffusionRepositoryController extends DiffusionController {
$bar = id(new PHUILeftRightView())
->setLeft($locate_file)
->setRight($clone_button)
->setRight(array($this->branchButton, $clone_button))
->addClass('diffusion-action-bar');
$view = id(new PHUITwoColumnView())
@ -145,6 +158,7 @@ final class DiffusionRepositoryController extends DiffusionController {
$commit = $drequest->getCommit();
$path = $drequest->getPath();
$futures = array();
$this->historyFuture = $this->callConduitMethod(
'diffusion.historyquery',
array(
@ -153,6 +167,7 @@ final class DiffusionRepositoryController extends DiffusionController {
'offset' => 0,
'limit' => 15,
));
$futures[] = $this->historyFuture;
$browse_pager = id(new PHUIPagerView())
->readFromRequest($request);
@ -164,11 +179,19 @@ final class DiffusionRepositoryController extends DiffusionController {
'path' => $path,
'limit' => $browse_pager->getPageSize() + 1,
));
$futures[] = $this->browseFuture;
if ($this->needBranchFuture()) {
$branch_limit = $this->getBranchLimit();
$this->branchFuture = $this->callConduitMethod(
'diffusion.branchquery',
array(
'closed' => false,
'limit' => $branch_limit + 1,
));
$futures[] = $this->branchFuture;
}
$futures = array(
$this->historyFuture,
$this->browseFuture,
);
$futures = array_filter($futures);
$futures = new FutureIterator($futures);
foreach ($futures as $future) {
@ -253,6 +276,18 @@ final class DiffusionRepositoryController extends DiffusionController {
$content[] = $readme;
}
try {
$branch_button = $this->buildBranchList($drequest);
$this->branchButton = $branch_button;
} catch (Exception $ex) {
if (!$repository->isImporting()) {
$content[] = $this->renderStatusMessage(
pht('Unable to Load Branches'),
$ex->getMessage());
}
}
return $content;
}
@ -375,6 +410,67 @@ final class DiffusionRepositoryController extends DiffusionController {
return $panel;
}
private function buildBranchList(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);
$actions = id(new PhabricatorActionListView())
->setViewer($viewer);
foreach ($branches as $branch) {
$branch_uri = $drequest->generateURI(
array(
'action' => 'browse',
'branch' => $branch->getShortname(),
));
$actions->addAction(
id(new PhabricatorActionView())
->setName($branch->getShortname())
->setIcon('fa-code-fork')
->setHref($branch_uri));
}
if ($more_branches) {
$more_uri = $drequest->generateURI(
array(
'action' => 'branches',
));
$actions->addAction(
id(new PhabricatorActionView())
->setType(PhabricatorActionView::TYPE_DIVIDER));
$actions->addAction(
id(new PhabricatorActionView())
->setName(pht('See More Branches'))
->setIcon('fa-external-link')
->setHref($more_uri));
}
$button = id(new PHUIButtonView())
->setText(pht('Branch: %s', $drequest->getBranch()))
->setTag('a')
->addClass('mmr')
->setIcon('fa-code-fork')
->setColor(PHUIButtonView::GREY)
->setDropdown(true)
->setDropdownMenu($actions);
return $button;
}
private function buildLocateFile() {
$request = $this->getRequest();
$viewer = $request->getUser();
@ -457,7 +553,17 @@ final class DiffusionRepositoryController extends DiffusionController {
->setPager($pager);
}
private function getTagLimit() {
private function needBranchFuture() {
$drequest = $this->getDiffusionRequest();
if ($drequest->getBranch() === null) {
return false;
}
return true;
}
private function getBranchLimit() {
return 15;
}

View file

@ -16,6 +16,23 @@
margin-bottom: 16px;
}
.device-phone .diffusion-action-bar {
display: block;
}
.device-phone .diffusion-action-bar .phui-lr-container {
display: block;
}
.device-phone .diffusion-action-bar .phui-lr-container .phui-left-view {
display: block;
}
.device-phone .diffusion-action-bar .phui-lr-container .phui-right-view {
padding-top: 12px;
display: block;
}
.diffusion-profile-locate .phui-form-view {
margin: 0;
padding: 0;

View file

@ -265,6 +265,14 @@ a.policy-control .phui-button-text {
right: 10px;
}
.phui-button-text {
display: inline-block;
}
.dropdown .phui-button-text {
margin-right: 16px;
}
.button.has-icon .phui-button-text {
margin-left: 16px;
}