Differential D20373 Diff 48598 src/applications/dashboard/controller/panel/PhabricatorDashboardPanelEditController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/dashboard/controller/panel/PhabricatorDashboardPanelEditController.php
<?php | <?php | ||||
final class PhabricatorDashboardPanelEditController | final class PhabricatorDashboardPanelEditController | ||||
extends PhabricatorDashboardController { | extends PhabricatorDashboardController { | ||||
public function handleRequest(AphrontRequest $request) { | public function handleRequest(AphrontRequest $request) { | ||||
$viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
$engine = id(new PhabricatorDashboardPanelEditEngine()) | $engine = id(new PhabricatorDashboardPanelEditEngine()) | ||||
->setController($this); | ->setController($this); | ||||
$id = $request->getURIData('id'); | // We can create or edit a panel in the context of a dashboard. If we | ||||
if (!$id) { | // started on a dashboard, we want to return to that dashboard when we're | ||||
// done editing. | |||||
$dashboard_id = $request->getStr('dashboardID'); | $dashboard_id = $request->getStr('dashboardID'); | ||||
$column_id = $request->getStr('columnID'); | |||||
if (strlen($dashboard_id)) { | if (strlen($dashboard_id)) { | ||||
$dashboard = id(new PhabricatorDashboardQuery()) | $dashboard = id(new PhabricatorDashboardQuery()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->withIDs(array($dashboard_id)) | ->withIDs(array($dashboard_id)) | ||||
->requireCapabilities( | ->requireCapabilities( | ||||
array( | array( | ||||
PhabricatorPolicyCapability::CAN_VIEW, | PhabricatorPolicyCapability::CAN_VIEW, | ||||
PhabricatorPolicyCapability::CAN_EDIT, | PhabricatorPolicyCapability::CAN_EDIT, | ||||
)) | )) | ||||
->executeOne(); | ->executeOne(); | ||||
if (!$dashboard) { | if (!$dashboard) { | ||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
} | } | ||||
$engine | |||||
->setDashboard($dashboard) | |||||
->addContextParameter('dashboardID', $dashboard_id); | |||||
} else { | } else { | ||||
$dashboard = null; | $dashboard = null; | ||||
} | } | ||||
$id = $request->getURIData('id'); | |||||
if (!$id) { | |||||
$column_id = $request->getStr('columnID'); | |||||
if ($dashboard) { | if ($dashboard) { | ||||
$cancel_uri = $dashboard->getURI(); | $cancel_uri = $dashboard->getURI(); | ||||
} else { | } else { | ||||
$cancel_uri = $this->getApplicationURI('panel/'); | $cancel_uri = $this->getApplicationURI('panel/'); | ||||
} | } | ||||
$panel_type = $request->getStr('panelType'); | $panel_type = $request->getStr('panelType'); | ||||
$panel_types = PhabricatorDashboardPanelType::getAllPanelTypes(); | $panel_types = PhabricatorDashboardPanelType::getAllPanelTypes(); | ||||
if (empty($panel_types[$panel_type])) { | if (empty($panel_types[$panel_type])) { | ||||
return $this->buildPanelTypeResponse($cancel_uri); | return $this->buildPanelTypeResponse($cancel_uri); | ||||
} | } | ||||
$engine | $engine | ||||
->addContextParameter('panelType', $panel_type) | ->addContextParameter('panelType', $panel_type) | ||||
->addContextParameter('dashboardID', $dashboard_id) | |||||
->addContextParameter('columnID', $column_id) | ->addContextParameter('columnID', $column_id) | ||||
->setPanelType($panel_type) | ->setPanelType($panel_type) | ||||
->setDashboard($dashboard) | |||||
->setColumnID($column_id); | ->setColumnID($column_id); | ||||
} | } | ||||
return $engine->buildResponse(); | return $engine->buildResponse(); | ||||
} | } | ||||
private function buildPanelTypeResponse($cancel_uri) { | private function buildPanelTypeResponse($cancel_uri) { | ||||
$viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
Show All 34 Lines |