mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-29 18:22:41 +01:00
Mostly modernize lint views and delete dead code
Summary: This is a mostly-faithful modernization of the Diffusion lint interfaces. It: - Makes them policy aware; - removes the last callsites for old/dead code (crumbs, nav). It's a little rough, but should be perfectly usable. At some point this should get another pass, but probably after we make it easier to populate the lint data. Test Plan: See screenshots. Reviewers: btrahan Reviewed By: btrahan CC: aran, FacebookPOC Differential Revision: https://secure.phabricator.com/D7065
This commit is contained in:
parent
0271b051ae
commit
bfa2abed84
3 changed files with 140 additions and 164 deletions
|
@ -25,53 +25,6 @@ abstract class DiffusionController extends PhabricatorController {
|
||||||
return $this->diffusionRequest;
|
return $this->diffusionRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
final protected function buildSideNav($selected, $has_change_view) {
|
|
||||||
$nav = new AphrontSideNavFilterView();
|
|
||||||
$nav->setBaseURI(new PhutilURI(''));
|
|
||||||
|
|
||||||
$navs = array(
|
|
||||||
'history' => pht('History View'),
|
|
||||||
'browse' => pht('Browse View'),
|
|
||||||
'change' => pht('Change View'),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!$has_change_view) {
|
|
||||||
unset($navs['change']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$drequest = $this->getDiffusionRequest();
|
|
||||||
$branch = $drequest->loadBranch();
|
|
||||||
|
|
||||||
if ($branch && $branch->getLintCommit()) {
|
|
||||||
$navs['lint'] = pht('Lint View');
|
|
||||||
}
|
|
||||||
|
|
||||||
$selected_href = null;
|
|
||||||
foreach ($navs as $action => $name) {
|
|
||||||
$href = $drequest->generateURI(
|
|
||||||
array(
|
|
||||||
'action' => $action,
|
|
||||||
));
|
|
||||||
if ($action == $selected) {
|
|
||||||
$selected_href = $href;
|
|
||||||
}
|
|
||||||
|
|
||||||
$nav->addFilter($href, $name, $href);
|
|
||||||
}
|
|
||||||
$nav->selectFilter($selected_href, null);
|
|
||||||
|
|
||||||
// TODO: URI encoding might need to be sorted out for this link.
|
|
||||||
|
|
||||||
$nav->addFilter(
|
|
||||||
'',
|
|
||||||
pht("Search Owners \xE2\x86\x97"),
|
|
||||||
'/owners/view/search/'.
|
|
||||||
'?repository='.phutil_escape_uri($drequest->getCallsign()).
|
|
||||||
'&path='.phutil_escape_uri('/'.$drequest->getPath()));
|
|
||||||
|
|
||||||
return $nav;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function buildCrumbs(array $spec = array()) {
|
public function buildCrumbs(array $spec = array()) {
|
||||||
$crumbs = $this->buildApplicationCrumbs();
|
$crumbs = $this->buildApplicationCrumbs();
|
||||||
$crumb_list = $this->buildCrumbList($spec);
|
$crumb_list = $this->buildCrumbList($spec);
|
||||||
|
@ -167,19 +120,6 @@ abstract class DiffusionController extends PhabricatorController {
|
||||||
$crumb = new PhabricatorCrumbView();
|
$crumb = new PhabricatorCrumbView();
|
||||||
$view = $spec['view'];
|
$view = $spec['view'];
|
||||||
|
|
||||||
$path = null;
|
|
||||||
if (isset($spec['path'])) {
|
|
||||||
$path = $drequest->getPath();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($raw_commit) {
|
|
||||||
$commit_link = DiffusionView::linkCommit(
|
|
||||||
$repository,
|
|
||||||
$raw_commit);
|
|
||||||
} else {
|
|
||||||
$commit_link = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
switch ($view) {
|
switch ($view) {
|
||||||
case 'history':
|
case 'history':
|
||||||
$view_name = pht('History');
|
$view_name = pht('History');
|
||||||
|
@ -195,74 +135,10 @@ abstract class DiffusionController extends PhabricatorController {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$uri_params = array(
|
|
||||||
'action' => $view,
|
|
||||||
);
|
|
||||||
|
|
||||||
$crumb = id(new PhabricatorCrumbView())
|
$crumb = id(new PhabricatorCrumbView())
|
||||||
->setName($view_name);
|
->setName($view_name);
|
||||||
|
|
||||||
if ($view == 'browse' || $view == 'change' || $view == 'history') {
|
|
||||||
$crumb_list[] = $crumb;
|
|
||||||
return $crumb_list;
|
|
||||||
}
|
|
||||||
|
|
||||||
$crumb->setHref($drequest->generateURI(
|
|
||||||
array(
|
|
||||||
'path' => '',
|
|
||||||
) + $uri_params));
|
|
||||||
$crumb_list[] = $crumb;
|
$crumb_list[] = $crumb;
|
||||||
|
|
||||||
$path_parts = explode('/', $path);
|
|
||||||
do {
|
|
||||||
$last = array_pop($path_parts);
|
|
||||||
} while (count($path_parts) && $last == '');
|
|
||||||
|
|
||||||
$path_sections = array();
|
|
||||||
$thus_far = '';
|
|
||||||
foreach ($path_parts as $path_part) {
|
|
||||||
$thus_far .= $path_part.'/';
|
|
||||||
$path_sections[] = '/';
|
|
||||||
$path_sections[] = phutil_tag(
|
|
||||||
'a',
|
|
||||||
array(
|
|
||||||
'href' => $drequest->generateURI(
|
|
||||||
array(
|
|
||||||
'path' => $thus_far,
|
|
||||||
) + $uri_params),
|
|
||||||
),
|
|
||||||
$path_part);
|
|
||||||
}
|
|
||||||
|
|
||||||
$path_sections[] = '/'.$last;
|
|
||||||
|
|
||||||
$crumb_list[] = id(new PhabricatorCrumbView())
|
|
||||||
->setName($path_sections);
|
|
||||||
|
|
||||||
$last_crumb = array_pop($crumb_list);
|
|
||||||
|
|
||||||
if ($raw_commit) {
|
|
||||||
$jump_link = phutil_tag(
|
|
||||||
'a',
|
|
||||||
array(
|
|
||||||
'href' => $drequest->generateURI(
|
|
||||||
array(
|
|
||||||
'commit' => '',
|
|
||||||
) + $uri_params),
|
|
||||||
),
|
|
||||||
pht('Jump to HEAD'));
|
|
||||||
|
|
||||||
$name = $last_crumb->getName();
|
|
||||||
$name = hsprintf('%s @ %s (%s)', $name, $commit_link, $jump_link);
|
|
||||||
$last_crumb->setName($name);
|
|
||||||
} else if ($spec['view'] != 'lint') {
|
|
||||||
$name = $last_crumb->getName();
|
|
||||||
$name = hsprintf('%s @ HEAD', $name);
|
|
||||||
$last_crumb->setName($name);
|
|
||||||
}
|
|
||||||
|
|
||||||
$crumb_list[] = $last_crumb;
|
|
||||||
|
|
||||||
return $crumb_list;
|
return $crumb_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,10 @@
|
||||||
|
|
||||||
final class DiffusionLintController extends DiffusionController {
|
final class DiffusionLintController extends DiffusionController {
|
||||||
|
|
||||||
|
public function shouldAllowPublic() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public function processRequest() {
|
public function processRequest() {
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
$user = $this->getRequest()->getUser();
|
$user = $this->getRequest()->getUser();
|
||||||
|
@ -17,7 +21,9 @@ final class DiffusionLintController extends DiffusionController {
|
||||||
$owners = array();
|
$owners = array();
|
||||||
if (!$drequest) {
|
if (!$drequest) {
|
||||||
if (!$request->getArr('owner')) {
|
if (!$request->getArr('owner')) {
|
||||||
$owners[$user->getPHID()] = $user->getFullName();
|
if ($user->isLoggedIn()) {
|
||||||
|
$owners[$user->getPHID()] = $user->getFullName();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$phids = $request->getArr('owner');
|
$phids = $request->getArr('owner');
|
||||||
$phid = reset($phids);
|
$phid = reset($phids);
|
||||||
|
@ -29,16 +35,23 @@ final class DiffusionLintController extends DiffusionController {
|
||||||
$codes = $this->loadLintCodes(array_keys($owners));
|
$codes = $this->loadLintCodes(array_keys($owners));
|
||||||
|
|
||||||
if ($codes && !$drequest) {
|
if ($codes && !$drequest) {
|
||||||
|
// TODO: Build some real Query classes for this stuff.
|
||||||
|
|
||||||
$branches = id(new PhabricatorRepositoryBranch())->loadAllWhere(
|
$branches = id(new PhabricatorRepositoryBranch())->loadAllWhere(
|
||||||
'id IN (%Ld)',
|
'id IN (%Ld)',
|
||||||
array_unique(ipull($codes, 'branchID')));
|
array_unique(ipull($codes, 'branchID')));
|
||||||
|
|
||||||
$repositories = id(new PhabricatorRepository())->loadAllWhere(
|
$repositories = id(new PhabricatorRepositoryQuery())
|
||||||
'id IN (%Ld)',
|
->setViewer($user)
|
||||||
array_unique(mpull($branches, 'getRepositoryID')));
|
->withIDs(mpull($branches, 'getRepositoryID'))
|
||||||
|
->execute();
|
||||||
|
|
||||||
$drequests = array();
|
$drequests = array();
|
||||||
foreach ($branches as $id => $branch) {
|
foreach ($branches as $id => $branch) {
|
||||||
|
if (empty($repositories[$branch->getRepositoryID()])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$drequests[$id] = DiffusionRequest::newFromDictionary(array(
|
$drequests[$id] = DiffusionRequest::newFromDictionary(array(
|
||||||
'user' => $user,
|
'user' => $user,
|
||||||
'repository' => $repositories[$branch->getRepositoryID()],
|
'repository' => $repositories[$branch->getRepositoryID()],
|
||||||
|
@ -48,11 +61,18 @@ final class DiffusionLintController extends DiffusionController {
|
||||||
}
|
}
|
||||||
|
|
||||||
$rows = array();
|
$rows = array();
|
||||||
|
$total = 0;
|
||||||
foreach ($codes as $code) {
|
foreach ($codes as $code) {
|
||||||
if (!$this->diffusionRequest) {
|
if (!$this->diffusionRequest) {
|
||||||
$drequest = $drequests[$code['branchID']];
|
$drequest = idx($drequests, $code['branchID']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!$drequest) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$total += $code['n'];
|
||||||
|
|
||||||
$rows[] = array(
|
$rows[] = array(
|
||||||
hsprintf(
|
hsprintf(
|
||||||
'<a href="%s">%s</a>',
|
'<a href="%s">%s</a>',
|
||||||
|
@ -95,16 +115,7 @@ final class DiffusionLintController extends DiffusionController {
|
||||||
$content = array();
|
$content = array();
|
||||||
|
|
||||||
$link = null;
|
$link = null;
|
||||||
if ($this->diffusionRequest) {
|
if (!$this->diffusionRequest) {
|
||||||
$link = hsprintf(
|
|
||||||
'<a href="%s">%s</a>',
|
|
||||||
$drequest->generateURI(array(
|
|
||||||
'action' => 'lint',
|
|
||||||
'lint' => '',
|
|
||||||
)),
|
|
||||||
pht('Switch to List View'));
|
|
||||||
|
|
||||||
} else {
|
|
||||||
$form = id(new AphrontFormView())
|
$form = id(new AphrontFormView())
|
||||||
->setUser($user)
|
->setUser($user)
|
||||||
->setMethod('GET')
|
->setMethod('GET')
|
||||||
|
@ -122,7 +133,7 @@ final class DiffusionLintController extends DiffusionController {
|
||||||
}
|
}
|
||||||
|
|
||||||
$content[] = id(new AphrontPanelView())
|
$content[] = id(new AphrontPanelView())
|
||||||
->setHeader(pht('%d Lint Message(s)', array_sum(ipull($codes, 'n'))))
|
->setNoBackground(true)
|
||||||
->setCaption($link)
|
->setCaption($link)
|
||||||
->appendChild($table);
|
->appendChild($table);
|
||||||
|
|
||||||
|
@ -133,21 +144,45 @@ final class DiffusionLintController extends DiffusionController {
|
||||||
'path' => true,
|
'path' => true,
|
||||||
'view' => 'lint',
|
'view' => 'lint',
|
||||||
));
|
));
|
||||||
|
|
||||||
if ($this->diffusionRequest) {
|
if ($this->diffusionRequest) {
|
||||||
$title[] = $drequest->getCallsign();
|
$title[] = $drequest->getCallsign();
|
||||||
$content = $this->buildSideNav('lint', false)
|
|
||||||
->setCrumbs($crumbs)
|
|
||||||
->appendChild($content);
|
|
||||||
} else {
|
} else {
|
||||||
array_unshift($content, $crumbs);
|
$crumbs->addCrumb(
|
||||||
|
id(new PhabricatorCrumbView())
|
||||||
|
->setName(pht('All Lint')));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->diffusionRequest) {
|
||||||
|
$branch = $drequest->loadBranch();
|
||||||
|
|
||||||
|
$header = id(new PHUIHeaderView())
|
||||||
|
->setHeader($this->renderPathLinks($drequest, 'lint'))
|
||||||
|
->setUser($user)
|
||||||
|
->setPolicyObject($drequest->getRepository());
|
||||||
|
$actions = $this->buildActionView($drequest);
|
||||||
|
$properties = $this->buildPropertyView(
|
||||||
|
$drequest,
|
||||||
|
$branch,
|
||||||
|
$total);
|
||||||
|
} else {
|
||||||
|
$header = null;
|
||||||
|
$actions = null;
|
||||||
|
$properties = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return $this->buildApplicationPage(
|
return $this->buildApplicationPage(
|
||||||
$content,
|
array(
|
||||||
|
$crumbs,
|
||||||
|
$header,
|
||||||
|
$actions,
|
||||||
|
$properties,
|
||||||
|
$content,
|
||||||
|
),
|
||||||
array(
|
array(
|
||||||
'title' => $title,
|
'title' => $title,
|
||||||
'device' => true,
|
));
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function loadLintCodes(array $owner_phids) {
|
private function loadLintCodes(array $owner_phids) {
|
||||||
|
@ -233,4 +268,81 @@ final class DiffusionLintController extends DiffusionController {
|
||||||
implode(' AND ', $where));
|
implode(' AND ', $where));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function buildActionView(DiffusionRequest $drequest) {
|
||||||
|
$viewer = $this->getRequest()->getUser();
|
||||||
|
|
||||||
|
$view = id(new PhabricatorActionListView())
|
||||||
|
->setUser($viewer);
|
||||||
|
|
||||||
|
$list_uri = $drequest->generateURI(
|
||||||
|
array(
|
||||||
|
'action' => 'lint',
|
||||||
|
'lint' => '',
|
||||||
|
));
|
||||||
|
|
||||||
|
$view->addAction(
|
||||||
|
id(new PhabricatorActionView())
|
||||||
|
->setName(pht('View As List'))
|
||||||
|
->setHref($list_uri)
|
||||||
|
->setIcon('transcript'));
|
||||||
|
|
||||||
|
$history_uri = $drequest->generateURI(
|
||||||
|
array(
|
||||||
|
'action' => 'history',
|
||||||
|
));
|
||||||
|
|
||||||
|
$view->addAction(
|
||||||
|
id(new PhabricatorActionView())
|
||||||
|
->setName(pht('View History'))
|
||||||
|
->setHref($history_uri)
|
||||||
|
->setIcon('history'));
|
||||||
|
|
||||||
|
$browse_uri = $drequest->generateURI(
|
||||||
|
array(
|
||||||
|
'action' => 'browse',
|
||||||
|
));
|
||||||
|
|
||||||
|
$view->addAction(
|
||||||
|
id(new PhabricatorActionView())
|
||||||
|
->setName(pht('Browse Content'))
|
||||||
|
->setHref($browse_uri)
|
||||||
|
->setIcon('file'));
|
||||||
|
|
||||||
|
return $view;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function buildPropertyView(
|
||||||
|
DiffusionRequest $drequest,
|
||||||
|
PhabricatorRepositoryBranch $branch,
|
||||||
|
$total) {
|
||||||
|
|
||||||
|
$viewer = $this->getRequest()->getUser();
|
||||||
|
|
||||||
|
$view = id(new PhabricatorPropertyListView())
|
||||||
|
->setUser($viewer);
|
||||||
|
|
||||||
|
$callsign = $drequest->getRepository()->getCallsign();
|
||||||
|
$lint_commit = $branch->getLintCommit();
|
||||||
|
|
||||||
|
$view->addProperty(
|
||||||
|
pht('Lint Commit'),
|
||||||
|
phutil_tag(
|
||||||
|
'a',
|
||||||
|
array(
|
||||||
|
'href' => $drequest->generateURI(
|
||||||
|
array(
|
||||||
|
'action' => 'commit',
|
||||||
|
'commit' => $lint_commit,
|
||||||
|
)),
|
||||||
|
),
|
||||||
|
$drequest->getRepository()->formatCommitName($lint_commit)));
|
||||||
|
|
||||||
|
$view->addProperty(
|
||||||
|
pht('Total Messages'),
|
||||||
|
pht('%s', new PhutilNumber($total)));
|
||||||
|
|
||||||
|
return $view;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,35 +68,23 @@ final class DiffusionLintDetailsController extends DiffusionController {
|
||||||
->setHasMorePages(count($messages) >= $limit)
|
->setHasMorePages(count($messages) >= $limit)
|
||||||
->setURI($this->getRequest()->getRequestURI(), 'offset');
|
->setURI($this->getRequest()->getRequestURI(), 'offset');
|
||||||
|
|
||||||
$lint = $drequest->getLint();
|
|
||||||
$link = hsprintf(
|
|
||||||
'<a href="%s">%s</a>',
|
|
||||||
$drequest->generateURI(array(
|
|
||||||
'action' => 'lint',
|
|
||||||
'lint' => null,
|
|
||||||
)),
|
|
||||||
pht('Switch to Grouped View'));
|
|
||||||
|
|
||||||
$content[] = id(new AphrontPanelView())
|
$content[] = id(new AphrontPanelView())
|
||||||
->setHeader(
|
->setNoBackground(true)
|
||||||
($lint != '' ? $lint." \xC2\xB7 " : '').
|
|
||||||
pht('%d Lint Message(s)', count($messages)))
|
|
||||||
->setCaption($link)
|
|
||||||
->appendChild($table)
|
->appendChild($table)
|
||||||
->appendChild($pager);
|
->appendChild($pager);
|
||||||
|
|
||||||
$nav = $this->buildSideNav('lint', false);
|
|
||||||
$nav->appendChild($content);
|
|
||||||
$crumbs = $this->buildCrumbs(
|
$crumbs = $this->buildCrumbs(
|
||||||
array(
|
array(
|
||||||
'branch' => true,
|
'branch' => true,
|
||||||
'path' => true,
|
'path' => true,
|
||||||
'view' => 'lint',
|
'view' => 'lint',
|
||||||
));
|
));
|
||||||
$nav->setCrumbs($crumbs);
|
|
||||||
|
|
||||||
return $this->buildApplicationPage(
|
return $this->buildApplicationPage(
|
||||||
$nav,
|
array(
|
||||||
|
$crumbs,
|
||||||
|
$content,
|
||||||
|
),
|
||||||
array(
|
array(
|
||||||
'device' => true,
|
'device' => true,
|
||||||
'title' =>
|
'title' =>
|
||||||
|
|
Loading…
Reference in a new issue