Skip to content

Commit cb605ad

Browse files
author
epriestley
committed
Add edit/view plumbing for dashboards and panels
Summary: Ref T3583. This doesn't add any dashboard/panel-specific code beyond headers/titles/buttons/etc., but allows you to create and view dashboards and panel skeletons. Test Plan: See screenshots. Reviewers: btrahan, chad Reviewed By: btrahan CC: aran Maniphest Tasks: T3583 Differential Revision: https://secure.phabricator.com/D8131
1 parent 5a9a967 commit cb605ad

18 files changed

+1040
-13
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
CREATE TABLE {$NAMESPACE}_dashboard.dashboard_transaction (
2+
id INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
3+
phid VARCHAR(64) NOT NULL COLLATE utf8_bin,
4+
authorPHID VARCHAR(64) NOT NULL COLLATE utf8_bin,
5+
objectPHID VARCHAR(64) NOT NULL COLLATE utf8_bin,
6+
viewPolicy VARCHAR(64) NOT NULL COLLATE utf8_bin,
7+
editPolicy VARCHAR(64) NOT NULL COLLATE utf8_bin,
8+
commentPHID VARCHAR(64) COLLATE utf8_bin,
9+
commentVersion INT UNSIGNED NOT NULL,
10+
transactionType VARCHAR(32) NOT NULL COLLATE utf8_bin,
11+
oldValue LONGTEXT NOT NULL COLLATE utf8_bin,
12+
newValue LONGTEXT NOT NULL COLLATE utf8_bin,
13+
contentSource LONGTEXT NOT NULL COLLATE utf8_bin,
14+
metadata LONGTEXT NOT NULL COLLATE utf8_bin,
15+
dateCreated INT UNSIGNED NOT NULL,
16+
dateModified INT UNSIGNED NOT NULL,
17+
18+
UNIQUE KEY `key_phid` (phid),
19+
KEY `key_object` (objectPHID)
20+
21+
) ENGINE=InnoDB, COLLATE utf8_general_ci;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
CREATE TABLE {$NAMESPACE}_dashboard.dashboard_paneltransaction (
2+
id INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
3+
phid VARCHAR(64) NOT NULL COLLATE utf8_bin,
4+
authorPHID VARCHAR(64) NOT NULL COLLATE utf8_bin,
5+
objectPHID VARCHAR(64) NOT NULL COLLATE utf8_bin,
6+
viewPolicy VARCHAR(64) NOT NULL COLLATE utf8_bin,
7+
editPolicy VARCHAR(64) NOT NULL COLLATE utf8_bin,
8+
commentPHID VARCHAR(64) COLLATE utf8_bin,
9+
commentVersion INT UNSIGNED NOT NULL,
10+
transactionType VARCHAR(32) NOT NULL COLLATE utf8_bin,
11+
oldValue LONGTEXT NOT NULL COLLATE utf8_bin,
12+
newValue LONGTEXT NOT NULL COLLATE utf8_bin,
13+
contentSource LONGTEXT NOT NULL COLLATE utf8_bin,
14+
metadata LONGTEXT NOT NULL COLLATE utf8_bin,
15+
dateCreated INT UNSIGNED NOT NULL,
16+
dateModified INT UNSIGNED NOT NULL,
17+
18+
UNIQUE KEY `key_phid` (phid),
19+
KEY `key_object` (objectPHID)
20+
21+
) ENGINE=InnoDB, COLLATE utf8_general_ci;

src/__phutil_library_map__.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1390,15 +1390,25 @@
13901390
'PhabricatorDashboard' => 'applications/dashboard/storage/PhabricatorDashboard.php',
13911391
'PhabricatorDashboardController' => 'applications/dashboard/controller/PhabricatorDashboardController.php',
13921392
'PhabricatorDashboardDAO' => 'applications/dashboard/storage/PhabricatorDashboardDAO.php',
1393+
'PhabricatorDashboardEditController' => 'applications/dashboard/controller/PhabricatorDashboardEditController.php',
13931394
'PhabricatorDashboardListController' => 'applications/dashboard/controller/PhabricatorDashboardListController.php',
13941395
'PhabricatorDashboardPHIDTypeDashboard' => 'applications/dashboard/phid/PhabricatorDashboardPHIDTypeDashboard.php',
13951396
'PhabricatorDashboardPHIDTypePanel' => 'applications/dashboard/phid/PhabricatorDashboardPHIDTypePanel.php',
13961397
'PhabricatorDashboardPanel' => 'applications/dashboard/storage/PhabricatorDashboardPanel.php',
1398+
'PhabricatorDashboardPanelEditController' => 'applications/dashboard/controller/PhabricatorDashboardPanelEditController.php',
13971399
'PhabricatorDashboardPanelListController' => 'applications/dashboard/controller/PhabricatorDashboardPanelListController.php',
13981400
'PhabricatorDashboardPanelQuery' => 'applications/dashboard/query/PhabricatorDashboardPanelQuery.php',
13991401
'PhabricatorDashboardPanelSearchEngine' => 'applications/dashboard/query/PhabricatorDashboardPanelSearchEngine.php',
1402+
'PhabricatorDashboardPanelTransaction' => 'applications/dashboard/storage/PhabricatorDashboardPanelTransaction.php',
1403+
'PhabricatorDashboardPanelTransactionEditor' => 'applications/dashboard/editor/PhabricatorDashboardPanelTransactionEditor.php',
1404+
'PhabricatorDashboardPanelTransactionQuery' => 'applications/dashboard/query/PhabricatorDashboardPanelTransactionQuery.php',
1405+
'PhabricatorDashboardPanelViewController' => 'applications/dashboard/controller/PhabricatorDashboardPanelViewController.php',
14001406
'PhabricatorDashboardQuery' => 'applications/dashboard/query/PhabricatorDashboardQuery.php',
14011407
'PhabricatorDashboardSearchEngine' => 'applications/dashboard/query/PhabricatorDashboardSearchEngine.php',
1408+
'PhabricatorDashboardTransaction' => 'applications/dashboard/storage/PhabricatorDashboardTransaction.php',
1409+
'PhabricatorDashboardTransactionEditor' => 'applications/dashboard/editor/PhabricatorDashboardTransactionEditor.php',
1410+
'PhabricatorDashboardTransactionQuery' => 'applications/dashboard/query/PhabricatorDashboardTransactionQuery.php',
1411+
'PhabricatorDashboardViewController' => 'applications/dashboard/controller/PhabricatorDashboardViewController.php',
14021412
'PhabricatorDataNotAttachedException' => 'infrastructure/storage/lisk/PhabricatorDataNotAttachedException.php',
14031413
'PhabricatorDebugController' => 'applications/system/PhabricatorDebugController.php',
14041414
'PhabricatorDefaultFileStorageEngineSelector' => 'applications/files/engineselector/PhabricatorDefaultFileStorageEngineSelector.php',
@@ -4046,23 +4056,37 @@
40464056
),
40474057
'PhabricatorDashboardController' => 'PhabricatorController',
40484058
'PhabricatorDashboardDAO' => 'PhabricatorLiskDAO',
4059+
'PhabricatorDashboardEditController' => 'PhabricatorDashboardController',
40494060
'PhabricatorDashboardListController' =>
40504061
array(
40514062
0 => 'PhabricatorDashboardController',
40524063
1 => 'PhabricatorApplicationSearchResultsControllerInterface',
40534064
),
40544065
'PhabricatorDashboardPHIDTypeDashboard' => 'PhabricatorPHIDType',
40554066
'PhabricatorDashboardPHIDTypePanel' => 'PhabricatorPHIDType',
4056-
'PhabricatorDashboardPanel' => 'PhabricatorDashboardDAO',
4067+
'PhabricatorDashboardPanel' =>
4068+
array(
4069+
0 => 'PhabricatorDashboardDAO',
4070+
1 => 'PhabricatorPolicyInterface',
4071+
),
4072+
'PhabricatorDashboardPanelEditController' => 'PhabricatorDashboardController',
40574073
'PhabricatorDashboardPanelListController' =>
40584074
array(
40594075
0 => 'PhabricatorDashboardController',
40604076
1 => 'PhabricatorApplicationSearchResultsControllerInterface',
40614077
),
40624078
'PhabricatorDashboardPanelQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
40634079
'PhabricatorDashboardPanelSearchEngine' => 'PhabricatorApplicationSearchEngine',
4080+
'PhabricatorDashboardPanelTransaction' => 'PhabricatorApplicationTransaction',
4081+
'PhabricatorDashboardPanelTransactionEditor' => 'PhabricatorApplicationTransactionEditor',
4082+
'PhabricatorDashboardPanelTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
4083+
'PhabricatorDashboardPanelViewController' => 'PhabricatorDashboardController',
40644084
'PhabricatorDashboardQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
40654085
'PhabricatorDashboardSearchEngine' => 'PhabricatorApplicationSearchEngine',
4086+
'PhabricatorDashboardTransaction' => 'PhabricatorApplicationTransaction',
4087+
'PhabricatorDashboardTransactionEditor' => 'PhabricatorApplicationTransactionEditor',
4088+
'PhabricatorDashboardTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
4089+
'PhabricatorDashboardViewController' => 'PhabricatorDashboardController',
40664090
'PhabricatorDataNotAttachedException' => 'Exception',
40674091
'PhabricatorDebugController' => 'PhabricatorController',
40684092
'PhabricatorDefaultFileStorageEngineSelector' => 'PhabricatorFileStorageEngineSelector',

src/applications/dashboard/application/PhabricatorApplicationDashboard.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public function getShortDescription() {
1111
}
1212

1313
public function getIconName() {
14-
return 'dashboard';
14+
return 'fancyhome';
1515
}
1616

1717
public function getRoutes() {
@@ -21,9 +21,14 @@ public function getRoutes() {
2121
'(?:query/(?P<queryKey>[^/]+)/)?'
2222
=> 'PhabricatorDashboardListController',
2323
'view/(?P<id>\d+)/' => 'PhabricatorDashboardViewController',
24+
'create/' => 'PhabricatorDashboardEditController',
25+
'edit/(?:(?P<id>\d+)/)?' => 'PhabricatorDashboardEditController',
26+
2427
'panel/' => array(
2528
'(?:query/(?P<queryKey>[^/]+)/)?'
2629
=> 'PhabricatorDashboardPanelListController',
30+
'create/' => 'PhabricatorDashboardPanelEditController',
31+
'edit/(?:(?P<id>\d+)/)?' => 'PhabricatorDashboardPanelEditController',
2732
),
2833
),
2934
);
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
<?php
2+
3+
final class PhabricatorDashboardEditController
4+
extends PhabricatorDashboardController {
5+
6+
private $id;
7+
8+
public function willProcessRequest(array $data) {
9+
$this->id = idx($data, 'id');
10+
}
11+
12+
public function processRequest() {
13+
$request = $this->getRequest();
14+
$viewer = $request->getUser();
15+
16+
if ($this->id) {
17+
$dashboard = id(new PhabricatorDashboardQuery())
18+
->setViewer($viewer)
19+
->withIDs(array($this->id))
20+
->requireCapabilities(
21+
array(
22+
PhabricatorPolicyCapability::CAN_VIEW,
23+
PhabricatorPolicyCapability::CAN_EDIT,
24+
))
25+
->executeOne();
26+
if (!$dashboard) {
27+
return new Aphront404Response();
28+
}
29+
30+
$is_new = false;
31+
} else {
32+
$dashboard = PhabricatorDashboard::initializeNewDashboard($viewer);
33+
34+
$is_new = true;
35+
}
36+
37+
$crumbs = $this->buildApplicationCrumbs();
38+
39+
if ($is_new) {
40+
$title = pht('Create Dashboard');
41+
$header = pht('Create Dashboard');
42+
$button = pht('Create Dashboard');
43+
$cancel_uri = $this->getApplicationURI();
44+
45+
$crumbs->addTextCrumb('Create Dashboard');
46+
} else {
47+
$id = $dashboard->getID();
48+
$cancel_uri = $this->getApplicationURI('view/'.$id.'/');
49+
50+
$title = pht('Edit Dashboard %d', $dashboard->getID());
51+
$header = pht('Edit Dashboard "%s"', $dashboard->getName());
52+
$button = pht('Save Changes');
53+
54+
$crumbs->addTextCrumb(pht('Dashboard %d', $id), $cancel_uri);
55+
$crumbs->addTextCrumb(pht('Edit'));
56+
}
57+
58+
$v_name = $dashboard->getName();
59+
$e_name = true;
60+
61+
$validation_exception = null;
62+
if ($request->isFormPost()) {
63+
$v_name = $request->getStr('name');
64+
65+
$xactions = array();
66+
67+
$type_name = PhabricatorDashboardTransaction::TYPE_NAME;
68+
69+
$xactions[] = id(new PhabricatorDashboardTransaction())
70+
->setTransactionType($type_name)
71+
->setNewValue($v_name);
72+
73+
try {
74+
$editor = id(new PhabricatorDashboardTransactionEditor())
75+
->setActor($viewer)
76+
->setContinueOnNoEffect(true)
77+
->setContentSourceFromRequest($request)
78+
->applyTransactions($dashboard, $xactions);
79+
80+
return id(new AphrontRedirectResponse())
81+
->setURI($this->getApplicationURI('view/'.$dashboard->getID().'/'));
82+
} catch (PhabricatorApplicationTransactionValidationException $ex) {
83+
$validation_exception = $ex;
84+
85+
$e_name = $validation_exception->getShortMessage($type_name);
86+
}
87+
}
88+
89+
$form = id(new AphrontFormView())
90+
->setUser($viewer)
91+
->appendChild(
92+
id(new AphrontFormTextControl())
93+
->setLabel(pht('Name'))
94+
->setName('name')
95+
->setValue($v_name)
96+
->setError($e_name))
97+
->appendChild(
98+
id(new AphrontFormSubmitControl())
99+
->setValue($button)
100+
->addCancelButton($cancel_uri));
101+
102+
103+
$box = id(new PHUIObjectBoxView())
104+
->setHeaderText($header)
105+
->setForm($form)
106+
->setValidationException($validation_exception);
107+
108+
return $this->buildApplicationPage(
109+
array(
110+
$crumbs,
111+
$box,
112+
),
113+
array(
114+
'title' => $title,
115+
'device' => true,
116+
));
117+
}
118+
119+
}

src/applications/dashboard/controller/PhabricatorDashboardListController.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,38 @@ public function buildSideNavView() {
3333
return $nav;
3434
}
3535

36+
public function buildApplicationCrumbs() {
37+
$crumbs = parent::buildApplicationCrumbs();
38+
39+
$crumbs->addAction(
40+
id(new PHUIListItemView())
41+
->setIcon('create')
42+
->setName(pht('Create Dashboard'))
43+
->setHref($this->getApplicationURI().'create/'));
44+
45+
return $crumbs;
46+
}
47+
3648
public function renderResultsList(
3749
array $dashboards,
3850
PhabricatorSavedQuery $query) {
51+
$viewer = $this->getRequest()->getUser();
52+
53+
$list = new PHUIObjectItemListView();
54+
$list->setUser($viewer);
55+
foreach ($dashboards as $dashboard) {
56+
$id = $dashboard->getID();
57+
58+
$item = id(new PHUIObjectItemView())
59+
->setObjectName(pht('Dashboard %d', $id))
60+
->setHeader($dashboard->getName())
61+
->setHref($this->getApplicationURI("view/{$id}/"))
62+
->setObject($dashboard);
63+
64+
$list->addItem($item);
65+
}
3966

40-
return 'got '.count($dashboards).' ok';
67+
return $list;
4168
}
4269

4370
}

0 commit comments

Comments
 (0)