mirror of
https://we.phorge.it/source/phorge.git
synced 2025-02-01 17:38:24 +01:00
Implement new-style "Summary" field
Summary: Ref T3886. - Adds "Summary" field. - Adds "CoreField" for fields stored on the actual object, to reduce code duplication a bit for the main fields. Test Plan: {F115902} Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T3886 Differential Revision: https://secure.phabricator.com/D8283
This commit is contained in:
parent
92ac8b5ad9
commit
be262f4b0c
5 changed files with 165 additions and 45 deletions
|
@ -355,6 +355,7 @@ phutil_register_library_map(array(
|
|||
'DifferentialCommitsFieldSpecification' => 'applications/differential/field/specification/DifferentialCommitsFieldSpecification.php',
|
||||
'DifferentialConflictsFieldSpecification' => 'applications/differential/field/specification/DifferentialConflictsFieldSpecification.php',
|
||||
'DifferentialController' => 'applications/differential/controller/DifferentialController.php',
|
||||
'DifferentialCoreCustomField' => 'applications/differential/customfield/DifferentialCoreCustomField.php',
|
||||
'DifferentialCustomField' => 'applications/differential/customfield/DifferentialCustomField.php',
|
||||
'DifferentialCustomFieldDependsOnParser' => 'applications/differential/field/parser/DifferentialCustomFieldDependsOnParser.php',
|
||||
'DifferentialCustomFieldDependsOnParserTestCase' => 'applications/differential/field/parser/__tests__/DifferentialCustomFieldDependsOnParserTestCase.php',
|
||||
|
@ -461,6 +462,7 @@ phutil_register_library_map(array(
|
|||
'DifferentialRevisionViewController' => 'applications/differential/controller/DifferentialRevisionViewController.php',
|
||||
'DifferentialSearchIndexer' => 'applications/differential/search/DifferentialSearchIndexer.php',
|
||||
'DifferentialSubscribeController' => 'applications/differential/controller/DifferentialSubscribeController.php',
|
||||
'DifferentialSummaryField' => 'applications/differential/customfield/DifferentialSummaryField.php',
|
||||
'DifferentialSummaryFieldSpecification' => 'applications/differential/field/specification/DifferentialSummaryFieldSpecification.php',
|
||||
'DifferentialTasksAttacher' => 'applications/differential/DifferentialTasksAttacher.php',
|
||||
'DifferentialTestPlanFieldSpecification' => 'applications/differential/field/specification/DifferentialTestPlanFieldSpecification.php',
|
||||
|
@ -2891,6 +2893,7 @@ phutil_register_library_map(array(
|
|||
'DifferentialCommitsFieldSpecification' => 'DifferentialFieldSpecification',
|
||||
'DifferentialConflictsFieldSpecification' => 'DifferentialFieldSpecification',
|
||||
'DifferentialController' => 'PhabricatorController',
|
||||
'DifferentialCoreCustomField' => 'DifferentialCustomField',
|
||||
'DifferentialCustomField' => 'PhabricatorCustomField',
|
||||
'DifferentialCustomFieldDependsOnParser' => 'PhabricatorCustomFieldMonogramParser',
|
||||
'DifferentialCustomFieldDependsOnParserTestCase' => 'PhabricatorTestCase',
|
||||
|
@ -3003,9 +3006,10 @@ phutil_register_library_map(array(
|
|||
'DifferentialRevisionViewController' => 'DifferentialController',
|
||||
'DifferentialSearchIndexer' => 'PhabricatorSearchDocumentIndexer',
|
||||
'DifferentialSubscribeController' => 'DifferentialController',
|
||||
'DifferentialSummaryField' => 'DifferentialCoreCustomField',
|
||||
'DifferentialSummaryFieldSpecification' => 'DifferentialFreeformFieldSpecification',
|
||||
'DifferentialTestPlanFieldSpecification' => 'DifferentialFieldSpecification',
|
||||
'DifferentialTitleField' => 'DifferentialCustomField',
|
||||
'DifferentialTitleField' => 'DifferentialCoreCustomField',
|
||||
'DifferentialTitleFieldSpecification' => 'DifferentialFreeformFieldSpecification',
|
||||
'DifferentialTransaction' => 'PhabricatorApplicationTransaction',
|
||||
'DifferentialTransactionComment' => 'PhabricatorApplicationTransactionComment',
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Base class for Differential fields with storage on the revision object
|
||||
* itself. This mostly wraps reading/writing field values to and from the
|
||||
* object.
|
||||
*/
|
||||
abstract class DifferentialCoreCustomField
|
||||
extends DifferentialCustomField {
|
||||
|
||||
private $value;
|
||||
private $fieldError;
|
||||
|
||||
abstract protected function readValueFromRevision(
|
||||
DifferentialRevision $revision);
|
||||
|
||||
abstract protected function writeValueToRevision(
|
||||
DifferentialRevision $revision,
|
||||
$value);
|
||||
|
||||
public function isCoreFieldRequired() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function canDisableField() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function shouldAppearInApplicationTransactions() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function shouldAppearInEditView() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function didSetObject(PhabricatorCustomFieldInterface $object) {
|
||||
if ($this->isCoreFieldRequired()) {
|
||||
$this->setFieldError(true);
|
||||
}
|
||||
$this->setValue($this->readValueFromRevision($object));
|
||||
}
|
||||
|
||||
public function getOldValueForApplicationTransactions() {
|
||||
return $this->readValueFromRevision($this->getObject());
|
||||
}
|
||||
|
||||
public function getNewValueForApplicationTransactions() {
|
||||
return $this->getValue();
|
||||
}
|
||||
|
||||
public function applyApplicationTransactionInternalEffects(
|
||||
PhabricatorApplicationTransaction $xaction) {
|
||||
$this->writeValueToRevision($this->getObject(), $xaction->getNewValue());
|
||||
}
|
||||
|
||||
public function setFieldError($field_error) {
|
||||
$this->fieldError = $field_error;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getFieldError() {
|
||||
return $this->fieldError;
|
||||
}
|
||||
|
||||
public function setValue($value) {
|
||||
$this->value = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getValue() {
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
final class DifferentialSummaryField
|
||||
extends DifferentialCoreCustomField {
|
||||
|
||||
public function getFieldKey() {
|
||||
return 'differential:summary';
|
||||
}
|
||||
|
||||
public function getFieldName() {
|
||||
return pht('Summary');
|
||||
}
|
||||
|
||||
public function getFieldDescription() {
|
||||
return pht('Stores a summary of the revision.');
|
||||
}
|
||||
|
||||
protected function readValueFromRevision(
|
||||
DifferentialRevision $revision) {
|
||||
return $revision->getSummary();
|
||||
}
|
||||
|
||||
protected function writeValueToRevision(
|
||||
DifferentialRevision $revision,
|
||||
$value) {
|
||||
$revision->setSummary($value);
|
||||
}
|
||||
|
||||
public function readValueFromRequest(AphrontRequest $request) {
|
||||
$this->setValue($request->getStr($this->getFieldKey()));
|
||||
}
|
||||
|
||||
public function renderEditControl() {
|
||||
return id(new PhabricatorRemarkupControl())
|
||||
->setName($this->getFieldKey())
|
||||
->setValue($this->getValue())
|
||||
->setError($this->getFieldError())
|
||||
->setLabel($this->getFieldName());
|
||||
}
|
||||
|
||||
public function getApplicationTransactionTitle(
|
||||
PhabricatorApplicationTransaction $xaction) {
|
||||
$author_phid = $xaction->getAuthorPHID();
|
||||
$old = $xaction->getOldValue();
|
||||
$new = $xaction->getNewValue();
|
||||
|
||||
return pht(
|
||||
'%s updated the summary for this revision.',
|
||||
$xaction->renderHandleLink($author_phid));
|
||||
}
|
||||
|
||||
public function getApplicationTransactionTitleForFeed(
|
||||
PhabricatorApplicationTransaction $xaction,
|
||||
PhabricatorFeedStory $story) {
|
||||
|
||||
$object_phid = $xaction->getObjectPHID();
|
||||
$author_phid = $xaction->getAuthorPHID();
|
||||
$old = $xaction->getOldValue();
|
||||
$new = $xaction->getNewValue();
|
||||
|
||||
return pht(
|
||||
'%s updated the summary for %s.',
|
||||
$xaction->renderHandleLink($author_phid),
|
||||
$xaction->renderHandleLink($object_phid));
|
||||
}
|
||||
|
||||
// TODO: Support hasChangeDetails() in CustomFields.
|
||||
|
||||
}
|
|
@ -1,19 +1,7 @@
|
|||
<?php
|
||||
|
||||
final class DifferentialTitleField
|
||||
extends DifferentialCustomField {
|
||||
|
||||
private $value;
|
||||
private $fieldError = true;
|
||||
|
||||
public function setFieldError($field_error) {
|
||||
$this->fieldError = $field_error;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getFieldError() {
|
||||
return $this->fieldError;
|
||||
}
|
||||
extends DifferentialCoreCustomField {
|
||||
|
||||
public function getFieldKey() {
|
||||
return 'differential:title';
|
||||
|
@ -27,28 +15,15 @@ final class DifferentialTitleField
|
|||
return pht('Stores the revision title.');
|
||||
}
|
||||
|
||||
public function canDisableField() {
|
||||
return false;
|
||||
protected function readValueFromRevision(
|
||||
DifferentialRevision $revision) {
|
||||
return $revision->getTitle();
|
||||
}
|
||||
|
||||
public function shouldAppearInApplicationTransactions() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function shouldAppearInEditView() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function didSetObject(PhabricatorCustomFieldInterface $object) {
|
||||
$this->value = $object->getTitle();
|
||||
}
|
||||
|
||||
public function getOldValueForApplicationTransactions() {
|
||||
return $this->getObject()->getTitle();
|
||||
}
|
||||
|
||||
public function getNewValueForApplicationTransactions() {
|
||||
return $this->value;
|
||||
protected function writeValueToRevision(
|
||||
DifferentialRevision $revision,
|
||||
$value) {
|
||||
$revision->setTitle($value);
|
||||
}
|
||||
|
||||
public function validateApplicationTransactions(
|
||||
|
@ -77,20 +52,15 @@ final class DifferentialTitleField
|
|||
}
|
||||
}
|
||||
|
||||
public function applyApplicationTransactionInternalEffects(
|
||||
PhabricatorApplicationTransaction $xaction) {
|
||||
$this->getObject()->setTitle($xaction->getNewValue());
|
||||
}
|
||||
|
||||
public function readValueFromRequest(AphrontRequest $request) {
|
||||
$this->value = $request->getStr($this->getFieldKey());
|
||||
$this->setValue($request->getStr($this->getFieldKey()));
|
||||
}
|
||||
|
||||
public function renderEditControl() {
|
||||
return id(new AphrontFormTextAreaControl())
|
||||
->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_SHORT)
|
||||
->setName($this->getFieldKey())
|
||||
->setValue($this->value)
|
||||
->setValue($this->getValue())
|
||||
->setError($this->getFieldError())
|
||||
->setLabel($this->getFieldName());
|
||||
}
|
||||
|
@ -138,5 +108,4 @@ final class DifferentialTitleField
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -465,10 +465,13 @@ final class DifferentialRevision extends DifferentialDAO
|
|||
|
||||
|
||||
public function getCustomFieldSpecificationForRole($role) {
|
||||
return array_fill_keys(
|
||||
array(
|
||||
$fields = array(
|
||||
new DifferentialTitleField(),
|
||||
new DifferentialSummaryField(),
|
||||
);
|
||||
|
||||
),
|
||||
return array_fill_keys(
|
||||
mpull($fields, 'getFieldKey'),
|
||||
array('disabled' => false));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue