Differential D20398 Diff 48689 src/applications/search/menuitem/PhabricatorDashboardProfileMenuItem.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/search/menuitem/PhabricatorDashboardProfileMenuItem.php
Show All 30 Lines | private function attachDashboard(PhabricatorDashboard $dashboard = null) { | ||||
$this->dashboard = $dashboard; | $this->dashboard = $dashboard; | ||||
return $this; | return $this; | ||||
} | } | ||||
private function getDashboard() { | private function getDashboard() { | ||||
return $this->dashboard; | return $this->dashboard; | ||||
} | } | ||||
public function getAffectedObjectPHIDs( | |||||
PhabricatorProfileMenuItemConfiguration $config) { | |||||
return array( | |||||
$this->getDashboardPHID($config), | |||||
); | |||||
} | |||||
public function newPageContent( | public function newPageContent( | ||||
PhabricatorProfileMenuItemConfiguration $config) { | PhabricatorProfileMenuItemConfiguration $config) { | ||||
$viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
$dashboard_phid = $config->getMenuItemProperty('dashboardPHID'); | $dashboard_phid = $this->getDashboardPHID($config); | ||||
// 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) { | ||||
Show All 14 Lines | public function newPageContent( | ||||
return $engine->renderDashboard(); | return $engine->renderDashboard(); | ||||
} | } | ||||
public function willGetMenuItemViewList(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[] = $this->getDashboardPHID($item); | ||||
} | } | ||||
$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); | $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 = $this->getDashboardPHID($item); | ||||
$dashboard = idx($dashboards, $dashboard_phid, null); | $dashboard = idx($dashboards, $dashboard_phid, null); | ||||
$menu_item = $item->getMenuItem(); | $menu_item = $item->getMenuItem(); | ||||
$menu_item | $menu_item | ||||
->attachDashboard($dashboard) | ->attachDashboard($dashboard) | ||||
->setDashboardHandle($handles[$dashboard_phid]); | ->setDashboardHandle($handles[$dashboard_phid]); | ||||
} | } | ||||
Show All 25 Lines | final class PhabricatorDashboardProfileMenuItem | ||||
public function buildEditEngineFields( | public function buildEditEngineFields( | ||||
PhabricatorProfileMenuItemConfiguration $config) { | PhabricatorProfileMenuItemConfiguration $config) { | ||||
return array( | return array( | ||||
id(new PhabricatorDatasourceEditField()) | id(new PhabricatorDatasourceEditField()) | ||||
->setKey(self::FIELD_DASHBOARD) | ->setKey(self::FIELD_DASHBOARD) | ||||
->setLabel(pht('Dashboard')) | ->setLabel(pht('Dashboard')) | ||||
->setIsRequired(true) | ->setIsRequired(true) | ||||
->setDatasource(new PhabricatorDashboardDatasource()) | ->setDatasource(new PhabricatorDashboardDatasource()) | ||||
->setSingleValue($config->getMenuItemProperty('dashboardPHID')), | ->setSingleValue($this->getDashboardPHID($config)), | ||||
id(new PhabricatorTextEditField()) | id(new PhabricatorTextEditField()) | ||||
->setKey('name') | ->setKey('name') | ||||
->setLabel(pht('Name')) | ->setLabel(pht('Name')) | ||||
->setValue($this->getName($config)), | ->setValue($this->getName($config)), | ||||
); | ); | ||||
} | } | ||||
private function getName( | private function getName( | ||||
▲ Show 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | if ($field_key == self::FIELD_DASHBOARD) { | ||||
$xaction['xaction']); | $xaction['xaction']); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
return $errors; | return $errors; | ||||
} | } | ||||
private function getDashboardPHID( | |||||
PhabricatorProfileMenuItemConfiguration $config) { | |||||
return $config->getMenuItemProperty('dashboardPHID'); | |||||
} | |||||
private function getDashboardHandle() { | private function getDashboardHandle() { | ||||
return $this->dashboardHandle; | return $this->dashboardHandle; | ||||
} | } | ||||
private function setDashboardHandle(PhabricatorObjectHandle $handle) { | private function setDashboardHandle(PhabricatorObjectHandle $handle) { | ||||
$this->dashboardHandle = $handle; | $this->dashboardHandle = $handle; | ||||
return $this; | return $this; | ||||
} | } | ||||
} | } |