Changeset View
Changeset View
Standalone View
Standalone View
src/view/page/PhabricatorStandardPageView.php
<?php | <?php | ||||
/** | /** | ||||
* This is a standard Phabricator page with menus, Javelin, DarkConsole, and | * This is a standard Phabricator page with menus, Javelin, DarkConsole, and | ||||
* basic styles. | * basic styles. | ||||
*/ | */ | ||||
final class PhabricatorStandardPageView extends PhabricatorBarePageView { | final class PhabricatorStandardPageView extends PhabricatorBarePageView | ||||
implements AphrontResponseProducerInterface { | |||||
private $baseURI; | private $baseURI; | ||||
private $applicationName; | private $applicationName; | ||||
private $glyph; | private $glyph; | ||||
private $menuContent; | private $menuContent; | ||||
private $showChrome = true; | private $showChrome = true; | ||||
private $classes = array(); | private $classes = array(); | ||||
private $disableConsole; | private $disableConsole; | ||||
private $pageObjects = array(); | private $pageObjects = array(); | ||||
private $applicationMenu; | private $applicationMenu; | ||||
private $showFooter = true; | private $showFooter = true; | ||||
private $showDurableColumn = true; | private $showDurableColumn = true; | ||||
private $quicksandConfig = array(); | |||||
private $crumbs; | |||||
private $navigation; | |||||
public function setShowFooter($show_footer) { | public function setShowFooter($show_footer) { | ||||
$this->showFooter = $show_footer; | $this->showFooter = $show_footer; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getShowFooter() { | public function getShowFooter() { | ||||
return $this->showFooter; | return $this->showFooter; | ||||
} | } | ||||
public function setApplicationMenu(PHUIListView $application_menu) { | public function setApplicationMenu($application_menu) { | ||||
// NOTE: For now, this can either be a PHUIListView or a | |||||
// PHUIApplicationMenuView. | |||||
$this->applicationMenu = $application_menu; | $this->applicationMenu = $application_menu; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getApplicationMenu() { | public function getApplicationMenu() { | ||||
return $this->applicationMenu; | return $this->applicationMenu; | ||||
} | } | ||||
Show All 29 Lines | public function getShowChrome() { | ||||
return $this->showChrome; | return $this->showChrome; | ||||
} | } | ||||
public function addClass($class) { | public function addClass($class) { | ||||
$this->classes[] = $class; | $this->classes[] = $class; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function appendPageObjects(array $objs) { | public function setPageObjectPHIDs(array $phids) { | ||||
foreach ($objs as $obj) { | $this->pageObjects = $phids; | ||||
$this->pageObjects[] = $obj; | return $this; | ||||
} | |||||
} | } | ||||
public function setShowDurableColumn($show) { | public function setShowDurableColumn($show) { | ||||
$this->showDurableColumn = $show; | $this->showDurableColumn = $show; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getShowDurableColumn() { | public function getShowDurableColumn() { | ||||
Show All 37 Lines | private function isQuicksandBlacklistURI() { | ||||
return false; | return false; | ||||
} | } | ||||
public function getDurableColumnVisible() { | public function getDurableColumnVisible() { | ||||
$column_key = PhabricatorUserPreferences::PREFERENCE_CONPHERENCE_COLUMN; | $column_key = PhabricatorUserPreferences::PREFERENCE_CONPHERENCE_COLUMN; | ||||
return (bool)$this->getUserPreference($column_key, 0); | return (bool)$this->getUserPreference($column_key, 0); | ||||
} | } | ||||
public function addQuicksandConfig(array $config) { | |||||
$this->quicksandConfig = $config + $this->quicksandConfig; | |||||
return $this; | |||||
} | |||||
public function getQuicksandConfig() { | |||||
return $this->quicksandConfig; | |||||
} | |||||
public function setCrumbs(PHUICrumbsView $crumbs) { | |||||
$this->crumbs = $crumbs; | |||||
return $this; | |||||
} | |||||
public function getCrumbs() { | |||||
return $this->crumbs; | |||||
} | |||||
public function setNavigation(AphrontSideNavFilterView $navigation) { | |||||
$this->navigation = $navigation; | |||||
return $this; | |||||
} | |||||
public function getNavigation() { | |||||
return $this->navigation; | |||||
} | |||||
public function getTitle() { | public function getTitle() { | ||||
$glyph_key = PhabricatorUserPreferences::PREFERENCE_TITLES; | $glyph_key = PhabricatorUserPreferences::PREFERENCE_TITLES; | ||||
if ($this->getUserPreference($glyph_key) == 'text') { | if ($this->getUserPreference($glyph_key) == 'text') { | ||||
$use_glyph = false; | $use_glyph = false; | ||||
} else { | } else { | ||||
$use_glyph = true; | $use_glyph = true; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 125 Lines • ▼ Show 20 Lines | protected function willRenderPage() { | ||||
$menu = id(new PhabricatorMainMenuView()) | $menu = id(new PhabricatorMainMenuView()) | ||||
->setUser($viewer); | ->setUser($viewer); | ||||
if ($this->getController()) { | if ($this->getController()) { | ||||
$menu->setController($this->getController()); | $menu->setController($this->getController()); | ||||
} | } | ||||
if ($this->getApplicationMenu()) { | $application_menu = $this->getApplicationMenu(); | ||||
$menu->setApplicationMenu($this->getApplicationMenu()); | if ($application_menu) { | ||||
if ($application_menu instanceof PHUIApplicationMenuView) { | |||||
$crumbs = $this->getCrumbs(); | |||||
if ($crumbs) { | |||||
$application_menu->setCrumbs($crumbs); | |||||
} | |||||
$application_menu = $application_menu->buildListView(); | |||||
} | |||||
$menu->setApplicationMenu($application_menu); | |||||
} | } | ||||
$this->menuContent = $menu->render(); | $this->menuContent = $menu->render(); | ||||
} | } | ||||
protected function getHead() { | protected function getHead() { | ||||
$monospaced = null; | $monospaced = null; | ||||
▲ Show 20 Lines • Show All 144 Lines • ▼ Show 20 Lines | return phutil_tag( | ||||
$main_page, | $main_page, | ||||
$durable_column, | $durable_column, | ||||
)); | )); | ||||
} | } | ||||
private function renderPageBodyContent() { | private function renderPageBodyContent() { | ||||
$console = $this->getConsole(); | $console = $this->getConsole(); | ||||
$body = parent::getBody(); | |||||
$nav = $this->getNavigation(); | |||||
if ($nav) { | |||||
$crumbs = $this->getCrumbs(); | |||||
if ($crumbs) { | |||||
$nav->setCrumbs($crumbs); | |||||
} | |||||
$nav->appendChild($body); | |||||
$body = phutil_implode_html('', array($nav->render())); | |||||
} else { | |||||
$crumbs = $this->getCrumbs(); | |||||
if ($crumbs) { | |||||
$body = phutil_implode_html('', array($crumbs, $body)); | |||||
} | |||||
} | |||||
return array( | return array( | ||||
($console ? hsprintf('<darkconsole />') : null), | ($console ? hsprintf('<darkconsole />') : null), | ||||
parent::getBody(), | $body, | ||||
$this->renderFooter(), | $this->renderFooter(), | ||||
); | ); | ||||
} | } | ||||
protected function getTail() { | protected function getTail() { | ||||
$request = $this->getRequest(); | $request = $this->getRequest(); | ||||
$user = $request->getUser(); | $user = $request->getUser(); | ||||
▲ Show 20 Lines • Show All 167 Lines • ▼ Show 20 Lines | private function renderFooter() { | ||||
return phutil_tag( | return phutil_tag( | ||||
'div', | 'div', | ||||
array( | array( | ||||
'class' => 'phabricator-standard-page-footer grouped', | 'class' => 'phabricator-standard-page-footer grouped', | ||||
), | ), | ||||
$foot); | $foot); | ||||
} | } | ||||
public function renderForQuicksand(array $extra_config) { | public function renderForQuicksand() { | ||||
parent::willRenderPage(); | parent::willRenderPage(); | ||||
$response = $this->renderPageBodyContent(); | $response = $this->renderPageBodyContent(); | ||||
$response = $this->willSendResponse($response); | $response = $this->willSendResponse($response); | ||||
$extra_config = $this->getQuicksandConfig(); | |||||
return array( | return array( | ||||
'content' => hsprintf('%s', $response), | 'content' => hsprintf('%s', $response), | ||||
) + $this->buildQuicksandConfig() | ) + $this->buildQuicksandConfig() | ||||
+ $extra_config; | + $extra_config; | ||||
} | } | ||||
private function buildQuicksandConfig() { | private function buildQuicksandConfig() { | ||||
$viewer = $this->getRequest()->getUser(); | $viewer = $this->getRequest()->getUser(); | ||||
▲ Show 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | private function getUserPreference($key, $default = null) { | ||||
$user = $request->getUser(); | $user = $request->getUser(); | ||||
if (!$user) { | if (!$user) { | ||||
return $default; | return $default; | ||||
} | } | ||||
return $user->loadPreferences()->getPreference($key, $default); | return $user->loadPreferences()->getPreference($key, $default); | ||||
} | } | ||||
public function produceAphrontResponse() { | |||||
$controller = $this->getController(); | |||||
if (!$this->getApplicationMenu()) { | |||||
$application_menu = $controller->buildApplicationMenu(); | |||||
if ($application_menu) { | |||||
$this->setApplicationMenu($application_menu); | |||||
} | |||||
} | |||||
$viewer = $this->getUser(); | |||||
if ($viewer && $viewer->getPHID()) { | |||||
$object_phids = $this->pageObjects; | |||||
foreach ($object_phids as $object_phid) { | |||||
PhabricatorFeedStoryNotification::updateObjectNotificationViews( | |||||
$viewer, | |||||
$object_phid); | |||||
} | |||||
} | |||||
if ($this->getRequest()->isQuicksand()) { | |||||
$content = $this->renderForQuicksand(); | |||||
$response = id(new AphrontAjaxResponse()) | |||||
->setContent($content); | |||||
} else { | |||||
$content = $this->render(); | |||||
$response = id(new AphrontWebpageResponse()) | |||||
->setContent($content); | |||||
} | |||||
return $response; | |||||
} | |||||
} | } |