1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-03 03:11:01 +01:00

Clean up the revision list view a bit.

This commit is contained in:
epriestley 2011-01-30 18:24:57 -08:00
parent a34f946b8e
commit 58d1506499
7 changed files with 179 additions and 11 deletions

View file

@ -118,7 +118,7 @@ celerity_register_resource_map(array(
), ),
'differential-revision-comment-css' => 'differential-revision-comment-css' =>
array( array(
'uri' => '/res/21572195/rsrc/css/application/differential/revision-comment.css', 'uri' => '/res/bf6369c6/rsrc/css/application/differential/revision-comment.css',
'type' => 'css', 'type' => 'css',
'requires' => 'requires' =>
array( array(

View file

@ -176,6 +176,9 @@ phutil_register_library_map(array(
'celerity_generate_unique_node_id' => 'infratructure/celerity/api', 'celerity_generate_unique_node_id' => 'infratructure/celerity/api',
'celerity_register_resource_map' => 'infratructure/celerity/map', 'celerity_register_resource_map' => 'infratructure/celerity/map',
'javelin_render_tag' => 'infratructure/javelin/markup', 'javelin_render_tag' => 'infratructure/javelin/markup',
'phabricator_format_relative_time' => 'view/utils',
'phabricator_format_timestamp' => 'view/utils',
'phabricator_format_units_generic' => 'view/utils',
'qsprintf' => 'storage/qsprintf', 'qsprintf' => 'storage/qsprintf',
'queryfx' => 'storage/queryfx', 'queryfx' => 'storage/queryfx',
'queryfx_all' => 'storage/queryfx', 'queryfx_all' => 'storage/queryfx',

View file

@ -113,11 +113,59 @@ class DifferentialRevisionListController extends DifferentialController {
phutil_escape_html($filter_desc['name']))); phutil_escape_html($filter_desc['name'])));
} }
$phids = array();
$rev_ids = array();
foreach ($queries as $key => $query) {
$revisions = $query['object']->loadRevisions();
foreach ($revisions as $revision) {
$phids[$revision->getAuthorPHID()] = true;
$rev_ids[$revision->getID()] = true;
}
$queries[$key]['revisions'] = $revisions;
}
$rev = new DifferentialRevision();
if ($rev_ids) {
$rev_ids = array_keys($rev_ids);
$reviewers = queryfx_all(
$rev->establishConnection('r'),
'SELECT revisionID, objectPHID FROM %T revision JOIN %T relationship
ON revision.id = relationship.revisionID
WHERE revision.id IN (%Ld)
AND relationship.relation = %s
AND relationship.forbidden = 0
ORDER BY sequence',
$rev->getTableName(),
DifferentialRevision::RELATIONSHIP_TABLE,
$rev_ids,
DifferentialRevision::RELATION_REVIEWER);
$reviewer_map = array();
foreach ($reviewers as $reviewer) {
$reviewer_map[$reviewer['revisionID']][] = $reviewer['objectPHID'];
}
foreach ($reviewer_map as $revision_id => $reviewer_ids) {
$phids[reset($reviewer_ids)] = true;
}
} else {
$reviewer_map = array();
}
if ($phids) {
$phids = array_keys($phids);
$handles = id(new PhabricatorObjectHandleData($phids))
->loadHandles();
} else {
$handles = array();
}
foreach ($queries as $query) { foreach ($queries as $query) {
$table = $this->renderRevisionTable( $table = $this->renderRevisionTable(
$query['object']->loadRevisions(), $query['revisions'],
$query['header'], $query['header'],
idx($query, 'nodata')); idx($query, 'nodata'),
$handles,
$reviewer_map);
$side_nav->appendChild($table); $side_nav->appendChild($table);
} }
@ -128,27 +176,45 @@ class DifferentialRevisionListController extends DifferentialController {
)); ));
} }
private function renderRevisionTable(array $revisions, $header, $nodata) { private function renderRevisionTable(
array $revisions,
$header,
$nodata,
array $handles,
array $reviewer_map) {
$rows = array(); $rows = array();
foreach ($revisions as $revision) { foreach ($revisions as $revision) {
$status = DifferentialRevisionStatus::getNameForRevisionStatus( $status = DifferentialRevisionStatus::getNameForRevisionStatus(
$revision->getStatus()); $revision->getStatus());
$reviewers = idx($reviewer_map, $revision->getID(), array());
if ($reviewers) {
$first = reset($reviewers);
if (count($reviewers) > 1) {
$suffix = ' (+'.(count($reviewers) - 1).')';
} else {
$suffix = null;
}
$reviewers = $handles[$first]->renderLink().$suffix;
} else {
$reviewers = '<em>None</em>';
}
$rows[] = array( $rows[] = array(
'D'.$revision->getID(), 'D'.$revision->getID(),
phutil_render_tag( '<strong>'.phutil_render_tag(
'a', 'a',
array( array(
'href' => '/D'.$revision->getID(), 'href' => '/D'.$revision->getID(),
), ),
phutil_escape_html($revision->getTitle())), phutil_escape_html($revision->getTitle())).'</strong>',
phutil_escape_html($status), phutil_escape_html($status),
number_format($revision->getLineCount()), number_format($revision->getLineCount()),
$revision->getAuthorPHID(), $handles[$revision->getAuthorPHID()]->renderLink(),
'TODO', $reviewers,
$revision->getDateModified(), phabricator_format_timestamp($revision->getDateModified()),
$revision->getDateCreated(), phabricator_format_timestamp($revision->getDateCreated()),
); );
} }

View file

@ -9,9 +9,13 @@
phutil_require_module('phabricator', 'applications/differential/constants/revisionstatus'); phutil_require_module('phabricator', 'applications/differential/constants/revisionstatus');
phutil_require_module('phabricator', 'applications/differential/controller/base'); phutil_require_module('phabricator', 'applications/differential/controller/base');
phutil_require_module('phabricator', 'applications/differential/data/revisionlist'); phutil_require_module('phabricator', 'applications/differential/data/revisionlist');
phutil_require_module('phabricator', 'applications/differential/storage/revision');
phutil_require_module('phabricator', 'applications/phid/handle/data');
phutil_require_module('phabricator', 'storage/queryfx');
phutil_require_module('phabricator', 'view/control/table'); phutil_require_module('phabricator', 'view/control/table');
phutil_require_module('phabricator', 'view/layout/panel'); phutil_require_module('phabricator', 'view/layout/panel');
phutil_require_module('phabricator', 'view/layout/sidenav'); phutil_require_module('phabricator', 'view/layout/sidenav');
phutil_require_module('phabricator', 'view/utils');
phutil_require_module('phutil', 'markup'); phutil_require_module('phutil', 'markup');
phutil_require_module('phutil', 'utils'); phutil_require_module('phutil', 'utils');

View file

@ -229,7 +229,7 @@ class DifferentialRevisionListData {
$data = vqueryfx_all( $data = vqueryfx_all(
$rev->establishConnection('r'), $rev->establishConnection('r'),
'SELECT * FROM %T revision WHERE '.$pattern, 'SELECT * FROM %T revision WHERE '.$pattern.' '.$this->getOrderClause(),
$argv); $argv);
return $rev->loadAllFromArray($data); return $rev->loadAllFromArray($data);

View file

@ -0,0 +1,10 @@
<?php
/**
* This file is automatically generated. Lint this module to rebuild it.
* @generated
*/
phutil_require_source('viewutils.php');

View file

@ -0,0 +1,85 @@
<?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.
*/
function phabricator_format_relative_time($duration) {
return phabricator_format_units_generic(
$duration,
array(60, 60, 24, 7),
array('s', 'm', 'h', 'd', 'w'),
$precision = 0);
}
function phabricator_format_timestamp($epoch) {
$difference = (time() - $epoch);
if ($difference < 60 * 60) {
return phabricator_format_relative_time($difference).' ago';
} else if (date('Y') == date('Y', $epoch)) {
return date('M jS, g:i A', $epoch);
} else {
return date('F jS, Y', $epoch);
}
}
function phabricator_format_units_generic(
$n,
array $scales,
array $labels,
$precision = 0,
&$remainder = null) {
$is_negative = false;
if ($n < 0) {
$is_negative = true;
$n = abs($n);
}
$remainder = 0;
$accum = 1;
$scale = array_shift($scales);
$label = array_shift($labels);
while ($n > $scale && count($labels)) {
$remainder += ($n % $scale) * $accum;
$n /= $scale;
$accum *= $scale;
$label = array_shift($labels);
if (!count($scales)) {
break;
}
$scale = array_shift($scales);
}
if ($is_negative) {
$n = -$n;
$remainder = -$remainder;
}
if ($precision) {
$num_string = number_format($n, $precision);
} else {
$num_string = (int)floor($n);
}
if ($label) {
$num_string .= ' '.$label;
}
return $num_string;
}