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

DifferentialRevisionList

This commit is contained in:
epriestley 2011-01-27 11:35:04 -08:00
parent 63c842105c
commit 9f1659b4c4
11 changed files with 506 additions and 14 deletions

View file

@ -17,7 +17,7 @@ celerity_register_resource_map(array(
),
'aphront-form-view-css' =>
array(
'path' => '/res/75636a53/rsrc/css/aphront/form-view.css',
'path' => '/res/785ac1c6/rsrc/css/aphront/form-view.css',
'type' => 'css',
'requires' =>
array(
@ -33,7 +33,7 @@ celerity_register_resource_map(array(
),
'aphront-side-nav-view-css' =>
array(
'path' => '/res/1a16f19a/rsrc/css/aphront/side-nav-view.css',
'path' => '/res/0fc0545c/rsrc/css/aphront/side-nav-view.css',
'type' => 'css',
'requires' =>
array(
@ -66,7 +66,7 @@ celerity_register_resource_map(array(
),
'phabricator-standard-page-view' =>
array(
'path' => '/res/0eef6905/rsrc/css/application/base/standard-page-view.css',
'path' => '/res/1f93ada7/rsrc/css/application/base/standard-page-view.css',
'type' => 'css',
'requires' =>
array(

View file

@ -89,6 +89,7 @@ phutil_register_library_map(array(
'DifferentialRevisionEditController' => 'applications/differential/controller/revisionedit',
'DifferentialRevisionEditor' => 'applications/differential/editor/revision',
'DifferentialRevisionListController' => 'applications/differential/controller/revisionlist',
'DifferentialRevisionListData' => 'applications/differential/data/revisionlist',
'DifferentialRevisionStatus' => 'applications/differential/constants/revisionstatus',
'DifferentialUnitStatus' => 'applications/differential/constants/unitstatus',
'Javelin' => 'infratructure/javelin/api',
@ -169,6 +170,7 @@ phutil_register_library_map(array(
'require_celerity_resource' => 'infratructure/celerity/api',
'vqsprintf' => 'storage/qsprintf',
'vqueryfx' => 'storage/queryfx',
'vqueryfx_all' => 'storage/queryfx',
'xsprintf_query' => 'storage/qsprintf',
),
'requires_class' =>

View file

@ -79,6 +79,7 @@ class AphrontDefaultApplicationConfiguration
'/differential/' => array(
'$' => 'DifferentialRevisionListController',
'filter/(?<filter>\w+)/$' => 'DifferentialRevisionListController',
'diff/(?<id>\d+)/$' => 'DifferentialDiffViewController',
'changeset/(?<id>\d+)/$' => 'DifferentialChangesetViewController',
'revision/edit/(?:(?<id>\d+)/)?$'

View file

@ -22,6 +22,7 @@
abstract class AphrontResponse {
private $request;
private $cacheable = false;
public function setRequest($request) {
$this->request = $request;
@ -35,12 +36,24 @@ abstract class AphrontResponse {
public function getHeaders() {
return array();
}
public function setCacheDurationInSeconds($duration) {
$this->cacheable = $duration;
return $this;
}
public function getCacheHeaders() {
return array(
array('Cache-Control', 'private, no-cache, no-store, must-revalidate'),
array('Expires', 'Sat, 01 Jan 2000 00:00:00 GMT'),
);
if ($this->cacheable) {
$epoch = time() + $this->cacheable;
return array(
array('Expires', gmdate('D, d M Y H:i:s', $epoch) . ' GMT'),
);
} else {
return array(
array('Cache-Control', 'private, no-cache, no-store, must-revalidate'),
array('Expires', 'Sat, 01 Jan 2000 00:00:00 GMT'),
);
}
}
abstract public function buildResponseString();

View file

@ -18,17 +18,108 @@
class DifferentialRevisionListController extends DifferentialController {
private $filter;
public function willProcessRequest(array $data) {
$this->filter = idx($data, 'filter');
}
public function processRequest() {
$side_nav = new AphrontSideNavView();
$side_nav->addNavItem(
phutil_render_tag(
'a',
array(
'href' => '/differential/',
$filters = array(
'active' => array(
'name' => 'Active Revisions',
'queries' => array(
array(
'query'
=> DifferentialRevisionListData::QUERY_NEED_ACTION_FROM_SELF,
'header' => 'Action Required',
'nodata' => 'You have no revisions requiring action.',
),
array(
'query'
=> DifferentialRevisionListData::QUERY_NEED_ACTION_FROM_OTHERS,
'header' => 'Waiting on Others',
'nodata' => 'You have no revisions waiting on others',
),
),
'Active Revisions'));
),
'open' => array(
'name' => 'Open Revisions',
'queries' => array(
array(
'query' => DifferentialRevisionListData::QUERY_OPEN_OWNED,
'header' => 'Open Revisions',
),
),
),
'reviews' => array(
'name' => 'Open Reviews',
'queries' => array(
array(
'query' => DifferentialRevisionListData::QUERY_OPEN_REVIEWER,
'header' => 'Open Reviews',
),
),
),
'all' => array(
'name' => 'All Revisions',
'queries' => array(
array(
'query' => DifferentialRevisionListData::QUERY_OWNED,
'header' => 'All Revisions',
),
),
),
'related' => array(
'name' => 'All Revisions and Reviews',
'queries' => array(
array(
'query' => DifferentialRevisionListData::QUERY_OWNED_OR_REVIEWER,
'header' => 'All Revisions and Reviews',
),
),
),
);
if (empty($filters[$this->filter])) {
$this->filter = key($filters);
}
$request = $this->getRequest();
$user = $request->getUser();
$queries = array();
$filter = $filters[$this->filter];
foreach ($filter['queries'] as $query) {
$query_object = new DifferentialRevisionListData(
$query['query'],
array($user->getPHID()));
$queries[] = array(
'object' => $query_object,
) + $query;
}
$side_nav = new AphrontSideNavView();
foreach ($filters as $filter_name => $filter_desc) {
$selected = ($filter_name == $this->filter);
$side_nav->addNavItem(
phutil_render_tag(
'a',
array(
'href' => '/differential/filter/'.$filter_name.'/',
'class' => $selected ? 'aphront-side-nav-selected' : null,
),
phutil_escape_html($filter_desc['name'])));
}
foreach ($queries as $query) {
$table = $this->renderRevisionTable(
$query['object']->loadRevisions(),
$query['header'],
idx($query, 'nodata'));
$side_nav->appendChild($table);
}
return $this->buildStandardPageResponse(
$side_nav,
@ -37,4 +128,63 @@ class DifferentialRevisionListController extends DifferentialController {
));
}
private function renderRevisionTable(array $revisions, $header, $nodata) {
$rows = array();
foreach ($revisions as $revision) {
$status = DifferentialRevisionStatus::getNameForRevisionStatus(
$revision->getStatus());
$rows[] = array(
'D'.$revision->getID(),
phutil_render_tag(
'a',
array(
'href' => '/D'.$revision->getID(),
),
phutil_escape_html($revision->getTitle())),
phutil_escape_html($status),
number_format($revision->getLineCount()),
$revision->getOwnerPHID(),
'TODO',
$revision->getDateModified(),
$revision->getDateCreated(),
);
}
$table = new AphrontTableView($rows);
$table->setHeaders(
array(
'ID',
'Revision',
'Status',
'Lines',
'Author',
'Reviewers',
'Updated',
'Created',
));
$table->setColumnClasses(
array(
null,
'wide',
null,
null,
null,
null,
null,
null,
));
if ($nodata !== null) {
$table->setNoDataString($nodata);
}
$panel = new AphrontPanelView();
$panel->setHeader($header);
$panel->appendChild($table);
return $panel;
}
}

View file

@ -6,10 +6,15 @@
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', 'view/control/table');
phutil_require_module('phabricator', 'view/layout/panel');
phutil_require_module('phabricator', 'view/layout/sidenav');
phutil_require_module('phutil', 'markup');
phutil_require_module('phutil', 'utils');
phutil_require_source('DifferentialRevisionListController.php');

View file

@ -0,0 +1,296 @@
<?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 DifferentialRevisionListData {
const QUERY_OPEN_OWNED = 'open';
const QUERY_OPEN_REVIEWER = 'reviewer';
const QUERY_OWNED = 'owned';
const QUERY_OWNED_OR_REVIEWER = 'related';
const QUERY_NEED_ACTION_FROM_OTHERS = 'need-other-action';
const QUERY_NEED_ACTION_FROM_SELF = 'need-self-action';
const QUERY_COMMITTABLE = 'committable';
const QUERY_REVISION_IDS = 'revision-ids';
const QUERY_PHIDS = 'phids';
const QUERY_CC = 'cc';
const QUERY_ALL_OPEN = 'all-open';
private $ids;
private $filter;
private $handles;
private $revisions;
private $order;
public function __construct($filter, array $ids) {
$this->filter = $filter;
$this->ids = $ids;
}
public function getRevisions() {
return $this->revisions;
}
public function setOrder($order) {
$this->order = $order;
return $this;
}
public function loadRevisions() {
switch ($this->filter) {
case self::QUERY_CC:
$this->revisions = $this->loadAllOpenWithCCs($this->ids);
break;
case self::QUERY_ALL_OPEN:
$this->revisions = $this->loadAllOpen();
break;
case self::QUERY_OPEN_OWNED:
$this->revisions = $this->loadAllWhere(
'revision.status in (%Ld) AND revision.ownerPHID in (%Ls)',
$this->getOpenStatuses(),
$this->ids);
break;
case self::QUERY_COMMITTABLE:
$this->revisions = $this->loadAllWhere(
'revision.status in (%Ld) AND revision.ownerPHID in (%Ls)',
array(
DifferentialRevisionStatus::ACCEPTED,
),
$this->ids);
break;
case self::QUERY_REVISION_IDS:
$this->revisions = $this->loadAllWhere(
'id in (%Ld)',
$this->ids);
break;
case self::QUERY_OPEN_REVIEWER:
$this->revisions = $this->loadAllWhereJoinReview(
'revision.status in (%Ld) AND relationship.objectPHID in (%Ls)',
$this->getOpenStatuses(),
$this->ids);
break;
case self::QUERY_OWNED:
$this->revisions = $this->loadAllWhere(
'revision.ownerPHID in (%Ls)',
$this->ids);
break;
case self::QUERY_OWNED_OR_REVIEWER:
$this->revisions = $this->loadAllWhereJoinReview(
'revision.ownerPHID in (%Ls) OR relationship.objectPHID in (%Ls)',
$this->ids,
$this->ids);
break;
case self::QUERY_NEED_ACTION_FROM_SELF:
$rev = new DifferentialRevision();
$data = queryfx_all(
$rev->establishConnection('r'),
'SELECT revision.* FROM %T revision
WHERE revision.ownerPHID in (%Ls)
AND revision.status in (%Ld)
UNION ALL
SELECT revision.* FROM %T revision JOIN %T relationship
ON relationship.revisionID = revision.id
AND relationship.relation = %s
AND relationship.forbidden = 0
WHERE relationship.objectPHID IN (%Ls)
AND revision.status in (%Ld)
%Q',
$rev->getTableName(),
$this->ids,
array(
DifferentialRevisionStatus::NEEDS_REVISION,
DifferentialRevisionStatus::ACCEPTED,
),
$rev->getTableName(),
DifferentialRevision::RELATIONSHIP_TABLE,
DifferentialRevision::RELATION_REVIEWER,
$this->ids,
array(
DifferentialRevisionStatus::NEEDS_REVIEW,
),
$this->getOrderClause());
$data = ipull($data, null, 'id');
$this->revisions = $rev->loadAllFromArray($data);
break;
case self::QUERY_NEED_ACTION_FROM_OTHERS:
$rev = new DifferentialRevision();
$data = queryfx_all(
$rev->establishConnection('r'),
'SELECT revision.* FROM %T revision
WHERE revision.ownerPHID in (%Ls)
AND revision.status IN (%Ld)
UNION ALL
SELECT revision.* FROM %T revision JOIN %T relationship
ON relationship.revisionID = revision.id
AND relationship.relation = %s
AND relationship.forbidden = 0
WHERE relationship.objectPHID IN (%Ls)
AND revision.status in (%Ld)
%Q',
$rev->getTableName(),
$this->ids,
array(
DifferentialRevisionStatus::NEEDS_REVIEW,
),
$rev->getTableName(),
DifferentialRevision::RELATIONSHIP_TABLE,
DifferentialRevision::RELATION_REVIEWER,
$this->ids,
array(
DifferentialRevisionStatus::NEEDS_REVISION,
DifferentialRevisionStatus::ACCEPTED,
),
$this->getOrderClause());
$data = ipull($data, null, 'id');
$this->revisions = $rev->loadAllFromArray($data);
break;
case self::QUERY_BY_PHID:
$this->revisions = $this->loadAllWhere(
'revision.phid in (%Ls)',
$this->ids);
break;
}
return $this->revisions;
}
private function getOpenStatuses() {
return array(
DifferentialRevisionStatus::NEEDS_REVIEW,
DifferentialRevisionStatus::NEEDS_REVISION,
DifferentialRevisionStatus::ACCEPTED,
);
}
private function loadAllOpen() {
return $this->loadAllWhere('status in (%Ld)', $this->getOpenStatuses());
}
private function loadAllWhereJoinReview($pattern) {
$reviewer = DifferentialRevision::RELATION_REVIEWER;
$argv = func_get_args();
$rev = new DifferentialRevision();
$pattern = array_shift($argv);
$pattern =
'SELECT revision.*
FROM %T revision LEFT JOIN %T relationship
ON revision.id = relationship.revisionID
AND relationship.relation = %s
AND relationship.forbidden = 0
WHERE '.$pattern.'
GROUP BY revision.id '.$this->getOrderClause();
array_unshift(
$argv,
$rev->getTableName(),
DifferentialRevision::RELATIONSHIP_TABLE,
DifferentialRevision::RELATION_REVIEWER);
$data = vqueryfx_all(
$rev->establishConnection('r'),
$pattern,
$argv);
return $rev->loadAllFromArray($data);
}
private function loadAllWhere($pattern) {
$rev = new DifferentialRevision();
$argv = func_get_args();
array_shift($argv);
array_unshift($argv, $rev->getTableName());
$data = vqueryfx_all(
$rev->establishConnection('r'),
'SELECT * FROM %T revision WHERE '.$pattern,
$argv);
return $rev->loadAllFromArray($data);
}
private function loadAllOpenWithCCs(array $ccphids) {
$revision = new DifferentialRevision();
$data = queryfx_all(
'SELECT revision.* FROM %T revision
JOIN %T relationship ON relationship.revisionID = revision.id
AND relationship.relation = %s
AND relationship.forbidden = 0
AND relationship.objectPHID in (%Ls)
WHERE revision.status in (%Ld) %Q',
$revision->getTableName(),
DifferentialRevision::RELATIONSHIP_TABLE,
DifferentialRevision::RELATION_SUBSCRIBED,
$ccphids,
$this->getOpenStatuses(),
$this->getOrderClause());
return $revision->loadAllFromArray($data);
}
private function getOrderClause() {
$reverse = false;
$order = $this->order;
if (strlen($order) && $order[0] == '-') {
$reverse = true;
$order = substr($order, 1);
}
$asc = $reverse ? 'DESC' : 'ASC';
switch ($order) {
case 'ID':
$clause = 'id';
break;
case 'Revision':
$clause = 'name';
break;
case 'Status':
$clause = 'status';
break;
case 'Lines':
$clause = 'lineCount';
break;
case 'Created':
$clause = 'dateCreated';
$asc = $reverse ? 'ASC' : 'DESC';
break;
case '':
case 'Modified':
$clause = 'dateModified';
$asc = $reverse ? 'ASC' : 'DESC';
break;
default:
throw new Exception("Invalid order '{$order}'.");
}
return "ORDER BY {$clause} {$asc}";
}
}

View file

@ -0,0 +1,16 @@
<?php
/**
* This file is automatically generated. Lint this module to rebuild it.
* @generated
*/
phutil_require_module('phabricator', 'applications/differential/constants/revisionstatus');
phutil_require_module('phabricator', 'applications/differential/storage/revision');
phutil_require_module('phabricator', 'storage/queryfx');
phutil_require_module('phutil', 'utils');
phutil_require_source('DifferentialRevisionListData.php');

View file

@ -57,6 +57,8 @@ class CelerityResourceController extends AphrontController {
$response->setMimeType("text/javascript; charset=utf-8");
break;
}
$response->setCacheDurationInSeconds(60 * 60 * 24 * 30);
return $response;
}

View file

@ -56,3 +56,9 @@ function queryfx_one($conn, $sql/*, ... */) {
}
return null;
}
function vqueryfx_all($conn, $sql, array $argv) {
array_unshift($argv, $conn, $sql);
$ret = call_user_func_array('queryfx', $argv);
return $conn->selectAllResults($ret);
}

View file

@ -4,6 +4,7 @@
table.aphront-side-nav-view {
width: 100%;
font-size: 13px;
}
td.aphront-side-nav-content {