@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.

Modularize Dashboard Panel transactionns

Summary: Depends on D20369. Ref T13272. Move toward a world where we can edit panels with just one controller, instead of separate "Edit" and "Editpro" controllers.

Test Plan: Created and edited panels. This will get vetted more thoroughly after additional changes.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13272

Differential Revision: https://secure.phabricator.com/D20370

+126 -192
+7 -1
src/__phutil_library_map__.php
··· 2936 2936 'PhabricatorDashboardPanelEditproController' => 'applications/dashboard/controller/panel/PhabricatorDashboardPanelEditproController.php', 2937 2937 'PhabricatorDashboardPanelHasDashboardEdgeType' => 'applications/dashboard/edge/PhabricatorDashboardPanelHasDashboardEdgeType.php', 2938 2938 'PhabricatorDashboardPanelListController' => 'applications/dashboard/controller/panel/PhabricatorDashboardPanelListController.php', 2939 + 'PhabricatorDashboardPanelNameTransaction' => 'applications/dashboard/xaction/panel/PhabricatorDashboardPanelNameTransaction.php', 2939 2940 'PhabricatorDashboardPanelNgrams' => 'applications/dashboard/storage/PhabricatorDashboardPanelNgrams.php', 2940 2941 'PhabricatorDashboardPanelPHIDType' => 'applications/dashboard/phid/PhabricatorDashboardPanelPHIDType.php', 2941 2942 'PhabricatorDashboardPanelQuery' => 'applications/dashboard/query/PhabricatorDashboardPanelQuery.php', ··· 2944 2945 'PhabricatorDashboardPanelSearchApplicationCustomField' => 'applications/dashboard/customfield/PhabricatorDashboardPanelSearchApplicationCustomField.php', 2945 2946 'PhabricatorDashboardPanelSearchEngine' => 'applications/dashboard/query/PhabricatorDashboardPanelSearchEngine.php', 2946 2947 'PhabricatorDashboardPanelSearchQueryCustomField' => 'applications/dashboard/customfield/PhabricatorDashboardPanelSearchQueryCustomField.php', 2948 + 'PhabricatorDashboardPanelStatusTransaction' => 'applications/dashboard/xaction/panel/PhabricatorDashboardPanelStatusTransaction.php', 2947 2949 'PhabricatorDashboardPanelTabsCustomField' => 'applications/dashboard/customfield/PhabricatorDashboardPanelTabsCustomField.php', 2948 2950 'PhabricatorDashboardPanelTransaction' => 'applications/dashboard/storage/PhabricatorDashboardPanelTransaction.php', 2949 2951 'PhabricatorDashboardPanelTransactionEditor' => 'applications/dashboard/editor/PhabricatorDashboardPanelTransactionEditor.php', 2950 2952 'PhabricatorDashboardPanelTransactionQuery' => 'applications/dashboard/query/PhabricatorDashboardPanelTransactionQuery.php', 2953 + 'PhabricatorDashboardPanelTransactionType' => 'applications/dashboard/xaction/panel/PhabricatorDashboardPanelTransactionType.php', 2951 2954 'PhabricatorDashboardPanelType' => 'applications/dashboard/paneltype/PhabricatorDashboardPanelType.php', 2952 2955 'PhabricatorDashboardPanelViewController' => 'applications/dashboard/controller/panel/PhabricatorDashboardPanelViewController.php', 2953 2956 'PhabricatorDashboardPortal' => 'applications/dashboard/storage/PhabricatorDashboardPortal.php', ··· 8915 8918 'PhabricatorDashboardPanelEditproController' => 'PhabricatorDashboardController', 8916 8919 'PhabricatorDashboardPanelHasDashboardEdgeType' => 'PhabricatorEdgeType', 8917 8920 'PhabricatorDashboardPanelListController' => 'PhabricatorDashboardController', 8921 + 'PhabricatorDashboardPanelNameTransaction' => 'PhabricatorDashboardPanelTransactionType', 8918 8922 'PhabricatorDashboardPanelNgrams' => 'PhabricatorSearchNgrams', 8919 8923 'PhabricatorDashboardPanelPHIDType' => 'PhabricatorPHIDType', 8920 8924 'PhabricatorDashboardPanelQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', ··· 8923 8927 'PhabricatorDashboardPanelSearchApplicationCustomField' => 'PhabricatorStandardCustomField', 8924 8928 'PhabricatorDashboardPanelSearchEngine' => 'PhabricatorApplicationSearchEngine', 8925 8929 'PhabricatorDashboardPanelSearchQueryCustomField' => 'PhabricatorStandardCustomField', 8930 + 'PhabricatorDashboardPanelStatusTransaction' => 'PhabricatorDashboardPanelTransactionType', 8926 8931 'PhabricatorDashboardPanelTabsCustomField' => 'PhabricatorStandardCustomField', 8927 - 'PhabricatorDashboardPanelTransaction' => 'PhabricatorApplicationTransaction', 8932 + 'PhabricatorDashboardPanelTransaction' => 'PhabricatorModularTransaction', 8928 8933 'PhabricatorDashboardPanelTransactionEditor' => 'PhabricatorApplicationTransactionEditor', 8929 8934 'PhabricatorDashboardPanelTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 8935 + 'PhabricatorDashboardPanelTransactionType' => 'PhabricatorModularTransactionType', 8930 8936 'PhabricatorDashboardPanelType' => 'Phobject', 8931 8937 'PhabricatorDashboardPanelViewController' => 'PhabricatorDashboardController', 8932 8938 'PhabricatorDashboardPortal' => array(
+2 -1
src/applications/dashboard/controller/PhabricatorDashboardQueryPanelInstallController.php
··· 98 98 $xactions = array(); 99 99 100 100 $xactions[] = id(new PhabricatorDashboardPanelTransaction()) 101 - ->setTransactionType(PhabricatorDashboardPanelTransaction::TYPE_NAME) 101 + ->setTransactionType( 102 + PhabricatorDashboardPanelNameTransaction::TRANSACTIONTYPE) 102 103 ->setNewValue($v_name); 103 104 104 105 $xactions[] = id(new PhabricatorDashboardPanelTransaction())
+2 -1
src/applications/dashboard/controller/dashboard/PhabricatorDashboardEditController.php
··· 198 198 $xactions = array(); 199 199 200 200 $xactions[] = id(new PhabricatorDashboardPanelTransaction()) 201 - ->setTransactionType(PhabricatorDashboardPanelTransaction::TYPE_NAME) 201 + ->setTransactionType( 202 + PhabricatorDashboardPanelNameTransaction::TRANSACTIONTYPE) 202 203 ->setNewValue($name); 203 204 204 205 $editor = id(new PhabricatorDashboardPanelTransactionEditor())
+2 -1
src/applications/dashboard/controller/panel/PhabricatorDashboardPanelArchiveController.php
··· 25 25 if ($request->isFormPost()) { 26 26 $xactions = array(); 27 27 $xactions[] = id(new PhabricatorDashboardPanelTransaction()) 28 - ->setTransactionType(PhabricatorDashboardPanelTransaction::TYPE_ARCHIVE) 28 + ->setTransactionType( 29 + PhabricatorDashboardPanelStatusTransaction::TRANSACTIONTYPE) 29 30 ->setNewValue((int)!$panel->getIsArchived()); 30 31 31 32 id(new PhabricatorDashboardPanelTransactionEditor())
+1 -1
src/applications/dashboard/controller/panel/PhabricatorDashboardPanelEditController.php
··· 112 112 $v_view_policy = $request->getStr('viewPolicy'); 113 113 $v_edit_policy = $request->getStr('editPolicy'); 114 114 115 - $type_name = PhabricatorDashboardPanelTransaction::TYPE_NAME; 115 + $type_name = PhabricatorDashboardPanelNameTransaction::TRANSACTIONTYPE; 116 116 $type_view_policy = PhabricatorTransactions::TYPE_VIEW_POLICY; 117 117 $type_edit_policy = PhabricatorTransactions::TYPE_EDIT_POLICY; 118 118
+2 -1
src/applications/dashboard/editor/PhabricatorDashboardPanelEditEngine.php
··· 91 91 ->setDescription(pht('Name of the panel.')) 92 92 ->setConduitDescription(pht('Rename the panel.')) 93 93 ->setConduitTypeDescription(pht('New panel name.')) 94 - ->setTransactionType(PhabricatorDashboardPanelTransaction::TYPE_NAME) 94 + ->setTransactionType( 95 + PhabricatorDashboardPanelNameTransaction::TRANSACTIONTYPE) 95 96 ->setIsRequired(true) 96 97 ->setValue($object->getName()), 97 98 );
-89
src/applications/dashboard/editor/PhabricatorDashboardPanelTransactionEditor.php
··· 18 18 $types[] = PhabricatorTransactions::TYPE_EDIT_POLICY; 19 19 $types[] = PhabricatorTransactions::TYPE_EDGE; 20 20 21 - $types[] = PhabricatorDashboardPanelTransaction::TYPE_NAME; 22 - $types[] = PhabricatorDashboardPanelTransaction::TYPE_ARCHIVE; 23 - 24 21 return $types; 25 22 } 26 - 27 - protected function getCustomTransactionOldValue( 28 - PhabricatorLiskDAO $object, 29 - PhabricatorApplicationTransaction $xaction) { 30 - switch ($xaction->getTransactionType()) { 31 - case PhabricatorDashboardPanelTransaction::TYPE_NAME: 32 - if ($this->getIsNewObject()) { 33 - return null; 34 - } 35 - return $object->getName(); 36 - case PhabricatorDashboardPanelTransaction::TYPE_ARCHIVE: 37 - return (int)$object->getIsArchived(); 38 - } 39 - 40 - return parent::getCustomTransactionOldValue($object, $xaction); 41 - } 42 - 43 - protected function getCustomTransactionNewValue( 44 - PhabricatorLiskDAO $object, 45 - PhabricatorApplicationTransaction $xaction) { 46 - switch ($xaction->getTransactionType()) { 47 - case PhabricatorDashboardPanelTransaction::TYPE_NAME: 48 - return $xaction->getNewValue(); 49 - case PhabricatorDashboardPanelTransaction::TYPE_ARCHIVE: 50 - return (int)$xaction->getNewValue(); 51 - } 52 - return parent::getCustomTransactionNewValue($object, $xaction); 53 - } 54 - 55 - protected function applyCustomInternalTransaction( 56 - PhabricatorLiskDAO $object, 57 - PhabricatorApplicationTransaction $xaction) { 58 - switch ($xaction->getTransactionType()) { 59 - case PhabricatorDashboardPanelTransaction::TYPE_NAME: 60 - $object->setName($xaction->getNewValue()); 61 - return; 62 - case PhabricatorDashboardPanelTransaction::TYPE_ARCHIVE: 63 - $object->setIsArchived((int)$xaction->getNewValue()); 64 - return; 65 - } 66 - 67 - return parent::applyCustomInternalTransaction($object, $xaction); 68 - } 69 - 70 - protected function applyCustomExternalTransaction( 71 - PhabricatorLiskDAO $object, 72 - PhabricatorApplicationTransaction $xaction) { 73 - 74 - switch ($xaction->getTransactionType()) { 75 - case PhabricatorDashboardPanelTransaction::TYPE_NAME: 76 - case PhabricatorDashboardPanelTransaction::TYPE_ARCHIVE: 77 - return; 78 - } 79 - 80 - return parent::applyCustomExternalTransaction($object, $xaction); 81 - } 82 - 83 - protected function validateTransaction( 84 - PhabricatorLiskDAO $object, 85 - $type, 86 - array $xactions) { 87 - 88 - $errors = parent::validateTransaction($object, $type, $xactions); 89 - 90 - switch ($type) { 91 - case PhabricatorDashboardPanelTransaction::TYPE_NAME: 92 - $missing = $this->validateIsEmptyTextField( 93 - $object->getName(), 94 - $xactions); 95 - 96 - if ($missing) { 97 - $error = new PhabricatorApplicationTransactionValidationError( 98 - $type, 99 - pht('Required'), 100 - pht('Panel name is required.'), 101 - nonempty(last($xactions), null)); 102 - 103 - $error->setIsMissingFieldError(true); 104 - $errors[] = $error; 105 - } 106 - break; 107 - } 108 - 109 - return $errors; 110 - } 111 - 112 23 113 24 }
+3 -97
src/applications/dashboard/storage/PhabricatorDashboardPanelTransaction.php
··· 1 1 <?php 2 2 3 3 final class PhabricatorDashboardPanelTransaction 4 - extends PhabricatorApplicationTransaction { 5 - 6 - const TYPE_NAME = 'dashpanel:name'; 7 - const TYPE_ARCHIVE = 'dashboard:archive'; 4 + extends PhabricatorModularTransaction { 8 5 9 6 public function getApplicationName() { 10 7 return 'dashboard'; ··· 14 11 return PhabricatorDashboardPanelPHIDType::TYPECONST; 15 12 } 16 13 17 - public function getTitle() { 18 - $author_phid = $this->getAuthorPHID(); 19 - $object_phid = $this->getObjectPHID(); 20 - 21 - $old = $this->getOldValue(); 22 - $new = $this->getNewValue(); 23 - 24 - $author_link = $this->renderHandleLink($author_phid); 25 - 26 - $type = $this->getTransactionType(); 27 - switch ($type) { 28 - case self::TYPE_NAME: 29 - if (!strlen($old)) { 30 - return pht( 31 - '%s created this panel.', 32 - $author_link); 33 - } else { 34 - return pht( 35 - '%s renamed this panel from "%s" to "%s".', 36 - $author_link, 37 - $old, 38 - $new); 39 - } 40 - case self::TYPE_ARCHIVE: 41 - if ($new) { 42 - return pht( 43 - '%s archived this panel.', 44 - $author_link); 45 - } else { 46 - return pht( 47 - '%s activated this panel.', 48 - $author_link); 49 - } 50 - } 51 - 52 - return parent::getTitle(); 53 - } 54 - 55 - public function getTitleForFeed() { 56 - $author_phid = $this->getAuthorPHID(); 57 - $object_phid = $this->getObjectPHID(); 58 - 59 - $old = $this->getOldValue(); 60 - $new = $this->getNewValue(); 61 - 62 - $author_link = $this->renderHandleLink($author_phid); 63 - $object_link = $this->renderHandleLink($object_phid); 64 - 65 - $type = $this->getTransactionType(); 66 - switch ($type) { 67 - case self::TYPE_NAME: 68 - if (!strlen($old)) { 69 - return pht( 70 - '%s created dashboard panel %s.', 71 - $author_link, 72 - $object_link); 73 - } else { 74 - return pht( 75 - '%s renamed dashboard panel %s from "%s" to "%s".', 76 - $author_link, 77 - $object_link, 78 - $old, 79 - $new); 80 - } 81 - case self::TYPE_ARCHIVE: 82 - if ($new) { 83 - return pht( 84 - '%s archived dashboard panel %s.', 85 - $author_link, 86 - $object_link); 87 - } else { 88 - return pht( 89 - '%s activated dashboard panel %s.', 90 - $author_link, 91 - $object_link); 92 - } 93 - } 94 - 95 - return parent::getTitleForFeed(); 14 + public function getBaseTransactionClass() { 15 + return 'PhabricatorDashboardPanelTransactionType'; 96 16 } 97 17 98 - public function getColor() { 99 - $old = $this->getOldValue(); 100 - $new = $this->getNewValue(); 101 - 102 - switch ($this->getTransactionType()) { 103 - case self::TYPE_NAME: 104 - if (!strlen($old)) { 105 - return PhabricatorTransactions::COLOR_GREEN; 106 - } 107 - break; 108 - } 109 - 110 - return parent::getColor(); 111 - } 112 18 }
+70
src/applications/dashboard/xaction/panel/PhabricatorDashboardPanelNameTransaction.php
··· 1 + <?php 2 + 3 + final class PhabricatorDashboardPanelNameTransaction 4 + extends PhabricatorDashboardPanelTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'dashpanel:name'; 7 + 8 + public function generateOldValue($object) { 9 + return $object->getName(); 10 + } 11 + 12 + public function applyInternalEffects($object, $value) { 13 + $object->setName($value); 14 + } 15 + 16 + public function getTitle() { 17 + $old = $this->getOldValue(); 18 + $new = $this->getNewValue(); 19 + 20 + return pht( 21 + '%s renamed this panel from %s to %s.', 22 + $this->renderAuthor(), 23 + $this->renderOldValue(), 24 + $this->renderNewValue()); 25 + } 26 + 27 + public function validateTransactions($object, array $xactions) { 28 + $errors = array(); 29 + 30 + $max_length = $object->getColumnMaximumByteLength('name'); 31 + foreach ($xactions as $xaction) { 32 + $new = $xaction->getNewValue(); 33 + if (!strlen($new)) { 34 + $errors[] = $this->newInvalidError( 35 + pht('Panels must have a title.'), 36 + $xaction); 37 + continue; 38 + } 39 + 40 + if (strlen($new) > $max_length) { 41 + $errors[] = $this->newInvalidError( 42 + pht( 43 + 'Panel names must not be longer than %s characters.', 44 + $max_length)); 45 + continue; 46 + } 47 + } 48 + 49 + if (!$errors) { 50 + if ($this->isEmptyTextTransaction($object->getName(), $xactions)) { 51 + $errors[] = $this->newRequiredError( 52 + pht('Panels must have a title.')); 53 + } 54 + } 55 + 56 + return $errors; 57 + } 58 + 59 + public function getTransactionTypeForConduit($xaction) { 60 + return 'name'; 61 + } 62 + 63 + public function getFieldValuesForConduit($xaction, $data) { 64 + return array( 65 + 'old' => $xaction->getOldValue(), 66 + 'new' => $xaction->getNewValue(), 67 + ); 68 + } 69 + 70 + }
+33
src/applications/dashboard/xaction/panel/PhabricatorDashboardPanelStatusTransaction.php
··· 1 + <?php 2 + 3 + final class PhabricatorDashboardPanelStatusTransaction 4 + extends PhabricatorDashboardPanelTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'dashpanel:archive'; 7 + 8 + public function generateOldValue($object) { 9 + return (bool)$object->getIsArchived(); 10 + } 11 + 12 + public function generateNewValue($object, $value) { 13 + return (bool)$value; 14 + } 15 + 16 + public function applyInternalEffects($object, $value) { 17 + $object->setIsArchived((int)$value); 18 + } 19 + 20 + public function getTitle() { 21 + $new = $this->getNewValue(); 22 + if ($new) { 23 + return pht( 24 + '%s archived this panel.', 25 + $this->renderAuthor()); 26 + } else { 27 + return pht( 28 + '%s activated this panel.', 29 + $this->renderAuthor()); 30 + } 31 + } 32 + 33 + }
+4
src/applications/dashboard/xaction/panel/PhabricatorDashboardPanelTransactionType.php
··· 1 + <?php 2 + 3 + abstract class PhabricatorDashboardPanelTransactionType 4 + extends PhabricatorModularTransactionType {}