1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 06:42:42 +01:00

DifferentialDiffView

This commit is contained in:
epriestley 2011-01-24 13:18:41 -08:00
parent 7779c67668
commit e85ecd03de
11 changed files with 447 additions and 3 deletions

View file

@ -1,7 +1,9 @@
{
"name" : "differential",
"src_base" : "https://github.com/facebook/differential/blob/master",
"name" : "Phabricator",
"src_base" : "https://github.com/facebook/phabricator/blob/master",
"groups" : {
"aphront" : "Aphront (Web Stack)",
"storage" : "Storage"
}
}

View file

@ -57,9 +57,13 @@ phutil_register_library_map(array(
'DifferentialAction' => 'applications/differential/constants/action',
'DifferentialChangeType' => 'applications/differential/constants/changetype',
'DifferentialChangeset' => 'applications/differential/storage/changeset',
'DifferentialChangesetDetailView' => 'applications/differential/view/changesetdetailview',
'DifferentialController' => 'applications/differential/controller/base',
'DifferentialDAO' => 'applications/differential/storage/base',
'DifferentialDiff' => 'applications/differential/storage/diff',
'DifferentialDiffProperty' => 'applications/differential/storage/diffproperty',
'DifferentialDiffTableOfContentsView' => 'applications/differential/view/difftableofcontents',
'DifferentialDiffViewController' => 'applications/differential/controller/diffview',
'DifferentialHunk' => 'applications/differential/storage/hunk',
'DifferentialLintStatus' => 'applications/differential/constants/lintstatus',
'DifferentialRevision' => 'applications/differential/storage/revision',
@ -160,9 +164,13 @@ phutil_register_library_map(array(
'ConduitAPI_file_upload_Method' => 'ConduitAPIMethod',
'ConduitAPI_user_find_Method' => 'ConduitAPIMethod',
'DifferentialChangeset' => 'DifferentialDAO',
'DifferentialChangesetDetailView' => 'AphrontView',
'DifferentialController' => 'PhabricatorController',
'DifferentialDAO' => 'PhabricatorLiskDAO',
'DifferentialDiff' => 'DifferentialDAO',
'DifferentialDiffProperty' => 'DifferentialDAO',
'DifferentialDiffTableOfContentsView' => 'AphrontView',
'DifferentialDiffViewController' => 'DifferentialController',
'DifferentialHunk' => 'DifferentialDAO',
'DifferentialRevision' => 'DifferentialDAO',
'PhabricatorConduitAPIController' => 'PhabricatorConduitController',

View file

@ -75,6 +75,11 @@ class AphrontDefaultApplicationConfiguration
'log/$' => 'PhabricatorConduitLogController',
),
'/api/(?<method>[^/]+)$' => 'PhabricatorConduitAPIController',
'/differential/' => array(
'diff/(?<id>\d+)/$' => 'DifferentialDiffViewController',
),
'.*' => 'AphrontDefaultApplicationController',
);
}

View file

@ -0,0 +1,34 @@
<?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.
*/
abstract class DifferentialController extends PhabricatorController {
public function buildStandardPageResponse($view, array $data) {
$page = new PhabricatorStandardPageView();
$page->setApplicationName('Differential');
$page->setBaseURI('/differential/');
$page->setTitle(idx($data, 'title'));
$page->setGlyph("\xE2\x9A\x99");
$page->appendChild($view);
$response = new AphrontWebpageResponse();
return $response->setContent($page->render());
}
}

View file

@ -0,0 +1,16 @@
<?php
/**
* This file is automatically generated. Lint this module to rebuild it.
* @generated
*/
phutil_require_module('phabricator', 'aphront/response/webpage');
phutil_require_module('phabricator', 'applications/base/controller/base');
phutil_require_module('phabricator', 'view/page/standard');
phutil_require_module('phutil', 'utils');
phutil_require_source('DifferentialController.php');

View file

@ -0,0 +1,52 @@
<?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() {
$diff = id(new DifferentialDiff())->load($this->id);
if (!$diff) {
return new Aphront404Response();
}
$changesets = $diff->loadChangesets();
$changesets = msort($changesets, 'getSortKey');
$table_of_contents = id(new DifferentialDiffTableOfContentsView())
->setChangesets($changesets);
$details = id(new DifferentialChangesetDetailView())
->setChangesets($changesets);
return $this->buildStandardPageResponse(
array(
$table_of_contents,
$details,
),
array(
'title' => 'Diff View',
));
}
}

View file

@ -0,0 +1,17 @@
<?php
/**
* This file is automatically generated. Lint this module to rebuild it.
* @generated
*/
phutil_require_module('phabricator', 'aphront/response/404');
phutil_require_module('phabricator', 'applications/differential/controller/base');
phutil_require_module('phabricator', 'applications/differential/storage/diff');
phutil_require_module('phabricator', 'applications/differential/view/difftableofcontents');
phutil_require_module('phutil', 'utils');
phutil_require_source('DifferentialDiffViewController.php');

View file

@ -0,0 +1,131 @@
<?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 DifferentialChangesetDetailView extends AphrontView {
private $changesets = array();
public function setChangesets($changesets) {
$this->changesets = $changesets;
return $this;
}
public function render() {
$against = array(); // TODO
$edit = false;
$changesets = $this->changesets;
foreach ($changesets as $key => $changeset) {
if (empty($against[$changeset->getID()])) {
$type = $changeset->getChangeType();
if ($type == DifferentialChangeType::TYPE_MOVE_AWAY ||
$type == DifferentialChangeType::TYPE_MULTICOPY) {
unset($changesets[$key]);
}
}
}
$output = array();
$mapping = array();
foreach ($changesets as $key => $changeset) {
$file = $changeset->getFilename();
$class = 'differential-changeset';
if (!$edit) {
$class .= ' differential-changeset-noneditable';
}
$id = $changeset->getID();
if ($id) {
$against_id = idx($against, $id);
} else {
$against_id = null;
}
/*
$detail_uri = URI($render_uri)
->addQueryData(array(
'changeset' => $id,
'against' => $against_id,
'whitespace' => $whitespace,
));
*/
$detail_uri = '!';
$detail = phutil_render_tag(
'a',
array(
'style' => 'float: right',
'href' => $detail_uri,
'target' => '_blank',
),
'Standalone View');
// $div = <div class="differential-loading">Loading&hellip;</div>;
$display_filename = $changeset->getDisplayFilename();
$output[] =
'<div>'.
'<h1>'.phutil_escape_html($display_filename).'</h1>'.
'<div>Loading...</div>'.
'</div>';
/*
<div class={$class}
sigil="differential-changeset"
meta={$changeset->getID()}>
{$detail}
<a name={alite_urlize($file)} /><h1>{$file}</h1>
{$div}
</div>;
*/
/*
$mapping[$div->requireUniqueId()] = array_filter(
array(
$changeset->getID(),
idx($against, $changeset->getID()),
));
*/
}
/*
require_static('differential-diff-css');
require_static('differential-syntax-css');
Javelin::initBehavior('differential-populate', array(
'registry' => $mapping,
'whitespace' => $whitespace,
'uri' => $render_uri,
));
Javelin::initBehavior('differential-context', array(
'uri' => $render_uri,
));
if ($edit) {
require_static('remarkup-css');
Javelin::initBehavior('differential-inline', array(
'uri' => '/differential/feedback/'.$revision->getID().'/',
));
}
*/
return
'<div class="differential-review-stage">'.
implode("\n", $output).
'</div>';
}
}

View file

@ -0,0 +1,121 @@
<?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.
*/
final class DifferentialDiffTableOfContentsView extends AphrontView {
private $changesets = array();
public function setChangesets($changesets) {
$this->changesets = $changesets;
return $this;
}
public function render() {
$rows = array();
$changesets = $this->changesets;
foreach ($changesets as $changeset) {
$file = $changeset->getFilename();
$display_file = $changeset->getDisplayFilename();
$type = $changeset->getChangeType();
$ftype = $changeset->getFileType();
if (DifferentialChangeType::isOldLocationChangeType($type)) {
$link = phutil_escape_html($display_file);
$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) {
$meta[] = $path;
}
$meta = implode('<br />', $meta);
} else {
if ($type == DifferentialChangeType::TYPE_MOVE_AWAY) {
$meta = 'Moved to '.reset($away);
} else {
$meta = 'Copied to '.reset($away);
}
}
} else {
$link = phutil_render_tag(
'a',
array(
'href' => '#', // TODO: filename normalizer
),
phutil_escape_html($display_file));
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());
} else {
$meta = null;
}
}
$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>'.
'<td class="differential-toc-char" title={$chartitle}>'.$char.'</td>'.
'<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>'.
'<td colspan="3" />'.
'<td class="differential-toc-meta">'.$meta.'</td>'.
'</tr>';
}
}
return
'<div class="differential-toc">'.
'<h1>Table of Contents</h1>'.
'<table>'.
implode("\n", $rows).
'</table>'.
'</div>';
}
}

View file

@ -0,0 +1,15 @@
<?php
/**
* This file is automatically generated. Lint this module to rebuild it.
* @generated
*/
phutil_require_module('phabricator', 'applications/differential/constants/changetype');
phutil_require_module('phabricator', 'view/base');
phutil_require_module('phutil', 'markup');
phutil_require_source('DifferentialDiffTableOfContentsView.php');

View file

@ -592,4 +592,47 @@ th.aphront-side-nav-navigation a.aphront-side-nav-selected:hover {
background: #d8dfea;
}
/******************************************************************************/
/* differential toc */
/******************************************************************************/
.differential-toc {
margin: 25px 0;
max-width: 1118px;
border: 1px solid #666622;
background: #efefdf;
padding: 15px 20px;
font-size: 13px;
}
.differential-toc-meta {
color: #666666;
padding-left: 1em;
}
.differential-toc-char,
.differential-toc-prop {
width: 1.25em;
text-align: center;
font-weight: bold;
}
.differential-toc-ftype {
padding: 0 .5em;
text-align: center;
color: #666666;
}
.differential-toc-file {
color: #444444;
}
.differential-toc h1 {
border-bottom: 1px solid #aaaa99;
padding-bottom: 8px;
margin-bottom: 8px;
}