1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-20 04:20:55 +01:00

Restore "author" link to diffusion

Summary: create the page by getting data from the search result.
Test Plan:
load page with url /author/, /author/valid_username, and
/uathor/invalid_username, and verified that it works as expected.

Reviewed By: epriestley
Reviewers: epriestley, tuomaspelkonen
Commenters: tuomaspelkonen
CC: hwang, aran, tuomaspelkonen, epriestley, jungejason
Differential Revision: 723
This commit is contained in:
Jason Ge 2011-07-23 17:09:03 -07:00
parent 9d94ea9fdf
commit 4dc6552af9
5 changed files with 195 additions and 0 deletions

View file

@ -193,6 +193,7 @@ phutil_register_library_map(array(
'DiffusionChangeController' => 'applications/diffusion/controller/change',
'DiffusionCommitChangeTableView' => 'applications/diffusion/view/commitchangetable',
'DiffusionCommitController' => 'applications/diffusion/controller/commit',
'DiffusionCommitListController' => 'applications/diffusion/controller/commitlist',
'DiffusionController' => 'applications/diffusion/controller/base',
'DiffusionDiffController' => 'applications/diffusion/controller/diff',
'DiffusionDiffQuery' => 'applications/diffusion/query/diff/base',
@ -781,6 +782,7 @@ phutil_register_library_map(array(
'DiffusionChangeController' => 'DiffusionController',
'DiffusionCommitChangeTableView' => 'DiffusionView',
'DiffusionCommitController' => 'DiffusionController',
'DiffusionCommitListController' => 'DiffusionController',
'DiffusionController' => 'PhabricatorController',
'DiffusionDiffController' => 'DiffusionController',
'DiffusionGitBranchQuery' => 'DiffusionBranchQuery',

View file

@ -246,6 +246,10 @@ class AphrontDefaultApplicationConfiguration
'validate/$' => 'DiffusionPathValidateController',
),
),
'author/' => array(
'$' => 'DiffusionCommitListController',
'(?P<username>\w+)/$' => 'DiffusionCommitListController',
),
),
'/daemon/' => array(

View file

@ -0,0 +1,144 @@
<?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 DiffusionCommitListController extends DiffusionController {
private $username;
public function willProcessRequest(array $data) {
if (isset($data['username'])) {
$this->username = $data['username'];
}
}
public function processRequest() {
$request = $this->getRequest();
if ($this->username) {
$user = id(new PhabricatorUser())->loadOneWhere(
'username = %s',
$this->username);
} else {
$user = $request->getUser();
}
$content = array();
if (!$user) {
$error_view = new AphrontErrorView();
$error_view->setSeverity(AphrontErrorView::SEVERITY_ERROR);
$error_body = 'User name '.
'<b>'.phutil_escape_html($this->username).'</b>'.
' doesn\'t exist.';
$error_view->setTitle("Error");
$error_view->appendChild('<p>'.$error_body.'</p>');
$content[] = $error_view;
} else {
$pager = new AphrontPagerView();
$pager->setOffset($request->getInt('offset'));
$pager->setURI($request->getRequestURI(), 'offset');
$query = new PhabricatorSearchQuery();
$query->setParameter('type', PhabricatorPHIDConstants::PHID_TYPE_CMIT);
$query->setParameter('author', array($user->getPHID()));
$query->setParameter('limit', $pager->getPageSize() + 1);
$query->setParameter('offset', $pager->getOffset());
$user_link = phutil_render_tag(
'a',
array(
'href' => '/p/'.$user->getUsername().'/',
),
phutil_escape_html($user->getUsername()));
$executor = new PhabricatorSearchMySQLExecutor();
$results = $executor->executeSearch($query);
$results = $pager->sliceResults($results);
$result_phids = ipull($results, 'phid');
$commit_table = self::createCommitTable($result_phids, $user);
$list_panel = new AphrontPanelView();
$list_panel->setHeader('Commits by '.$user_link);
$list_panel->appendChild($commit_table);
$list_panel->appendChild($pager);
$content[] = $list_panel;
}
return $this->buildStandardPageResponse(
$content,
array(
'title' => 'Commit List',
));
}
/**
* @param array $commit_phids phids of the commits to render
* @param PhabricatorUser $user phabricator user
* @return AphrontTableView
*/
private static function createCommitTable(
array $commit_phids, PhabricatorUser $user) {
$loader = new PhabricatorObjectHandleData($commit_phids);
$handles = $loader->loadHandles();
$objects = $loader->loadObjects();
$rows = array();
foreach ($commit_phids as $phid) {
$handle = $handles[$phid];
$object = $objects[$phid];
$commit_data = $object->getCommitData();
$epoch = $handle->getTimeStamp();
$date = phabricator_date($epoch, $user);
$time = phabricator_time($epoch, $user);
$link = phutil_render_tag(
'a',
array(
'href' => $handle->getURI(),
),
phutil_escape_html($handle->getName()));
$rows[] = array(
$link,
$date,
$time,
phutil_escape_html($commit_data->getSummary()),
);
}
$commit_table = new AphrontTableView($rows);
$commit_table->setHeaders(
array(
'Commit',
'Date',
'Time',
'Summary',
));
$commit_table->setColumnClasses(
array(
'',
'',
'right',
'wide',
));
return $commit_table;
}
}

View file

@ -0,0 +1,25 @@
<?php
/**
* This file is automatically generated. Lint this module to rebuild it.
* @generated
*/
phutil_require_module('phabricator', 'applications/diffusion/controller/base');
phutil_require_module('phabricator', 'applications/people/storage/user');
phutil_require_module('phabricator', 'applications/phid/constants');
phutil_require_module('phabricator', 'applications/phid/handle/data');
phutil_require_module('phabricator', 'applications/search/execute/mysql');
phutil_require_module('phabricator', 'applications/search/storage/query');
phutil_require_module('phabricator', 'view/control/pager');
phutil_require_module('phabricator', 'view/control/table');
phutil_require_module('phabricator', 'view/form/error');
phutil_require_module('phabricator', 'view/layout/panel');
phutil_require_module('phabricator', 'view/utils');
phutil_require_module('phutil', 'markup');
phutil_require_module('phutil', 'utils');
phutil_require_source('DiffusionCommitListController.php');

View file

@ -141,6 +141,14 @@ class PhabricatorPeopleProfileController extends PhabricatorPeopleController {
$engine = PhabricatorMarkupEngine::newProfileMarkupEngine();
$blurb = $engine->markupText($blurb);
$commit_list =
phutil_render_tag(
'a',
array(
'href' => '/diffusion/author/'.
phutil_escape_uri($user->getUsername()),
),
'Recent Commits');
$content =
'<div class="phabricator-profile-info-group">
@ -170,6 +178,18 @@ class PhabricatorPeopleProfileController extends PhabricatorPeopleController {
</table>
</div>
</div>';
$content .=
'<div class="phabricator-profile-info-group">
<h1 class="phabricator-profile-info-header">Recent Activities</h1>
<div class="phabricator-profile-info-pane">
<table class="phabricator-profile-info-table">
<tr>
<th>Commits</th>
<td>'.$commit_list.'</td>
</tr>
</table>
</div>
</div>';
return $content;
}