2011-01-24 22:18:41 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2012-01-16 07:25:53 +01:00
|
|
|
* Copyright 2012 Facebook, Inc.
|
2011-01-24 22:18:41 +01:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
final class DifferentialDiffTableOfContentsView extends AphrontView {
|
|
|
|
|
|
|
|
private $changesets = array();
|
2011-04-15 23:25:23 +02:00
|
|
|
private $standaloneViewLink = null;
|
|
|
|
private $renderURI = '/differential/changeset/';
|
|
|
|
private $revisionID;
|
2011-04-28 06:16:35 +02:00
|
|
|
private $whitespace;
|
2011-01-24 22:18:41 +01:00
|
|
|
|
|
|
|
public function setChangesets($changesets) {
|
|
|
|
$this->changesets = $changesets;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-04-15 23:25:23 +02:00
|
|
|
public function setStandaloneViewLink($standalone_view_link) {
|
|
|
|
$this->standaloneViewLink = $standalone_view_link;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setVsMap(array $vs_map) {
|
|
|
|
$this->vsMap = $vs_map;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setRevisionID($revision_id) {
|
|
|
|
$this->revisionID = $revision_id;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-04-28 06:16:35 +02:00
|
|
|
public function setWhitespace($whitespace) {
|
|
|
|
$this->whitespace = $whitespace;
|
|
|
|
return $this;
|
|
|
|
}
|
2011-04-15 23:25:23 +02:00
|
|
|
|
2011-01-24 22:18:41 +01:00
|
|
|
public function render() {
|
2011-01-27 23:55:52 +01:00
|
|
|
|
|
|
|
require_celerity_resource('differential-core-view-css');
|
2011-01-25 20:57:47 +01:00
|
|
|
require_celerity_resource('differential-table-of-contents-css');
|
2011-01-24 22:18:41 +01:00
|
|
|
|
|
|
|
$rows = array();
|
|
|
|
|
|
|
|
$changesets = $this->changesets;
|
|
|
|
foreach ($changesets as $changeset) {
|
|
|
|
$type = $changeset->getChangeType();
|
|
|
|
$ftype = $changeset->getFileType();
|
2012-01-24 09:37:50 +01:00
|
|
|
$link = $this->renderChangesetLink($changeset);
|
2012-01-16 07:43:54 +01:00
|
|
|
|
2011-01-24 22:18:41 +01:00
|
|
|
if (DifferentialChangeType::isOldLocationChangeType($type)) {
|
|
|
|
$away = $changeset->getAwayPaths();
|
|
|
|
if (count($away) > 1) {
|
|
|
|
$meta = array();
|
|
|
|
if ($type == DifferentialChangeType::TYPE_MULTICOPY) {
|
|
|
|
$meta[] = 'Deleted after being copied to multiple locations:';
|
|
|
|
} else {
|
|
|
|
$meta[] = 'Copied to multiple locations:';
|
|
|
|
}
|
|
|
|
foreach ($away as $path) {
|
2012-01-16 07:25:53 +01:00
|
|
|
$meta[] = phutil_escape_html($path);
|
2011-01-24 22:18:41 +01:00
|
|
|
}
|
|
|
|
$meta = implode('<br />', $meta);
|
|
|
|
} else {
|
|
|
|
if ($type == DifferentialChangeType::TYPE_MOVE_AWAY) {
|
2012-01-16 07:25:53 +01:00
|
|
|
$meta = 'Moved to '.phutil_escape_html(reset($away));
|
2011-01-24 22:18:41 +01:00
|
|
|
} else {
|
2012-01-16 07:25:53 +01:00
|
|
|
$meta = 'Copied to '.phutil_escape_html(reset($away));
|
2011-01-24 22:18:41 +01:00
|
|
|
}
|
|
|
|
}
|
2012-01-16 07:43:54 +01:00
|
|
|
} else if ($type == DifferentialChangeType::TYPE_MOVE_HERE) {
|
|
|
|
$meta = 'Moved from '.phutil_escape_html($changeset->getOldFile());
|
|
|
|
} else if ($type == DifferentialChangeType::TYPE_COPY_HERE) {
|
|
|
|
$meta = 'Copied from '.phutil_escape_html($changeset->getOldFile());
|
2011-01-24 22:18:41 +01:00
|
|
|
} else {
|
2012-01-16 07:43:54 +01:00
|
|
|
$meta = null;
|
2011-01-24 22:18:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$line_count = $changeset->getAffectedLineCount();
|
|
|
|
if ($line_count == 0) {
|
|
|
|
$lines = null;
|
|
|
|
} else if ($line_count == 1) {
|
|
|
|
$lines = ' (1 line)';
|
|
|
|
} else {
|
|
|
|
$lines = ' ('.$line_count.' lines)';
|
|
|
|
}
|
|
|
|
|
|
|
|
$char = DifferentialChangeType::getSummaryCharacterForChangeType($type);
|
|
|
|
$chartitle = DifferentialChangeType::getFullNameForChangeType($type);
|
|
|
|
$desc = DifferentialChangeType::getShortNameForFileType($ftype);
|
|
|
|
if ($desc) {
|
|
|
|
$desc = '('.$desc.')';
|
|
|
|
}
|
|
|
|
$pchar =
|
|
|
|
($changeset->getOldProperties() === $changeset->getNewProperties())
|
|
|
|
? null
|
|
|
|
: '<span title="Properties Changed">M</span>';
|
|
|
|
|
|
|
|
$rows[] =
|
|
|
|
'<tr>'.
|
2011-04-15 23:25:23 +02:00
|
|
|
'<td class="differential-toc-char" title='.$chartitle.'>'.$char.
|
|
|
|
'</td>'.
|
2011-01-24 22:18:41 +01:00
|
|
|
'<td class="differential-toc-prop">'.$pchar.'</td>'.
|
|
|
|
'<td class="differential-toc-ftype">'.$desc.'</td>'.
|
|
|
|
'<td class="differential-toc-file">'.$link.$lines.'</td>'.
|
|
|
|
'</tr>';
|
|
|
|
if ($meta) {
|
|
|
|
$rows[] =
|
|
|
|
'<tr>'.
|
2011-01-26 00:19:06 +01:00
|
|
|
'<td colspan="3"></td>'.
|
2011-01-24 22:18:41 +01:00
|
|
|
'<td class="differential-toc-meta">'.$meta.'</td>'.
|
|
|
|
'</tr>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
2011-01-27 23:55:52 +01:00
|
|
|
'<div class="differential-toc differential-panel">'.
|
2011-01-24 22:18:41 +01:00
|
|
|
'<h1>Table of Contents</h1>'.
|
|
|
|
'<table>'.
|
|
|
|
implode("\n", $rows).
|
|
|
|
'</table>'.
|
|
|
|
'</div>';
|
|
|
|
}
|
2012-01-24 09:37:50 +01:00
|
|
|
|
|
|
|
private function renderChangesetLink(DifferentialChangeset $changeset) {
|
|
|
|
$display_file = $changeset->getDisplayFilename();
|
|
|
|
|
|
|
|
if ($this->standaloneViewLink) {
|
|
|
|
$id = $changeset->getID();
|
|
|
|
$vs_id = idx($this->vsMap, $id);
|
|
|
|
|
|
|
|
$ref = $vs_id ? $id.'/'.$vs_id : $id;
|
|
|
|
$detail_uri = new PhutilURI($this->renderURI);
|
|
|
|
$detail_uri->setQueryParams(
|
|
|
|
array(
|
|
|
|
'ref' => $ref,
|
|
|
|
'whitespace' => $this->whitespace,
|
|
|
|
'revision_id' => $this->revisionID,
|
|
|
|
));
|
|
|
|
|
|
|
|
return phutil_render_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => $detail_uri,
|
|
|
|
'target' => '_blank',
|
|
|
|
),
|
|
|
|
phutil_escape_html($display_file));
|
|
|
|
}
|
|
|
|
return phutil_render_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => '#'.$changeset->getAnchorName(),
|
|
|
|
),
|
|
|
|
phutil_escape_html($display_file));
|
|
|
|
}
|
2011-01-24 22:18:41 +01:00
|
|
|
}
|