2011-03-08 00:13:36 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2012-03-10 00:46:25 +01:00
|
|
|
* Copyright 2012 Facebook, Inc.
|
2011-03-08 00:13:36 +01:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2012-03-10 00:46:25 +01:00
|
|
|
final class DiffusionHomeController extends DiffusionController {
|
2011-03-08 00:13:36 +01:00
|
|
|
|
|
|
|
public function processRequest() {
|
2011-06-18 22:07:02 +02:00
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
2011-03-08 00:13:36 +01:00
|
|
|
|
2011-03-31 09:33:44 +02:00
|
|
|
$shortcuts = id(new PhabricatorRepositoryShortcut())->loadAll();
|
|
|
|
if ($shortcuts) {
|
|
|
|
$shortcuts = msort($shortcuts, 'getSequence');
|
|
|
|
|
|
|
|
$rows = array();
|
|
|
|
foreach ($shortcuts as $shortcut) {
|
|
|
|
$rows[] = array(
|
|
|
|
phutil_render_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => $shortcut->getHref(),
|
|
|
|
),
|
|
|
|
phutil_escape_html($shortcut->getName())),
|
|
|
|
phutil_escape_html($shortcut->getDescription()),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$shortcut_table = new AphrontTableView($rows);
|
|
|
|
$shortcut_table->setHeaders(
|
|
|
|
array(
|
|
|
|
'Link',
|
|
|
|
'',
|
|
|
|
));
|
|
|
|
$shortcut_table->setColumnClasses(
|
|
|
|
array(
|
|
|
|
'pri',
|
|
|
|
'wide',
|
|
|
|
));
|
|
|
|
|
|
|
|
$shortcut_panel = new AphrontPanelView();
|
|
|
|
$shortcut_panel->setHeader('Shortcuts');
|
|
|
|
$shortcut_panel->appendChild($shortcut_table);
|
|
|
|
} else {
|
|
|
|
$shortcut_panel = null;
|
|
|
|
}
|
2011-03-08 00:13:36 +01:00
|
|
|
|
2011-03-21 01:46:02 +01:00
|
|
|
$repository = new PhabricatorRepository();
|
|
|
|
|
|
|
|
$repositories = $repository->loadAll();
|
2011-03-15 21:38:14 +01:00
|
|
|
foreach ($repositories as $key => $repository) {
|
2011-09-16 20:42:45 +02:00
|
|
|
if (!$repository->isTracked()) {
|
2011-03-15 21:38:14 +01:00
|
|
|
unset($repositories[$key]);
|
|
|
|
}
|
|
|
|
}
|
2011-03-08 00:13:36 +01:00
|
|
|
|
2011-03-21 01:46:02 +01:00
|
|
|
$repository_ids = mpull($repositories, 'getID');
|
|
|
|
$summaries = array();
|
2011-03-13 07:51:40 +01:00
|
|
|
$commits = array();
|
2011-03-21 01:46:02 +01:00
|
|
|
if ($repository_ids) {
|
|
|
|
$summaries = queryfx_all(
|
|
|
|
$repository->establishConnection('r'),
|
|
|
|
'SELECT * FROM %T WHERE repositoryID IN (%Ld)',
|
|
|
|
PhabricatorRepository::TABLE_SUMMARY,
|
|
|
|
$repository_ids);
|
|
|
|
$summaries = ipull($summaries, null, 'repositoryID');
|
|
|
|
|
|
|
|
$commit_ids = array_filter(ipull($summaries, 'lastCommitID'));
|
|
|
|
if ($commit_ids) {
|
|
|
|
$commit = new PhabricatorRepositoryCommit();
|
|
|
|
$commits = $commit->loadAllWhere('id IN (%Ld)', $commit_ids);
|
|
|
|
$commits = mpull($commits, null, 'getRepositoryID');
|
2011-03-13 07:51:40 +01:00
|
|
|
}
|
|
|
|
}
|
2011-03-08 00:13:36 +01:00
|
|
|
|
|
|
|
$rows = array();
|
|
|
|
foreach ($repositories as $repository) {
|
2011-03-13 07:51:40 +01:00
|
|
|
$id = $repository->getID();
|
|
|
|
$commit = idx($commits, $id);
|
2011-03-21 01:46:02 +01:00
|
|
|
|
|
|
|
$size = idx(idx($summaries, $id, array()), 'size', 0);
|
|
|
|
|
|
|
|
$date = '-';
|
|
|
|
$time = '-';
|
2011-03-13 07:51:40 +01:00
|
|
|
if ($commit) {
|
2011-06-18 22:07:02 +02:00
|
|
|
$date = phabricator_date($commit->getEpoch(), $user);
|
|
|
|
$time = phabricator_time($commit->getEpoch(), $user);
|
2011-03-13 07:51:40 +01:00
|
|
|
}
|
|
|
|
|
2011-03-08 00:13:36 +01:00
|
|
|
$rows[] = array(
|
|
|
|
phutil_render_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
2011-03-13 01:17:34 +01:00
|
|
|
'href' => '/diffusion/'.$repository->getCallsign().'/',
|
2011-03-08 00:13:36 +01:00
|
|
|
),
|
|
|
|
phutil_escape_html($repository->getName())),
|
2011-04-02 02:11:05 +02:00
|
|
|
phutil_escape_html($repository->getDetail('description')),
|
2011-03-15 21:38:14 +01:00
|
|
|
PhabricatorRepositoryType::getNameForRepositoryType(
|
|
|
|
$repository->getVersionControlSystem()),
|
2011-03-21 01:46:02 +01:00
|
|
|
$size ? number_format($size) : '-',
|
2011-03-08 00:13:36 +01:00
|
|
|
$commit
|
2011-03-13 07:51:40 +01:00
|
|
|
? DiffusionView::linkCommit(
|
|
|
|
$repository,
|
|
|
|
$commit->getCommitIdentifier())
|
2011-03-21 01:46:02 +01:00
|
|
|
: '-',
|
2011-03-13 07:51:40 +01:00
|
|
|
$date,
|
|
|
|
$time,
|
2011-03-08 00:13:36 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$table = new AphrontTableView($rows);
|
|
|
|
$table->setHeaders(
|
|
|
|
array(
|
|
|
|
'Repository',
|
2011-04-02 02:11:05 +02:00
|
|
|
'Description',
|
2011-03-08 00:13:36 +01:00
|
|
|
'VCS',
|
|
|
|
'Size',
|
|
|
|
'Last',
|
2011-03-13 07:51:40 +01:00
|
|
|
'Date',
|
|
|
|
'Time',
|
2011-03-08 00:13:36 +01:00
|
|
|
));
|
|
|
|
$table->setColumnClasses(
|
|
|
|
array(
|
2011-04-02 02:11:05 +02:00
|
|
|
'pri',
|
2011-03-08 00:13:36 +01:00
|
|
|
'wide',
|
2011-03-13 07:51:40 +01:00
|
|
|
'',
|
|
|
|
'n',
|
|
|
|
'n',
|
|
|
|
'',
|
|
|
|
'right',
|
2011-03-08 00:13:36 +01:00
|
|
|
));
|
|
|
|
|
|
|
|
$panel = new AphrontPanelView();
|
|
|
|
$panel->setHeader('Browse Repositories');
|
|
|
|
$panel->appendChild($table);
|
|
|
|
|
2011-03-13 01:17:34 +01:00
|
|
|
$crumbs = $this->buildCrumbs();
|
|
|
|
|
2011-03-08 00:13:36 +01:00
|
|
|
return $this->buildStandardPageResponse(
|
2011-03-13 01:17:34 +01:00
|
|
|
array(
|
|
|
|
$crumbs,
|
2011-03-31 09:33:44 +02:00
|
|
|
$shortcut_panel,
|
2011-03-13 01:17:34 +01:00
|
|
|
$panel,
|
|
|
|
),
|
2011-03-08 00:13:36 +01:00
|
|
|
array(
|
|
|
|
'title' => 'Diffusion',
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|