From 58d150649988b015332e65c9d6c712d1d1251c23 Mon Sep 17 00:00:00 2001 From: epriestley Date: Sun, 30 Jan 2011 18:24:57 -0800 Subject: [PATCH] Clean up the revision list view a bit. --- src/__celerity_resource_map__.php | 2 +- src/__phutil_library_map__.php | 3 + .../DifferentialRevisionListController.php | 84 ++++++++++++++++-- .../controller/revisionlist/__init__.php | 4 + .../DifferentialRevisionListData.php | 2 +- src/view/utils/__init__.php | 10 +++ src/view/utils/viewutils.php | 85 +++++++++++++++++++ 7 files changed, 179 insertions(+), 11 deletions(-) create mode 100644 src/view/utils/__init__.php create mode 100644 src/view/utils/viewutils.php diff --git a/src/__celerity_resource_map__.php b/src/__celerity_resource_map__.php index d7e9a5c5fb..5ff960b7ed 100644 --- a/src/__celerity_resource_map__.php +++ b/src/__celerity_resource_map__.php @@ -118,7 +118,7 @@ celerity_register_resource_map(array( ), 'differential-revision-comment-css' => array( - 'uri' => '/res/21572195/rsrc/css/application/differential/revision-comment.css', + 'uri' => '/res/bf6369c6/rsrc/css/application/differential/revision-comment.css', 'type' => 'css', 'requires' => array( diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index e8a816c867..ce345f6e52 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -176,6 +176,9 @@ phutil_register_library_map(array( 'celerity_generate_unique_node_id' => 'infratructure/celerity/api', 'celerity_register_resource_map' => 'infratructure/celerity/map', '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', 'queryfx' => 'storage/queryfx', 'queryfx_all' => 'storage/queryfx', diff --git a/src/applications/differential/controller/revisionlist/DifferentialRevisionListController.php b/src/applications/differential/controller/revisionlist/DifferentialRevisionListController.php index 956b1f5a16..c7f5e3c309 100644 --- a/src/applications/differential/controller/revisionlist/DifferentialRevisionListController.php +++ b/src/applications/differential/controller/revisionlist/DifferentialRevisionListController.php @@ -113,11 +113,59 @@ class DifferentialRevisionListController extends DifferentialController { 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) { $table = $this->renderRevisionTable( - $query['object']->loadRevisions(), + $query['revisions'], $query['header'], - idx($query, 'nodata')); + idx($query, 'nodata'), + $handles, + $reviewer_map); $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(); foreach ($revisions as $revision) { $status = DifferentialRevisionStatus::getNameForRevisionStatus( $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 = 'None'; + } + $rows[] = array( 'D'.$revision->getID(), - phutil_render_tag( + ''.phutil_render_tag( 'a', array( 'href' => '/D'.$revision->getID(), ), - phutil_escape_html($revision->getTitle())), + phutil_escape_html($revision->getTitle())).'', phutil_escape_html($status), number_format($revision->getLineCount()), - $revision->getAuthorPHID(), - 'TODO', - $revision->getDateModified(), - $revision->getDateCreated(), + $handles[$revision->getAuthorPHID()]->renderLink(), + $reviewers, + phabricator_format_timestamp($revision->getDateModified()), + phabricator_format_timestamp($revision->getDateCreated()), ); } diff --git a/src/applications/differential/controller/revisionlist/__init__.php b/src/applications/differential/controller/revisionlist/__init__.php index 8f45af9de8..4c51609136 100644 --- a/src/applications/differential/controller/revisionlist/__init__.php +++ b/src/applications/differential/controller/revisionlist/__init__.php @@ -9,9 +9,13 @@ phutil_require_module('phabricator', 'applications/differential/constants/revisionstatus'); phutil_require_module('phabricator', 'applications/differential/controller/base'); 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/layout/panel'); phutil_require_module('phabricator', 'view/layout/sidenav'); +phutil_require_module('phabricator', 'view/utils'); phutil_require_module('phutil', 'markup'); phutil_require_module('phutil', 'utils'); diff --git a/src/applications/differential/data/revisionlist/DifferentialRevisionListData.php b/src/applications/differential/data/revisionlist/DifferentialRevisionListData.php index ded367bfee..1fe22bb4c3 100755 --- a/src/applications/differential/data/revisionlist/DifferentialRevisionListData.php +++ b/src/applications/differential/data/revisionlist/DifferentialRevisionListData.php @@ -229,7 +229,7 @@ class DifferentialRevisionListData { $data = vqueryfx_all( $rev->establishConnection('r'), - 'SELECT * FROM %T revision WHERE '.$pattern, + 'SELECT * FROM %T revision WHERE '.$pattern.' '.$this->getOrderClause(), $argv); return $rev->loadAllFromArray($data); diff --git a/src/view/utils/__init__.php b/src/view/utils/__init__.php new file mode 100644 index 0000000000..61ad9be643 --- /dev/null +++ b/src/view/utils/__init__.php @@ -0,0 +1,10 @@ + $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; +} +