Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/dashboard/editor/PhabricatorDashboardPanelEditEngine.php
13434 views
1
<?php
2
3
final class PhabricatorDashboardPanelEditEngine
4
extends PhabricatorEditEngine {
5
6
const ENGINECONST = 'dashboard.panel';
7
8
private $panelType;
9
private $contextObject;
10
private $columnKey;
11
12
public function setPanelType($panel_type) {
13
$this->panelType = $panel_type;
14
return $this;
15
}
16
17
public function getPanelType() {
18
return $this->panelType;
19
}
20
21
public function setContextObject($context) {
22
$this->contextObject = $context;
23
return $this;
24
}
25
26
public function getContextObject() {
27
return $this->contextObject;
28
}
29
30
public function setColumnKey($column_key) {
31
$this->columnKey = $column_key;
32
return $this;
33
}
34
35
public function getColumnKey() {
36
return $this->columnKey;
37
}
38
39
public function isEngineConfigurable() {
40
return false;
41
}
42
43
public function getEngineName() {
44
return pht('Dashboard Panels');
45
}
46
47
public function getSummaryHeader() {
48
return pht('Edit Dashboard Panels');
49
}
50
51
protected function supportsSearch() {
52
return true;
53
}
54
55
public function getSummaryText() {
56
return pht('This engine is used to modify dashboard panels.');
57
}
58
59
public function getEngineApplicationClass() {
60
return 'PhabricatorDashboardApplication';
61
}
62
63
protected function newEditableObject() {
64
$viewer = $this->getViewer();
65
$panel = PhabricatorDashboardPanel::initializeNewPanel($viewer);
66
67
if ($this->panelType) {
68
$panel->setPanelType($this->panelType);
69
}
70
71
return $panel;
72
}
73
74
protected function newEditableObjectForDocumentation() {
75
$panel = parent::newEditableObjectForDocumentation();
76
77
$text_type = id(new PhabricatorDashboardTextPanelType())
78
->getPanelTypeKey();
79
80
$panel->setPanelType($text_type);
81
82
return $panel;
83
}
84
85
protected function newObjectQuery() {
86
return new PhabricatorDashboardPanelQuery();
87
}
88
89
protected function getObjectCreateTitleText($object) {
90
return pht('Create Dashboard Panel');
91
}
92
93
protected function getObjectCreateButtonText($object) {
94
return pht('Create Panel');
95
}
96
97
protected function getObjectCreateCancelURI($object) {
98
$context = $this->getContextObject();
99
if ($context) {
100
return $context->getURI();
101
}
102
103
return parent::getObjectCreateCancelURI($object);
104
}
105
106
public function getEffectiveObjectEditDoneURI($object) {
107
$context = $this->getContextObject();
108
if ($context) {
109
return $context->getURI();
110
}
111
112
return parent::getEffectiveObjectEditDoneURI($object);
113
}
114
115
protected function getObjectEditCancelURI($object) {
116
$context = $this->getContextObject();
117
if ($context) {
118
return $context->getURI();
119
}
120
121
return parent::getObjectEditCancelURI($object);
122
}
123
124
protected function getObjectEditTitleText($object) {
125
return pht('Edit Panel: %s', $object->getName());
126
}
127
128
protected function getObjectEditShortText($object) {
129
return pht('Edit Panel');
130
}
131
132
protected function getObjectCreateShortText() {
133
return pht('Edit Panel');
134
}
135
136
protected function getObjectName() {
137
return pht('Dashboard Panel');
138
}
139
140
protected function getObjectViewURI($object) {
141
return $object->getURI();
142
}
143
144
protected function didApplyTransactions($object, array $xactions) {
145
$context = $this->getContextObject();
146
147
if ($context instanceof PhabricatorDashboard) {
148
// Only add the panel to the dashboard when we're creating a new panel,
149
// not if we're editing an existing panel.
150
if (!$this->getIsCreate()) {
151
return;
152
}
153
154
$viewer = $this->getViewer();
155
$controller = $this->getController();
156
$request = $controller->getRequest();
157
158
$dashboard = $context;
159
160
$xactions = array();
161
162
$ref_list = clone $dashboard->getPanelRefList();
163
164
$ref_list->newPanelRef($object, $this->getColumnKey());
165
$new_panels = $ref_list->toDictionary();
166
167
$xactions[] = $dashboard->getApplicationTransactionTemplate()
168
->setTransactionType(
169
PhabricatorDashboardPanelsTransaction::TRANSACTIONTYPE)
170
->setNewValue($new_panels);
171
172
$editor = $dashboard->getApplicationTransactionEditor()
173
->setActor($viewer)
174
->setContentSourceFromRequest($request)
175
->setContinueOnNoEffect(true)
176
->setContinueOnMissingFields(true);
177
178
$editor->applyTransactions($dashboard, $xactions);
179
}
180
}
181
182
protected function buildCustomEditFields($object) {
183
$fields = array(
184
id(new PhabricatorTextEditField())
185
->setKey('name')
186
->setLabel(pht('Name'))
187
->setDescription(pht('Name of the panel.'))
188
->setConduitDescription(pht('Rename the panel.'))
189
->setConduitTypeDescription(pht('New panel name.'))
190
->setTransactionType(
191
PhabricatorDashboardPanelNameTransaction::TRANSACTIONTYPE)
192
->setIsRequired(true)
193
->setValue($object->getName()),
194
);
195
196
$panel_fields = $object->getEditEngineFields();
197
foreach ($panel_fields as $panel_field) {
198
$fields[] = $panel_field;
199
}
200
201
return $fields;
202
}
203
204
}
205
206