mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-27 01:02:42 +01:00
Add a paginated list of all repository tags to Diffusion
Summary: Now supports more than 25 tags! Test Plan: Set page size to 1, paginated. Verified SVN / Hg don't break/explode. Reviewers: davidreuss, vrana, btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T1130 Differential Revision: https://secure.phabricator.com/D2268
This commit is contained in:
parent
9be054443f
commit
944049d871
10 changed files with 167 additions and 7 deletions
|
@ -365,6 +365,7 @@ phutil_register_library_map(array(
|
|||
'DiffusionSvnTagListQuery' => 'applications/diffusion/query/taglist/svn',
|
||||
'DiffusionSymbolController' => 'applications/diffusion/controller/symbol',
|
||||
'DiffusionSymbolQuery' => 'applications/diffusion/query/symbol',
|
||||
'DiffusionTagListController' => 'applications/diffusion/controller/taglist',
|
||||
'DiffusionTagListQuery' => 'applications/diffusion/query/taglist/base',
|
||||
'DiffusionTagListView' => 'applications/diffusion/view/taglist',
|
||||
'DiffusionURITestCase' => 'applications/diffusion/request/base/__tests__',
|
||||
|
@ -1314,6 +1315,7 @@ phutil_register_library_map(array(
|
|||
'DiffusionSvnRequest' => 'DiffusionRequest',
|
||||
'DiffusionSvnTagListQuery' => 'DiffusionTagListQuery',
|
||||
'DiffusionSymbolController' => 'DiffusionController',
|
||||
'DiffusionTagListController' => 'DiffusionController',
|
||||
'DiffusionTagListQuery' => 'DiffusionQuery',
|
||||
'DiffusionTagListView' => 'DiffusionView',
|
||||
'DiffusionURITestCase' => 'ArcanistPhutilTestCase',
|
||||
|
|
|
@ -260,6 +260,7 @@ class AphrontDefaultApplicationConfiguration
|
|||
'browse/(?P<dblob>.*)' => 'DiffusionBrowseController',
|
||||
'lastmodified/(?P<dblob>.*)' => 'DiffusionLastModifiedController',
|
||||
'diff/' => 'DiffusionDiffController',
|
||||
'tags/(?P<dblob>.*)' => 'DiffusionTagListController',
|
||||
),
|
||||
'inline/(?P<phid>[^/]+)/' => 'DiffusionInlineCommentController',
|
||||
'services/' => array(
|
||||
|
|
|
@ -161,6 +161,12 @@ abstract class DiffusionController extends PhabricatorController {
|
|||
|
||||
private function buildCrumbList(array $spec = array()) {
|
||||
|
||||
$spec = $spec + array(
|
||||
'commit' => null,
|
||||
'tags' => null,
|
||||
'view' => null,
|
||||
);
|
||||
|
||||
$crumb_list = array();
|
||||
|
||||
// On the home page, we don't have a DiffusionRequest.
|
||||
|
@ -187,14 +193,14 @@ abstract class DiffusionController extends PhabricatorController {
|
|||
$callsign = $repository->getCallsign();
|
||||
$repository_name = phutil_escape_html($repository->getName()).' Repository';
|
||||
|
||||
if (empty($spec['commit'])) {
|
||||
if (!$spec['commit'] && !$spec['tags']) {
|
||||
$branch_name = $drequest->getBranch();
|
||||
if ($branch_name) {
|
||||
$repository_name .= ' ('.phutil_escape_html($branch_name).')';
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($spec['view']) && empty($spec['commit'])) {
|
||||
if (!$spec['view'] && !$spec['commit'] && !$spec['tags']) {
|
||||
$crumb_list[] = $repository_name;
|
||||
return $crumb_list;
|
||||
}
|
||||
|
@ -207,11 +213,16 @@ abstract class DiffusionController extends PhabricatorController {
|
|||
$repository_name);
|
||||
|
||||
$raw_commit = $drequest->getRawCommit();
|
||||
if (isset($spec['commit'])) {
|
||||
if ($spec['commit']) {
|
||||
$crumb_list[] = "r{$callsign}{$raw_commit}";
|
||||
return $crumb_list;
|
||||
}
|
||||
|
||||
if ($spec['tags']) {
|
||||
$crumb_list[] = 'Tags';
|
||||
return $crumb_list;
|
||||
}
|
||||
|
||||
$view = $spec['view'];
|
||||
|
||||
$path = null;
|
||||
|
|
|
@ -155,14 +155,19 @@ final class DiffusionRepositoryController extends DiffusionController {
|
|||
}
|
||||
|
||||
private function buildTagListTable(DiffusionRequest $drequest) {
|
||||
$tag_limit = 25;
|
||||
|
||||
$query = DiffusionTagListQuery::newFromDiffusionRequest($drequest);
|
||||
$query->setLimit(25);
|
||||
$query->setLimit($tag_limit + 1);
|
||||
$tags = $query->loadTags();
|
||||
|
||||
if (!$tags) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$more_tags = (count($tags) > $tag_limit);
|
||||
$tags = array_slice($tags, 0, $tag_limit);
|
||||
|
||||
$commits = id(new PhabricatorAuditCommitQuery())
|
||||
->withIdentifiers(
|
||||
$drequest->getRepository()->getID(),
|
||||
|
@ -182,6 +187,22 @@ final class DiffusionRepositoryController extends DiffusionController {
|
|||
|
||||
$panel = new AphrontPanelView();
|
||||
$panel->setHeader('Tags');
|
||||
|
||||
if ($more_tags) {
|
||||
$panel->setCaption('Showing the '.$tag_limit.' most recent tags.');
|
||||
}
|
||||
|
||||
$panel->addButton(
|
||||
phutil_render_tag(
|
||||
'a',
|
||||
array(
|
||||
'href' => $drequest->generateURI(
|
||||
array(
|
||||
'action' => 'tags',
|
||||
)),
|
||||
'class' => 'grey button',
|
||||
),
|
||||
"Show All Tags \xC2\xBB"));
|
||||
$panel->appendChild($view);
|
||||
|
||||
return $panel;
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2012 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.
|
||||
*/
|
||||
|
||||
final class DiffusionTagListController extends DiffusionController {
|
||||
|
||||
public function processRequest() {
|
||||
$drequest = $this->getDiffusionRequest();
|
||||
$request = $this->getRequest();
|
||||
$user = $request->getUser();
|
||||
|
||||
$repository = $drequest->getRepository();
|
||||
|
||||
$pager = new AphrontPagerView();
|
||||
$pager->setURI($request->getRequestURI(), 'offset');
|
||||
$pager->setOffset($request->getInt('offset'));
|
||||
|
||||
$query = DiffusionTagListQuery::newFromDiffusionRequest($drequest);
|
||||
$query->setOffset($pager->getOffset());
|
||||
$query->setLimit($pager->getPageSize() + 1);
|
||||
$tags = $query->loadTags();
|
||||
$tags = $pager->sliceResults($tags);
|
||||
|
||||
$content = null;
|
||||
if (!$tags) {
|
||||
$content = new AphrontErrorView();
|
||||
$content->setTitle('No Tags');
|
||||
$content->appendChild('This repository has no tags.');
|
||||
$content->setSeverity(AphrontErrorView::SEVERITY_NODATA);
|
||||
} else {
|
||||
$commits = id(new PhabricatorAuditCommitQuery())
|
||||
->withIdentifiers(
|
||||
$drequest->getRepository()->getID(),
|
||||
mpull($tags, 'getCommitIdentifier'))
|
||||
->needCommitData(true)
|
||||
->execute();
|
||||
|
||||
$view = id(new DiffusionTagListView())
|
||||
->setTags($tags)
|
||||
->setUser($user)
|
||||
->setCommits($commits)
|
||||
->setDiffusionRequest($drequest);
|
||||
|
||||
$phids = $view->getRequiredHandlePHIDs();
|
||||
$handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
|
||||
$view->setHandles($handles);
|
||||
|
||||
$panel = id(new AphrontPanelView())
|
||||
->setHeader('Tags')
|
||||
->appendChild($view)
|
||||
->appendChild($pager);
|
||||
|
||||
$content = $panel;
|
||||
}
|
||||
|
||||
return $this->buildStandardPageResponse(
|
||||
array(
|
||||
$this->buildCrumbs(array('tags' => true)),
|
||||
$content,
|
||||
),
|
||||
array(
|
||||
'title' => array(
|
||||
'Tags',
|
||||
$repository->getCallsign().' Repository',
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
}
|
21
src/applications/diffusion/controller/taglist/__init__.php
Normal file
21
src/applications/diffusion/controller/taglist/__init__.php
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'applications/audit/query/commit');
|
||||
phutil_require_module('phabricator', 'applications/diffusion/controller/base');
|
||||
phutil_require_module('phabricator', 'applications/diffusion/query/taglist/base');
|
||||
phutil_require_module('phabricator', 'applications/diffusion/view/taglist');
|
||||
phutil_require_module('phabricator', 'applications/phid/handle/data');
|
||||
phutil_require_module('phabricator', 'view/control/pager');
|
||||
phutil_require_module('phabricator', 'view/form/error');
|
||||
phutil_require_module('phabricator', 'view/layout/panel');
|
||||
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
||||
|
||||
phutil_require_source('DiffusionTagListController.php');
|
|
@ -19,6 +19,16 @@
|
|||
abstract class DiffusionTagListQuery extends DiffusionQuery {
|
||||
|
||||
private $limit;
|
||||
private $offset;
|
||||
|
||||
public function setOffset($offset) {
|
||||
$this->offset = $offset;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getOffset() {
|
||||
return $this->offset;
|
||||
}
|
||||
|
||||
public function setLimit($limit) {
|
||||
$this->limit = $limit;
|
||||
|
|
|
@ -22,11 +22,11 @@ final class DiffusionGitTagListQuery extends DiffusionTagListQuery {
|
|||
$drequest = $this->getRequest();
|
||||
$repository = $drequest->getRepository();
|
||||
|
||||
$limit = $this->getLimit();
|
||||
$count = $this->getOffset() + $this->getLimit();
|
||||
|
||||
list($stdout) = $repository->execxLocalCommand(
|
||||
'for-each-ref %C --sort=-creatordate --format=%s refs/tags',
|
||||
$limit ? '--count='.(int)$limit : null,
|
||||
$count ? '--count='.(int)$count : null,
|
||||
'%(objectname) %(objecttype) %(refname) %(*objectname) %(*objecttype) '.
|
||||
'%(subject)%01%(creator)'
|
||||
);
|
||||
|
@ -67,6 +67,11 @@ final class DiffusionGitTagListQuery extends DiffusionTagListQuery {
|
|||
$tags[] = $tag;
|
||||
}
|
||||
|
||||
$offset = $this->getOffset();
|
||||
if ($offset) {
|
||||
$tags = array_slice($tags, $offset);
|
||||
}
|
||||
|
||||
return $tags;
|
||||
}
|
||||
|
||||
|
|
|
@ -355,6 +355,7 @@ abstract class DiffusionRequest {
|
|||
case 'browse':
|
||||
case 'change':
|
||||
case 'lastmodified':
|
||||
case 'tags':
|
||||
$req_callsign = true;
|
||||
break;
|
||||
case 'branch':
|
||||
|
@ -387,6 +388,7 @@ abstract class DiffusionRequest {
|
|||
case 'history':
|
||||
case 'browse':
|
||||
case 'lastmodified':
|
||||
case 'tags':
|
||||
$uri = "/diffusion/{$callsign}{$action}/{$path}{$commit}{$line}";
|
||||
break;
|
||||
case 'branch':
|
||||
|
|
|
@ -26,7 +26,11 @@ abstract class AphrontPageView extends AphrontView {
|
|||
}
|
||||
|
||||
public function getTitle() {
|
||||
return $this->title;
|
||||
$title = $this->title;
|
||||
if (is_array($title)) {
|
||||
$title = implode(" \xC2\xB7 ", $title);
|
||||
}
|
||||
return $title;
|
||||
}
|
||||
|
||||
protected function getHead() {
|
||||
|
|
Loading…
Reference in a new issue