1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-28 00:10:57 +01:00

Implement remarkup custom control

Summary: Ref T2575. Adds "remarkup" control, which displays a remarkup control and uses the remarkup cache. Grants fields access to remarkup pipeline.

Test Plan:
{F35067}
{F35068}

Used DarkConsole to verify cache interaction with services.

Reviewers: hach-que, btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2575

Differential Revision: https://secure.phabricator.com/D5286
This commit is contained in:
epriestley 2013-03-07 17:24:33 -08:00
parent 3f56ca681f
commit 30d6cd91da
5 changed files with 91 additions and 13 deletions

View file

@ -2084,6 +2084,7 @@ phutil_register_library_map(array(
'LiskMigrationIterator' => 'PhutilBufferedIterator',
'ManiphestAction' => 'ManiphestConstants',
'ManiphestAuxiliaryFieldDefaultSpecification' => 'ManiphestAuxiliaryFieldSpecification',
'ManiphestAuxiliaryFieldSpecification' => 'PhabricatorMarkupInterface',
'ManiphestAuxiliaryFieldTypeException' => 'Exception',
'ManiphestAuxiliaryFieldValidationException' => 'Exception',
'ManiphestBatchEditController' => 'ManiphestController',

View file

@ -15,11 +15,12 @@ class ManiphestAuxiliaryFieldDefaultSpecification
private $error;
private $shouldCopyWhenCreatingSimilarTask;
const TYPE_SELECT = 'select';
const TYPE_STRING = 'string';
const TYPE_INT = 'int';
const TYPE_BOOL = 'bool';
const TYPE_DATE = 'date';
const TYPE_SELECT = 'select';
const TYPE_STRING = 'string';
const TYPE_INT = 'int';
const TYPE_BOOL = 'bool';
const TYPE_DATE = 'date';
const TYPE_REMARKUP = 'remarkup';
public function getFieldType() {
return $this->fieldType;
@ -97,6 +98,10 @@ class ManiphestAuxiliaryFieldDefaultSpecification
$control = new AphrontFormDateControl();
$control->setUser($this->getUser());
break;
case self::TYPE_REMARKUP:
$control = new PhabricatorRemarkupControl();
$control->setUser($this->getUser());
break;
default:
$label = $this->getLabel();
throw new ManiphestAuxiliaryFieldTypeException(
@ -193,6 +198,14 @@ class ManiphestAuxiliaryFieldDefaultSpecification
}
}
public function getMarkupFields() {
switch ($this->getFieldType()) {
case self::TYPE_REMARKUP:
return array('default');
}
return parent::getMarkupFields();
}
public function renderForDetailView() {
switch ($this->getFieldType()) {
case self::TYPE_BOOL:
@ -202,11 +215,13 @@ class ManiphestAuxiliaryFieldDefaultSpecification
return null;
}
case self::TYPE_SELECT:
$display = idx($this->getSelectOptions(), $this->getValue());
return $display;
return idx($this->getSelectOptions(), $this->getValue());
case self::TYPE_DATE:
$display = phabricator_datetime($this->getValue(), $this->getUser());
return $display;
return phabricator_datetime($this->getValue(), $this->getUser());
case self::TYPE_REMARKUP:
return $this->getMarkupEngine()->getOutput(
$this,
'default');
}
return parent::renderForDetailView();
}
@ -247,6 +262,10 @@ class ManiphestAuxiliaryFieldDefaultSpecification
"from '{$old_display}' to '{$new_display}'";
}
break;
case self::TYPE_REMARKUP:
// TODO: After we get ApplicationTransactions, straighten this out.
$desc = "updated field '{$label}'";
break;
default:
if (!strlen($old)) {
if (!strlen($new)) {

View file

@ -3,7 +3,8 @@
/**
* @group maniphest
*/
abstract class ManiphestAuxiliaryFieldSpecification {
abstract class ManiphestAuxiliaryFieldSpecification
implements PhabricatorMarkupInterface {
const RENDER_TARGET_HTML = 'html';
const RENDER_TARGET_TEXT = 'text';
@ -14,6 +15,7 @@ abstract class ManiphestAuxiliaryFieldSpecification {
private $value;
private $user;
private $task;
private $markupEngine;
public function setTask(ManiphestTask $task) {
$this->task = $task;
@ -158,4 +160,52 @@ abstract class ManiphestAuxiliaryFieldSpecification {
}
public function getMarkupFields() {
return array();
}
public function setMarkupEngine(PhabricatorMarkupEngine $engine) {
$this->markupEngine = $engine;
return $this;
}
public function getMarkupEngine() {
return $this->markupEngine;
}
/* -( PhabricatorMarkupInterface )----------------------------------------- */
public function getMarkupFieldKey($field) {
$hash = PhabricatorHash::digestForIndex($this->getMarkupText($field));
return 'maux:'.$this->getAuxiliaryKey().':'.$hash;
}
public function newMarkupEngine($field) {
return PhabricatorMarkupEngine::newManiphestMarkupEngine();
}
public function getMarkupText($field) {
return $this->getValue();
}
public function didMarkupText(
$field,
$output,
PhutilMarkupEngine $engine) {
return phutil_tag(
'div',
array(
'class' => 'phabricator-remarkup',
),
$output);
}
public function shouldUseMarkupCache($field) {
return true;
}
}

View file

@ -126,11 +126,19 @@ final class ManiphestTaskDetailController extends ManiphestController {
$engine->addObject($xaction, ManiphestTransaction::MARKUP_FIELD_BODY);
}
}
$engine->process();
$extensions = ManiphestTaskExtensions::newExtensions();
$aux_fields = $extensions->loadFields($task, $user);
foreach ($aux_fields as $aux_field) {
foreach ($aux_field->getMarkupFields() as $markup_field) {
$engine->addObject($aux_field, $markup_field);
$aux_field->setMarkupEngine($engine);
}
}
$engine->process();
$transaction_types = ManiphestTransactionType::getTransactionTypeMap();
$resolution_types = ManiphestTaskStatus::getTaskStatusMap();

View file

@ -44,8 +44,8 @@ Each array key must be unique, and is used to organize the internal storage of
the field. These options are available:
- **label**: Display label for the field on the edit and detail interfaces.
- **type**: Field type, one of **int**, **string**, **bool**, **select** or
**date**.
- **type**: Field type, one of **int**, **string**, **bool**, **select**,
**remarkup**, or **date**.
- **caption**: A caption to display underneath the field (optional).
- **required**: True if the user should be required to provide a value.
- **options**: If type is set to **select**, provide options for the dropdown