mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-19 05:12:41 +01:00
Let dashboard panel types use customfield to manage editing
Summary: Ref T3583. Use the same approach Harbormaster does to give panels cheap forms. Test Plan: {F149218} {F149219} {F149220} Reviewers: chad, btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T3583 Differential Revision: https://secure.phabricator.com/D8919
This commit is contained in:
parent
dbadfeb6b7
commit
d41416faf0
8 changed files with 136 additions and 4 deletions
|
@ -1440,7 +1440,9 @@ phutil_register_library_map(array(
|
|||
'PhabricatorDashboardPHIDTypeDashboard' => 'applications/dashboard/phid/PhabricatorDashboardPHIDTypeDashboard.php',
|
||||
'PhabricatorDashboardPHIDTypePanel' => 'applications/dashboard/phid/PhabricatorDashboardPHIDTypePanel.php',
|
||||
'PhabricatorDashboardPanel' => 'applications/dashboard/storage/PhabricatorDashboardPanel.php',
|
||||
'PhabricatorDashboardPanelCoreCustomField' => 'applications/dashboard/customfield/PhabricatorDashboardPanelCoreCustomField.php',
|
||||
'PhabricatorDashboardPanelCreateController' => 'applications/dashboard/controller/PhabricatorDashboardPanelCreateController.php',
|
||||
'PhabricatorDashboardPanelCustomField' => 'applications/dashboard/customfield/PhabricatorDashboardPanelCustomField.php',
|
||||
'PhabricatorDashboardPanelEditController' => 'applications/dashboard/controller/PhabricatorDashboardPanelEditController.php',
|
||||
'PhabricatorDashboardPanelListController' => 'applications/dashboard/controller/PhabricatorDashboardPanelListController.php',
|
||||
'PhabricatorDashboardPanelQuery' => 'applications/dashboard/query/PhabricatorDashboardPanelQuery.php',
|
||||
|
@ -4249,8 +4251,15 @@ phutil_register_library_map(array(
|
|||
array(
|
||||
0 => 'PhabricatorDashboardDAO',
|
||||
1 => 'PhabricatorPolicyInterface',
|
||||
2 => 'PhabricatorCustomFieldInterface',
|
||||
),
|
||||
'PhabricatorDashboardPanelCoreCustomField' =>
|
||||
array(
|
||||
0 => 'PhabricatorDashboardPanelCustomField',
|
||||
1 => 'PhabricatorStandardCustomFieldInterface',
|
||||
),
|
||||
'PhabricatorDashboardPanelCreateController' => 'PhabricatorDashboardController',
|
||||
'PhabricatorDashboardPanelCustomField' => 'PhabricatorCustomField',
|
||||
'PhabricatorDashboardPanelEditController' => 'PhabricatorDashboardController',
|
||||
'PhabricatorDashboardPanelListController' =>
|
||||
array(
|
||||
|
|
|
@ -58,6 +58,13 @@ final class PhabricatorDashboardPanelEditController
|
|||
$v_name = $panel->getName();
|
||||
$e_name = true;
|
||||
|
||||
$field_list = PhabricatorCustomField::getObjectFields(
|
||||
$panel,
|
||||
PhabricatorCustomField::ROLE_EDIT);
|
||||
$field_list
|
||||
->setViewer($viewer)
|
||||
->readFieldsFromStorage($panel);
|
||||
|
||||
$validation_exception = null;
|
||||
if ($request->isFormPost()) {
|
||||
$v_name = $request->getStr('name');
|
||||
|
@ -65,11 +72,15 @@ final class PhabricatorDashboardPanelEditController
|
|||
$xactions = array();
|
||||
|
||||
$type_name = PhabricatorDashboardPanelTransaction::TYPE_NAME;
|
||||
|
||||
$xactions[] = id(new PhabricatorDashboardPanelTransaction())
|
||||
->setTransactionType($type_name)
|
||||
->setNewValue($v_name);
|
||||
|
||||
$field_xactions = $field_list->buildFieldTransactionsFromRequest(
|
||||
new PhabricatorDashboardPanelTransaction(),
|
||||
$request);
|
||||
$xactions = array_merge($xactions, $field_xactions);
|
||||
|
||||
try {
|
||||
$editor = id(new PhabricatorDashboardPanelTransactionEditor())
|
||||
->setActor($viewer)
|
||||
|
@ -93,7 +104,11 @@ final class PhabricatorDashboardPanelEditController
|
|||
->setLabel(pht('Name'))
|
||||
->setName('name')
|
||||
->setValue($v_name)
|
||||
->setError($e_name))
|
||||
->setError($e_name));
|
||||
|
||||
$field_list->appendFieldsToForm($form);
|
||||
|
||||
$form
|
||||
->appendChild(
|
||||
id(new AphrontFormSubmitControl())
|
||||
->setValue($button)
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorDashboardPanelCoreCustomField
|
||||
extends PhabricatorDashboardPanelCustomField
|
||||
implements PhabricatorStandardCustomFieldInterface {
|
||||
|
||||
public function getStandardCustomFieldNamespace() {
|
||||
return 'dashboard:core';
|
||||
}
|
||||
|
||||
public function createFields($object) {
|
||||
$impl = $object->requireImplementation();
|
||||
$specs = $impl->getFieldSpecifications();
|
||||
return PhabricatorStandardCustomField::buildStandardFields($this, $specs);
|
||||
}
|
||||
|
||||
public function shouldUseStorage() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function readValueFromObject(PhabricatorCustomFieldInterface $object) {
|
||||
$key = $this->getProxy()->getRawStandardFieldKey();
|
||||
$this->setValueFromStorage($object->getProperty($key));
|
||||
}
|
||||
|
||||
public function applyApplicationTransactionInternalEffects(
|
||||
PhabricatorApplicationTransaction $xaction) {
|
||||
$object = $this->getObject();
|
||||
$key = $this->getProxy()->getRawStandardFieldKey();
|
||||
|
||||
$this->setValueFromApplicationTransactions($xaction->getNewValue());
|
||||
$value = $this->getValueForStorage();
|
||||
|
||||
$object->setProperty($key, $value);
|
||||
}
|
||||
|
||||
public function applyApplicationTransactionExternalEffects(
|
||||
PhabricatorApplicationTransaction $xaction) {
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
|
||||
abstract class PhabricatorDashboardPanelCustomField
|
||||
extends PhabricatorCustomField {
|
||||
|
||||
}
|
|
@ -5,6 +5,7 @@ abstract class PhabricatorDashboardPanelType extends Phobject {
|
|||
abstract public function getPanelTypeKey();
|
||||
abstract public function getPanelTypeName();
|
||||
abstract public function getPanelTypeDescription();
|
||||
abstract public function getFieldSpecifications();
|
||||
|
||||
public static function getAllPanelTypes() {
|
||||
static $types;
|
||||
|
@ -43,9 +44,17 @@ abstract class PhabricatorDashboardPanelType extends Phobject {
|
|||
PhabricatorUser $viewer,
|
||||
PhabricatorDashboardPanel $panel) {
|
||||
|
||||
$content = $this->renderPanelContent($viewer, $panel);
|
||||
|
||||
return id(new PHUIObjectBoxView())
|
||||
->setHeaderText($panel->getName())
|
||||
->appendChild(pht('TODO: Panel content goes here.'));
|
||||
->appendChild($content);
|
||||
}
|
||||
|
||||
protected function renderPanelContent(
|
||||
PhabricatorUser $viewer,
|
||||
PhabricatorDashboardPanel $panel) {
|
||||
return pht('TODO: Panel content goes here.');
|
||||
}
|
||||
|
||||
public function shouldRenderAsync() {
|
||||
|
|
|
@ -17,4 +17,28 @@ final class PhabricatorDashboardPanelTypeText
|
|||
'provide instructions or context.');
|
||||
}
|
||||
|
||||
public function getFieldSpecifications() {
|
||||
return array(
|
||||
'text' => array(
|
||||
'name' => pht('Text'),
|
||||
'type' => 'remarkup',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
protected function renderPanelContent(
|
||||
PhabricatorUser $viewer,
|
||||
PhabricatorDashboardPanel $panel) {
|
||||
|
||||
$text = $panel->getProperty('text', '');
|
||||
|
||||
$text_content = PhabricatorMarkupEngine::renderOneObject(
|
||||
id(new PhabricatorMarkupOneOff())->setContent($text),
|
||||
'default',
|
||||
$viewer);
|
||||
|
||||
return id(new PHUIPropertyListView())
|
||||
->addTextContent($text_content);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,7 +5,9 @@
|
|||
*/
|
||||
final class PhabricatorDashboardPanel
|
||||
extends PhabricatorDashboardDAO
|
||||
implements PhabricatorPolicyInterface {
|
||||
implements
|
||||
PhabricatorPolicyInterface,
|
||||
PhabricatorCustomFieldInterface {
|
||||
|
||||
protected $name;
|
||||
protected $panelType;
|
||||
|
@ -13,6 +15,8 @@ final class PhabricatorDashboardPanel
|
|||
protected $editPolicy;
|
||||
protected $properties = array();
|
||||
|
||||
private $customFields = self::ATTACHABLE;
|
||||
|
||||
public static function initializeNewPanel(PhabricatorUser $actor) {
|
||||
return id(new PhabricatorDashboardPanel())
|
||||
->setName('')
|
||||
|
@ -94,4 +98,25 @@ final class PhabricatorDashboardPanel
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
/* -( PhabricatorCustomFieldInterface )------------------------------------ */
|
||||
|
||||
|
||||
public function getCustomFieldSpecificationForRole($role) {
|
||||
return array();
|
||||
}
|
||||
|
||||
public function getCustomFieldBaseClass() {
|
||||
return 'PhabricatorDashboardPanelCustomField';
|
||||
}
|
||||
|
||||
public function getCustomFields() {
|
||||
return $this->assertAttached($this->customFields);
|
||||
}
|
||||
|
||||
public function attachCustomFields(PhabricatorCustomFieldAttachment $fields) {
|
||||
$this->customFields = $fields;
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -83,8 +83,10 @@ final class HarbormasterBuildStep extends HarbormasterDAO
|
|||
return pht('A build step has the same policies as its build plan.');
|
||||
}
|
||||
|
||||
|
||||
/* -( PhabricatorCustomFieldInterface )------------------------------------ */
|
||||
|
||||
|
||||
public function getCustomFieldSpecificationForRole($role) {
|
||||
return array();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue