3 final class PhabricatorDashboardPanelEditController
4 extends PhabricatorDashboardController
{
6 public function handleRequest(AphrontRequest
$request) {
7 $viewer = $this->getViewer();
9 $engine = id(new PhabricatorDashboardPanelEditEngine())
10 ->setController($this);
12 // We can create or edit a panel in the context of a dashboard or
13 // container panel, like a tab panel. If we started this flow on some
14 // container object, we want to return to that container when we're done
17 $context_phid = $request->getStr('contextPHID');
18 if (strlen($context_phid)) {
19 $context = id(new PhabricatorObjectQuery())
21 ->withPHIDs(array($context_phid))
22 ->requireCapabilities(
24 PhabricatorPolicyCapability
::CAN_VIEW
,
25 PhabricatorPolicyCapability
::CAN_EDIT
,
29 return new Aphront404Response();
32 if (!($context instanceof PhabricatorDashboardPanelContainerInterface
)) {
33 return new Aphront404Response();
37 ->setContextObject($context)
38 ->addContextParameter('contextPHID', $context_phid);
43 $id = $request->getURIData('id');
45 $column_key = $request->getStr('columnKey');
48 $cancel_uri = $context->getURI();
50 $cancel_uri = $this->getApplicationURI('panel/');
53 $panel_type = $request->getStr('panelType');
54 $panel_types = PhabricatorDashboardPanelType
::getAllPanelTypes();
55 if (empty($panel_types[$panel_type])) {
56 return $this->buildPanelTypeResponse($cancel_uri);
60 ->addContextParameter('panelType', $panel_type)
61 ->addContextParameter('columnKey', $column_key)
62 ->setPanelType($panel_type)
63 ->setColumnKey($column_key);
66 return $engine->buildResponse();
69 private function buildPanelTypeResponse($cancel_uri) {
70 $viewer = $this->getViewer();
71 $request = $this->getRequest();
73 $base_uri = $request->getRequestURI();
74 $base_uri = new PhutilURI($base_uri);
76 $menu = id(new PHUIObjectItemListView())
81 $panel_types = PhabricatorDashboardPanelType
::getAllPanelTypes();
82 foreach ($panel_types as $panel_type) {
83 $item = id(new PHUIObjectItemView())
85 ->setImageIcon($panel_type->getIcon())
86 ->setHeader($panel_type->getPanelTypeName())
87 ->addAttribute($panel_type->getPanelTypeDescription());
89 $type_uri = id(clone $base_uri)
90 ->replaceQueryParam('panelType', $panel_type->getPanelTypeKey());
92 $item->setHref($type_uri);
94 $menu->addItem($item);
97 return $this->newDialog()
98 ->setTitle(pht('Choose Panel Type'))
99 ->setWidth(AphrontDialogView
::WIDTH_FORM
)
101 ->addCancelButton($cancel_uri);