Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / dashboard / controller / panel / PhabricatorDashboardPanelEditController.php
blob4ab76d18b50f334c3764071218f3481c49d48ecc
1 <?php
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
15 // editing.
17 $context_phid = $request->getStr('contextPHID');
18 if (strlen($context_phid)) {
19 $context = id(new PhabricatorObjectQuery())
20 ->setViewer($viewer)
21 ->withPHIDs(array($context_phid))
22 ->requireCapabilities(
23 array(
24 PhabricatorPolicyCapability::CAN_VIEW,
25 PhabricatorPolicyCapability::CAN_EDIT,
27 ->executeOne();
28 if (!$context) {
29 return new Aphront404Response();
32 if (!($context instanceof PhabricatorDashboardPanelContainerInterface)) {
33 return new Aphront404Response();
36 $engine
37 ->setContextObject($context)
38 ->addContextParameter('contextPHID', $context_phid);
39 } else {
40 $context = null;
43 $id = $request->getURIData('id');
44 if (!$id) {
45 $column_key = $request->getStr('columnKey');
47 if ($context) {
48 $cancel_uri = $context->getURI();
49 } else {
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);
59 $engine
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())
77 ->setViewer($viewer)
78 ->setFlush(true)
79 ->setBig(true);
81 $panel_types = PhabricatorDashboardPanelType::getAllPanelTypes();
82 foreach ($panel_types as $panel_type) {
83 $item = id(new PHUIObjectItemView())
84 ->setClickable(true)
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)
100 ->appendChild($menu)
101 ->addCancelButton($cancel_uri);