1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-28 01:32:42 +01:00
phorge-phorge/src/view/phui/PHUICrumbsView.php

145 lines
3.2 KiB
PHP
Raw Normal View History

<?php
final class PHUICrumbsView extends AphrontView {
private $crumbs = array();
private $actions = array();
private $border;
protected function canAppendChild() {
return false;
}
/**
* 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(
id(new PHUICrumbView())
->setName($text)
->setHref($href));
}
public function addCrumb(PHUICrumbView $crumb) {
$this->crumbs[] = $crumb;
return $this;
}
public function addAction(PHUIListItemView $action) {
$this->actions[] = $action;
return $this;
}
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;
}
public function render() {
require_celerity_resource('phui-crumbs-view-css');
$action_view = null;
if ($this->actions) {
$actions = array();
foreach ($this->actions as $action) {
if ($action->getType() == PHUIListItemView::TYPE_DIVIDER) {
$actions[] = phutil_tag(
'span',
array(
'class' => 'phui-crumb-action-divider',
));
continue;
}
$icon = null;
if ($action->getIcon()) {
$icon_name = $action->getIcon();
if ($action->getDisabled()) {
$icon_name .= ' lightgreytext';
}
$icon = id(new PHUIIconView())
->setIcon($icon_name);
}
$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';
}
$action_sigils = $action->getSigils();
if ($action->getWorkflow()) {
$action_sigils[] = 'workflow';
}
if ($action->getDisabled()) {
$action_classes[] = 'phui-crumbs-action-disabled';
}
$actions[] = javelin_tag(
'a',
array(
'href' => $action->getHref(),
'class' => implode(' ', $action_classes),
'sigil' => implode(' ', $action_sigils),
'style' => $action->getStyle(),
'meta' => $action->getMetadata(),
),
array(
$icon,
$name,
));
}
$action_view = phutil_tag(
'div',
array(
'class' => 'phui-crumbs-actions',
),
$actions);
}
if ($this->crumbs) {
last($this->crumbs)->setIsLastCrumb(true);
}
$classes = array();
$classes[] = 'phui-crumbs-view';
if ($this->border) {
$classes[] = 'phui-crumbs-border';
}
return phutil_tag(
'div',
array(
'class' => implode(' ', $classes),
),
array(
$action_view,
$this->crumbs,
));
}
}