1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 01:08:50 +02:00

Provide a web interface to view raw source text in Differential

Summary:
Add links to the 'standalone view' to grab the raw source text. I think this
operation is rare enough that it's okay to hide it like this. I changed
'Standalone View' to 'View Standalone / Raw' to improve discoverability.

This also fixes the broken Standalone View links in Diffusion by no longer
rendering them.

Test Plan:
viewed old and new sources for a changeset

Reviewed By: tuomaspelkonen
Reviewers: tuomaspelkonen, jungejason, aran
CC: aran, tuomaspelkonen
Differential Revision: 243
This commit is contained in:
epriestley 2011-05-06 12:58:53 -07:00
parent 7566f50d8f
commit 7ebd0d1efe
7 changed files with 94 additions and 28 deletions

View file

@ -136,7 +136,7 @@ celerity_register_resource_map(array(
),
'differential-changeset-view-css' =>
array(
'uri' => '/res/f26ca6f9/rsrc/css/application/differential/changeset-view.css',
'uri' => '/res/32a8bac6/rsrc/css/application/differential/changeset-view.css',
'type' => 'css',
'requires' =>
array(
@ -690,7 +690,7 @@ celerity_register_resource_map(array(
'uri' => '/res/pkg/6c786373/differential.pkg.js',
'type' => 'js',
),
'8d8a971a' =>
'8e4ef51b' =>
array (
'name' => 'differential.pkg.css',
'symbols' =>
@ -704,7 +704,7 @@ celerity_register_resource_map(array(
6 => 'differential-revision-add-comment-css',
7 => 'differential-revision-comment-list-css',
),
'uri' => '/res/pkg/8d8a971a/differential.pkg.css',
'uri' => '/res/pkg/8e4ef51b/differential.pkg.css',
'type' => 'css',
),
'eadf6ec3' =>
@ -728,14 +728,14 @@ celerity_register_resource_map(array(
'aphront-table-view-css' => '4270730a',
'aphront-tokenizer-control-css' => '4270730a',
'aphront-typeahead-control-css' => '4270730a',
'differential-changeset-view-css' => '8d8a971a',
'differential-core-view-css' => '8d8a971a',
'differential-revision-add-comment-css' => '8d8a971a',
'differential-revision-comment-css' => '8d8a971a',
'differential-revision-comment-list-css' => '8d8a971a',
'differential-revision-detail-css' => '8d8a971a',
'differential-revision-history-css' => '8d8a971a',
'differential-table-of-contents-css' => '8d8a971a',
'differential-changeset-view-css' => '8e4ef51b',
'differential-core-view-css' => '8e4ef51b',
'differential-revision-add-comment-css' => '8e4ef51b',
'differential-revision-comment-css' => '8e4ef51b',
'differential-revision-comment-list-css' => '8e4ef51b',
'differential-revision-detail-css' => '8e4ef51b',
'differential-revision-history-css' => '8e4ef51b',
'differential-table-of-contents-css' => '8e4ef51b',
'diffusion-commit-view-css' => 'eadf6ec3',
'javelin-behavior-differential-diff-radios' => '6c786373',
'javelin-behavior-differential-edit-inline-comments' => '6c786373',

View file

@ -33,6 +33,19 @@ class DifferentialChangesetViewController extends DifferentialController {
return new Aphront404Response();
}
$view = $request->getStr('view');
if ($view) {
$changeset->attachHunks($changeset->loadHunks());
switch ($view) {
case 'new':
return $this->buildRawFileResponse($changeset->makeNewFile());
case 'old':
return $this->buildRawFileResponse($changeset->makeOldFile());
default:
return new Aphront400Response();
}
}
if ($vs && ($vs != -1)) {
$vs_changeset = id(new DifferentialChangeset())->load($vs);
if (!$vs_changeset) {
@ -177,6 +190,26 @@ class DifferentialChangesetViewController extends DifferentialController {
$detail = new DifferentialChangesetDetailView();
$detail->setChangeset($changeset);
$detail->appendChild($output);
if (!$vs) {
$detail->addButton(
phutil_render_tag(
'a',
array(
'href' => $request->getRequestURI()->alter('view', 'old'),
'class' => 'grey button small',
),
'View Raw File (Old Version)'));
$detail->addButton(
phutil_render_tag(
'a',
array(
'href' => $request->getRequestURI()->alter('view', 'new'),
'class' => 'grey button small',
),
'View Raw File (New Version)'));
}
$detail->setRevisionID($request->getInt('revision_id'));
$output =
@ -202,5 +235,10 @@ class DifferentialChangesetViewController extends DifferentialController {
$author_phid);
}
private function buildRawFileResponse($text) {
return id(new AphrontFileResponse())
->setMimeType('text/plain')
->setContent($text);
}
}

View file

@ -8,8 +8,10 @@
phutil_require_module('arcanist', 'parser/diff');
phutil_require_module('phabricator', 'aphront/response/400');
phutil_require_module('phabricator', 'aphront/response/404');
phutil_require_module('phabricator', 'aphront/response/ajax');
phutil_require_module('phabricator', 'aphront/response/file');
phutil_require_module('phabricator', 'applications/differential/controller/base');
phutil_require_module('phabricator', 'applications/differential/parser/changeset');
phutil_require_module('phabricator', 'applications/differential/parser/markup');
@ -23,6 +25,7 @@ phutil_require_module('phabricator', 'infrastructure/javelin/api');
phutil_require_module('phutil', 'filesystem');
phutil_require_module('phutil', 'filesystem/tempfile');
phutil_require_module('phutil', 'future/exec');
phutil_require_module('phutil', 'markup');
phutil_require_module('phutil', 'utils');

View file

@ -179,6 +179,7 @@ class DifferentialRevisionViewController extends DifferentialController {
$changeset_view = new DifferentialChangesetListView();
$changeset_view->setChangesets($visible_changesets);
$changeset_view->setEditable(true);
$changeset_view->setStandaloneViews(true);
$changeset_view->setRevision($revision);
$changeset_view->setVsMap($vs_map);
$changeset_view->setWhitespace($whitespace);

View file

@ -53,6 +53,14 @@ class DifferentialChangesetDetailView extends AphrontView {
$class .= ' differential-changeset-immutable';
}
$buttons = null;
if ($this->buttons) {
$buttons =
'<div class="differential-changeset-buttons">'.
implode('', $this->buttons).
'</div>';
}
$display_filename = $changeset->getDisplayFilename();
$output = javelin_render_tag(
'div',
@ -70,7 +78,7 @@ class DifferentialChangesetDetailView extends AphrontView {
'name' => $changeset->getAnchorName(),
),
'').
implode('', $this->buttons).
$buttons.
'<h1>'.phutil_escape_html($display_filename).'</h1>'.
'<div style="clear: both;"></div>'.
$this->renderChildren());

View file

@ -24,6 +24,7 @@ class DifferentialChangesetListView extends AphrontView {
private $renderURI = '/differential/changeset/';
private $vsMap = array();
private $whitespace;
private $standaloneViews;
public function setChangesets($changesets) {
$this->changesets = $changesets;
@ -35,6 +36,11 @@ class DifferentialChangesetListView extends AphrontView {
return $this;
}
public function setStandaloneViews($has_standalone_views) {
$this->standaloneViews = $has_standalone_views;
return $this;
}
public function setRevision(DifferentialRevision $revision) {
$this->revision = $revision;
return $this;
@ -78,23 +84,25 @@ class DifferentialChangesetListView extends AphrontView {
$ref = $changeset->getRenderingReference();
$detail_uri = new PhutilURI($this->renderURI);
$detail_uri->setQueryParams(
array(
'id' => $ref,
'vs' => $vs_id,
'whitespace' => $this->whitespace,
));
$detail_button = null;
if ($this->standaloneViews) {
$detail_uri = new PhutilURI($this->renderURI);
$detail_uri->setQueryParams(
array(
'id' => $ref,
'vs' => $vs_id,
'whitespace' => $this->whitespace,
));
$detail_button = phutil_render_tag(
'a',
array(
'style' => 'float: right',
'class' => 'button small grey',
'href' => $detail_uri,
'target' => '_blank',
),
'Standalone View');
$detail_button = phutil_render_tag(
'a',
array(
'class' => 'button small grey',
'href' => $detail_uri,
'target' => '_blank',
),
'View Standalone / Raw');
}
$uniq_id = celerity_generate_unique_node_id();

View file

@ -172,3 +172,11 @@
width: 100%;
height: 12em;
}
.differential-changeset-buttons {
float: right;
}
.differential-changeset-buttons a.button {
margin-left: 8px;
}