2011-03-08 00:13:36 +01:00
|
|
|
<?php
|
|
|
|
|
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(
|
2013-01-18 03:43:35 +01:00
|
|
|
phutil_tag(
|
2011-03-31 09:33:44 +02:00
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => $shortcut->getHref(),
|
|
|
|
),
|
2013-01-18 03:43:35 +01:00
|
|
|
$shortcut->getName()),
|
2011-03-31 09:33:44 +02:00
|
|
|
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
|
|
|
|
2012-12-19 20:07:06 +01:00
|
|
|
$repositories = id(new PhabricatorRepositoryQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->execute();
|
2011-03-21 01:46:02 +01:00
|
|
|
|
2012-03-29 22:24:06 +02:00
|
|
|
foreach ($repositories as $key => $repo) {
|
|
|
|
if (!$repo->isTracked()) {
|
2012-04-03 22:54:01 +02:00
|
|
|
unset($repositories[$key]);
|
2011-03-15 21:38:14 +01:00
|
|
|
}
|
|
|
|
}
|
2013-01-16 19:51:08 +01:00
|
|
|
$repositories = msort($repositories, 'getName');
|
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(
|
2012-12-19 20:07:06 +01:00
|
|
|
id(new PhabricatorRepository())->establishConnection('r'),
|
2011-03-21 01:46:02 +01:00
|
|
|
'SELECT * FROM %T WHERE repositoryID IN (%Ld)',
|
|
|
|
PhabricatorRepository::TABLE_SUMMARY,
|
|
|
|
$repository_ids);
|
2012-12-19 20:07:06 +01:00
|
|
|
$summaries = ipull($summaries, null, 'repositoryID');
|
2011-03-21 01:46:02 +01:00
|
|
|
|
|
|
|
$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
|
|
|
|
2012-11-08 03:11:52 +01:00
|
|
|
$branch = new PhabricatorRepositoryBranch();
|
|
|
|
$lint_messages = queryfx_all(
|
|
|
|
$branch->establishConnection('r'),
|
|
|
|
'SELECT b.repositoryID, b.name, COUNT(lm.id) AS n
|
|
|
|
FROM %T b
|
|
|
|
LEFT JOIN %T lm ON b.id = lm.branchID
|
|
|
|
GROUP BY b.id',
|
|
|
|
$branch->getTableName(),
|
|
|
|
PhabricatorRepository::TABLE_LINTMESSAGE);
|
|
|
|
$lint_messages = igroup($lint_messages, 'repositoryID');
|
|
|
|
|
2011-03-08 00:13:36 +01:00
|
|
|
$rows = array();
|
2012-11-08 03:11:52 +01:00
|
|
|
$show_lint = false;
|
2011-03-08 00:13:36 +01:00
|
|
|
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
|
|
|
|
2012-11-08 22:45:21 +01:00
|
|
|
$size = idx(idx($summaries, $id, array()), 'size', '-');
|
|
|
|
if ($size != '-') {
|
|
|
|
$size = hsprintf(
|
|
|
|
'<a href="%s">%s</a>',
|
|
|
|
DiffusionRequest::generateDiffusionURI(array(
|
|
|
|
'callsign' => $repository->getCallsign(),
|
|
|
|
'action' => 'history',
|
|
|
|
)),
|
|
|
|
number_format($size));
|
|
|
|
}
|
2011-03-21 01:46:02 +01:00
|
|
|
|
2012-11-08 20:11:44 +01:00
|
|
|
$lint_count = '';
|
2012-11-08 03:11:52 +01:00
|
|
|
$lint_branches = ipull(idx($lint_messages, $id, array()), 'n', 'name');
|
|
|
|
$branch = $repository->getDefaultArcanistBranch();
|
|
|
|
if (isset($lint_branches[$branch])) {
|
|
|
|
$show_lint = true;
|
2013-01-18 09:32:58 +01:00
|
|
|
$lint_count = phutil_tag(
|
2012-11-08 20:11:44 +01:00
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => DiffusionRequest::generateDiffusionURI(array(
|
|
|
|
'callsign' => $repository->getCallsign(),
|
|
|
|
'action' => 'lint',
|
|
|
|
)),
|
|
|
|
),
|
|
|
|
number_format($lint_branches[$branch]));
|
2012-11-08 03:11:52 +01:00
|
|
|
}
|
|
|
|
|
2011-03-21 01:46:02 +01:00
|
|
|
$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(
|
2013-01-18 03:43:35 +01:00
|
|
|
phutil_tag(
|
2011-03-08 00:13:36 +01:00
|
|
|
'a',
|
|
|
|
array(
|
2011-03-13 01:17:34 +01:00
|
|
|
'href' => '/diffusion/'.$repository->getCallsign().'/',
|
2011-03-08 00:13:36 +01:00
|
|
|
),
|
2013-01-18 03:43:35 +01:00
|
|
|
$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()),
|
2012-11-08 22:45:21 +01:00
|
|
|
$size,
|
2012-11-08 20:11:44 +01:00
|
|
|
$lint_count,
|
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
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-07-30 18:09:40 +02:00
|
|
|
$repository_tool_uri = PhabricatorEnv::getProductionURI('/repository/');
|
2013-01-18 03:57:09 +01:00
|
|
|
$repository_tool = phutil_tag('a',
|
2012-07-30 18:09:40 +02:00
|
|
|
array(
|
|
|
|
'href' => $repository_tool_uri,
|
|
|
|
),
|
|
|
|
'repository tool');
|
|
|
|
$no_repositories_txt = 'This instance of Phabricator does not have any '.
|
|
|
|
'configured repositories. ';
|
|
|
|
if ($user->getIsAdmin()) {
|
|
|
|
$no_repositories_txt .= 'To setup one or more repositories, visit the '.
|
|
|
|
$repository_tool.'.';
|
|
|
|
} else {
|
|
|
|
$no_repositories_txt .= 'Ask an administrator to setup one or more '.
|
|
|
|
'repositories via the '.$repository_tool.'.';
|
|
|
|
}
|
|
|
|
|
2011-03-08 00:13:36 +01:00
|
|
|
$table = new AphrontTableView($rows);
|
2012-07-30 18:09:40 +02:00
|
|
|
$table->setNoDataString($no_repositories_txt);
|
2011-03-08 00:13:36 +01:00
|
|
|
$table->setHeaders(
|
|
|
|
array(
|
|
|
|
'Repository',
|
2011-04-02 02:11:05 +02:00
|
|
|
'Description',
|
2011-03-08 00:13:36 +01:00
|
|
|
'VCS',
|
2012-03-21 22:07:17 +01:00
|
|
|
'Commits',
|
2012-11-08 03:11:52 +01:00
|
|
|
'Lint',
|
2011-03-08 00:13:36 +01:00
|
|
|
'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',
|
2012-11-08 03:11:52 +01:00
|
|
|
'n',
|
2011-03-13 07:51:40 +01:00
|
|
|
'',
|
|
|
|
'right',
|
2011-03-08 00:13:36 +01:00
|
|
|
));
|
2012-11-08 03:11:52 +01:00
|
|
|
$table->setColumnVisibility(
|
|
|
|
array(
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
$show_lint,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
));
|
2011-03-08 00:13:36 +01:00
|
|
|
|
|
|
|
$panel = new AphrontPanelView();
|
|
|
|
$panel->setHeader('Browse Repositories');
|
|
|
|
$panel->appendChild($table);
|
2013-01-15 01:40:04 +01:00
|
|
|
$panel->setNoBackground();
|
2011-03-08 00:13:36 +01:00
|
|
|
|
2011-03-13 01:17:34 +01:00
|
|
|
$crumbs = $this->buildCrumbs();
|
2012-12-13 03:40:18 +01:00
|
|
|
$crumbs->addCrumb(
|
|
|
|
id(new PhabricatorCrumbView())
|
|
|
|
->setName(pht('All Repositories'))
|
|
|
|
->setHref($this->getApplicationURI()));
|
2011-03-13 01:17:34 +01:00
|
|
|
|
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',
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|