1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 14:00:56 +01:00

Modernize file browse controller

Summary: This needs some more cleanup, but gets us a step closer to something reasonable.

Test Plan: See screenshot.

Reviewers: btrahan, chad

Reviewed By: btrahan

CC: aran

Differential Revision: https://secure.phabricator.com/D7043
This commit is contained in:
epriestley 2013-09-19 16:01:04 -07:00
parent 6bc5ed39a2
commit 1ec021bf8c
3 changed files with 181 additions and 154 deletions

View file

@ -30,7 +30,7 @@ final class DiffusionBrowseController extends DiffusionController {
$content = array(); $content = array();
$content[] = $this->buildHeaderView($drequest); $content[] = $this->buildHeaderView($drequest);
$content[] = $this->buildActionView($drequest); $content[] = $this->buildBrowseActionView($drequest);
$content[] = $this->buildPropertyView($drequest); $content[] = $this->buildPropertyView($drequest);
$content[] = $this->renderSearchForm(); $content[] = $this->renderSearchForm();
@ -278,55 +278,6 @@ final class DiffusionBrowseController extends DiffusionController {
return $header; return $header;
} }
private function buildActionView(DiffusionRequest $drequest) {
$viewer = $this->getRequest()->getUser();
$view = id(new PhabricatorActionListView())
->setUser($viewer);
$history_uri = $drequest->generateURI(
array(
'action' => 'history',
));
$view->addAction(
id(new PhabricatorActionView())
->setName(pht('View History'))
->setHref($history_uri)
->setIcon('perflab'));
$behind_head = $drequest->getRawCommit();
$head_uri = $drequest->generateURI(
array(
'commit' => '',
'action' => 'browse',
));
$view->addAction(
id(new PhabricatorActionView())
->setName(pht('Jump to HEAD'))
->setHref($head_uri)
->setIcon('home')
->setDisabled(!$behind_head));
// TODO: Ideally, this should live in Owners and be event-triggered, but
// there's no reasonable object for it to react to right now.
$owners_uri = id(new PhutilURI('/owners/view/search/'))
->setQueryParams(
array(
'repository' => $drequest->getCallsign(),
'path' => '/'.$drequest->getPath(),
));
$view->addAction(
id(new PhabricatorActionView())
->setName(pht('Find Owners'))
->setHref((string)$owners_uri)
->setIcon('preview'));
return $view;
}
private function buildPropertyView(DiffusionRequest $drequest) { private function buildPropertyView(DiffusionRequest $drequest) {
$viewer = $this->getRequest()->getUser(); $viewer = $this->getRequest()->getUser();
@ -361,47 +312,4 @@ final class DiffusionBrowseController extends DiffusionController {
return $view; return $view;
} }
private function renderPathLinks(DiffusionRequest $drequest) {
$path = $drequest->getPath();
$path_parts = array_filter(explode('/', trim($path, '/')));
$links = array();
if ($path_parts) {
$links[] = phutil_tag(
'a',
array(
'href' => $drequest->generateURI(
array(
'action' => 'browse',
'path' => '',
)),
),
'r'.$drequest->getRepository()->getCallsign().'/');
$accum = '';
$last_key = last_key($path_parts);
foreach ($path_parts as $key => $part) {
$links[] = ' ';
$accum .= '/'.$part;
if ($key === $last_key) {
$links[] = $part;
} else {
$links[] = phutil_tag(
'a',
array(
'href' => $drequest->generateURI(
array(
'action' => 'browse',
'path' => $accum,
)),
),
$part.'/');
}
}
} else {
$links[] = 'r'.$drequest->getRepository()->getCallsign().'/';
}
return $links;
}
} }

View file

@ -71,15 +71,14 @@ final class DiffusionBrowseFileController extends DiffusionController {
require_celerity_resource('diffusion-source-css'); require_celerity_resource('diffusion-source-css');
if ($this->corpusType == 'text') {
$view_select_panel = $this->renderViewSelectPanel($selected);
} else {
$view_select_panel = null;
}
// Render the page. // Render the page.
$content = array(); $content = array();
$content[] = $this->buildHeaderView($drequest);
$view = $this->buildBrowseActionView($drequest);
$content[] = $this->enrichActionView($view, $drequest, $selected);
$content[] = $this->buildPropertyView($drequest);
$follow = $request->getStr('follow'); $follow = $request->getStr('follow');
if ($follow) { if ($follow) {
$notice = new AphrontErrorView(); $notice = new AphrontErrorView();
@ -111,24 +110,23 @@ final class DiffusionBrowseFileController extends DiffusionController {
$content[] = $notice; $content[] = $notice;
} }
$content[] = $view_select_panel;
$content[] = $corpus; $content[] = $corpus;
$content[] = $this->buildOpenRevisions(); $content[] = $this->buildOpenRevisions();
$nav = $this->buildSideNav('browse', true);
$nav->appendChild($content);
$crumbs = $this->buildCrumbs( $crumbs = $this->buildCrumbs(
array( array(
'branch' => true, 'branch' => true,
'path' => true, 'path' => true,
'view' => 'browse', 'view' => 'browse',
)); ));
$nav->setCrumbs($crumbs);
$basename = basename($this->getDiffusionRequest()->getPath()); $basename = basename($this->getDiffusionRequest()->getPath());
return $this->buildApplicationPage( return $this->buildApplicationPage(
$nav, array(
$crumbs,
$content,
),
array( array(
'title' => $basename, 'title' => $basename,
)); ));
@ -296,7 +294,14 @@ final class DiffusionBrowseFileController extends DiffusionController {
return $corpus; return $corpus;
} }
private function renderViewSelectPanel($selected) { private function enrichActionView(
PhabricatorActionListView $view,
DiffusionRequest $drequest,
$selected) {
$viewer = $this->getRequest()->getUser();
$base_uri = $this->getRequest()->getRequestURI();
$toggle_blame = array( $toggle_blame = array(
'highlighted' => 'blame', 'highlighted' => 'blame',
'blame' => 'highlighted', 'blame' => 'highlighted',
@ -304,6 +309,7 @@ final class DiffusionBrowseFileController extends DiffusionController {
'plainblame' => 'plain', 'plainblame' => 'plain',
'raw' => 'raw', // not a real case. 'raw' => 'raw', // not a real case.
); );
$toggle_highlight = array( $toggle_highlight = array(
'highlighted' => 'plain', 'highlighted' => 'plain',
'blame' => 'plainblame', 'blame' => 'plainblame',
@ -312,32 +318,40 @@ final class DiffusionBrowseFileController extends DiffusionController {
'raw' => 'raw', // not a real case. 'raw' => 'raw', // not a real case.
); );
$user = $this->getRequest()->getUser();
$base_uri = $this->getRequest()->getRequestURI();
$blame_on = ($selected == 'blame' || $selected == 'plainblame'); $blame_on = ($selected == 'blame' || $selected == 'plainblame');
if ($blame_on) { if ($blame_on) {
$blame_text = pht('Disable Blame'); $blame_text = pht('Disable Blame');
$blame_icon = 'blame-grey';
} else { } else {
$blame_text = pht('Enable Blame'); $blame_text = pht('Enable Blame');
$blame_icon = 'blame';
} }
$blame_button = $this->createViewAction( $view->addAction(
$blame_text, id(new PhabricatorActionView())
$base_uri->alter('view', $toggle_blame[$selected]), ->setName($blame_text)
$user); ->setHref($base_uri->alter('view', $toggle_blame[$selected]))
->setIcon($blame_icon)
->setUser($viewer)
->setRenderAsForm(true));
$highlight_on = ($selected == 'blame' || $selected == 'highlighted'); $highlight_on = ($selected == 'blame' || $selected == 'highlighted');
if ($highlight_on) { if ($highlight_on) {
$highlight_text = pht('Disable Highlighting'); $highlight_text = pht('Disable Highlighting');
$highlight_icon = 'highlight-grey';
} else { } else {
$highlight_text = pht('Enable Highlighting'); $highlight_text = pht('Enable Highlighting');
$highlight_icon = 'highlight';
} }
$highlight_button = $this->createViewAction(
$highlight_text, $view->addAction(
$base_uri->alter('view', $toggle_highlight[$selected]), id(new PhabricatorActionView())
$user); ->setName($highlight_text)
->setHref($base_uri->alter('view', $toggle_highlight[$selected]))
->setIcon($highlight_icon)
->setUser($viewer)
->setRenderAsForm(true));
$href = null; $href = null;
@ -347,7 +361,6 @@ final class DiffusionBrowseFileController extends DiffusionController {
} else if ($this->lintCommit === null) { } else if ($this->lintCommit === null) {
$lint_text = pht('Lint not Available'); $lint_text = pht('Lint not Available');
} else { } else {
$lint_text = pht( $lint_text = pht(
'Show %d Lint Message(s)', 'Show %d Lint Message(s)',
@ -358,46 +371,22 @@ final class DiffusionBrowseFileController extends DiffusionController {
))->alter('lint', ''); ))->alter('lint', '');
} }
$lint_button = $this->createViewAction( $view->addAction(
$lint_text, id(new PhabricatorActionView())
$href, ->setName($lint_text)
$user); ->setHref($href)
->setIcon('warning')
->setDisabled(!$href));
if (!$href) { $view->addAction(
$lint_button->setDisabled(true); id(new PhabricatorActionView())
} ->setName(pht('View Raw File'))
->setHref($base_uri->alter('view', 'raw'))
->setIcon('file'));
$view->addAction($this->createEditAction());
$raw_button = $this->createViewAction( return $view;
pht('View Raw File'),
$base_uri->alter('view', 'raw'),
$user,
'file');
$edit_button = $this->createEditAction();
return id(new PhabricatorActionListView())
->setUser($user)
->setObjectURI($this->getRequest()->getRequestURI())
->addAction($blame_button)
->addAction($highlight_button)
->addAction($lint_button)
->addAction($raw_button)
->addAction($edit_button);
}
private function createViewAction(
$localized_text,
$href,
$user,
$icon = null) {
return id(new PhabricatorActionView())
->setName($localized_text)
->setIcon($icon)
->setUser($user)
->setRenderAsForm(true)
->setHref($href);
} }
private function createEditAction() { private function createEditAction() {
@ -979,4 +968,40 @@ final class DiffusionBrowseFileController extends DiffusionController {
return head($parents); return head($parents);
} }
private function buildHeaderView(DiffusionRequest $drequest) {
$viewer = $this->getRequest()->getUser();
$header = id(new PHUIHeaderView())
->setUser($viewer)
->setHeader($this->renderPathLinks($drequest))
->setPolicyObject($drequest->getRepository());
return $header;
}
private function buildPropertyView(DiffusionRequest $drequest) {
$viewer = $this->getRequest()->getUser();
$view = id(new PhabricatorPropertyListView())
->setUser($viewer);
$stable_commit = $drequest->getStableCommitName();
$callsign = $drequest->getRepository()->getCallsign();
$view->addProperty(
pht('Commit'),
phutil_tag(
'a',
array(
'href' => $drequest->generateURI(
array(
'action' => 'commit',
'commit' => $stable_commit,
)),
),
$drequest->getRepository()->formatCommitName($stable_commit)));
return $view;
}
} }

View file

@ -344,4 +344,98 @@ abstract class DiffusionController extends PhabricatorController {
return $this->getApplicationURI($repository->getCallsign().'/'.$path); return $this->getApplicationURI($repository->getCallsign().'/'.$path);
} }
protected function buildBrowseActionView(DiffusionRequest $drequest) {
$viewer = $this->getRequest()->getUser();
$view = id(new PhabricatorActionListView())
->setUser($viewer);
$history_uri = $drequest->generateURI(
array(
'action' => 'history',
));
$view->addAction(
id(new PhabricatorActionView())
->setName(pht('View History'))
->setHref($history_uri)
->setIcon('perflab'));
$behind_head = $drequest->getRawCommit();
$head_uri = $drequest->generateURI(
array(
'commit' => '',
'action' => 'browse',
));
$view->addAction(
id(new PhabricatorActionView())
->setName(pht('Jump to HEAD'))
->setHref($head_uri)
->setIcon('home')
->setDisabled(!$behind_head));
// TODO: Ideally, this should live in Owners and be event-triggered, but
// there's no reasonable object for it to react to right now.
$owners_uri = id(new PhutilURI('/owners/view/search/'))
->setQueryParams(
array(
'repository' => $drequest->getCallsign(),
'path' => '/'.$drequest->getPath(),
));
$view->addAction(
id(new PhabricatorActionView())
->setName(pht('Find Owners'))
->setHref((string)$owners_uri)
->setIcon('preview'));
return $view;
}
protected function renderPathLinks(DiffusionRequest $drequest) {
$path = $drequest->getPath();
$path_parts = array_filter(explode('/', trim($path, '/')));
$links = array();
if ($path_parts) {
$links[] = phutil_tag(
'a',
array(
'href' => $drequest->generateURI(
array(
'action' => 'browse',
'path' => '',
)),
),
'r'.$drequest->getRepository()->getCallsign().'/');
$accum = '';
$last_key = last_key($path_parts);
foreach ($path_parts as $key => $part) {
$links[] = ' ';
$accum .= '/'.$part;
if ($key === $last_key) {
$links[] = $part;
} else {
$links[] = phutil_tag(
'a',
array(
'href' => $drequest->generateURI(
array(
'action' => 'browse',
'path' => $accum,
)),
),
$part.'/');
}
}
} else {
$links[] = 'r'.$drequest->getRepository()->getCallsign().'/';
}
return $links;
}
} }