Skip to content

Commit fa6d3e2

Browse files
author
epriestley
committedJul 3, 2016
Implement a "pro" EditEngine for dashboard panels
Summary: Ref T10855. This can't replace the old edit flow yet, but get the basics in place. (This is actually much closer to just being able to swap than I anticipated since CustomFields sort of just work, but the exiting flow has some "clone existing panel" / "place directly on dashboard" stuff that this doesn't yet.) Test Plan: Created and edited a panel by manually using the "editpro" flow. Reviewers: chad Reviewed By: chad Maniphest Tasks: T10855 Differential Revision: https://secure.phabricator.com/D16226
1 parent d7b4c50 commit fa6d3e2

8 files changed

+237
-21
lines changed
 

‎src/__phutil_library_map__.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -2295,7 +2295,10 @@
22952295
'PhabricatorDashboardPanelArchiveController' => 'applications/dashboard/controller/PhabricatorDashboardPanelArchiveController.php',
22962296
'PhabricatorDashboardPanelCoreCustomField' => 'applications/dashboard/customfield/PhabricatorDashboardPanelCoreCustomField.php',
22972297
'PhabricatorDashboardPanelCustomField' => 'applications/dashboard/customfield/PhabricatorDashboardPanelCustomField.php',
2298+
'PhabricatorDashboardPanelEditConduitAPIMethod' => 'applications/dashboard/conduit/PhabricatorDashboardPanelEditConduitAPIMethod.php',
22982299
'PhabricatorDashboardPanelEditController' => 'applications/dashboard/controller/PhabricatorDashboardPanelEditController.php',
2300+
'PhabricatorDashboardPanelEditEngine' => 'applications/dashboard/editor/PhabricatorDashboardPanelEditEngine.php',
2301+
'PhabricatorDashboardPanelEditproController' => 'applications/dashboard/controller/PhabricatorDashboardPanelEditproController.php',
22992302
'PhabricatorDashboardPanelHasDashboardEdgeType' => 'applications/dashboard/edge/PhabricatorDashboardPanelHasDashboardEdgeType.php',
23002303
'PhabricatorDashboardPanelListController' => 'applications/dashboard/controller/PhabricatorDashboardPanelListController.php',
23012304
'PhabricatorDashboardPanelPHIDType' => 'applications/dashboard/phid/PhabricatorDashboardPanelPHIDType.php',
@@ -6942,7 +6945,6 @@
69426945
'PhabricatorPolicyInterface',
69436946
'PhabricatorCustomFieldInterface',
69446947
'PhabricatorFlaggableInterface',
6945-
'PhabricatorProjectInterface',
69466948
'PhabricatorDestructibleInterface',
69476949
),
69486950
'PhabricatorDashboardPanelArchiveController' => 'PhabricatorDashboardController',
@@ -6951,7 +6953,10 @@
69516953
'PhabricatorStandardCustomFieldInterface',
69526954
),
69536955
'PhabricatorDashboardPanelCustomField' => 'PhabricatorCustomField',
6956+
'PhabricatorDashboardPanelEditConduitAPIMethod' => 'PhabricatorEditEngineAPIMethod',
69546957
'PhabricatorDashboardPanelEditController' => 'PhabricatorDashboardController',
6958+
'PhabricatorDashboardPanelEditEngine' => 'PhabricatorEditEngine',
6959+
'PhabricatorDashboardPanelEditproController' => 'PhabricatorDashboardController',
69556960
'PhabricatorDashboardPanelHasDashboardEdgeType' => 'PhabricatorEdgeType',
69566961
'PhabricatorDashboardPanelListController' => 'PhabricatorDashboardController',
69576962
'PhabricatorDashboardPanelPHIDType' => 'PhabricatorPHIDType',

‎src/applications/dashboard/application/PhabricatorDashboardApplication.php

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public function getRoutes() {
4040
'(?:query/(?P<queryKey>[^/]+)/)?'
4141
=> 'PhabricatorDashboardPanelListController',
4242
'create/' => 'PhabricatorDashboardPanelEditController',
43+
$this->getEditRoutePattern('editpro/')
44+
=> 'PhabricatorDashboardPanelEditproController',
4345
'edit/(?:(?P<id>\d+)/)?' => 'PhabricatorDashboardPanelEditController',
4446
'render/(?P<id>\d+)/' => 'PhabricatorDashboardPanelRenderController',
4547
'archive/(?P<id>\d+)/'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
final class PhabricatorDashboardPanelEditConduitAPIMethod
4+
extends PhabricatorEditEngineAPIMethod {
5+
6+
public function getAPIMethodName() {
7+
return 'dashboard.panel.edit';
8+
}
9+
10+
public function newEditEngine() {
11+
return new PhabricatorDashboardPanelEditEngine();
12+
}
13+
14+
public function getMethodSummary() {
15+
return pht(
16+
'Apply transactions to create a new dashboard panel or edit an '.
17+
'existing one.');
18+
}
19+
20+
}

‎src/applications/dashboard/controller/PhabricatorDashboardPanelEditController.php

-19
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ public function handleRequest(AphrontRequest $request) {
5151
if (!$panel) {
5252
return new Aphront404Response();
5353
}
54-
$v_projects = PhabricatorEdgeQuery::loadDestinationPHIDs(
55-
$panel->getPHID(),
56-
PhabricatorProjectObjectHasProjectEdgeType::EDGECONST);
57-
$v_projects = array_reverse($v_projects);
5854

5955
if ($dashboard) {
6056
$can_edit = PhabricatorPolicyFilter::hasCapability(
@@ -84,7 +80,6 @@ public function handleRequest(AphrontRequest $request) {
8480
if (empty($types[$type])) {
8581
return $this->processPanelTypeRequest($request);
8682
}
87-
$v_projects = array();
8883

8984
$panel->setPanelType($type);
9085
}
@@ -135,7 +130,6 @@ public function handleRequest(AphrontRequest $request) {
135130
$v_name = $request->getStr('name');
136131
$v_view_policy = $request->getStr('viewPolicy');
137132
$v_edit_policy = $request->getStr('editPolicy');
138-
$v_projects = $request->getArr('projects');
139133

140134
$type_name = PhabricatorDashboardPanelTransaction::TYPE_NAME;
141135
$type_view_policy = PhabricatorTransactions::TYPE_VIEW_POLICY;
@@ -155,12 +149,6 @@ public function handleRequest(AphrontRequest $request) {
155149
->setTransactionType($type_edit_policy)
156150
->setNewValue($v_edit_policy);
157151

158-
$proj_edge_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST;
159-
$xactions[] = id(new PhabricatorDashboardPanelTransaction())
160-
->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
161-
->setMetadataValue('edge:type', $proj_edge_type)
162-
->setNewValue(array('=' => array_fuse($v_projects)));
163-
164152
$field_xactions = $field_list->buildFieldTransactionsFromRequest(
165153
new PhabricatorDashboardPanelTransaction(),
166154
$request);
@@ -238,13 +226,6 @@ public function handleRequest(AphrontRequest $request) {
238226
->setCapability(PhabricatorPolicyCapability::CAN_EDIT)
239227
->setPolicies($policies));
240228

241-
$form->appendControl(
242-
id(new AphrontFormTokenizerControl())
243-
->setLabel(pht('Tags'))
244-
->setName('projects')
245-
->setValue($v_projects)
246-
->setDatasource(new PhabricatorProjectDatasource()));
247-
248229
$field_list->appendFieldsToForm($form);
249230

250231
$crumbs = $this->buildApplicationCrumbs();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?php
2+
3+
final class PhabricatorDashboardPanelEditproController
4+
extends PhabricatorDashboardController {
5+
6+
public function handleRequest(AphrontRequest $request) {
7+
$engine = id(new PhabricatorDashboardPanelEditEngine())
8+
->setController($this);
9+
10+
$id = $request->getURIData('id');
11+
if (!$id) {
12+
$list_uri = $this->getApplicationURI('panel/');
13+
14+
$panel_type = $request->getStr('panelType');
15+
$panel_types = PhabricatorDashboardPanelType::getAllPanelTypes();
16+
if (empty($panel_types[$panel_type])) {
17+
return $this->buildPanelTypeResponse($list_uri);
18+
}
19+
20+
$engine
21+
->addContextParameter('panelType', $panel_type)
22+
->setPanelType($panel_type);
23+
}
24+
25+
return $engine->buildResponse();
26+
}
27+
28+
private function buildPanelTypeResponse($cancel_uri) {
29+
$panel_types = PhabricatorDashboardPanelType::getAllPanelTypes();
30+
31+
$viewer = $this->getViewer();
32+
$request = $this->getRequest();
33+
34+
$e_type = null;
35+
$errors = array();
36+
if ($request->isFormPost()) {
37+
$e_type = pht('Required');
38+
$errors[] = pht(
39+
'To create a new dashboard panel, you must select a panel type.');
40+
}
41+
42+
$type_control = id(new AphrontFormRadioButtonControl())
43+
->setLabel(pht('Panel Type'))
44+
->setName('panelType')
45+
->setError($e_type);
46+
47+
foreach ($panel_types as $key => $type) {
48+
$type_control->addButton(
49+
$key,
50+
$type->getPanelTypeName(),
51+
$type->getPanelTypeDescription());
52+
}
53+
54+
$form = id(new AphrontFormView())
55+
->setUser($viewer)
56+
->appendRemarkupInstructions(
57+
pht('Choose the type of dashboard panel to create:'))
58+
->appendChild($type_control);
59+
60+
if ($request->isAjax()) {
61+
return $this->newDialog()
62+
->setTitle(pht('Add New Panel'))
63+
->setWidth(AphrontDialogView::WIDTH_FORM)
64+
->setErrors($errors)
65+
->appendForm($form)
66+
->addCancelButton($cancel_uri)
67+
->addSubmitButton(pht('Continue'));
68+
}
69+
70+
$form->appendChild(
71+
id(new AphrontFormSubmitControl())
72+
->setValue(pht('Continue'))
73+
->addCancelButton($cancel_uri));
74+
75+
$title = pht('Create Dashboard Panel');
76+
$header_icon = 'fa-plus-square';
77+
78+
$crumbs = $this->buildApplicationCrumbs();
79+
$crumbs->addTextCrumb(
80+
pht('Panels'),
81+
$this->getApplicationURI('panel/'));
82+
$crumbs->addTextCrumb(pht('New Panel'));
83+
$crumbs->setBorder(true);
84+
85+
$box = id(new PHUIObjectBoxView())
86+
->setHeaderText(pht('Panel'))
87+
->setFormErrors($errors)
88+
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
89+
->setForm($form);
90+
91+
$header = id(new PHUIHeaderView())
92+
->setHeader($title)
93+
->setHeaderIcon($header_icon);
94+
95+
$view = id(new PHUITwoColumnView())
96+
->setHeader($header)
97+
->setFooter($box);
98+
99+
return $this->newPage()
100+
->setTitle($title)
101+
->setCrumbs($crumbs)
102+
->appendChild($view);
103+
}
104+
105+
}

‎src/applications/dashboard/customfield/PhabricatorDashboardPanelCoreCustomField.php

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ public function getStandardCustomFieldNamespace() {
99
}
1010

1111
public function createFields($object) {
12+
if (!$object->getPanelType()) {
13+
return array();
14+
}
15+
1216
$impl = $object->requireImplementation();
1317
$specs = $impl->getFieldSpecifications();
1418
return PhabricatorStandardCustomField::buildStandardFields($this, $specs);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?php
2+
3+
final class PhabricatorDashboardPanelEditEngine
4+
extends PhabricatorEditEngine {
5+
6+
const ENGINECONST = 'dashboard.panel';
7+
8+
private $panelType;
9+
10+
public function setPanelType($panel_type) {
11+
$this->panelType = $panel_type;
12+
return $this;
13+
}
14+
15+
public function getPanelType() {
16+
return $this->panelType;
17+
}
18+
19+
public function isEngineConfigurable() {
20+
return false;
21+
}
22+
23+
public function getEngineName() {
24+
return pht('Dashboard Panels');
25+
}
26+
27+
public function getSummaryHeader() {
28+
return pht('Edit Dashboard Panels');
29+
}
30+
31+
public function getSummaryText() {
32+
return pht('This engine is used to modify dashboard panels.');
33+
}
34+
35+
public function getEngineApplicationClass() {
36+
return 'PhabricatorSearchApplication';
37+
}
38+
39+
protected function newEditableObject() {
40+
$viewer = $this->getViewer();
41+
$panel = PhabricatorDashboardPanel::initializeNewPanel($viewer);
42+
43+
if ($this->panelType) {
44+
$panel->setPanelType($this->panelType);
45+
}
46+
47+
return $panel;
48+
}
49+
50+
protected function newObjectQuery() {
51+
return new PhabricatorDashboardPanelQuery();
52+
}
53+
54+
protected function getObjectCreateTitleText($object) {
55+
return pht('Create Dashboard Panel');
56+
}
57+
58+
protected function getObjectCreateButtonText($object) {
59+
return pht('Create Panel');
60+
}
61+
62+
protected function getObjectEditTitleText($object) {
63+
return pht('Edit Panel: %s', $object->getName());
64+
}
65+
66+
protected function getObjectEditShortText($object) {
67+
return pht('Edit Panel');
68+
}
69+
70+
protected function getObjectCreateShortText() {
71+
return pht('Edit Panel');
72+
}
73+
74+
protected function getObjectName() {
75+
return pht('Dashboard Panel');
76+
}
77+
78+
protected function getObjectViewURI($object) {
79+
return $object->getURI();
80+
}
81+
82+
protected function buildCustomEditFields($object) {
83+
return array(
84+
id(new PhabricatorTextEditField())
85+
->setKey('name')
86+
->setLabel(pht('Name'))
87+
->setDescription(pht('Name of the panel.'))
88+
->setConduitDescription(pht('Rename the panel.'))
89+
->setConduitTypeDescription(pht('New panel name.'))
90+
->setTransactionType(PhabricatorDashboardPanelTransaction::TYPE_NAME)
91+
->setIsRequired(true)
92+
->setValue($object->getName()),
93+
);
94+
}
95+
96+
}

‎src/applications/dashboard/storage/PhabricatorDashboardPanel.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ final class PhabricatorDashboardPanel
1010
PhabricatorPolicyInterface,
1111
PhabricatorCustomFieldInterface,
1212
PhabricatorFlaggableInterface,
13-
PhabricatorProjectInterface,
1413
PhabricatorDestructibleInterface {
1514

1615
protected $name;
@@ -72,6 +71,10 @@ public function getMonogram() {
7271
return 'W'.$this->getID();
7372
}
7473

74+
public function getURI() {
75+
return '/'.$this->getMonogram();
76+
}
77+
7578
public function getPanelTypes() {
7679
$panel_types = PhabricatorDashboardPanelType::getAllPanelTypes();
7780
$panel_types = mpull($panel_types, 'getPanelTypeName', 'getPanelTypeKey');

0 commit comments

Comments
 (0)
Failed to load comments.