mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-30 16:38:21 +01:00
Add a Dashboard MenuItem
Summary: Built similar to Projects, allows setting of a Dashboard to MenuItem. Test Plan: Add a dashboard with and without a name / icon to a Project. Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin Differential Revision: https://secure.phabricator.com/D17092
This commit is contained in:
parent
28d74ae572
commit
5e6afa97bc
3 changed files with 118 additions and 0 deletions
|
@ -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',
|
||||
|
|
|
@ -120,6 +120,10 @@ final class PhabricatorDashboard extends PhabricatorDashboardDAO
|
|||
return ($this->getStatus() == self::STATUS_ARCHIVED);
|
||||
}
|
||||
|
||||
public function getViewURI() {
|
||||
return '/dashboard/view/'.$this->getID().'/';
|
||||
}
|
||||
|
||||
|
||||
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
|
||||
|
||||
|
|
|
@ -0,0 +1,112 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorDashboardProfileMenuItem
|
||||
extends PhabricatorProfileMenuItem {
|
||||
|
||||
const MENUITEMKEY = 'dashboard';
|
||||
|
||||
private $dashboard;
|
||||
|
||||
public function getMenuItemTypeIcon() {
|
||||
return 'fa-dashboard';
|
||||
}
|
||||
|
||||
public function getMenuItemTypeName() {
|
||||
return pht('Dashboard');
|
||||
}
|
||||
|
||||
public function canAddToObject($object) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function attachDashboard($dashboard) {
|
||||
$this->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,
|
||||
);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue