Differential D20358 Diff 48609 src/applications/search/menuitem/PhabricatorDashboardProfileMenuItem.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/search/menuitem/PhabricatorDashboardProfileMenuItem.php
<?php | <?php | ||||
final class PhabricatorDashboardProfileMenuItem | final class PhabricatorDashboardProfileMenuItem | ||||
extends PhabricatorProfileMenuItem { | extends PhabricatorProfileMenuItem { | ||||
const MENUITEMKEY = 'dashboard'; | const MENUITEMKEY = 'dashboard'; | ||||
const FIELD_DASHBOARD = 'dashboardPHID'; | const FIELD_DASHBOARD = 'dashboardPHID'; | ||||
private $dashboard; | private $dashboard; | ||||
private $dashboardHandle; | |||||
public function getMenuItemTypeIcon() { | public function getMenuItemTypeIcon() { | ||||
return 'fa-dashboard'; | return 'fa-dashboard'; | ||||
} | } | ||||
public function getMenuItemTypeName() { | public function getMenuItemTypeName() { | ||||
return pht('Dashboard'); | return pht('Dashboard'); | ||||
} | } | ||||
public function canAddToObject($object) { | public function canAddToObject($object) { | ||||
return true; | return true; | ||||
} | } | ||||
public function canMakeDefault( | public function canMakeDefault( | ||||
PhabricatorProfileMenuItemConfiguration $config) { | PhabricatorProfileMenuItemConfiguration $config) { | ||||
return true; | return true; | ||||
} | } | ||||
public function attachDashboard($dashboard) { | private function attachDashboard(PhabricatorDashboard $dashboard = null) { | ||||
$this->dashboard = $dashboard; | $this->dashboard = $dashboard; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getDashboard() { | private function getDashboard() { | ||||
$dashboard = $this->dashboard; | return $this->dashboard; | ||||
if (!$dashboard) { | |||||
return null; | |||||
} else if ($dashboard->isArchived()) { | |||||
return null; | |||||
} | |||||
return $dashboard; | |||||
} | } | ||||
public function newPageContent( | public function newPageContent( | ||||
PhabricatorProfileMenuItemConfiguration $config) { | PhabricatorProfileMenuItemConfiguration $config) { | ||||
$viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
$dashboard_phid = $config->getMenuItemProperty('dashboardPHID'); | $dashboard_phid = $config->getMenuItemProperty('dashboardPHID'); | ||||
// Reload the dashboard to attach panels, which we need for rendering. | // Reload the dashboard to attach panels, which we need for rendering. | ||||
$dashboard = id(new PhabricatorDashboardQuery()) | $dashboard = id(new PhabricatorDashboardQuery()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->withPHIDs(array($dashboard_phid)) | ->withPHIDs(array($dashboard_phid)) | ||||
->needPanels(true) | ->needPanels(true) | ||||
->executeOne(); | ->executeOne(); | ||||
if (!$dashboard) { | if (!$dashboard) { | ||||
return null; | return $this->newEmptyView( | ||||
pht('Invalid Dashboard'), | |||||
pht('This dashboard is invalid and could not be loaded.')); | |||||
} | |||||
if ($dashboard->isArchived()) { | |||||
return $this->newEmptyView( | |||||
pht('Archived Dashboard'), | |||||
pht('This dashboard has been archived.')); | |||||
} | } | ||||
$engine = id(new PhabricatorDashboardRenderingEngine()) | $engine = id(new PhabricatorDashboardRenderingEngine()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->setDashboard($dashboard); | ->setDashboard($dashboard); | ||||
return $engine->renderDashboard(); | return $engine->renderDashboard(); | ||||
} | } | ||||
public function willBuildNavigationItems(array $items) { | public function willGetMenuItemViewList(array $items) { | ||||
$viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
$dashboard_phids = array(); | $dashboard_phids = array(); | ||||
foreach ($items as $item) { | foreach ($items as $item) { | ||||
$dashboard_phids[] = $item->getMenuItemProperty('dashboardPHID'); | $dashboard_phids[] = $item->getMenuItemProperty('dashboardPHID'); | ||||
} | } | ||||
$dashboards = id(new PhabricatorDashboardQuery()) | $dashboards = id(new PhabricatorDashboardQuery()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->withPHIDs($dashboard_phids) | ->withPHIDs($dashboard_phids) | ||||
->execute(); | ->execute(); | ||||
$handles = $viewer->loadHandles($dashboard_phids); | |||||
$dashboards = mpull($dashboards, null, 'getPHID'); | $dashboards = mpull($dashboards, null, 'getPHID'); | ||||
foreach ($items as $item) { | foreach ($items as $item) { | ||||
$dashboard_phid = $item->getMenuItemProperty('dashboardPHID'); | $dashboard_phid = $item->getMenuItemProperty('dashboardPHID'); | ||||
$dashboard = idx($dashboards, $dashboard_phid, null); | $dashboard = idx($dashboards, $dashboard_phid, null); | ||||
$item->getMenuItem()->attachDashboard($dashboard); | |||||
$menu_item = $item->getMenuItem(); | |||||
$menu_item | |||||
->attachDashboard($dashboard) | |||||
->setDashboardHandle($handles[$dashboard_phid]); | |||||
} | } | ||||
} | } | ||||
public function getDisplayName( | public function getDisplayName( | ||||
PhabricatorProfileMenuItemConfiguration $config) { | PhabricatorProfileMenuItemConfiguration $config) { | ||||
$dashboard = $this->getDashboard(); | $dashboard = $this->getDashboard(); | ||||
if (!$dashboard) { | if (!$dashboard) { | ||||
return pht('(Restricted/Invalid Dashboard)'); | if ($this->getDashboardHandle()->getPolicyFiltered()) { | ||||
return pht('Restricted Dashboard'); | |||||
} else { | |||||
return pht('Invalid Dashboard'); | |||||
} | |||||
} | |||||
if ($dashboard->isArchived()) { | |||||
return pht('Archived Dashboard'); | |||||
} | } | ||||
if (strlen($this->getName($config))) { | if (strlen($this->getName($config))) { | ||||
return $this->getName($config); | return $this->getName($config); | ||||
} else { | } else { | ||||
return $dashboard->getName(); | return $dashboard->getName(); | ||||
} | } | ||||
} | } | ||||
Show All 14 Lines | public function buildEditEngineFields( | ||||
); | ); | ||||
} | } | ||||
private function getName( | private function getName( | ||||
PhabricatorProfileMenuItemConfiguration $config) { | PhabricatorProfileMenuItemConfiguration $config) { | ||||
return $config->getMenuItemProperty('name'); | return $config->getMenuItemProperty('name'); | ||||
} | } | ||||
protected function newNavigationMenuItems( | protected function newMenuItemViewList( | ||||
PhabricatorProfileMenuItemConfiguration $config) { | PhabricatorProfileMenuItemConfiguration $config) { | ||||
$dashboard = $this->getDashboard(); | $is_disabled = true; | ||||
if (!$dashboard) { | $action_uri = null; | ||||
return array(); | |||||
} | |||||
$dashboard = $this->getDashboard(); | |||||
if ($dashboard) { | |||||
if ($dashboard->isArchived()) { | |||||
$icon = 'fa-ban'; | |||||
$name = $this->getDisplayName($config); | |||||
} else { | |||||
$icon = $dashboard->getIcon(); | $icon = $dashboard->getIcon(); | ||||
$name = $this->getDisplayName($config); | $name = $this->getDisplayName($config); | ||||
$href = $this->getItemViewURI($config); | $is_disabled = false; | ||||
$action_href = '/dashboard/arrange/'.$dashboard->getID().'/'; | $action_uri = '/dashboard/arrange/'.$dashboard->getID().'/'; | ||||
} | |||||
} else { | |||||
$icon = 'fa-ban'; | |||||
if ($this->getDashboardHandle()->getPolicyFiltered()) { | |||||
$name = pht('Restricted Dashboard'); | |||||
} else { | |||||
$name = pht('Invalid Dashboard'); | |||||
} | |||||
} | |||||
$item = $this->newItem() | $uri = $this->getItemViewURI($config); | ||||
->setHref($href) | |||||
$item = $this->newItemView() | |||||
->setURI($uri) | |||||
->setName($name) | ->setName($name) | ||||
->setIcon($icon) | ->setIcon($icon) | ||||
->setActionIcon('fa-pencil', $action_href); | ->setDisabled($is_disabled); | ||||
if ($action_uri) { | |||||
$item->newAction($action_uri); | |||||
} | |||||
return array( | return array( | ||||
$item, | $item, | ||||
); | ); | ||||
} | } | ||||
public function validateTransactions( | public function validateTransactions( | ||||
PhabricatorProfileMenuItemConfiguration $config, | PhabricatorProfileMenuItemConfiguration $config, | ||||
Show All 35 Lines | if ($field_key == self::FIELD_DASHBOARD) { | ||||
$xaction['xaction']); | $xaction['xaction']); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
return $errors; | return $errors; | ||||
} | } | ||||
private function getDashboardHandle() { | |||||
return $this->dashboardHandle; | |||||
} | |||||
private function setDashboardHandle(PhabricatorObjectHandle $handle) { | |||||
$this->dashboardHandle = $handle; | |||||
return $this; | |||||
} | |||||
} | } |