2011-01-24 22:18:41 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2011 Facebook, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class DifferentialDiffViewController extends DifferentialController {
|
|
|
|
|
|
|
|
private $id;
|
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
$this->id = $data['id'];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
2011-01-31 03:52:29 +01:00
|
|
|
$request = $this->getRequest();
|
|
|
|
|
2011-01-24 22:18:41 +01:00
|
|
|
$diff = id(new DifferentialDiff())->load($this->id);
|
|
|
|
if (!$diff) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
2011-05-03 02:44:47 +02:00
|
|
|
if ($diff->getRevisionID()) {
|
|
|
|
$top_panel = new AphrontPanelView();
|
|
|
|
$top_panel->setWidth(AphrontPanelView::WIDTH_WIDE);
|
|
|
|
$link = phutil_render_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => PhabricatorEnv::getURI('/D'.$diff->getRevisionID()),
|
|
|
|
),
|
|
|
|
phutil_escape_html('D'.$diff->getRevisionID()));
|
|
|
|
$top_panel->appendChild("<h1>This diff belongs to revision {$link}</h1>");
|
|
|
|
} else {
|
|
|
|
$action_panel = new AphrontPanelView();
|
|
|
|
$action_panel->setHeader('Preview Diff');
|
|
|
|
$action_panel->setWidth(AphrontPanelView::WIDTH_WIDE);
|
|
|
|
$action_panel->appendChild(
|
|
|
|
'<p class="aphront-panel-instructions">Review the diff for '.
|
|
|
|
'correctness. When you are satisfied, either <strong>create a new '.
|
|
|
|
'revision</strong> or <strong>update an existing revision</strong>.');
|
|
|
|
|
|
|
|
// TODO: implmenent optgroup support in AphrontFormSelectControl?
|
|
|
|
$select = array();
|
|
|
|
$select[] = '<optgroup label="Create New Revision">';
|
|
|
|
$select[] = '<option value="">Create a new Revision...</option>';
|
2011-02-04 00:41:58 +01:00
|
|
|
$select[] = '</optgroup>';
|
|
|
|
|
2011-05-03 02:44:47 +02:00
|
|
|
$revision_data = new DifferentialRevisionListData(
|
|
|
|
DifferentialRevisionListData::QUERY_OPEN_OWNED,
|
|
|
|
array($request->getUser()->getPHID()));
|
|
|
|
$revisions = $revision_data->loadRevisions();
|
|
|
|
|
|
|
|
if ($revisions) {
|
|
|
|
$select[] = '<optgroup label="Update Existing Revision">';
|
|
|
|
foreach ($revisions as $revision) {
|
|
|
|
$select[] = phutil_render_tag(
|
|
|
|
'option',
|
|
|
|
array(
|
|
|
|
'value' => $revision->getID(),
|
|
|
|
),
|
|
|
|
phutil_escape_html($revision->getTitle()));
|
|
|
|
}
|
|
|
|
$select[] = '</optgroup>';
|
|
|
|
}
|
|
|
|
|
|
|
|
$select =
|
|
|
|
'<select name="revisionID">'.
|
2011-02-04 00:41:58 +01:00
|
|
|
implode("\n", $select).
|
2011-05-03 02:44:47 +02:00
|
|
|
'</select>';
|
|
|
|
|
|
|
|
$action_form = new AphrontFormView();
|
|
|
|
$action_form
|
|
|
|
->setUser($request->getUser())
|
|
|
|
->setAction('/differential/revision/edit/')
|
|
|
|
->addHiddenInput('diffID', $diff->getID())
|
|
|
|
->addHiddenInput('viaDiffView', 1)
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormMarkupControl())
|
2011-01-26 00:19:06 +01:00
|
|
|
->setLabel('Attach To')
|
2011-02-04 00:41:58 +01:00
|
|
|
->setValue($select))
|
2011-05-03 02:44:47 +02:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSubmitControl())
|
2011-01-26 00:19:06 +01:00
|
|
|
->setValue('Continue'));
|
|
|
|
|
2011-05-03 02:44:47 +02:00
|
|
|
$action_panel->appendChild($action_form);
|
|
|
|
|
|
|
|
$top_panel = $action_panel;
|
|
|
|
}
|
2011-01-26 00:19:06 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2011-01-24 22:18:41 +01:00
|
|
|
$changesets = $diff->loadChangesets();
|
|
|
|
$changesets = msort($changesets, 'getSortKey');
|
|
|
|
|
|
|
|
$table_of_contents = id(new DifferentialDiffTableOfContentsView())
|
|
|
|
->setChangesets($changesets);
|
|
|
|
|
2011-05-13 21:27:12 +02:00
|
|
|
$refs = array();
|
|
|
|
foreach ($changesets as $changeset) {
|
|
|
|
$refs[$changeset->getID()] = $changeset->getID();
|
|
|
|
}
|
|
|
|
|
2011-01-25 20:57:47 +01:00
|
|
|
$details = id(new DifferentialChangesetListView())
|
2011-05-13 21:27:12 +02:00
|
|
|
->setChangesets($changesets)
|
|
|
|
->setRenderingReferences($refs);
|
2011-01-24 22:18:41 +01:00
|
|
|
|
|
|
|
return $this->buildStandardPageResponse(
|
2011-06-08 21:39:03 +02:00
|
|
|
id(new DifferentialPrimaryPaneView())
|
|
|
|
->setLineWidthFromChangesets($changesets)
|
|
|
|
->appendChild(
|
2011-01-26 00:19:06 +01:00
|
|
|
array(
|
2011-05-03 02:44:47 +02:00
|
|
|
$top_panel->render(),
|
2011-01-26 00:19:06 +01:00
|
|
|
$table_of_contents->render(),
|
|
|
|
$details->render(),
|
2011-06-08 21:39:03 +02:00
|
|
|
)),
|
2011-01-24 22:18:41 +01:00
|
|
|
array(
|
|
|
|
'title' => 'Diff View',
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|