2012-12-07 22:35:17 +01:00
|
|
|
<?php
|
|
|
|
|
2015-01-23 20:35:09 +01:00
|
|
|
final class PHUICrumbsView extends AphrontView {
|
2012-12-07 22:35:17 +01:00
|
|
|
|
|
|
|
private $crumbs = array();
|
|
|
|
private $actions = array();
|
2015-01-28 18:33:49 +01:00
|
|
|
private $border;
|
2012-12-07 22:35:17 +01:00
|
|
|
|
|
|
|
protected function canAppendChild() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-12-19 02:47:34 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Convenience method for adding a simple crumb with just text, or text and
|
|
|
|
* a link.
|
|
|
|
*
|
|
|
|
* @param string Text of the crumb.
|
|
|
|
* @param string? Optional href for the crumb.
|
|
|
|
* @return this
|
|
|
|
*/
|
|
|
|
public function addTextCrumb($text, $href = null) {
|
|
|
|
return $this->addCrumb(
|
2015-01-23 20:35:09 +01:00
|
|
|
id(new PHUICrumbView())
|
2013-12-19 02:47:34 +01:00
|
|
|
->setName($text)
|
|
|
|
->setHref($href));
|
|
|
|
}
|
|
|
|
|
2015-01-23 20:35:09 +01:00
|
|
|
public function addCrumb(PHUICrumbView $crumb) {
|
2012-12-07 22:35:17 +01:00
|
|
|
$this->crumbs[] = $crumb;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-06-05 17:41:43 +02:00
|
|
|
public function addAction(PHUIListItemView $action) {
|
2012-12-07 22:35:17 +01:00
|
|
|
$this->actions[] = $action;
|
2013-04-09 21:42:03 +02:00
|
|
|
return $this;
|
|
|
|
}
|
2012-12-07 22:35:17 +01:00
|
|
|
|
2015-01-28 18:33:49 +01:00
|
|
|
public function setBorder($border) {
|
|
|
|
$this->border = $border;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
Make mobile navigation work properly by default in more cases
Summary:
Fixes T5752. This obsoletes a bunch of old patterns and I'll follow up on those with a big "go do a bunch of mechanical code changes" task. Major goals are:
- Don't load named queries multiple times on search pages.
- Don't require extra code to get standard navigation right on mobile.
- Reduce the amount of boilerplate in ListControllers.
- Reduce the amount of boilerplate around navigation/menus in all controllers.
Specifically, here's what this does:
- The StandardPage is now a smarter/more structured object with `setNavigation()` and `setCrumbs()` methods. More rendering decisions are delayed until the last possible moment.
- It uses this to automatically add crumb actions to the application menu.
- It uses this to automatically reuse one SearchEngine instead of running queries multiple times.
- The new preferred way to build responses is `$this->newPage()` (like `$this->newDialog()`), which has structured methods for adding stuff (`setTitle()`, etc).
- SearchEngine exposes a new convenience method so you don't have to do all the controller delegation stuff.
- Building menus is generally simpler.
Test Plan:
- Tested paste list, view, edit, comment, raw controllers for functionality, mobile menu, crumbs, navigation menu.
- Edited saved queries.
- Tested Differential, Maniphest (no changes).
- Verified the paste pages don't run any duplicate NamedQuery queries.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T5752
Differential Revision: https://secure.phabricator.com/D14382
2015-11-02 21:06:28 +01:00
|
|
|
public function getActions() {
|
|
|
|
return $this->actions;
|
|
|
|
}
|
|
|
|
|
2012-12-07 22:35:17 +01:00
|
|
|
public function render() {
|
2015-01-23 20:35:09 +01:00
|
|
|
require_celerity_resource('phui-crumbs-view-css');
|
2012-12-07 22:35:17 +01:00
|
|
|
|
|
|
|
$action_view = null;
|
2015-01-12 16:24:35 +01:00
|
|
|
if ($this->actions) {
|
2012-12-07 22:35:17 +01:00
|
|
|
$actions = array();
|
|
|
|
foreach ($this->actions as $action) {
|
2016-02-10 16:31:02 +01:00
|
|
|
if ($action->getType() == PHUIListItemView::TYPE_DIVIDER) {
|
|
|
|
$actions[] = phutil_tag(
|
|
|
|
'span',
|
|
|
|
array(
|
|
|
|
'class' => 'phui-crumb-action-divider',
|
|
|
|
));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-12-07 22:35:17 +01:00
|
|
|
$icon = null;
|
|
|
|
if ($action->getIcon()) {
|
2013-10-15 03:21:06 +02:00
|
|
|
$icon_name = $action->getIcon();
|
|
|
|
if ($action->getDisabled()) {
|
2014-05-12 19:08:32 +02:00
|
|
|
$icon_name .= ' lightgreytext';
|
2013-10-15 03:21:06 +02:00
|
|
|
}
|
|
|
|
|
2014-05-12 19:08:32 +02:00
|
|
|
$icon = id(new PHUIIconView())
|
2016-01-28 05:38:01 +01:00
|
|
|
->setIcon($icon_name);
|
2014-05-12 19:08:32 +02:00
|
|
|
|
2012-12-07 22:35:17 +01:00
|
|
|
}
|
2016-02-10 16:31:02 +01:00
|
|
|
|
|
|
|
$action_classes = $action->getClasses();
|
|
|
|
$action_classes[] = 'phui-crumbs-action';
|
|
|
|
|
|
|
|
$name = null;
|
|
|
|
if ($action->getName()) {
|
|
|
|
$name = phutil_tag(
|
|
|
|
'span',
|
|
|
|
array(
|
|
|
|
'class' => 'phui-crumbs-action-name',
|
|
|
|
),
|
|
|
|
$action->getName());
|
|
|
|
} else {
|
|
|
|
$action_classes[] = 'phui-crumbs-action-icon';
|
|
|
|
}
|
2013-04-09 21:42:03 +02:00
|
|
|
|
2013-05-24 19:50:18 +02:00
|
|
|
$action_sigils = $action->getSigils();
|
|
|
|
if ($action->getWorkflow()) {
|
|
|
|
$action_sigils[] = 'workflow';
|
|
|
|
}
|
2013-10-15 03:21:06 +02:00
|
|
|
|
|
|
|
if ($action->getDisabled()) {
|
2015-01-23 20:35:09 +01:00
|
|
|
$action_classes[] = 'phui-crumbs-action-disabled';
|
2013-10-15 03:21:06 +02:00
|
|
|
}
|
|
|
|
|
2013-01-25 21:57:17 +01:00
|
|
|
$actions[] = javelin_tag(
|
2012-12-07 22:35:17 +01:00
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => $action->getHref(),
|
2013-05-24 19:50:18 +02:00
|
|
|
'class' => implode(' ', $action_classes),
|
|
|
|
'sigil' => implode(' ', $action_sigils),
|
2014-10-07 15:01:04 +02:00
|
|
|
'style' => $action->getStyle(),
|
2015-05-27 20:11:11 +02:00
|
|
|
'meta' => $action->getMetadata(),
|
2012-12-07 22:35:17 +01:00
|
|
|
),
|
2013-01-25 21:57:17 +01:00
|
|
|
array(
|
|
|
|
$icon,
|
2013-03-26 21:15:15 +01:00
|
|
|
$name,
|
2013-01-25 21:57:17 +01:00
|
|
|
));
|
2012-12-07 22:35:17 +01:00
|
|
|
}
|
|
|
|
|
2013-01-31 18:07:31 +01:00
|
|
|
$action_view = phutil_tag(
|
2012-12-07 22:35:17 +01:00
|
|
|
'div',
|
|
|
|
array(
|
2015-01-23 20:35:09 +01:00
|
|
|
'class' => 'phui-crumbs-actions',
|
2012-12-07 22:35:17 +01:00
|
|
|
),
|
2013-03-09 22:52:41 +01:00
|
|
|
$actions);
|
2012-12-07 22:35:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->crumbs) {
|
|
|
|
last($this->crumbs)->setIsLastCrumb(true);
|
|
|
|
}
|
|
|
|
|
2015-01-26 17:27:54 +01:00
|
|
|
$classes = array();
|
|
|
|
$classes[] = 'phui-crumbs-view';
|
2015-01-28 18:33:49 +01:00
|
|
|
if ($this->border) {
|
|
|
|
$classes[] = 'phui-crumbs-border';
|
|
|
|
}
|
2015-01-26 17:27:54 +01:00
|
|
|
|
2013-01-31 18:07:31 +01:00
|
|
|
return phutil_tag(
|
2012-12-07 22:35:17 +01:00
|
|
|
'div',
|
|
|
|
array(
|
2015-01-26 17:27:54 +01:00
|
|
|
'class' => implode(' ', $classes),
|
2012-12-07 22:35:17 +01:00
|
|
|
),
|
2013-03-09 22:52:41 +01:00
|
|
|
array(
|
|
|
|
$action_view,
|
|
|
|
$this->crumbs,
|
|
|
|
));
|
2012-12-07 22:35:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|