diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 896745594a..b3438afc96 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -2471,6 +2471,7 @@ phutil_register_library_map(array( 'PhabricatorDashboardPanelTransactionQuery' => 'applications/dashboard/query/PhabricatorDashboardPanelTransactionQuery.php', 'PhabricatorDashboardPanelType' => 'applications/dashboard/paneltype/PhabricatorDashboardPanelType.php', 'PhabricatorDashboardPanelViewController' => 'applications/dashboard/controller/PhabricatorDashboardPanelViewController.php', + 'PhabricatorDashboardProfileMenuItem' => 'applications/search/menuitem/PhabricatorDashboardProfileMenuItem.php', 'PhabricatorDashboardQuery' => 'applications/dashboard/query/PhabricatorDashboardQuery.php', 'PhabricatorDashboardQueryPanelType' => 'applications/dashboard/paneltype/PhabricatorDashboardQueryPanelType.php', 'PhabricatorDashboardRemarkupRule' => 'applications/dashboard/remarkup/PhabricatorDashboardRemarkupRule.php', @@ -7439,6 +7440,7 @@ phutil_register_library_map(array( 'PhabricatorDashboardPanelTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 'PhabricatorDashboardPanelType' => 'Phobject', 'PhabricatorDashboardPanelViewController' => 'PhabricatorDashboardController', + 'PhabricatorDashboardProfileMenuItem' => 'PhabricatorProfileMenuItem', 'PhabricatorDashboardQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhabricatorDashboardQueryPanelType' => 'PhabricatorDashboardPanelType', 'PhabricatorDashboardRemarkupRule' => 'PhabricatorObjectRemarkupRule', diff --git a/src/applications/dashboard/storage/PhabricatorDashboard.php b/src/applications/dashboard/storage/PhabricatorDashboard.php index b9e40a76f6..fb50cba692 100644 --- a/src/applications/dashboard/storage/PhabricatorDashboard.php +++ b/src/applications/dashboard/storage/PhabricatorDashboard.php @@ -120,6 +120,10 @@ final class PhabricatorDashboard extends PhabricatorDashboardDAO return ($this->getStatus() == self::STATUS_ARCHIVED); } + public function getViewURI() { + return '/dashboard/view/'.$this->getID().'/'; + } + /* -( PhabricatorApplicationTransactionInterface )------------------------- */ diff --git a/src/applications/search/menuitem/PhabricatorDashboardProfileMenuItem.php b/src/applications/search/menuitem/PhabricatorDashboardProfileMenuItem.php new file mode 100644 index 0000000000..9074b1b117 --- /dev/null +++ b/src/applications/search/menuitem/PhabricatorDashboardProfileMenuItem.php @@ -0,0 +1,112 @@ +dashboard = $dashboard; + return $this; + } + + public function getDashboard() { + $dashboard = $this->dashboard; + if (!$dashboard) { + return null; + } else if ($dashboard->isArchived()) { + return null; + } + return $dashboard; + } + + public function willBuildNavigationItems(array $items) { + $viewer = $this->getViewer(); + $dashboard_phids = array(); + foreach ($items as $item) { + $dashboard_phids[] = $item->getMenuItemProperty('dashboardPHID'); + } + + $dashboards = id(new PhabricatorDashboardQuery()) + ->setViewer($viewer) + ->withPHIDs($dashboard_phids) + ->execute(); + + $dashboards = mpull($dashboards, null, 'getPHID'); + foreach ($items as $item) { + $dashboard_phid = $item->getMenuItemProperty('dashboardPHID'); + $dashboard = idx($dashboards, $dashboard_phid, null); + $item->getMenuItem()->attachDashboard($dashboard); + } + } + + public function getDisplayName( + PhabricatorProfileMenuItemConfiguration $config) { + $dashboard = $this->getDashboard(); + if (!$dashboard) { + return pht('(Restricted/Invalid Dashboard)'); + } + if (strlen($this->getName($config))) { + return $this->getName($config); + } else { + return $dashboard->getName(); + } + } + + public function buildEditEngineFields( + PhabricatorProfileMenuItemConfiguration $config) { + return array( + id(new PhabricatorTextEditField()) + ->setKey('name') + ->setLabel(pht('Name')) + ->setValue($this->getName($config)), + id(new PhabricatorDatasourceEditField()) + ->setKey('dashboardPHID') + ->setLabel(pht('Dashboard')) + ->setDatasource(new PhabricatorDashboardDatasource()) + ->setSingleValue($config->getMenuItemProperty('dashboardPHID')), + ); + } + + private function getName( + PhabricatorProfileMenuItemConfiguration $config) { + return $config->getMenuItemProperty('name'); + } + + protected function newNavigationMenuItems( + PhabricatorProfileMenuItemConfiguration $config) { + + $dashboard = $this->getDashboard(); + if (!$dashboard) { + return array(); + } + + $icon = $dashboard->getIcon(); + $name = $this->getDisplayName($config); + $href = $dashboard->getViewURI(); + + $item = $this->newItem() + ->setHref($href) + ->setName($name) + ->setIcon($icon); + + return array( + $item, + ); + } + +}