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

View file

@ -45,6 +45,25 @@ final class DifferentialChangesetParser {
private $highlightAs; private $highlightAs;
private $showEditAndReplyLinks = true; 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) { public function setShowEditAndReplyLinks($bool) {
$this->showEditAndReplyLinks = $bool; $this->showEditAndReplyLinks = $bool;
return $this; return $this;

View file

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

View file

@ -20,6 +20,16 @@ final class DifferentialChangesetListView extends AphrontView {
private $vsMap = array(); private $vsMap = array();
private $title; private $title;
private $parser;
public function setParser(DifferentialChangesetParser $parser) {
$this->parser = $parser;
return $this;
}
public function getParser() {
return $this->parser;
}
public function setTitle($title) { public function setTitle($title) {
$this->title = $title; $this->title = $title;
@ -168,38 +178,46 @@ final class DifferentialChangesetListView extends AphrontView {
$detail->setVsChangesetID(idx($this->vsMap, $changeset->getID())); $detail->setVsChangesetID(idx($this->vsMap, $changeset->getID()));
$detail->setEditable(true); $detail->setEditable(true);
$detail->setRenderingRef($ref); $detail->setRenderingRef($ref);
$detail->setAutoload(isset($this->visibleChangesets[$key]));
$detail->setRenderURI($this->renderURI); $detail->setRenderURI($this->renderURI);
$detail->setWhitespace($this->whitespace); $detail->setWhitespace($this->whitespace);
$detail->setRenderer($renderer); $detail->setRenderer($renderer);
if (isset($this->visibleChangesets[$key])) { if ($this->getParser()) {
$load = 'Loading...'; $detail->appendChild($this->getParser()->renderChangeset());
$detail->setLoaded(true);
} else { } else {
$load = javelin_tag( $detail->setAutoload(isset($this->visibleChangesets[$key]));
'a', if (isset($this->visibleChangesets[$key])) {
array( $load = 'Loading...';
'class' => 'button grey', } else {
'href' => '#'.$uniq_id, $load = javelin_tag(
'sigil' => 'differential-load', 'a',
'meta' => array( array(
'id' => $detail->getID(), 'class' => 'button grey',
'kill' => true, 'href' => '#'.$uniq_id,
'sigil' => 'differential-load',
'meta' => array(
'id' => $detail->getID(),
'kill' => true,
),
'mustcapture' => true,
), ),
'mustcapture' => true, pht('Load File'));
), }
pht('Load File')); $detail->appendChild(
phutil_tag(
'div',
array(
'id' => $uniq_id,
),
phutil_tag(
'div',
array('class' => 'differential-loading'),
$load)));
} }
$detail->appendChild(
phutil_tag(
'div',
array(
'id' => $uniq_id,
),
phutil_tag('div', array('class' => 'differential-loading'), $load)));
$output[] = $detail->render();
$output[] = $detail->render();
$ids[] = $detail->getID(); $ids[] = $detail->getID();
} }

View file

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