1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 23:02:42 +01:00

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
This commit is contained in:
epriestley 2019-04-02 09:54:44 -07:00
parent 597ef60d7e
commit 81b58dba8f
11 changed files with 126 additions and 192 deletions

View file

@ -2936,6 +2936,7 @@ phutil_register_library_map(array(
'PhabricatorDashboardPanelEditproController' => 'applications/dashboard/controller/panel/PhabricatorDashboardPanelEditproController.php', 'PhabricatorDashboardPanelEditproController' => 'applications/dashboard/controller/panel/PhabricatorDashboardPanelEditproController.php',
'PhabricatorDashboardPanelHasDashboardEdgeType' => 'applications/dashboard/edge/PhabricatorDashboardPanelHasDashboardEdgeType.php', 'PhabricatorDashboardPanelHasDashboardEdgeType' => 'applications/dashboard/edge/PhabricatorDashboardPanelHasDashboardEdgeType.php',
'PhabricatorDashboardPanelListController' => 'applications/dashboard/controller/panel/PhabricatorDashboardPanelListController.php', 'PhabricatorDashboardPanelListController' => 'applications/dashboard/controller/panel/PhabricatorDashboardPanelListController.php',
'PhabricatorDashboardPanelNameTransaction' => 'applications/dashboard/xaction/panel/PhabricatorDashboardPanelNameTransaction.php',
'PhabricatorDashboardPanelNgrams' => 'applications/dashboard/storage/PhabricatorDashboardPanelNgrams.php', 'PhabricatorDashboardPanelNgrams' => 'applications/dashboard/storage/PhabricatorDashboardPanelNgrams.php',
'PhabricatorDashboardPanelPHIDType' => 'applications/dashboard/phid/PhabricatorDashboardPanelPHIDType.php', 'PhabricatorDashboardPanelPHIDType' => 'applications/dashboard/phid/PhabricatorDashboardPanelPHIDType.php',
'PhabricatorDashboardPanelQuery' => 'applications/dashboard/query/PhabricatorDashboardPanelQuery.php', 'PhabricatorDashboardPanelQuery' => 'applications/dashboard/query/PhabricatorDashboardPanelQuery.php',
@ -2944,10 +2945,12 @@ phutil_register_library_map(array(
'PhabricatorDashboardPanelSearchApplicationCustomField' => 'applications/dashboard/customfield/PhabricatorDashboardPanelSearchApplicationCustomField.php', 'PhabricatorDashboardPanelSearchApplicationCustomField' => 'applications/dashboard/customfield/PhabricatorDashboardPanelSearchApplicationCustomField.php',
'PhabricatorDashboardPanelSearchEngine' => 'applications/dashboard/query/PhabricatorDashboardPanelSearchEngine.php', 'PhabricatorDashboardPanelSearchEngine' => 'applications/dashboard/query/PhabricatorDashboardPanelSearchEngine.php',
'PhabricatorDashboardPanelSearchQueryCustomField' => 'applications/dashboard/customfield/PhabricatorDashboardPanelSearchQueryCustomField.php', 'PhabricatorDashboardPanelSearchQueryCustomField' => 'applications/dashboard/customfield/PhabricatorDashboardPanelSearchQueryCustomField.php',
'PhabricatorDashboardPanelStatusTransaction' => 'applications/dashboard/xaction/panel/PhabricatorDashboardPanelStatusTransaction.php',
'PhabricatorDashboardPanelTabsCustomField' => 'applications/dashboard/customfield/PhabricatorDashboardPanelTabsCustomField.php', 'PhabricatorDashboardPanelTabsCustomField' => 'applications/dashboard/customfield/PhabricatorDashboardPanelTabsCustomField.php',
'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',
'PhabricatorDashboardPanelTransactionType' => 'applications/dashboard/xaction/panel/PhabricatorDashboardPanelTransactionType.php',
'PhabricatorDashboardPanelType' => 'applications/dashboard/paneltype/PhabricatorDashboardPanelType.php', 'PhabricatorDashboardPanelType' => 'applications/dashboard/paneltype/PhabricatorDashboardPanelType.php',
'PhabricatorDashboardPanelViewController' => 'applications/dashboard/controller/panel/PhabricatorDashboardPanelViewController.php', 'PhabricatorDashboardPanelViewController' => 'applications/dashboard/controller/panel/PhabricatorDashboardPanelViewController.php',
'PhabricatorDashboardPortal' => 'applications/dashboard/storage/PhabricatorDashboardPortal.php', 'PhabricatorDashboardPortal' => 'applications/dashboard/storage/PhabricatorDashboardPortal.php',
@ -8915,6 +8918,7 @@ phutil_register_library_map(array(
'PhabricatorDashboardPanelEditproController' => 'PhabricatorDashboardController', 'PhabricatorDashboardPanelEditproController' => 'PhabricatorDashboardController',
'PhabricatorDashboardPanelHasDashboardEdgeType' => 'PhabricatorEdgeType', 'PhabricatorDashboardPanelHasDashboardEdgeType' => 'PhabricatorEdgeType',
'PhabricatorDashboardPanelListController' => 'PhabricatorDashboardController', 'PhabricatorDashboardPanelListController' => 'PhabricatorDashboardController',
'PhabricatorDashboardPanelNameTransaction' => 'PhabricatorDashboardPanelTransactionType',
'PhabricatorDashboardPanelNgrams' => 'PhabricatorSearchNgrams', 'PhabricatorDashboardPanelNgrams' => 'PhabricatorSearchNgrams',
'PhabricatorDashboardPanelPHIDType' => 'PhabricatorPHIDType', 'PhabricatorDashboardPanelPHIDType' => 'PhabricatorPHIDType',
'PhabricatorDashboardPanelQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhabricatorDashboardPanelQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
@ -8923,10 +8927,12 @@ phutil_register_library_map(array(
'PhabricatorDashboardPanelSearchApplicationCustomField' => 'PhabricatorStandardCustomField', 'PhabricatorDashboardPanelSearchApplicationCustomField' => 'PhabricatorStandardCustomField',
'PhabricatorDashboardPanelSearchEngine' => 'PhabricatorApplicationSearchEngine', 'PhabricatorDashboardPanelSearchEngine' => 'PhabricatorApplicationSearchEngine',
'PhabricatorDashboardPanelSearchQueryCustomField' => 'PhabricatorStandardCustomField', 'PhabricatorDashboardPanelSearchQueryCustomField' => 'PhabricatorStandardCustomField',
'PhabricatorDashboardPanelStatusTransaction' => 'PhabricatorDashboardPanelTransactionType',
'PhabricatorDashboardPanelTabsCustomField' => 'PhabricatorStandardCustomField', 'PhabricatorDashboardPanelTabsCustomField' => 'PhabricatorStandardCustomField',
'PhabricatorDashboardPanelTransaction' => 'PhabricatorApplicationTransaction', 'PhabricatorDashboardPanelTransaction' => 'PhabricatorModularTransaction',
'PhabricatorDashboardPanelTransactionEditor' => 'PhabricatorApplicationTransactionEditor', 'PhabricatorDashboardPanelTransactionEditor' => 'PhabricatorApplicationTransactionEditor',
'PhabricatorDashboardPanelTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 'PhabricatorDashboardPanelTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
'PhabricatorDashboardPanelTransactionType' => 'PhabricatorModularTransactionType',
'PhabricatorDashboardPanelType' => 'Phobject', 'PhabricatorDashboardPanelType' => 'Phobject',
'PhabricatorDashboardPanelViewController' => 'PhabricatorDashboardController', 'PhabricatorDashboardPanelViewController' => 'PhabricatorDashboardController',
'PhabricatorDashboardPortal' => array( 'PhabricatorDashboardPortal' => array(

View file

@ -98,7 +98,8 @@ final class PhabricatorDashboardQueryPanelInstallController
$xactions = array(); $xactions = array();
$xactions[] = id(new PhabricatorDashboardPanelTransaction()) $xactions[] = id(new PhabricatorDashboardPanelTransaction())
->setTransactionType(PhabricatorDashboardPanelTransaction::TYPE_NAME) ->setTransactionType(
PhabricatorDashboardPanelNameTransaction::TRANSACTIONTYPE)
->setNewValue($v_name); ->setNewValue($v_name);
$xactions[] = id(new PhabricatorDashboardPanelTransaction()) $xactions[] = id(new PhabricatorDashboardPanelTransaction())

View file

@ -198,7 +198,8 @@ final class PhabricatorDashboardEditController
$xactions = array(); $xactions = array();
$xactions[] = id(new PhabricatorDashboardPanelTransaction()) $xactions[] = id(new PhabricatorDashboardPanelTransaction())
->setTransactionType(PhabricatorDashboardPanelTransaction::TYPE_NAME) ->setTransactionType(
PhabricatorDashboardPanelNameTransaction::TRANSACTIONTYPE)
->setNewValue($name); ->setNewValue($name);
$editor = id(new PhabricatorDashboardPanelTransactionEditor()) $editor = id(new PhabricatorDashboardPanelTransactionEditor())

View file

@ -25,7 +25,8 @@ final class PhabricatorDashboardPanelArchiveController
if ($request->isFormPost()) { if ($request->isFormPost()) {
$xactions = array(); $xactions = array();
$xactions[] = id(new PhabricatorDashboardPanelTransaction()) $xactions[] = id(new PhabricatorDashboardPanelTransaction())
->setTransactionType(PhabricatorDashboardPanelTransaction::TYPE_ARCHIVE) ->setTransactionType(
PhabricatorDashboardPanelStatusTransaction::TRANSACTIONTYPE)
->setNewValue((int)!$panel->getIsArchived()); ->setNewValue((int)!$panel->getIsArchived());
id(new PhabricatorDashboardPanelTransactionEditor()) id(new PhabricatorDashboardPanelTransactionEditor())

View file

@ -112,7 +112,7 @@ final class PhabricatorDashboardPanelEditController
$v_view_policy = $request->getStr('viewPolicy'); $v_view_policy = $request->getStr('viewPolicy');
$v_edit_policy = $request->getStr('editPolicy'); $v_edit_policy = $request->getStr('editPolicy');
$type_name = PhabricatorDashboardPanelTransaction::TYPE_NAME; $type_name = PhabricatorDashboardPanelNameTransaction::TRANSACTIONTYPE;
$type_view_policy = PhabricatorTransactions::TYPE_VIEW_POLICY; $type_view_policy = PhabricatorTransactions::TYPE_VIEW_POLICY;
$type_edit_policy = PhabricatorTransactions::TYPE_EDIT_POLICY; $type_edit_policy = PhabricatorTransactions::TYPE_EDIT_POLICY;

View file

@ -91,7 +91,8 @@ final class PhabricatorDashboardPanelEditEngine
->setDescription(pht('Name of the panel.')) ->setDescription(pht('Name of the panel.'))
->setConduitDescription(pht('Rename the panel.')) ->setConduitDescription(pht('Rename the panel.'))
->setConduitTypeDescription(pht('New panel name.')) ->setConduitTypeDescription(pht('New panel name.'))
->setTransactionType(PhabricatorDashboardPanelTransaction::TYPE_NAME) ->setTransactionType(
PhabricatorDashboardPanelNameTransaction::TRANSACTIONTYPE)
->setIsRequired(true) ->setIsRequired(true)
->setValue($object->getName()), ->setValue($object->getName()),
); );

View file

@ -18,96 +18,7 @@ final class PhabricatorDashboardPanelTransactionEditor
$types[] = PhabricatorTransactions::TYPE_EDIT_POLICY; $types[] = PhabricatorTransactions::TYPE_EDIT_POLICY;
$types[] = PhabricatorTransactions::TYPE_EDGE; $types[] = PhabricatorTransactions::TYPE_EDGE;
$types[] = PhabricatorDashboardPanelTransaction::TYPE_NAME;
$types[] = PhabricatorDashboardPanelTransaction::TYPE_ARCHIVE;
return $types; return $types;
} }
protected function getCustomTransactionOldValue(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
case PhabricatorDashboardPanelTransaction::TYPE_NAME:
if ($this->getIsNewObject()) {
return null;
}
return $object->getName();
case PhabricatorDashboardPanelTransaction::TYPE_ARCHIVE:
return (int)$object->getIsArchived();
}
return parent::getCustomTransactionOldValue($object, $xaction);
}
protected function getCustomTransactionNewValue(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
case PhabricatorDashboardPanelTransaction::TYPE_NAME:
return $xaction->getNewValue();
case PhabricatorDashboardPanelTransaction::TYPE_ARCHIVE:
return (int)$xaction->getNewValue();
}
return parent::getCustomTransactionNewValue($object, $xaction);
}
protected function applyCustomInternalTransaction(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
case PhabricatorDashboardPanelTransaction::TYPE_NAME:
$object->setName($xaction->getNewValue());
return;
case PhabricatorDashboardPanelTransaction::TYPE_ARCHIVE:
$object->setIsArchived((int)$xaction->getNewValue());
return;
}
return parent::applyCustomInternalTransaction($object, $xaction);
}
protected function applyCustomExternalTransaction(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
case PhabricatorDashboardPanelTransaction::TYPE_NAME:
case PhabricatorDashboardPanelTransaction::TYPE_ARCHIVE:
return;
}
return parent::applyCustomExternalTransaction($object, $xaction);
}
protected function validateTransaction(
PhabricatorLiskDAO $object,
$type,
array $xactions) {
$errors = parent::validateTransaction($object, $type, $xactions);
switch ($type) {
case PhabricatorDashboardPanelTransaction::TYPE_NAME:
$missing = $this->validateIsEmptyTextField(
$object->getName(),
$xactions);
if ($missing) {
$error = new PhabricatorApplicationTransactionValidationError(
$type,
pht('Required'),
pht('Panel name is required.'),
nonempty(last($xactions), null));
$error->setIsMissingFieldError(true);
$errors[] = $error;
}
break;
}
return $errors;
}
} }

View file

@ -1,10 +1,7 @@
<?php <?php
final class PhabricatorDashboardPanelTransaction final class PhabricatorDashboardPanelTransaction
extends PhabricatorApplicationTransaction { extends PhabricatorModularTransaction {
const TYPE_NAME = 'dashpanel:name';
const TYPE_ARCHIVE = 'dashboard:archive';
public function getApplicationName() { public function getApplicationName() {
return 'dashboard'; return 'dashboard';
@ -14,99 +11,8 @@ final class PhabricatorDashboardPanelTransaction
return PhabricatorDashboardPanelPHIDType::TYPECONST; return PhabricatorDashboardPanelPHIDType::TYPECONST;
} }
public function getTitle() { public function getBaseTransactionClass() {
$author_phid = $this->getAuthorPHID(); return 'PhabricatorDashboardPanelTransactionType';
$object_phid = $this->getObjectPHID();
$old = $this->getOldValue();
$new = $this->getNewValue();
$author_link = $this->renderHandleLink($author_phid);
$type = $this->getTransactionType();
switch ($type) {
case self::TYPE_NAME:
if (!strlen($old)) {
return pht(
'%s created this panel.',
$author_link);
} else {
return pht(
'%s renamed this panel from "%s" to "%s".',
$author_link,
$old,
$new);
}
case self::TYPE_ARCHIVE:
if ($new) {
return pht(
'%s archived this panel.',
$author_link);
} else {
return pht(
'%s activated this panel.',
$author_link);
}
}
return parent::getTitle();
} }
public function getTitleForFeed() {
$author_phid = $this->getAuthorPHID();
$object_phid = $this->getObjectPHID();
$old = $this->getOldValue();
$new = $this->getNewValue();
$author_link = $this->renderHandleLink($author_phid);
$object_link = $this->renderHandleLink($object_phid);
$type = $this->getTransactionType();
switch ($type) {
case self::TYPE_NAME:
if (!strlen($old)) {
return pht(
'%s created dashboard panel %s.',
$author_link,
$object_link);
} else {
return pht(
'%s renamed dashboard panel %s from "%s" to "%s".',
$author_link,
$object_link,
$old,
$new);
}
case self::TYPE_ARCHIVE:
if ($new) {
return pht(
'%s archived dashboard panel %s.',
$author_link,
$object_link);
} else {
return pht(
'%s activated dashboard panel %s.',
$author_link,
$object_link);
}
}
return parent::getTitleForFeed();
}
public function getColor() {
$old = $this->getOldValue();
$new = $this->getNewValue();
switch ($this->getTransactionType()) {
case self::TYPE_NAME:
if (!strlen($old)) {
return PhabricatorTransactions::COLOR_GREEN;
}
break;
}
return parent::getColor();
}
} }

View file

@ -0,0 +1,70 @@
<?php
final class PhabricatorDashboardPanelNameTransaction
extends PhabricatorDashboardPanelTransactionType {
const TRANSACTIONTYPE = 'dashpanel:name';
public function generateOldValue($object) {
return $object->getName();
}
public function applyInternalEffects($object, $value) {
$object->setName($value);
}
public function getTitle() {
$old = $this->getOldValue();
$new = $this->getNewValue();
return pht(
'%s renamed this panel from %s to %s.',
$this->renderAuthor(),
$this->renderOldValue(),
$this->renderNewValue());
}
public function validateTransactions($object, array $xactions) {
$errors = array();
$max_length = $object->getColumnMaximumByteLength('name');
foreach ($xactions as $xaction) {
$new = $xaction->getNewValue();
if (!strlen($new)) {
$errors[] = $this->newInvalidError(
pht('Panels must have a title.'),
$xaction);
continue;
}
if (strlen($new) > $max_length) {
$errors[] = $this->newInvalidError(
pht(
'Panel names must not be longer than %s characters.',
$max_length));
continue;
}
}
if (!$errors) {
if ($this->isEmptyTextTransaction($object->getName(), $xactions)) {
$errors[] = $this->newRequiredError(
pht('Panels must have a title.'));
}
}
return $errors;
}
public function getTransactionTypeForConduit($xaction) {
return 'name';
}
public function getFieldValuesForConduit($xaction, $data) {
return array(
'old' => $xaction->getOldValue(),
'new' => $xaction->getNewValue(),
);
}
}

View file

@ -0,0 +1,33 @@
<?php
final class PhabricatorDashboardPanelStatusTransaction
extends PhabricatorDashboardPanelTransactionType {
const TRANSACTIONTYPE = 'dashpanel:archive';
public function generateOldValue($object) {
return (bool)$object->getIsArchived();
}
public function generateNewValue($object, $value) {
return (bool)$value;
}
public function applyInternalEffects($object, $value) {
$object->setIsArchived((int)$value);
}
public function getTitle() {
$new = $this->getNewValue();
if ($new) {
return pht(
'%s archived this panel.',
$this->renderAuthor());
} else {
return pht(
'%s activated this panel.',
$this->renderAuthor());
}
}
}

View file

@ -0,0 +1,4 @@
<?php
abstract class PhabricatorDashboardPanelTransactionType
extends PhabricatorModularTransactionType {}