1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-23 07:12:41 +01:00

Use ChangesetListView on Differential standalone view

Summary:
Fixes T4452. Ref T2009. There's a hierarchy of changeset rendering power: only low-level calls, use of ChangesetDetailView, then use of ChangesetListView (a list of DetailViews).

Prior to work here, the various changeset rendering controllers got their hands dirty to varying degrees, with some using only the lowest-level rendering pipeline:

  - Phriction: no view (lowest level)
  - Diffusion: DetailView
  - Differential Changeset: DetailView
  - Differential Diff: ListView
  - Differential Revision: ListView

I brought Phriction up to use DetailView, but want to bring everything all the way up to use ListView. Each composition layer adds more features to diff browsing. In particular, this change enables "Highlight As", switching 1up vs 2up, adding inlines, etc., on the standalone view.

Test Plan:
  - Viewed a changeset standalone. Could change highlighting, switch 1up vs 2up, add and edit inlines, etc.
  - Viewed a revision; no behavioral changes.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T4452, T2009

Differential Revision: https://secure.phabricator.com/D12012
This commit is contained in:
epriestley 2015-03-08 04:10:11 -07:00
parent 33a3bbbd7a
commit c35cafda2c
5 changed files with 103 additions and 73 deletions

View file

@ -147,13 +147,13 @@ final class DifferentialChangesetViewController extends DifferentialController {
list($range_s, $range_e, $mask) =
DifferentialChangesetParser::parseRangeSpecification($spec);
$parser = new DifferentialChangesetParser();
$parser->setCoverage($coverage);
$parser->setChangeset($changeset);
$parser->setRenderingReference($rendering_reference);
$parser->setRenderCacheKey($render_cache_key);
$parser->setRightSideCommentMapping($right_source, $right_new);
$parser->setLeftSideCommentMapping($left_source, $left_new);
$parser = id(new DifferentialChangesetParser())
->setCoverage($coverage)
->setChangeset($changeset)
->setRenderingReference($rendering_reference)
->setRenderCacheKey($render_cache_key)
->setRightSideCommentMapping($right_source, $right_new)
->setLeftSideCommentMapping($left_source, $left_new);
$parser->readParametersFromRequest($request);
@ -200,66 +200,51 @@ final class DifferentialChangesetViewController extends DifferentialController {
}
$engine->process();
$parser->setMarkupEngine($engine);
$parser->setUser($request->getUser());
$parser
->setUser($request->getUser())
->setMarkupEngine($engine)
->setShowEditAndReplyLinks(true)
->setRange($range_s, $range_e)
->setMask($mask);
if ($request->isAjax()) {
$parser->setShowEditAndReplyLinks(true);
} else {
$parser->setShowEditAndReplyLinks(false);
}
$output = $parser->render($range_s, $range_e, $mask);
$mcov = $parser->renderModifiedCoverage();
if ($request->isAjax()) {
$coverage = array(
'differential-mcoverage-'.md5($changeset->getFilename()) => $mcov,
);
return id(new PhabricatorChangesetResponse())
->setRenderedChangeset($output)
->setRenderedChangeset($parser->renderChangeset())
->setCoverage($coverage);
}
// TODO: [HTML] Clean up DifferentialChangesetParser output, but it's
// undergoing like six kinds of refactoring anyway.
$output = phutil_safe_html($output);
$diff = $changeset->getDiff();
$detail = id(new DifferentialChangesetDetailView())
$detail = id(new DifferentialChangesetListView())
->setUser($this->getViewer())
->setChangeset($changeset)
->setRenderingRef($rendering_reference)
->setChangesets(array($changeset))
->setVisibleChangesets(array($changeset))
->setRenderingReferences(array($rendering_reference))
->setRenderURI('/differential/changeset/')
->setRenderer($parser->getRenderer()->getRendererKey())
->appendChild($output)
->setVsChangesetID($left_source);
->setDiff($diff)
->setTitle(pht('Standalone View'))
->setParser($parser);
Javelin::initBehavior('differential-populate', array(
'changesetViewIDs' => array($detail->getID()),
));
Javelin::initBehavior('differential-comment-jump', array());
$panel = new DifferentialPrimaryPaneView();
$panel->appendChild(
phutil_tag(
'div',
array(
'class' => 'differential-review-stage',
'id' => 'differential-review-stage',
),
$detail->render()));
$revision_id = $diff->getRevisionID();
if ($revision_id) {
$detail->setInlineCommentControllerURI(
'/differential/comment/inline/edit/'.$revision_id.'/');
}
$crumbs = $this->buildApplicationCrumbs();
$revision_id = $changeset->getDiff()->getRevisionID();
if ($revision_id) {
$crumbs->addTextCrumb('D'.$revision_id, '/D'.$revision_id);
}
$diff_id = $changeset->getDiff()->getID();
$diff_id = $diff->getID();
if ($diff_id) {
$crumbs->addTextCrumb(
pht('Diff %d', $diff_id),
@ -268,14 +253,10 @@ final class DifferentialChangesetViewController extends DifferentialController {
$crumbs->addTextCrumb($changeset->getDisplayFilename());
$box = id(new PHUIObjectBoxView())
->setHeaderText(pht('Standalone View'))
->appendChild($panel);
return $this->buildApplicationPage(
array(
$crumbs,
$box,
$detail,
),
array(
'title' => pht('Changeset View'),

View file

@ -45,6 +45,25 @@ final class DifferentialChangesetParser {
private $highlightAs;
private $showEditAndReplyLinks = true;
private $rangeStart;
private $rangeEnd;
private $mask;
public function setRange($start, $end) {
$this->rangeStart = $start;
$this->rangeEnd = $end;
return $this;
}
public function setMask(array $mask) {
$this->mask = $mask;
return $this;
}
public function renderChangeset() {
return $this->render($this->rangeStart, $this->rangeEnd, $this->mask);
}
public function setShowEditAndReplyLinks($bool) {
$this->showEditAndReplyLinks = $bool;
return $this;

View file

@ -12,6 +12,7 @@ final class DifferentialChangesetDetailView extends AphrontView {
private $whitespace;
private $renderingRef;
private $autoload;
private $loaded;
private $renderer;
public function setAutoload($autoload) {
@ -23,6 +24,15 @@ final class DifferentialChangesetDetailView extends AphrontView {
return $this->autoload;
}
public function setLoaded($loaded) {
$this->loaded = $loaded;
return $this;
}
public function getLoaded() {
return $this->loaded;
}
public function setRenderingRef($rendering_ref) {
$this->renderingRef = $rendering_ref;
return $this;
@ -213,6 +223,7 @@ final class DifferentialChangesetDetailView extends AphrontView {
'renderer' => $this->getRenderer(),
'ref' => $this->getRenderingRef(),
'autoload' => $this->getAutoload(),
'loaded' => $this->getLoaded(),
),
'class' => $class,
'id' => $id,

View file

@ -20,6 +20,16 @@ final class DifferentialChangesetListView extends AphrontView {
private $vsMap = array();
private $title;
private $parser;
public function setParser(DifferentialChangesetParser $parser) {
$this->parser = $parser;
return $this;
}
public function getParser() {
return $this->parser;
}
public function setTitle($title) {
$this->title = $title;
@ -168,12 +178,16 @@ final class DifferentialChangesetListView extends AphrontView {
$detail->setVsChangesetID(idx($this->vsMap, $changeset->getID()));
$detail->setEditable(true);
$detail->setRenderingRef($ref);
$detail->setAutoload(isset($this->visibleChangesets[$key]));
$detail->setRenderURI($this->renderURI);
$detail->setWhitespace($this->whitespace);
$detail->setRenderer($renderer);
if ($this->getParser()) {
$detail->appendChild($this->getParser()->renderChangeset());
$detail->setLoaded(true);
} else {
$detail->setAutoload(isset($this->visibleChangesets[$key]));
if (isset($this->visibleChangesets[$key])) {
$load = 'Loading...';
} else {
@ -197,9 +211,13 @@ final class DifferentialChangesetListView extends AphrontView {
array(
'id' => $uniq_id,
),
phutil_tag('div', array('class' => 'differential-loading'), $load)));
$output[] = $detail->render();
phutil_tag(
'div',
array('class' => 'differential-loading'),
$load)));
}
$output[] = $detail->render();
$ids[] = $detail->getID();
}

View file

@ -23,6 +23,7 @@ JX.install('ChangesetViewManager', {
this._renderer = data.renderer;
this._highlight = data.highlight;
this._encoding = data.encoding;
this._loaded = data.loaded;
},
members: {