1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-26 16:52:41 +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:
epriestley 2012-03-19 19:57:41 -07:00
parent e1ccd270fa
commit 1227c8d5da
6 changed files with 151 additions and 71 deletions

View file

@ -243,7 +243,11 @@ final class DifferentialRevisionViewController extends DifferentialController {
'/differential/comment/inline/edit/'.$revision->getID().'/'); '/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->setUser($user);
$changeset_view->setDiff($target); $changeset_view->setDiff($target);
$changeset_view->setRenderingReferences($rendering_references); $changeset_view->setRenderingReferences($rendering_references);

View file

@ -23,7 +23,11 @@ final class DifferentialChangesetListView extends AphrontView {
private $inlineURI; private $inlineURI;
private $renderURI = '/differential/changeset/'; private $renderURI = '/differential/changeset/';
private $whitespace; private $whitespace;
private $standaloneViews;
private $standaloneURI;
private $leftRawFileURI;
private $rightRawFileURI;
private $user; private $user;
private $symbolIndexes = array(); private $symbolIndexes = array();
private $repository; private $repository;
@ -40,11 +44,6 @@ final class DifferentialChangesetListView extends AphrontView {
return $this; return $this;
} }
public function setStandaloneViews($has_standalone_views) {
$this->standaloneViews = $has_standalone_views;
return $this;
}
public function setUser(PhabricatorUser $user) { public function setUser(PhabricatorUser $user) {
$this->user = $user; $this->user = $user;
return $this; return $this;
@ -89,22 +88,26 @@ final class DifferentialChangesetListView extends AphrontView {
return $this->vsMap; 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() { public function render() {
require_celerity_resource('differential-changeset-view-css'); require_celerity_resource('differential-changeset-view-css');
$changesets = $this->changesets; $changesets = $this->changesets;
if ($this->standaloneViews) {
Javelin::initBehavior(
'differential-dropdown-menus',
array());
}
Javelin::initBehavior('buoyant', array()); Javelin::initBehavior('buoyant', array());
$output = array(); $output = array();
$mapping = array(); $mapping = array();
$repository = $this->repository;
foreach ($changesets as $key => $changeset) { foreach ($changesets as $key => $changeset) {
$file = $changeset->getFilename(); $file = $changeset->getFilename();
$class = 'differential-changeset'; $class = 'differential-changeset';
@ -116,59 +119,13 @@ final class DifferentialChangesetListView extends AphrontView {
$detail = new DifferentialChangesetDetailView(); $detail = new DifferentialChangesetDetailView();
$detail_button = null; $view_options = $this->renderViewOptionsDropdown(
if ($this->standaloneViews) { $detail,
$detail_uri = new PhutilURI($this->renderURI); $ref,
$detail_uri->setQueryParams(array('ref' => $ref)); $changeset);
$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");
}
$detail->setChangeset($changeset); $detail->setChangeset($changeset);
$detail->addButton($detail_button); $detail->addButton($view_options);
$detail->setSymbolIndex(idx($this->symbolIndexes, $key)); $detail->setSymbolIndex(idx($this->symbolIndexes, $key));
$detail->setVsChangesetID(idx($this->vsMap, $changeset->getID())); $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");
}
} }

View file

@ -223,6 +223,14 @@ final class DiffusionCommitController extends DiffusionController {
$change_list->setRenderURI('/diffusion/'.$callsign.'/diff/'); $change_list->setRenderURI('/diffusion/'.$callsign.'/diff/');
$change_list->setUser($user); $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( $change_list->setInlineCommentControllerURI(
'/diffusion/inline/'.phutil_escape_uri($commit->getPHID()).'/'); '/diffusion/inline/'.phutil_escape_uri($commit->getPHID()).'/');

View file

@ -32,6 +32,31 @@ final class DiffusionDiffController extends DiffusionController {
$request = $this->getRequest(); $request = $this->getRequest();
$user = $request->getUser(); $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); $diff_query = DiffusionDiffQuery::newFromDiffusionRequest($drequest);
$changeset = $diff_query->loadChangeset(); $changeset = $diff_query->loadChangeset();

View file

@ -7,6 +7,7 @@
phutil_require_module('phabricator', 'aphront/response/404'); 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/audit/storage/inlinecommment');
phutil_require_module('phabricator', 'applications/differential/parser/changeset'); phutil_require_module('phabricator', 'applications/differential/parser/changeset');
phutil_require_module('phabricator', 'applications/diffusion/controller/base'); phutil_require_module('phabricator', 'applications/diffusion/controller/base');

View file

@ -41,27 +41,37 @@ JX.behavior('differential-dropdown-menus', function(config) {
var reveal_item = new JX.PhabricatorMenuItem('', show_more); var reveal_item = new JX.PhabricatorMenuItem('', show_more);
var diffusion_item = link_to('Browse in Diffusion', data.diffusionURI); var diffusion_item;
if (!data.diffusionURI) { if (data.diffusionURI) {
diffusion_item.setDisabled(true); // 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]) var menu = new JX.PhabricatorDropdownMenu(buttons[ii])
.addItem(reveal_item) .addItem(reveal_item);
.addItem(diffusion_item)
.addItem(link_to('View Standalone', data.detailURI)); if (diffusion_item) {
menu.addItem(diffusion_item);
}
menu.addItem(link_to('View Standalone', data.standaloneURI));
if (data.leftURI) { if (data.leftURI) {
menu.addItem(link_to('Show Raw File (Left)', data.leftURI)); menu.addItem(link_to('Show Raw File (Left)', data.leftURI));
} }
if (data.rightURI) { if (data.rightURI) {
menu.addItem(link_to('Show Raw File (Right)', data.rightURI)); menu.addItem(link_to('Show Raw File (Right)', data.rightURI));
} }
if (data.editor) { if (data.editor) {
menu.addItem(new JX.PhabricatorMenuItem( menu.addItem(new JX.PhabricatorMenuItem(
'Open in Editor', 'Open in Editor',
JX.bind(null, location.assign, data.editor), // Open in the same window. JX.bind(null, location.assign, data.editor), // Open in the same window.
data.editor)); data.editor));
} }
if (data.editorConfigure) { if (data.editorConfigure) {
menu.addItem(link_to('Configure Editor', data.editorConfigure)); menu.addItem(link_to('Configure Editor', data.editorConfigure));
} }