mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-22 23:02:42 +01:00
Add "View Options" dropdown to Differential / Audit
Summary: Depends on D1921. Depends on D1899. Add the "View Options" dropdown menu to Diffusion, with options like "show standalone", "show raw file", "show all", etc. Test Plan: Viewed commits in Differential and Diffusion. Reviewers: davidreuss, nh, btrahan Reviewed By: btrahan CC: aran, epriestley Maniphest Tasks: T904 Differential Revision: https://secure.phabricator.com/D1932
This commit is contained in:
parent
e1ccd270fa
commit
1227c8d5da
6 changed files with 151 additions and 71 deletions
|
@ -243,7 +243,11 @@ final class DifferentialRevisionViewController extends DifferentialController {
|
|||
'/differential/comment/inline/edit/'.$revision->getID().'/');
|
||||
}
|
||||
|
||||
$changeset_view->setStandaloneViews(true);
|
||||
$changeset_view->setStandaloneURI('/differential/changeset/');
|
||||
$changeset_view->setRawFileURIs(
|
||||
'/differential/changeset/?view=old',
|
||||
'/differential/changeset/?view=new');
|
||||
|
||||
$changeset_view->setUser($user);
|
||||
$changeset_view->setDiff($target);
|
||||
$changeset_view->setRenderingReferences($rendering_references);
|
||||
|
|
|
@ -23,7 +23,11 @@ final class DifferentialChangesetListView extends AphrontView {
|
|||
private $inlineURI;
|
||||
private $renderURI = '/differential/changeset/';
|
||||
private $whitespace;
|
||||
private $standaloneViews;
|
||||
|
||||
private $standaloneURI;
|
||||
private $leftRawFileURI;
|
||||
private $rightRawFileURI;
|
||||
|
||||
private $user;
|
||||
private $symbolIndexes = array();
|
||||
private $repository;
|
||||
|
@ -40,11 +44,6 @@ final class DifferentialChangesetListView extends AphrontView {
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function setStandaloneViews($has_standalone_views) {
|
||||
$this->standaloneViews = $has_standalone_views;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setUser(PhabricatorUser $user) {
|
||||
$this->user = $user;
|
||||
return $this;
|
||||
|
@ -89,22 +88,26 @@ final class DifferentialChangesetListView extends AphrontView {
|
|||
return $this->vsMap;
|
||||
}
|
||||
|
||||
public function setStandaloneURI($uri) {
|
||||
$this->standaloneURI = $uri;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setRawFileURIs($l, $r) {
|
||||
$this->leftRawFileURI = $l;
|
||||
$this->rightRawFileURI = $r;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function render() {
|
||||
require_celerity_resource('differential-changeset-view-css');
|
||||
|
||||
$changesets = $this->changesets;
|
||||
|
||||
if ($this->standaloneViews) {
|
||||
Javelin::initBehavior(
|
||||
'differential-dropdown-menus',
|
||||
array());
|
||||
}
|
||||
|
||||
Javelin::initBehavior('buoyant', array());
|
||||
|
||||
$output = array();
|
||||
$mapping = array();
|
||||
$repository = $this->repository;
|
||||
foreach ($changesets as $key => $changeset) {
|
||||
$file = $changeset->getFilename();
|
||||
$class = 'differential-changeset';
|
||||
|
@ -116,59 +119,13 @@ final class DifferentialChangesetListView extends AphrontView {
|
|||
|
||||
$detail = new DifferentialChangesetDetailView();
|
||||
|
||||
$detail_button = null;
|
||||
if ($this->standaloneViews) {
|
||||
$detail_uri = new PhutilURI($this->renderURI);
|
||||
$detail_uri->setQueryParams(array('ref' => $ref));
|
||||
|
||||
$diffusion_uri = null;
|
||||
if ($repository) {
|
||||
$diffusion_uri = $repository->getDiffusionBrowseURIForPath(
|
||||
$changeset->getAbsoluteRepositoryPath($this->diff, $repository));
|
||||
}
|
||||
|
||||
$meta = array(
|
||||
'detailURI' =>
|
||||
(string)$detail_uri->alter('whitespace', $this->whitespace),
|
||||
'diffusionURI' => $diffusion_uri,
|
||||
'containerID' => $detail->getID(),
|
||||
);
|
||||
$change = $changeset->getChangeType();
|
||||
if ($change != DifferentialChangeType::TYPE_ADD) {
|
||||
$meta['leftURI'] = (string)$detail_uri->alter('view', 'old');
|
||||
}
|
||||
if ($change != DifferentialChangeType::TYPE_DELETE &&
|
||||
$change != DifferentialChangeType::TYPE_MULTICOPY) {
|
||||
$meta['rightURI'] = (string)$detail_uri->alter('view', 'new');
|
||||
}
|
||||
|
||||
if ($this->user && $repository) {
|
||||
$path = ltrim(
|
||||
$changeset->getAbsoluteRepositoryPath($this->diff, $repository),
|
||||
'/');
|
||||
$line = 1; // TODO: get first changed line
|
||||
$editor_link = $this->user->loadEditorLink($path, $line, $repository);
|
||||
if ($editor_link) {
|
||||
$meta['editor'] = $editor_link;
|
||||
} else {
|
||||
$meta['editorConfigure'] = '/settings/page/preferences/';
|
||||
}
|
||||
}
|
||||
|
||||
$detail_button = javelin_render_tag(
|
||||
'a',
|
||||
array(
|
||||
'class' => 'button small grey',
|
||||
'meta' => $meta,
|
||||
'href' => $meta['detailURI'],
|
||||
'target' => '_blank',
|
||||
'sigil' => 'differential-view-options',
|
||||
),
|
||||
"View Options \xE2\x96\xBC");
|
||||
}
|
||||
$view_options = $this->renderViewOptionsDropdown(
|
||||
$detail,
|
||||
$ref,
|
||||
$changeset);
|
||||
|
||||
$detail->setChangeset($changeset);
|
||||
$detail->addButton($detail_button);
|
||||
$detail->addButton($view_options);
|
||||
$detail->setSymbolIndex(idx($this->symbolIndexes, $key));
|
||||
$detail->setVsChangesetID(idx($this->vsMap, $changeset->getID()));
|
||||
|
||||
|
@ -250,4 +207,79 @@ final class DifferentialChangesetListView extends AphrontView {
|
|||
);
|
||||
}
|
||||
|
||||
private function renderViewOptionsDropdown(
|
||||
DifferentialChangesetDetailView $detail,
|
||||
$ref,
|
||||
DifferentialChangeset $changeset) {
|
||||
|
||||
$meta = array();
|
||||
|
||||
$qparams = array(
|
||||
'ref' => $ref,
|
||||
'whitespace' => $this->whitespace,
|
||||
);
|
||||
|
||||
if ($this->standaloneURI) {
|
||||
$uri = new PhutilURI($this->standaloneURI);
|
||||
$uri->setQueryParams($uri->getQueryParams() + $qparams);
|
||||
$meta['standaloneURI'] = (string)$uri;
|
||||
}
|
||||
|
||||
$repository = $this->repository;
|
||||
if ($repository) {
|
||||
$meta['diffusionURI'] = $repository->getDiffusionBrowseURIForPath(
|
||||
$changeset->getAbsoluteRepositoryPath($this->diff, $repository));
|
||||
}
|
||||
|
||||
$change = $changeset->getChangeType();
|
||||
|
||||
if ($this->leftRawFileURI) {
|
||||
if ($change != DifferentialChangeType::TYPE_ADD) {
|
||||
$uri = new PhutilURI($this->leftRawFileURI);
|
||||
$uri->setQueryParams($uri->getQueryParams() + $qparams);
|
||||
$meta['leftURI'] = (string)$uri;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->rightRawFileURI) {
|
||||
if ($change != DifferentialChangeType::TYPE_DELETE &&
|
||||
$change != DifferentialChangeType::TYPE_MULTICOPY) {
|
||||
$uri = new PhutilURI($this->rightRawFileURI);
|
||||
$uri->setQueryParams($uri->getQueryParams() + $qparams);
|
||||
$meta['rightURI'] = (string)$uri;
|
||||
}
|
||||
}
|
||||
|
||||
$user = $this->user;
|
||||
if ($user && $repository) {
|
||||
$path = ltrim(
|
||||
$changeset->getAbsoluteRepositoryPath($this->diff, $repository),
|
||||
'/');
|
||||
$line = 1; // TODO: get first changed line
|
||||
$editor_link = $user->loadEditorLink($path, $line, $repository);
|
||||
if ($editor_link) {
|
||||
$meta['editor'] = $editor_link;
|
||||
} else {
|
||||
$meta['editorConfigure'] = '/settings/page/preferences/';
|
||||
}
|
||||
}
|
||||
|
||||
$meta['containerID'] = $detail->getID();
|
||||
|
||||
Javelin::initBehavior(
|
||||
'differential-dropdown-menus',
|
||||
array());
|
||||
|
||||
return javelin_render_tag(
|
||||
'a',
|
||||
array(
|
||||
'class' => 'button small grey',
|
||||
'meta' => $meta,
|
||||
'href' => idx($meta, 'detailURI', '#'),
|
||||
'target' => '_blank',
|
||||
'sigil' => 'differential-view-options',
|
||||
),
|
||||
"View Options \xE2\x96\xBC");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -223,6 +223,14 @@ final class DiffusionCommitController extends DiffusionController {
|
|||
$change_list->setRenderURI('/diffusion/'.$callsign.'/diff/');
|
||||
$change_list->setUser($user);
|
||||
|
||||
$change_list->setStandaloneURI(
|
||||
'/diffusion/'.$callsign.'/diff/');
|
||||
$change_list->setRawFileURIs(
|
||||
// TODO: Implement this, somewhat tricky if there's an octopus merge
|
||||
// or whatever?
|
||||
null,
|
||||
'/diffusion/'.$callsign.'/diff/?view=r');
|
||||
|
||||
$change_list->setInlineCommentControllerURI(
|
||||
'/diffusion/inline/'.phutil_escape_uri($commit->getPHID()).'/');
|
||||
|
||||
|
|
|
@ -32,6 +32,31 @@ final class DiffusionDiffController extends DiffusionController {
|
|||
$request = $this->getRequest();
|
||||
$user = $request->getUser();
|
||||
|
||||
if (!$request->isAjax()) {
|
||||
|
||||
// This request came out of the dropdown menu, either "View Standalone"
|
||||
// or "View Raw File".
|
||||
|
||||
$view = $request->getStr('view');
|
||||
if ($view == 'r') {
|
||||
$uri = $drequest->generateURI(
|
||||
array(
|
||||
'action' => 'browse',
|
||||
'params' => array(
|
||||
'view' => 'raw',
|
||||
),
|
||||
));
|
||||
} else {
|
||||
$uri = $drequest->generateURI(
|
||||
array(
|
||||
'action' => 'change',
|
||||
));
|
||||
}
|
||||
|
||||
return id(new AphrontRedirectResponse())->setURI($uri);
|
||||
}
|
||||
|
||||
|
||||
$diff_query = DiffusionDiffQuery::newFromDiffusionRequest($drequest);
|
||||
$changeset = $diff_query->loadChangeset();
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
|
||||
phutil_require_module('phabricator', 'aphront/response/404');
|
||||
phutil_require_module('phabricator', 'aphront/response/redirect');
|
||||
phutil_require_module('phabricator', 'applications/audit/storage/inlinecommment');
|
||||
phutil_require_module('phabricator', 'applications/differential/parser/changeset');
|
||||
phutil_require_module('phabricator', 'applications/diffusion/controller/base');
|
||||
|
|
|
@ -41,27 +41,37 @@ JX.behavior('differential-dropdown-menus', function(config) {
|
|||
|
||||
var reveal_item = new JX.PhabricatorMenuItem('', show_more);
|
||||
|
||||
var diffusion_item = link_to('Browse in Diffusion', data.diffusionURI);
|
||||
if (!data.diffusionURI) {
|
||||
diffusion_item.setDisabled(true);
|
||||
var diffusion_item;
|
||||
if (data.diffusionURI) {
|
||||
// Show this only if we have a link, since when this appears in Diffusion
|
||||
// it is otherwise potentially confusing.
|
||||
diffusion_item = link_to('Browse in Diffusion', data.diffusionURI);
|
||||
}
|
||||
|
||||
var menu = new JX.PhabricatorDropdownMenu(buttons[ii])
|
||||
.addItem(reveal_item)
|
||||
.addItem(diffusion_item)
|
||||
.addItem(link_to('View Standalone', data.detailURI));
|
||||
.addItem(reveal_item);
|
||||
|
||||
if (diffusion_item) {
|
||||
menu.addItem(diffusion_item);
|
||||
}
|
||||
|
||||
menu.addItem(link_to('View Standalone', data.standaloneURI));
|
||||
|
||||
if (data.leftURI) {
|
||||
menu.addItem(link_to('Show Raw File (Left)', data.leftURI));
|
||||
}
|
||||
|
||||
if (data.rightURI) {
|
||||
menu.addItem(link_to('Show Raw File (Right)', data.rightURI));
|
||||
}
|
||||
|
||||
if (data.editor) {
|
||||
menu.addItem(new JX.PhabricatorMenuItem(
|
||||
'Open in Editor',
|
||||
JX.bind(null, location.assign, data.editor), // Open in the same window.
|
||||
data.editor));
|
||||
}
|
||||
|
||||
if (data.editorConfigure) {
|
||||
menu.addItem(link_to('Configure Editor', data.editorConfigure));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue