Skip to content

Commit a6b550b

Browse files
author
Chad Little
committedJul 11, 2017
Move Clone Repository to Dialog
Summary: This moves the clone details on the Repository Home to a button / dialog. Functionally this is to pull content on the page way up, while giving full space to all the clone options. I think we can build this into some FancyJS if needed, but this seems to clean ui the UI dramatically with little overhead. I don't want to attempt the JS dropdown unless we're sure that's the best path (it exposes the most common URI by default, saving a click). Test Plan: Tested hg, svn, git repositories and the raw URL page. Test close button. Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin Differential Revision: https://secure.phabricator.com/D18203
1 parent b987b4d commit a6b550b

File tree

5 files changed

+152
-128
lines changed

5 files changed

+152
-128
lines changed
 

‎src/__phutil_library_map__.php

+2
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,7 @@
619619
'DiffusionCachedResolveRefsQuery' => 'applications/diffusion/query/DiffusionCachedResolveRefsQuery.php',
620620
'DiffusionChangeController' => 'applications/diffusion/controller/DiffusionChangeController.php',
621621
'DiffusionChangeHeraldFieldGroup' => 'applications/diffusion/herald/DiffusionChangeHeraldFieldGroup.php',
622+
'DiffusionCloneController' => 'applications/diffusion/controller/DiffusionCloneController.php',
622623
'DiffusionCloneURIView' => 'applications/diffusion/view/DiffusionCloneURIView.php',
623624
'DiffusionCommandEngine' => 'applications/diffusion/protocol/DiffusionCommandEngine.php',
624625
'DiffusionCommandEngineTestCase' => 'applications/diffusion/protocol/__tests__/DiffusionCommandEngineTestCase.php',
@@ -5610,6 +5611,7 @@
56105611
'DiffusionCachedResolveRefsQuery' => 'DiffusionLowLevelQuery',
56115612
'DiffusionChangeController' => 'DiffusionController',
56125613
'DiffusionChangeHeraldFieldGroup' => 'HeraldFieldGroup',
5614+
'DiffusionCloneController' => 'DiffusionController',
56135615
'DiffusionCloneURIView' => 'AphrontView',
56145616
'DiffusionCommandEngine' => 'Phobject',
56155617
'DiffusionCommandEngineTestCase' => 'PhabricatorTestCase',

‎src/applications/diffusion/application/PhabricatorDiffusionApplication.php

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public function getRoutes() {
5555
'' => 'DiffusionRepositoryController',
5656
'repository/(?P<dblob>.*)' => 'DiffusionRepositoryController',
5757
'change/(?P<dblob>.*)' => 'DiffusionChangeController',
58+
'clone/' => 'DiffusionCloneController',
5859
'history/(?P<dblob>.*)' => 'DiffusionHistoryController',
5960
'graph/(?P<dblob>.*)' => 'DiffusionGraphController',
6061
'browse/(?P<dblob>.*)' => 'DiffusionBrowseController',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
<?php
2+
3+
final class DiffusionCloneController extends DiffusionController {
4+
5+
public function shouldAllowPublic() {
6+
return true;
7+
}
8+
9+
public function handleRequest(AphrontRequest $request) {
10+
$viewer = $request->getViewer();
11+
$response = $this->loadDiffusionContext();
12+
if ($response) {
13+
return $response;
14+
}
15+
16+
$drequest = $this->getDiffusionRequest();
17+
$repository = $drequest->getRepository();
18+
19+
$view = id(new PHUIPropertyListView())
20+
->setUser($viewer);
21+
22+
$display_never = PhabricatorRepositoryURI::DISPLAY_NEVER;
23+
$warning = null;
24+
25+
$uris = $repository->getURIs();
26+
foreach ($uris as $uri) {
27+
if ($uri->getIsDisabled()) {
28+
continue;
29+
}
30+
31+
if ($uri->getEffectiveDisplayType() == $display_never) {
32+
continue;
33+
}
34+
35+
if ($repository->isSVN()) {
36+
$label = phutil_tag_div('diffusion-clone-label', pht('Checkout'));
37+
} else {
38+
$label = phutil_tag_div('diffusion-clone-label', pht('Clone'));
39+
}
40+
41+
$view->addProperty(
42+
$label,
43+
$this->renderCloneURI($repository, $uri));
44+
}
45+
46+
if (!$view->hasAnyProperties()) {
47+
$view = id(new PHUIInfoView())
48+
->setSeverity(PHUIInfoView::SEVERITY_NOTICE)
49+
->appendChild(pht('Repository has no URIs set.'));
50+
}
51+
52+
$info = null;
53+
54+
// Try to load alternatives. This may fail for repositories which have not
55+
// cloned yet. If it does, just ignore it and continue.
56+
try {
57+
$alternatives = $drequest->getRefAlternatives();
58+
} catch (ConduitClientException $ex) {
59+
$alternatives = array();
60+
}
61+
62+
if ($alternatives) {
63+
$message = array(
64+
pht(
65+
'The ref "%s" is ambiguous in this repository.',
66+
$drequest->getBranch()),
67+
' ',
68+
phutil_tag(
69+
'a',
70+
array(
71+
'href' => $drequest->generateURI(
72+
array(
73+
'action' => 'refs',
74+
)),
75+
),
76+
pht('View Alternatives')),
77+
);
78+
79+
$messages = array($message);
80+
81+
$warning = id(new PHUIInfoView())
82+
->setSeverity(PHUIInfoView::SEVERITY_WARNING)
83+
->setErrors(array($message));
84+
}
85+
86+
$cancel_uri = $drequest->generateURI(
87+
array(
88+
'action' => 'branch',
89+
'path' => '/',
90+
));
91+
92+
return $this->newDialog()
93+
->setTitle(pht('Clone Repository'))
94+
->setWidth(AphrontDialogView::WIDTH_FORM)
95+
->addCancelButton($cancel_uri, pht('Close'))
96+
->appendChild(array($view, $warning));
97+
}
98+
99+
private function renderCloneURI(
100+
PhabricatorRepository $repository,
101+
PhabricatorRepositoryURI $uri) {
102+
103+
if ($repository->isSVN()) {
104+
$display = csprintf(
105+
'svn checkout %R %R',
106+
(string)$uri->getDisplayURI(),
107+
$repository->getCloneName());
108+
} else {
109+
$display = csprintf('%R', (string)$uri->getDisplayURI());
110+
}
111+
112+
$display = (string)$display;
113+
$viewer = $this->getViewer();
114+
115+
return id(new DiffusionCloneURIView())
116+
->setViewer($viewer)
117+
->setRepository($repository)
118+
->setRepositoryURI($uri)
119+
->setDisplayURI($display);
120+
}
121+
122+
}

‎src/applications/diffusion/controller/DiffusionRepositoryController.php

+23-128
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public function handleRequest(AphrontRequest $request) {
2727
$crumbs->setBorder(true);
2828

2929
$header = $this->buildHeaderView($repository);
30-
$property_table = $this->buildPropertiesTable($repository);
3130
$actions = $this->buildActionList($repository);
3231
$description = $this->buildDescriptionView($repository);
3332
$locate_file = $this->buildLocateFile();
@@ -90,12 +89,28 @@ public function handleRequest(AphrontRequest $request) {
9089

9190
$tabs = $this->buildTabsView('home');
9291

92+
$clone_uri = $drequest->generateURI(
93+
array(
94+
'action' => 'clone',
95+
));
96+
97+
$clone_button = id(new PHUIButtonView())
98+
->setTag('a')
99+
->setText('Clone')
100+
->setColor(PHUIButtonView::GREEN)
101+
->setIcon('fa-download')
102+
->setWorkflow(true)
103+
->setHref($clone_uri);
104+
105+
$bar = id(new PHUILeftRightView())
106+
->setLeft($locate_file)
107+
->setRight($clone_button);
108+
93109
$view = id(new PHUITwoColumnView())
94110
->setHeader($header)
95111
->setTabs($tabs)
96112
->setFooter(array(
97-
$locate_file,
98-
$property_table,
113+
$bar,
99114
$description,
100115
$content,
101116
));
@@ -302,87 +317,6 @@ private function buildDescriptionView(PhabricatorRepository $repository) {
302317
return null;
303318
}
304319

305-
private function buildPropertiesTable(PhabricatorRepository $repository) {
306-
$viewer = $this->getViewer();
307-
308-
$view = id(new PHUIPropertyListView())
309-
->setUser($viewer);
310-
311-
$display_never = PhabricatorRepositoryURI::DISPLAY_NEVER;
312-
313-
$uris = $repository->getURIs();
314-
foreach ($uris as $uri) {
315-
if ($uri->getIsDisabled()) {
316-
continue;
317-
}
318-
319-
if ($uri->getEffectiveDisplayType() == $display_never) {
320-
continue;
321-
}
322-
323-
if ($repository->isSVN()) {
324-
$label = phutil_tag_div('diffusion-clone-label', pht('Checkout'));
325-
} else {
326-
$label = phutil_tag_div('diffusion-clone-label', pht('Clone'));
327-
}
328-
329-
$view->addProperty(
330-
$label,
331-
$this->renderCloneURI($repository, $uri));
332-
}
333-
334-
if (!$view->hasAnyProperties()) {
335-
$view = id(new PHUIInfoView())
336-
->setSeverity(PHUIInfoView::SEVERITY_NOTICE)
337-
->appendChild(pht('Repository has no URIs set.'));
338-
}
339-
340-
$box = id(new PHUIObjectBoxView())
341-
->setHeaderText(pht('Details'))
342-
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
343-
->appendChild($view);
344-
345-
$info = null;
346-
$drequest = $this->getDiffusionRequest();
347-
348-
// Try to load alternatives. This may fail for repositories which have not
349-
// cloned yet. If it does, just ignore it and continue.
350-
try {
351-
$alternatives = $drequest->getRefAlternatives();
352-
} catch (ConduitClientException $ex) {
353-
$alternatives = array();
354-
}
355-
356-
if ($alternatives) {
357-
$message = array(
358-
pht(
359-
'The ref "%s" is ambiguous in this repository.',
360-
$drequest->getBranch()),
361-
' ',
362-
phutil_tag(
363-
'a',
364-
array(
365-
'href' => $drequest->generateURI(
366-
array(
367-
'action' => 'refs',
368-
)),
369-
),
370-
pht('View Alternatives')),
371-
);
372-
373-
$messages = array($message);
374-
375-
$info = id(new PHUIInfoView())
376-
->setSeverity(PHUIInfoView::SEVERITY_WARNING)
377-
->setErrors(array($message));
378-
379-
$box->setInfoView($info);
380-
}
381-
382-
383-
return $box;
384-
}
385-
386320
private function buildHistoryTable(
387321
$history_results,
388322
$history,
@@ -504,52 +438,13 @@ private function buildBrowseTable(
504438
}
505439

506440
$browse_uri = $drequest->generateURI(array('action' => 'browse'));
507-
508-
$browse_panel = id(new PHUIObjectBoxView())
509-
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY);
510-
$header = id(new PHUIHeaderView())
511-
->setHeader($repository->getName());
512-
513-
$button = id(new PHUIButtonView())
514-
->setText(pht('Browse'))
515-
->setTag('a')
516-
->setIcon('fa-code')
517-
->setHref($browse_uri);
518-
519-
$header->addActionLink($button);
520-
$browse_panel->setHeader($header);
521-
$browse_panel->setTable($browse_table);
522-
523441
$pager->setURI($browse_uri, 'offset');
524442

525-
if ($pager->willShowPagingControls()) {
526-
$browse_panel->setPager($pager);
527-
}
528-
529-
return $browse_panel;
530-
}
531-
532-
private function renderCloneURI(
533-
PhabricatorRepository $repository,
534-
PhabricatorRepositoryURI $uri) {
535-
536-
if ($repository->isSVN()) {
537-
$display = csprintf(
538-
'svn checkout %R %R',
539-
(string)$uri->getDisplayURI(),
540-
$repository->getCloneName());
541-
} else {
542-
$display = csprintf('%R', (string)$uri->getDisplayURI());
543-
}
544-
545-
$display = (string)$display;
546-
$viewer = $this->getViewer();
547-
548-
return id(new DiffusionCloneURIView())
549-
->setViewer($viewer)
550-
->setRepository($repository)
551-
->setRepositoryURI($uri)
552-
->setDisplayURI($display);
443+
return id(new PHUIObjectBoxView())
444+
->setHeaderText($repository->getName())
445+
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
446+
->setTable($browse_table)
447+
->setPager($pager);
553448
}
554449

555450
private function getTagLimit() {

‎src/applications/repository/storage/PhabricatorRepository.php

+4
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,7 @@ public function generateURI(array $params) {
700700
switch ($action) {
701701
case 'history':
702702
case 'graph':
703+
case 'clone':
703704
case 'browse':
704705
case 'change':
705706
case 'lastmodified':
@@ -818,6 +819,9 @@ public function generateURI(array $params) {
818819
// it came from a URI.
819820
$uri = rawurldecode("{$path}{$commit}");
820821
break;
822+
case 'clone':
823+
$uri = $this->getPathURI("/{$action}/");
824+
break;
821825
}
822826

823827
if ($action == 'rendering-ref') {

0 commit comments

Comments
 (0)
Failed to load comments.