@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+192 -1
+2
resources/sql/autopatches/20140430.dash.1.paneltype.sql
··· 1 + ALTER TABLE {$NAMESPACE}_dashboard.dashboard_panel 2 + ADD panelType VARCHAR(64) NOT NULL COLLATE utf8_bin AFTER name;
+6
src/__phutil_library_map__.php
··· 1439 1439 'PhabricatorDashboardPHIDTypeDashboard' => 'applications/dashboard/phid/PhabricatorDashboardPHIDTypeDashboard.php', 1440 1440 'PhabricatorDashboardPHIDTypePanel' => 'applications/dashboard/phid/PhabricatorDashboardPHIDTypePanel.php', 1441 1441 'PhabricatorDashboardPanel' => 'applications/dashboard/storage/PhabricatorDashboardPanel.php', 1442 + 'PhabricatorDashboardPanelCreateController' => 'applications/dashboard/controller/PhabricatorDashboardPanelCreateController.php', 1442 1443 'PhabricatorDashboardPanelEditController' => 'applications/dashboard/controller/PhabricatorDashboardPanelEditController.php', 1443 1444 'PhabricatorDashboardPanelListController' => 'applications/dashboard/controller/PhabricatorDashboardPanelListController.php', 1444 1445 'PhabricatorDashboardPanelQuery' => 'applications/dashboard/query/PhabricatorDashboardPanelQuery.php', ··· 1446 1447 'PhabricatorDashboardPanelTransaction' => 'applications/dashboard/storage/PhabricatorDashboardPanelTransaction.php', 1447 1448 'PhabricatorDashboardPanelTransactionEditor' => 'applications/dashboard/editor/PhabricatorDashboardPanelTransactionEditor.php', 1448 1449 'PhabricatorDashboardPanelTransactionQuery' => 'applications/dashboard/query/PhabricatorDashboardPanelTransactionQuery.php', 1450 + 'PhabricatorDashboardPanelType' => 'applications/dashboard/paneltype/PhabricatorDashboardPanelType.php', 1451 + 'PhabricatorDashboardPanelTypeText' => 'applications/dashboard/paneltype/PhabricatorDashboardPanelTypeText.php', 1449 1452 'PhabricatorDashboardPanelViewController' => 'applications/dashboard/controller/PhabricatorDashboardPanelViewController.php', 1450 1453 'PhabricatorDashboardQuery' => 'applications/dashboard/query/PhabricatorDashboardQuery.php', 1451 1454 'PhabricatorDashboardSearchEngine' => 'applications/dashboard/query/PhabricatorDashboardSearchEngine.php', ··· 4242 4245 0 => 'PhabricatorDashboardDAO', 4243 4246 1 => 'PhabricatorPolicyInterface', 4244 4247 ), 4248 + 'PhabricatorDashboardPanelCreateController' => 'PhabricatorDashboardController', 4245 4249 'PhabricatorDashboardPanelEditController' => 'PhabricatorDashboardController', 4246 4250 'PhabricatorDashboardPanelListController' => 4247 4251 array( ··· 4253 4257 'PhabricatorDashboardPanelTransaction' => 'PhabricatorApplicationTransaction', 4254 4258 'PhabricatorDashboardPanelTransactionEditor' => 'PhabricatorApplicationTransactionEditor', 4255 4259 'PhabricatorDashboardPanelTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 4260 + 'PhabricatorDashboardPanelType' => 'Phobject', 4261 + 'PhabricatorDashboardPanelTypeText' => 'PhabricatorDashboardPanelType', 4256 4262 'PhabricatorDashboardPanelViewController' => 'PhabricatorDashboardController', 4257 4263 'PhabricatorDashboardQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 4258 4264 'PhabricatorDashboardSearchEngine' => 'PhabricatorApplicationSearchEngine',
+1 -1
src/applications/dashboard/application/PhabricatorApplicationDashboard.php
··· 27 27 'panel/' => array( 28 28 '(?:query/(?P<queryKey>[^/]+)/)?' 29 29 => 'PhabricatorDashboardPanelListController', 30 - 'create/' => 'PhabricatorDashboardPanelEditController', 30 + 'create/' => 'PhabricatorDashboardPanelCreateController', 31 31 'edit/(?:(?P<id>\d+)/)?' => 'PhabricatorDashboardPanelEditController', 32 32 ), 33 33 ),
+3
src/applications/dashboard/controller/PhabricatorDashboardListController.php
··· 28 28 ->setViewer($user) 29 29 ->addNavigationItems($nav->getMenu()); 30 30 31 + $nav->addLabel(pht('Panels')); 32 + $nav->addFilter('panel/', pht('Manage Panels')); 33 + 31 34 $nav->selectFilter(null); 32 35 33 36 return $nav;
+75
src/applications/dashboard/controller/PhabricatorDashboardPanelCreateController.php
··· 1 + <?php 2 + 3 + final class PhabricatorDashboardPanelCreateController 4 + extends PhabricatorDashboardController { 5 + 6 + public function processRequest() { 7 + $request = $this->getRequest(); 8 + $viewer = $request->getUser(); 9 + 10 + $types = PhabricatorDashboardPanelType::getAllPanelTypes(); 11 + 12 + $v_type = null; 13 + $errors = array(); 14 + if ($request->isFormPost()) { 15 + $v_type = $request->getStr('type'); 16 + if (!isset($types[$v_type])) { 17 + $errors[] = pht('You must select a type of panel to create.'); 18 + } 19 + 20 + if (!$errors) { 21 + return id(new AphrontRedirectResponse())->setURI( 22 + $this->getApplicationURI('panel/edit/?type='.$v_type)); 23 + } 24 + } 25 + 26 + $cancel_uri = $this->getApplicationURI('panel/'); 27 + 28 + if (!$v_type) { 29 + $v_type = key($types); 30 + } 31 + 32 + $panel_types = id(new AphrontFormRadioButtonControl()) 33 + ->setName('type') 34 + ->setValue($v_type); 35 + 36 + foreach ($types as $key => $type) { 37 + $panel_types->addButton( 38 + $key, 39 + $type->getPanelTypeName(), 40 + $type->getPanelTypeDescription()); 41 + } 42 + 43 + $form = id(new AphrontFormView()) 44 + ->setUser($viewer) 45 + ->appendChild($panel_types) 46 + ->appendChild( 47 + id(new AphrontFormSubmitControl()) 48 + ->setValue(pht('Continue')) 49 + ->addCancelButton($cancel_uri)); 50 + 51 + $crumbs = $this->buildApplicationCrumbs(); 52 + $crumbs->addTextCrumb( 53 + pht('Panels'), 54 + $this->getApplicationURI('panel/')); 55 + $crumbs->addTextCrumb(pht('New Panel')); 56 + 57 + $title = pht('Create Dashboard Panel'); 58 + 59 + $box = id(new PHUIObjectBoxView()) 60 + ->setHeaderText($title) 61 + ->setFormErrors($errors) 62 + ->setForm($form); 63 + 64 + return $this->buildApplicationPage( 65 + array( 66 + $crumbs, 67 + $box, 68 + ), 69 + array( 70 + 'title' => $title, 71 + 'device' => true, 72 + )); 73 + } 74 + 75 + }
+9
src/applications/dashboard/controller/PhabricatorDashboardPanelEditController.php
··· 33 33 $is_create = true; 34 34 35 35 $panel = PhabricatorDashboardPanel::initializeNewPanel($viewer); 36 + 37 + $types = PhabricatorDashboardPanelType::getAllPanelTypes(); 38 + $type = $request->getStr('type'); 39 + if (empty($types[$type])) { 40 + return new Aphront404Response(); 41 + } 42 + 43 + $panel->setPanelType($type); 36 44 } 37 45 38 46 if ($is_create) { ··· 97 105 $this->getApplicationURI('panel/')); 98 106 if ($is_create) { 99 107 $crumbs->addTextCrumb(pht('New Panel')); 108 + $form->addHiddenInput('type', $panel->getPanelType()); 100 109 } else { 101 110 $crumbs->addTextCrumb( 102 111 $panel->getMonogram(),
+14
src/applications/dashboard/controller/PhabricatorDashboardPanelViewController.php
··· 94 94 $viewer, 95 95 $panel); 96 96 97 + $panel_type = $panel->getImplementation(); 98 + if ($panel_type) { 99 + $type_name = $panel_type->getPanelTypeName(); 100 + } else { 101 + $type_name = phutil_tag( 102 + 'em', 103 + array(), 104 + nonempty($panel->getPanelType(), pht('null'))); 105 + } 106 + 107 + $properties->addProperty( 108 + pht('Panel Type'), 109 + $type_name); 110 + 97 111 $properties->addProperty( 98 112 pht('Editable By'), 99 113 $descriptions[PhabricatorPolicyCapability::CAN_EDIT]);
+42
src/applications/dashboard/paneltype/PhabricatorDashboardPanelType.php
··· 1 + <?php 2 + 3 + abstract class PhabricatorDashboardPanelType extends Phobject { 4 + 5 + abstract public function getPanelTypeKey(); 6 + abstract public function getPanelTypeName(); 7 + abstract public function getPanelTypeDescription(); 8 + 9 + public static function getAllPanelTypes() { 10 + static $types; 11 + 12 + if ($types === null) { 13 + $objects = id(new PhutilSymbolLoader()) 14 + ->setAncestorClass(__CLASS__) 15 + ->loadObjects(); 16 + 17 + $map = array(); 18 + foreach ($objects as $object) { 19 + $key = $object->getPanelTypeKey(); 20 + if (!empty($map[$key])) { 21 + $this_class = get_class($object); 22 + $that_class = get_class($map[$key]); 23 + throw new Exception( 24 + pht( 25 + 'Two dashboard panels (of classes "%s" and "%s") have the '. 26 + 'same panel type key ("%s"). Each panel type must have a '. 27 + 'unique panel type key.', 28 + $this_class, 29 + $that_class, 30 + $key)); 31 + } 32 + 33 + $map[$key] = $object; 34 + } 35 + 36 + $types = $map; 37 + } 38 + 39 + return $types; 40 + } 41 + 42 + }
+20
src/applications/dashboard/paneltype/PhabricatorDashboardPanelTypeText.php
··· 1 + <?php 2 + 3 + final class PhabricatorDashboardPanelTypeText 4 + extends PhabricatorDashboardPanelType { 5 + 6 + public function getPanelTypeKey() { 7 + return 'text'; 8 + } 9 + 10 + public function getPanelTypeName() { 11 + return pht('Text Panel'); 12 + } 13 + 14 + public function getPanelTypeDescription() { 15 + return pht( 16 + 'Add some static text to the dashboard. This can be used to '. 17 + 'provide instructions or context.'); 18 + } 19 + 20 + }
+20
src/applications/dashboard/storage/PhabricatorDashboardPanel.php
··· 8 8 implements PhabricatorPolicyInterface { 9 9 10 10 protected $name; 11 + protected $panelType; 11 12 protected $viewPolicy; 12 13 protected $editPolicy; 13 14 protected $properties = array(); ··· 44 45 45 46 public function getMonogram() { 46 47 return 'W'.$this->getID(); 48 + } 49 + 50 + public function getImplementation() { 51 + return idx( 52 + PhabricatorDashboardPanelType::getAllPanelTypes(), 53 + $this->getPanelType()); 54 + } 55 + 56 + public function requireImplementation() { 57 + $impl = $this->getImplementation(); 58 + if (!$impl) { 59 + throw new Exception( 60 + pht( 61 + 'Attempting to use a panel in a way that requires an '. 62 + 'implementation, but the panel implementation ("%s") is unknown to '. 63 + 'Phabricator.', 64 + $this->getPanelType())); 65 + } 66 + return $impl; 47 67 } 48 68 49 69