1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-24 06:20:56 +01:00

Support comments as an EditEngine field

Summary:
Ref T9132. This adds an automatic "Comments" field, like the Subscribers/Projects/Policy fields.

The primary goals here are:

  - Allow users to make comments via Conduit.
  - In the future, get stackable action support.

As a side effect, this also allows you to put comments on create forms. This is a little silly but seems fine, and may be relevant on edit forms (which I'm not 100% sure how I want to handle yet). I've just hidden them by default for now.

Test Plan:
{F976036}

{F976037}

{F976038}

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T9132

Differential Revision: https://secure.phabricator.com/D14515
This commit is contained in:
epriestley 2015-11-18 14:11:21 -08:00
parent 269e0bfc94
commit c034752578
9 changed files with 102 additions and 3 deletions

View file

@ -1843,6 +1843,8 @@ phutil_register_library_map(array(
'PhabricatorChatLogQuery' => 'applications/chatlog/query/PhabricatorChatLogQuery.php', 'PhabricatorChatLogQuery' => 'applications/chatlog/query/PhabricatorChatLogQuery.php',
'PhabricatorChunkedFileStorageEngine' => 'applications/files/engine/PhabricatorChunkedFileStorageEngine.php', 'PhabricatorChunkedFileStorageEngine' => 'applications/files/engine/PhabricatorChunkedFileStorageEngine.php',
'PhabricatorClusterConfigOptions' => 'applications/config/option/PhabricatorClusterConfigOptions.php', 'PhabricatorClusterConfigOptions' => 'applications/config/option/PhabricatorClusterConfigOptions.php',
'PhabricatorCommentEditField' => 'applications/transactions/editfield/PhabricatorCommentEditField.php',
'PhabricatorCommentEditType' => 'applications/transactions/edittype/PhabricatorCommentEditType.php',
'PhabricatorCommitBranchesField' => 'applications/repository/customfield/PhabricatorCommitBranchesField.php', 'PhabricatorCommitBranchesField' => 'applications/repository/customfield/PhabricatorCommitBranchesField.php',
'PhabricatorCommitCustomField' => 'applications/repository/customfield/PhabricatorCommitCustomField.php', 'PhabricatorCommitCustomField' => 'applications/repository/customfield/PhabricatorCommitCustomField.php',
'PhabricatorCommitMergedCommitsField' => 'applications/repository/customfield/PhabricatorCommitMergedCommitsField.php', 'PhabricatorCommitMergedCommitsField' => 'applications/repository/customfield/PhabricatorCommitMergedCommitsField.php',
@ -5890,6 +5892,8 @@ phutil_register_library_map(array(
'PhabricatorChatLogQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhabricatorChatLogQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhabricatorChunkedFileStorageEngine' => 'PhabricatorFileStorageEngine', 'PhabricatorChunkedFileStorageEngine' => 'PhabricatorFileStorageEngine',
'PhabricatorClusterConfigOptions' => 'PhabricatorApplicationConfigOptions', 'PhabricatorClusterConfigOptions' => 'PhabricatorApplicationConfigOptions',
'PhabricatorCommentEditField' => 'PhabricatorEditField',
'PhabricatorCommentEditType' => 'PhabricatorEditType',
'PhabricatorCommitBranchesField' => 'PhabricatorCommitCustomField', 'PhabricatorCommitBranchesField' => 'PhabricatorCommitCustomField',
'PhabricatorCommitCustomField' => 'PhabricatorCustomField', 'PhabricatorCommitCustomField' => 'PhabricatorCustomField',
'PhabricatorCommitMergedCommitsField' => 'PhabricatorCommitCustomField', 'PhabricatorCommitMergedCommitsField' => 'PhabricatorCommitCustomField',

View file

@ -90,11 +90,19 @@ EOTEXT
$label = $key; $label = $key;
} }
if ($field->getIsHidden()) {
$value = $lock_hidden;
} else if ($field->getIsLocked()) {
$value = $lock_locked;
} else {
$value = $lock_visible;
}
$form->appendControl( $form->appendControl(
id(new AphrontFormSelectControl()) id(new AphrontFormSelectControl())
->setName('locks['.$key.']') ->setName('locks['.$key.']')
->setLabel($label) ->setLabel($label)
->setValue(idx($locks, $key, $lock_visible)) ->setValue($value)
->setOptions($map)); ->setOptions($map));
} }

View file

@ -214,6 +214,22 @@ abstract class PhabricatorEditEngine
} }
} }
$xaction = $object->getApplicationTransactionTemplate();
$comment = $xaction->getApplicationTransactionCommentObject();
if ($comment) {
$comment_type = PhabricatorTransactions::TYPE_COMMENT;
$comment_field = id(new PhabricatorCommentEditField())
->setKey('comment')
->setLabel(pht('Comments'))
->setDescription(pht('Add comments.'))
->setAliases(array('comments'))
->setIsHidden(true)
->setTransactionType($comment_type)
->setValue(null);
$fields[] = $comment_field;
}
$config = $this->getEditEngineConfiguration(); $config = $this->getEditEngineConfiguration();
$fields = $config->applyConfigurationToFields($this, $fields); $fields = $config->applyConfigurationToFields($this, $fields);

View file

@ -0,0 +1,25 @@
<?php
final class PhabricatorCommentEditField
extends PhabricatorEditField {
protected function newControl() {
return new PhabricatorRemarkupControl();
}
protected function newEditType() {
return new PhabricatorCommentEditType();
}
public function generateTransaction(
PhabricatorApplicationTransaction $xaction) {
$spec = array(
'value' => $this->getValueForTransaction(),
);
return head($this->getEditTransactionTypes())
->generateTransaction($xaction, $spec);
}
}

View file

@ -357,6 +357,11 @@ abstract class PhabricatorEditField extends Phobject {
return $this->editTypeKey; return $this->editTypeKey;
} }
protected function newEditType() {
return id(new PhabricatorSimpleEditType())
->setValueType($this->getHTTPParameterType()->getTypeName());
}
public function getEditTransactionTypes() { public function getEditTransactionTypes() {
$transaction_type = $this->getTransactionType(); $transaction_type = $this->getTransactionType();
if ($transaction_type === null) { if ($transaction_type === null) {
@ -411,10 +416,9 @@ abstract class PhabricatorEditField extends Phobject {
} }
return array( return array(
id(new PhabricatorSimpleEditType()) $this->newEditType()
->setEditType($type_key) ->setEditType($type_key)
->setTransactionType($transaction_type) ->setTransactionType($transaction_type)
->setValueType($this->getHTTPParameterType()->getTypeName())
->setDescription($this->getDescription()) ->setDescription($this->getDescription())
->setMetadata($this->metadata), ->setMetadata($this->metadata),
); );

View file

@ -7,4 +7,8 @@ final class PhabricatorInstructionsEditField
return $form->appendRemarkupInstructions($this->getValue()); return $form->appendRemarkupInstructions($this->getValue());
} }
protected function newHTTPParameterType() {
return null;
}
} }

View file

@ -0,0 +1,31 @@
<?php
final class PhabricatorCommentEditType extends PhabricatorEditType {
public function getValueType() {
return id(new AphrontStringHTTPParameterType())->getTypeName();
}
public function generateTransaction(
PhabricatorApplicationTransaction $template,
array $spec) {
$comment = $template->getApplicationTransactionCommentObject()
->setContent(idx($spec, 'value'));
$template
->setTransactionType($this->getTransactionType())
->attachComment($comment);
foreach ($this->getMetadata() as $key => $value) {
$template->setMetadataValue($key, $value);
}
return $template;
}
public function getValueDescription() {
return pht('Comment to add, formated as remarkup.');
}
}

View file

@ -106,13 +106,19 @@ final class PhabricatorEditEngineConfiguration
$key = $field->getKey(); $key = $field->getKey();
switch (idx($locks, $key)) { switch (idx($locks, $key)) {
case self::LOCK_LOCKED: case self::LOCK_LOCKED:
$field->setIsHidden(false);
$field->setIsLocked(true); $field->setIsLocked(true);
break; break;
case self::LOCK_HIDDEN: case self::LOCK_HIDDEN:
$field->setIsHidden(true); $field->setIsHidden(true);
$field->setIsLocked(false);
break; break;
case self::LOCK_VISIBLE: case self::LOCK_VISIBLE:
$field->setIsHidden(false);
$field->setIsLocked(false);
break;
default: default:
// If we don't have an explicit value, don't make any adjustments.
break; break;
} }
} }

View file

@ -42,6 +42,7 @@ final class PhabricatorApplicationEditHTTPParameterHelpView
$type = $field->getHTTPParameterType(); $type = $field->getHTTPParameterType();
if ($type === null) { if ($type === null) {
unset($fields[$key]); unset($fields[$key]);
continue;
} }
$types[$type->getTypeName()] = $type; $types[$type->getTypeName()] = $type;
} }