mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-22 14:52:41 +01:00
Add dashboard panel types
Summary: Ref T3583. These will be the primary class carrying panel implementations. Test Plan: {F149125} {F149126} Reviewers: chad, btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T3583 Differential Revision: https://secure.phabricator.com/D8912
This commit is contained in:
parent
5f02ed5bbb
commit
ea954c37e4
10 changed files with 192 additions and 1 deletions
2
resources/sql/autopatches/20140430.dash.1.paneltype.sql
Normal file
2
resources/sql/autopatches/20140430.dash.1.paneltype.sql
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
ALTER TABLE {$NAMESPACE}_dashboard.dashboard_panel
|
||||||
|
ADD panelType VARCHAR(64) NOT NULL COLLATE utf8_bin AFTER name;
|
|
@ -1439,6 +1439,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorDashboardPHIDTypeDashboard' => 'applications/dashboard/phid/PhabricatorDashboardPHIDTypeDashboard.php',
|
'PhabricatorDashboardPHIDTypeDashboard' => 'applications/dashboard/phid/PhabricatorDashboardPHIDTypeDashboard.php',
|
||||||
'PhabricatorDashboardPHIDTypePanel' => 'applications/dashboard/phid/PhabricatorDashboardPHIDTypePanel.php',
|
'PhabricatorDashboardPHIDTypePanel' => 'applications/dashboard/phid/PhabricatorDashboardPHIDTypePanel.php',
|
||||||
'PhabricatorDashboardPanel' => 'applications/dashboard/storage/PhabricatorDashboardPanel.php',
|
'PhabricatorDashboardPanel' => 'applications/dashboard/storage/PhabricatorDashboardPanel.php',
|
||||||
|
'PhabricatorDashboardPanelCreateController' => 'applications/dashboard/controller/PhabricatorDashboardPanelCreateController.php',
|
||||||
'PhabricatorDashboardPanelEditController' => 'applications/dashboard/controller/PhabricatorDashboardPanelEditController.php',
|
'PhabricatorDashboardPanelEditController' => 'applications/dashboard/controller/PhabricatorDashboardPanelEditController.php',
|
||||||
'PhabricatorDashboardPanelListController' => 'applications/dashboard/controller/PhabricatorDashboardPanelListController.php',
|
'PhabricatorDashboardPanelListController' => 'applications/dashboard/controller/PhabricatorDashboardPanelListController.php',
|
||||||
'PhabricatorDashboardPanelQuery' => 'applications/dashboard/query/PhabricatorDashboardPanelQuery.php',
|
'PhabricatorDashboardPanelQuery' => 'applications/dashboard/query/PhabricatorDashboardPanelQuery.php',
|
||||||
|
@ -1446,6 +1447,8 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorDashboardPanelTransaction' => 'applications/dashboard/storage/PhabricatorDashboardPanelTransaction.php',
|
'PhabricatorDashboardPanelTransaction' => 'applications/dashboard/storage/PhabricatorDashboardPanelTransaction.php',
|
||||||
'PhabricatorDashboardPanelTransactionEditor' => 'applications/dashboard/editor/PhabricatorDashboardPanelTransactionEditor.php',
|
'PhabricatorDashboardPanelTransactionEditor' => 'applications/dashboard/editor/PhabricatorDashboardPanelTransactionEditor.php',
|
||||||
'PhabricatorDashboardPanelTransactionQuery' => 'applications/dashboard/query/PhabricatorDashboardPanelTransactionQuery.php',
|
'PhabricatorDashboardPanelTransactionQuery' => 'applications/dashboard/query/PhabricatorDashboardPanelTransactionQuery.php',
|
||||||
|
'PhabricatorDashboardPanelType' => 'applications/dashboard/paneltype/PhabricatorDashboardPanelType.php',
|
||||||
|
'PhabricatorDashboardPanelTypeText' => 'applications/dashboard/paneltype/PhabricatorDashboardPanelTypeText.php',
|
||||||
'PhabricatorDashboardPanelViewController' => 'applications/dashboard/controller/PhabricatorDashboardPanelViewController.php',
|
'PhabricatorDashboardPanelViewController' => 'applications/dashboard/controller/PhabricatorDashboardPanelViewController.php',
|
||||||
'PhabricatorDashboardQuery' => 'applications/dashboard/query/PhabricatorDashboardQuery.php',
|
'PhabricatorDashboardQuery' => 'applications/dashboard/query/PhabricatorDashboardQuery.php',
|
||||||
'PhabricatorDashboardSearchEngine' => 'applications/dashboard/query/PhabricatorDashboardSearchEngine.php',
|
'PhabricatorDashboardSearchEngine' => 'applications/dashboard/query/PhabricatorDashboardSearchEngine.php',
|
||||||
|
@ -4242,6 +4245,7 @@ phutil_register_library_map(array(
|
||||||
0 => 'PhabricatorDashboardDAO',
|
0 => 'PhabricatorDashboardDAO',
|
||||||
1 => 'PhabricatorPolicyInterface',
|
1 => 'PhabricatorPolicyInterface',
|
||||||
),
|
),
|
||||||
|
'PhabricatorDashboardPanelCreateController' => 'PhabricatorDashboardController',
|
||||||
'PhabricatorDashboardPanelEditController' => 'PhabricatorDashboardController',
|
'PhabricatorDashboardPanelEditController' => 'PhabricatorDashboardController',
|
||||||
'PhabricatorDashboardPanelListController' =>
|
'PhabricatorDashboardPanelListController' =>
|
||||||
array(
|
array(
|
||||||
|
@ -4253,6 +4257,8 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorDashboardPanelTransaction' => 'PhabricatorApplicationTransaction',
|
'PhabricatorDashboardPanelTransaction' => 'PhabricatorApplicationTransaction',
|
||||||
'PhabricatorDashboardPanelTransactionEditor' => 'PhabricatorApplicationTransactionEditor',
|
'PhabricatorDashboardPanelTransactionEditor' => 'PhabricatorApplicationTransactionEditor',
|
||||||
'PhabricatorDashboardPanelTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
|
'PhabricatorDashboardPanelTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
|
||||||
|
'PhabricatorDashboardPanelType' => 'Phobject',
|
||||||
|
'PhabricatorDashboardPanelTypeText' => 'PhabricatorDashboardPanelType',
|
||||||
'PhabricatorDashboardPanelViewController' => 'PhabricatorDashboardController',
|
'PhabricatorDashboardPanelViewController' => 'PhabricatorDashboardController',
|
||||||
'PhabricatorDashboardQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
'PhabricatorDashboardQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||||
'PhabricatorDashboardSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
'PhabricatorDashboardSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||||
|
|
|
@ -27,7 +27,7 @@ final class PhabricatorApplicationDashboard extends PhabricatorApplication {
|
||||||
'panel/' => array(
|
'panel/' => array(
|
||||||
'(?:query/(?P<queryKey>[^/]+)/)?'
|
'(?:query/(?P<queryKey>[^/]+)/)?'
|
||||||
=> 'PhabricatorDashboardPanelListController',
|
=> 'PhabricatorDashboardPanelListController',
|
||||||
'create/' => 'PhabricatorDashboardPanelEditController',
|
'create/' => 'PhabricatorDashboardPanelCreateController',
|
||||||
'edit/(?:(?P<id>\d+)/)?' => 'PhabricatorDashboardPanelEditController',
|
'edit/(?:(?P<id>\d+)/)?' => 'PhabricatorDashboardPanelEditController',
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
@ -28,6 +28,9 @@ final class PhabricatorDashboardListController
|
||||||
->setViewer($user)
|
->setViewer($user)
|
||||||
->addNavigationItems($nav->getMenu());
|
->addNavigationItems($nav->getMenu());
|
||||||
|
|
||||||
|
$nav->addLabel(pht('Panels'));
|
||||||
|
$nav->addFilter('panel/', pht('Manage Panels'));
|
||||||
|
|
||||||
$nav->selectFilter(null);
|
$nav->selectFilter(null);
|
||||||
|
|
||||||
return $nav;
|
return $nav;
|
||||||
|
|
|
@ -0,0 +1,75 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class PhabricatorDashboardPanelCreateController
|
||||||
|
extends PhabricatorDashboardController {
|
||||||
|
|
||||||
|
public function processRequest() {
|
||||||
|
$request = $this->getRequest();
|
||||||
|
$viewer = $request->getUser();
|
||||||
|
|
||||||
|
$types = PhabricatorDashboardPanelType::getAllPanelTypes();
|
||||||
|
|
||||||
|
$v_type = null;
|
||||||
|
$errors = array();
|
||||||
|
if ($request->isFormPost()) {
|
||||||
|
$v_type = $request->getStr('type');
|
||||||
|
if (!isset($types[$v_type])) {
|
||||||
|
$errors[] = pht('You must select a type of panel to create.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$errors) {
|
||||||
|
return id(new AphrontRedirectResponse())->setURI(
|
||||||
|
$this->getApplicationURI('panel/edit/?type='.$v_type));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$cancel_uri = $this->getApplicationURI('panel/');
|
||||||
|
|
||||||
|
if (!$v_type) {
|
||||||
|
$v_type = key($types);
|
||||||
|
}
|
||||||
|
|
||||||
|
$panel_types = id(new AphrontFormRadioButtonControl())
|
||||||
|
->setName('type')
|
||||||
|
->setValue($v_type);
|
||||||
|
|
||||||
|
foreach ($types as $key => $type) {
|
||||||
|
$panel_types->addButton(
|
||||||
|
$key,
|
||||||
|
$type->getPanelTypeName(),
|
||||||
|
$type->getPanelTypeDescription());
|
||||||
|
}
|
||||||
|
|
||||||
|
$form = id(new AphrontFormView())
|
||||||
|
->setUser($viewer)
|
||||||
|
->appendChild($panel_types)
|
||||||
|
->appendChild(
|
||||||
|
id(new AphrontFormSubmitControl())
|
||||||
|
->setValue(pht('Continue'))
|
||||||
|
->addCancelButton($cancel_uri));
|
||||||
|
|
||||||
|
$crumbs = $this->buildApplicationCrumbs();
|
||||||
|
$crumbs->addTextCrumb(
|
||||||
|
pht('Panels'),
|
||||||
|
$this->getApplicationURI('panel/'));
|
||||||
|
$crumbs->addTextCrumb(pht('New Panel'));
|
||||||
|
|
||||||
|
$title = pht('Create Dashboard Panel');
|
||||||
|
|
||||||
|
$box = id(new PHUIObjectBoxView())
|
||||||
|
->setHeaderText($title)
|
||||||
|
->setFormErrors($errors)
|
||||||
|
->setForm($form);
|
||||||
|
|
||||||
|
return $this->buildApplicationPage(
|
||||||
|
array(
|
||||||
|
$crumbs,
|
||||||
|
$box,
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'title' => $title,
|
||||||
|
'device' => true,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -33,6 +33,14 @@ final class PhabricatorDashboardPanelEditController
|
||||||
$is_create = true;
|
$is_create = true;
|
||||||
|
|
||||||
$panel = PhabricatorDashboardPanel::initializeNewPanel($viewer);
|
$panel = PhabricatorDashboardPanel::initializeNewPanel($viewer);
|
||||||
|
|
||||||
|
$types = PhabricatorDashboardPanelType::getAllPanelTypes();
|
||||||
|
$type = $request->getStr('type');
|
||||||
|
if (empty($types[$type])) {
|
||||||
|
return new Aphront404Response();
|
||||||
|
}
|
||||||
|
|
||||||
|
$panel->setPanelType($type);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($is_create) {
|
if ($is_create) {
|
||||||
|
@ -97,6 +105,7 @@ final class PhabricatorDashboardPanelEditController
|
||||||
$this->getApplicationURI('panel/'));
|
$this->getApplicationURI('panel/'));
|
||||||
if ($is_create) {
|
if ($is_create) {
|
||||||
$crumbs->addTextCrumb(pht('New Panel'));
|
$crumbs->addTextCrumb(pht('New Panel'));
|
||||||
|
$form->addHiddenInput('type', $panel->getPanelType());
|
||||||
} else {
|
} else {
|
||||||
$crumbs->addTextCrumb(
|
$crumbs->addTextCrumb(
|
||||||
$panel->getMonogram(),
|
$panel->getMonogram(),
|
||||||
|
|
|
@ -94,6 +94,20 @@ final class PhabricatorDashboardPanelViewController
|
||||||
$viewer,
|
$viewer,
|
||||||
$panel);
|
$panel);
|
||||||
|
|
||||||
|
$panel_type = $panel->getImplementation();
|
||||||
|
if ($panel_type) {
|
||||||
|
$type_name = $panel_type->getPanelTypeName();
|
||||||
|
} else {
|
||||||
|
$type_name = phutil_tag(
|
||||||
|
'em',
|
||||||
|
array(),
|
||||||
|
nonempty($panel->getPanelType(), pht('null')));
|
||||||
|
}
|
||||||
|
|
||||||
|
$properties->addProperty(
|
||||||
|
pht('Panel Type'),
|
||||||
|
$type_name);
|
||||||
|
|
||||||
$properties->addProperty(
|
$properties->addProperty(
|
||||||
pht('Editable By'),
|
pht('Editable By'),
|
||||||
$descriptions[PhabricatorPolicyCapability::CAN_EDIT]);
|
$descriptions[PhabricatorPolicyCapability::CAN_EDIT]);
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
abstract class PhabricatorDashboardPanelType extends Phobject {
|
||||||
|
|
||||||
|
abstract public function getPanelTypeKey();
|
||||||
|
abstract public function getPanelTypeName();
|
||||||
|
abstract public function getPanelTypeDescription();
|
||||||
|
|
||||||
|
public static function getAllPanelTypes() {
|
||||||
|
static $types;
|
||||||
|
|
||||||
|
if ($types === null) {
|
||||||
|
$objects = id(new PhutilSymbolLoader())
|
||||||
|
->setAncestorClass(__CLASS__)
|
||||||
|
->loadObjects();
|
||||||
|
|
||||||
|
$map = array();
|
||||||
|
foreach ($objects as $object) {
|
||||||
|
$key = $object->getPanelTypeKey();
|
||||||
|
if (!empty($map[$key])) {
|
||||||
|
$this_class = get_class($object);
|
||||||
|
$that_class = get_class($map[$key]);
|
||||||
|
throw new Exception(
|
||||||
|
pht(
|
||||||
|
'Two dashboard panels (of classes "%s" and "%s") have the '.
|
||||||
|
'same panel type key ("%s"). Each panel type must have a '.
|
||||||
|
'unique panel type key.',
|
||||||
|
$this_class,
|
||||||
|
$that_class,
|
||||||
|
$key));
|
||||||
|
}
|
||||||
|
|
||||||
|
$map[$key] = $object;
|
||||||
|
}
|
||||||
|
|
||||||
|
$types = $map;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $types;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class PhabricatorDashboardPanelTypeText
|
||||||
|
extends PhabricatorDashboardPanelType {
|
||||||
|
|
||||||
|
public function getPanelTypeKey() {
|
||||||
|
return 'text';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPanelTypeName() {
|
||||||
|
return pht('Text Panel');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPanelTypeDescription() {
|
||||||
|
return pht(
|
||||||
|
'Add some static text to the dashboard. This can be used to '.
|
||||||
|
'provide instructions or context.');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -8,6 +8,7 @@ final class PhabricatorDashboardPanel
|
||||||
implements PhabricatorPolicyInterface {
|
implements PhabricatorPolicyInterface {
|
||||||
|
|
||||||
protected $name;
|
protected $name;
|
||||||
|
protected $panelType;
|
||||||
protected $viewPolicy;
|
protected $viewPolicy;
|
||||||
protected $editPolicy;
|
protected $editPolicy;
|
||||||
protected $properties = array();
|
protected $properties = array();
|
||||||
|
@ -46,6 +47,25 @@ final class PhabricatorDashboardPanel
|
||||||
return 'W'.$this->getID();
|
return 'W'.$this->getID();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getImplementation() {
|
||||||
|
return idx(
|
||||||
|
PhabricatorDashboardPanelType::getAllPanelTypes(),
|
||||||
|
$this->getPanelType());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function requireImplementation() {
|
||||||
|
$impl = $this->getImplementation();
|
||||||
|
if (!$impl) {
|
||||||
|
throw new Exception(
|
||||||
|
pht(
|
||||||
|
'Attempting to use a panel in a way that requires an '.
|
||||||
|
'implementation, but the panel implementation ("%s") is unknown to '.
|
||||||
|
'Phabricator.',
|
||||||
|
$this->getPanelType()));
|
||||||
|
}
|
||||||
|
return $impl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue