Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/dashboard/controller/panel/PhabricatorDashboardPanelEditController.php
12242 views
1
<?php
2
3
final class PhabricatorDashboardPanelEditController
4
extends PhabricatorDashboardController {
5
6
public function handleRequest(AphrontRequest $request) {
7
$viewer = $this->getViewer();
8
9
$engine = id(new PhabricatorDashboardPanelEditEngine())
10
->setController($this);
11
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.
16
17
$context_phid = $request->getStr('contextPHID');
18
if (phutil_nonempty_string($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,
26
))
27
->executeOne();
28
if (!$context) {
29
return new Aphront404Response();
30
}
31
32
if (!($context instanceof PhabricatorDashboardPanelContainerInterface)) {
33
return new Aphront404Response();
34
}
35
36
$engine
37
->setContextObject($context)
38
->addContextParameter('contextPHID', $context_phid);
39
} else {
40
$context = null;
41
}
42
43
$id = $request->getURIData('id');
44
if (!$id) {
45
$column_key = $request->getStr('columnKey');
46
47
if ($context) {
48
$cancel_uri = $context->getURI();
49
} else {
50
$cancel_uri = $this->getApplicationURI('panel/');
51
}
52
53
$panel_type = $request->getStr('panelType');
54
$panel_types = PhabricatorDashboardPanelType::getAllPanelTypes();
55
if (empty($panel_types[$panel_type])) {
56
return $this->buildPanelTypeResponse($cancel_uri);
57
}
58
59
$engine
60
->addContextParameter('panelType', $panel_type)
61
->addContextParameter('columnKey', $column_key)
62
->setPanelType($panel_type)
63
->setColumnKey($column_key);
64
}
65
66
return $engine->buildResponse();
67
}
68
69
private function buildPanelTypeResponse($cancel_uri) {
70
$viewer = $this->getViewer();
71
$request = $this->getRequest();
72
73
$base_uri = $request->getRequestURI();
74
$base_uri = new PhutilURI($base_uri);
75
76
$menu = id(new PHUIObjectItemListView())
77
->setViewer($viewer)
78
->setFlush(true)
79
->setBig(true);
80
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());
88
89
$type_uri = id(clone $base_uri)
90
->replaceQueryParam('panelType', $panel_type->getPanelTypeKey());
91
92
$item->setHref($type_uri);
93
94
$menu->addItem($item);
95
}
96
97
return $this->newDialog()
98
->setTitle(pht('Choose Panel Type'))
99
->setWidth(AphrontDialogView::WIDTH_FORM)
100
->appendChild($menu)
101
->addCancelButton($cancel_uri);
102
}
103
104
}
105
106