2011-01-25 15:19:06 -08:00
|
|
|
<?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 DifferentialRevisionListController extends DifferentialController {
|
|
|
|
|
|
2011-01-27 11:35:04 -08:00
|
|
|
private $filter;
|
|
|
|
|
|
2011-10-24 12:27:16 -07:00
|
|
|
public function shouldRequireLogin() {
|
|
|
|
|
return !$this->allowsAnonymousAccess();
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-27 11:35:04 -08:00
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
|
$this->filter = idx($data, 'filter');
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-25 15:19:06 -08:00
|
|
|
public function processRequest() {
|
2011-04-11 02:03:30 -07:00
|
|
|
$request = $this->getRequest();
|
|
|
|
|
$user = $request->getUser();
|
2011-10-24 12:27:16 -07:00
|
|
|
$viewer_is_anonymous = !$user->isLoggedIn();
|
2011-04-11 02:03:30 -07:00
|
|
|
|
|
|
|
|
if ($request->isFormPost()) {
|
|
|
|
|
$phid_arr = $request->getArr('view_user');
|
|
|
|
|
$view_target = head($phid_arr);
|
|
|
|
|
return id(new AphrontRedirectResponse())
|
|
|
|
|
->setURI($request->getRequestURI()->alter('phid', $view_target));
|
|
|
|
|
}
|
2011-01-25 15:19:06 -08:00
|
|
|
|
2011-10-24 12:27:16 -07:00
|
|
|
$filters = array();
|
|
|
|
|
if (!$viewer_is_anonymous) {
|
|
|
|
|
$filters = array(
|
|
|
|
|
'User Revisions',
|
|
|
|
|
'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',
|
|
|
|
|
),
|
2011-01-27 11:35:04 -08:00
|
|
|
),
|
|
|
|
|
),
|
2011-10-24 12:27:16 -07:00
|
|
|
'open' => array(
|
|
|
|
|
'name' => 'Open Revisions',
|
|
|
|
|
'queries' => array(
|
|
|
|
|
array(
|
|
|
|
|
'query' => DifferentialRevisionListData::QUERY_OPEN_OWNED,
|
|
|
|
|
'header' => 'Your Open Revisions',
|
|
|
|
|
),
|
2011-01-27 11:35:04 -08:00
|
|
|
),
|
|
|
|
|
),
|
2011-10-24 12:27:16 -07:00
|
|
|
'reviews' => array(
|
|
|
|
|
'name' => 'Open Reviews',
|
|
|
|
|
'queries' => array(
|
|
|
|
|
array(
|
|
|
|
|
'query' => DifferentialRevisionListData::QUERY_OPEN_REVIEWER,
|
|
|
|
|
'header' => 'Your Open Reviews',
|
|
|
|
|
),
|
2011-01-27 11:35:04 -08:00
|
|
|
),
|
|
|
|
|
),
|
2011-10-24 12:27:16 -07:00
|
|
|
'all' => array(
|
|
|
|
|
'name' => 'All Revisions',
|
|
|
|
|
'queries' => array(
|
|
|
|
|
array(
|
|
|
|
|
'query' => DifferentialRevisionListData::QUERY_OWNED,
|
|
|
|
|
'header' => 'Your Revisions',
|
|
|
|
|
),
|
2011-01-27 11:35:04 -08:00
|
|
|
),
|
2011-01-25 15:19:06 -08:00
|
|
|
),
|
2011-10-24 12:27:16 -07:00
|
|
|
'related' => array(
|
|
|
|
|
'name' => 'All Revisions and Reviews',
|
|
|
|
|
'queries' => array(
|
|
|
|
|
array(
|
|
|
|
|
'query' => DifferentialRevisionListData::QUERY_OWNED_OR_REVIEWER,
|
|
|
|
|
'header' => 'Your Revisions and Reviews',
|
|
|
|
|
),
|
2011-02-22 23:37:43 -08:00
|
|
|
),
|
|
|
|
|
),
|
2011-10-24 12:27:16 -07:00
|
|
|
'<hr />'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
$filters = array_merge($filters, array(
|
2011-02-22 23:37:43 -08:00
|
|
|
'All Revisions',
|
|
|
|
|
'allopen' => array(
|
|
|
|
|
'name' => 'Open',
|
2011-04-11 02:03:30 -07:00
|
|
|
'nofilter' => true,
|
2011-02-22 23:37:43 -08:00
|
|
|
'queries' => array(
|
|
|
|
|
array(
|
|
|
|
|
'query' => DifferentialRevisionListData::QUERY_ALL_OPEN,
|
|
|
|
|
'header' => 'All Open Revisions',
|
2011-01-27 11:35:04 -08:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
2011-10-24 12:27:16 -07:00
|
|
|
));
|
2011-01-27 11:35:04 -08:00
|
|
|
|
|
|
|
|
if (empty($filters[$this->filter])) {
|
2011-10-24 12:27:16 -07:00
|
|
|
if (!$viewer_is_anonymous) {
|
|
|
|
|
$this->filter = 'active';
|
|
|
|
|
} else {
|
|
|
|
|
$this->filter = 'allopen';
|
|
|
|
|
}
|
2011-01-27 11:35:04 -08:00
|
|
|
}
|
|
|
|
|
|
2011-04-11 02:03:30 -07:00
|
|
|
$view_phid = nonempty($request->getStr('phid'), $user->getPHID());
|
2011-01-27 11:35:04 -08:00
|
|
|
|
|
|
|
|
$queries = array();
|
|
|
|
|
$filter = $filters[$this->filter];
|
|
|
|
|
foreach ($filter['queries'] as $query) {
|
|
|
|
|
$query_object = new DifferentialRevisionListData(
|
|
|
|
|
$query['query'],
|
2011-04-11 02:03:30 -07:00
|
|
|
array($view_phid));
|
2011-01-27 11:35:04 -08:00
|
|
|
$queries[] = array(
|
|
|
|
|
'object' => $query_object,
|
|
|
|
|
) + $query;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$side_nav = new AphrontSideNavView();
|
2011-02-22 23:37:43 -08:00
|
|
|
|
2011-04-11 02:03:30 -07:00
|
|
|
$query = null;
|
|
|
|
|
if ($view_phid) {
|
|
|
|
|
$query = '?phid='.$view_phid;
|
|
|
|
|
}
|
2011-02-22 23:37:43 -08:00
|
|
|
|
2011-01-27 11:35:04 -08:00
|
|
|
foreach ($filters as $filter_name => $filter_desc) {
|
2011-02-22 23:37:43 -08:00
|
|
|
if (is_int($filter_name)) {
|
|
|
|
|
$side_nav->addNavItem(
|
|
|
|
|
phutil_render_tag(
|
|
|
|
|
'span',
|
|
|
|
|
array(),
|
|
|
|
|
$filter_desc));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2011-01-27 11:35:04 -08:00
|
|
|
$selected = ($filter_name == $this->filter);
|
|
|
|
|
$side_nav->addNavItem(
|
|
|
|
|
phutil_render_tag(
|
|
|
|
|
'a',
|
|
|
|
|
array(
|
2011-04-11 02:03:30 -07:00
|
|
|
'href' => '/differential/filter/'.$filter_name.'/'.$query,
|
2011-01-27 11:35:04 -08:00
|
|
|
'class' => $selected ? 'aphront-side-nav-selected' : null,
|
|
|
|
|
),
|
|
|
|
|
phutil_escape_html($filter_desc['name'])));
|
|
|
|
|
}
|
2011-01-25 15:19:06 -08:00
|
|
|
|
2011-01-30 18:24:57 -08:00
|
|
|
$rev_ids = array();
|
|
|
|
|
foreach ($queries as $key => $query) {
|
|
|
|
|
$revisions = $query['object']->loadRevisions();
|
|
|
|
|
foreach ($revisions as $revision) {
|
|
|
|
|
$rev_ids[$revision->getID()] = true;
|
|
|
|
|
}
|
|
|
|
|
$queries[$key]['revisions'] = $revisions;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($rev_ids) {
|
2011-10-02 11:42:41 -07:00
|
|
|
$rev = new DifferentialRevision();
|
|
|
|
|
$relationships = queryfx_all(
|
2011-01-30 18:24:57 -08:00
|
|
|
$rev->establishConnection('r'),
|
2011-10-02 11:42:41 -07:00
|
|
|
'SELECT * FROM %T WHERE revisionID IN (%Ld) ORDER BY sequence',
|
2011-01-30 18:24:57 -08:00
|
|
|
DifferentialRevision::RELATIONSHIP_TABLE,
|
2011-10-02 11:42:41 -07:00
|
|
|
array_keys($rev_ids));
|
|
|
|
|
$relationships = igroup($relationships, 'revisionID');
|
|
|
|
|
} else {
|
|
|
|
|
$relationships = array();
|
|
|
|
|
}
|
2011-01-30 18:24:57 -08:00
|
|
|
|
2011-10-02 11:42:41 -07:00
|
|
|
foreach ($queries as $query) {
|
|
|
|
|
foreach ($query['revisions'] as $revision) {
|
|
|
|
|
$revision->attachRelationships(
|
|
|
|
|
idx(
|
|
|
|
|
$relationships,
|
|
|
|
|
$revision->getID(),
|
|
|
|
|
array()));
|
2011-01-30 18:24:57 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-02 11:42:41 -07:00
|
|
|
$phids = array();
|
|
|
|
|
foreach ($queries as $key => $query) {
|
|
|
|
|
$view = id(new DifferentialRevisionListView())
|
|
|
|
|
->setRevisions($query['revisions'])
|
|
|
|
|
->setUser($user)
|
|
|
|
|
->setNoDataString(idx($query, 'nodata'));
|
|
|
|
|
$phids[] = $view->getRequiredHandlePHIDs();
|
|
|
|
|
$queries[$key]['view'] = $view;
|
|
|
|
|
}
|
|
|
|
|
$phids = array_mergev($phids);
|
2011-10-07 12:03:24 -07:00
|
|
|
$phids[] = $view_phid;
|
|
|
|
|
|
2011-10-02 11:42:41 -07:00
|
|
|
$handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
|
|
|
|
|
|
|
|
|
|
foreach ($queries as $query) {
|
|
|
|
|
$query['view']->setHandles($handles);
|
2011-01-30 18:24:57 -08:00
|
|
|
}
|
|
|
|
|
|
2011-04-11 02:03:30 -07:00
|
|
|
if (empty($filters[$this->filter]['nofilter'])) {
|
|
|
|
|
$filter_form = id(new AphrontFormView())
|
|
|
|
|
->setUser($user)
|
|
|
|
|
->appendChild(
|
|
|
|
|
id(new AphrontFormTokenizerControl())
|
|
|
|
|
->setDatasource('/typeahead/common/users/')
|
|
|
|
|
->setLabel('View User')
|
|
|
|
|
->setName('view_user')
|
|
|
|
|
->setValue(
|
|
|
|
|
array(
|
|
|
|
|
$view_phid => $handles[$view_phid]->getFullName(),
|
|
|
|
|
))
|
2011-12-01 16:05:54 -08:00
|
|
|
->setLimit(1))
|
|
|
|
|
->appendChild(
|
|
|
|
|
id(new AphrontFormSubmitControl())
|
|
|
|
|
->setValue('Filter Revisions'));
|
2011-04-11 02:03:30 -07:00
|
|
|
$filter_view = new AphrontListFilterView();
|
|
|
|
|
$filter_view->appendChild($filter_form);
|
2011-12-01 16:05:54 -08:00
|
|
|
|
|
|
|
|
$viewer_is_anonymous = !$this->getRequest()->getUser()->isLoggedIn();
|
|
|
|
|
if (!$viewer_is_anonymous) {
|
|
|
|
|
$create_uri = new PhutilURI('/differential/diff/create/');
|
|
|
|
|
$filter_view->addButton(
|
|
|
|
|
phutil_render_tag(
|
|
|
|
|
'a',
|
|
|
|
|
array(
|
|
|
|
|
'href' => (string)$create_uri,
|
|
|
|
|
'class' => 'green button',
|
|
|
|
|
),
|
|
|
|
|
'Create Revision'));
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-11 02:03:30 -07:00
|
|
|
$side_nav->appendChild($filter_view);
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-27 11:35:04 -08:00
|
|
|
foreach ($queries as $query) {
|
2011-10-02 11:42:41 -07:00
|
|
|
$table = $query['view']->render();
|
|
|
|
|
|
|
|
|
|
$panel = new AphrontPanelView();
|
|
|
|
|
$panel->setHeader($query['header']);
|
|
|
|
|
$panel->appendChild($table);
|
|
|
|
|
|
|
|
|
|
$side_nav->appendChild($panel);
|
2011-01-27 11:35:04 -08:00
|
|
|
}
|
2011-01-25 15:19:06 -08:00
|
|
|
|
|
|
|
|
return $this->buildStandardPageResponse(
|
|
|
|
|
$side_nav,
|
|
|
|
|
array(
|
|
|
|
|
'title' => 'Differential Home',
|
2011-02-05 12:20:18 -08:00
|
|
|
'tab' => 'revisions',
|
2011-01-25 15:19:06 -08:00
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|