1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 08:52:39 +01:00

Implement Maniphest "date" auxiliary field type

Summary:
Ref T404. Ref T2575. Adds a "date" type to Maniphest.

This doesn't let you default the date to anything other than `time()`; I'll do that in the next diff.

Test Plan: Created and edited a task with date fields.

Reviewers: hach-que, btrahan

Reviewed By: btrahan

CC: aran, mbishopim3

Maniphest Tasks: T404, T2575

Differential Revision: https://secure.phabricator.com/D5281
This commit is contained in:
epriestley 2013-03-07 17:23:09 -08:00
parent a3099e27bc
commit ba4649679c
2 changed files with 62 additions and 16 deletions

View file

@ -19,6 +19,7 @@ class ManiphestAuxiliaryFieldDefaultSpecification
const TYPE_STRING = 'string'; const TYPE_STRING = 'string';
const TYPE_INT = 'int'; const TYPE_INT = 'int';
const TYPE_BOOL = 'bool'; const TYPE_BOOL = 'bool';
const TYPE_DATE = 'date';
public function getFieldType() { public function getFieldType() {
return $this->fieldType; return $this->fieldType;
@ -92,6 +93,11 @@ class ManiphestAuxiliaryFieldDefaultSpecification
case self::TYPE_BOOL: case self::TYPE_BOOL:
$control = new AphrontFormCheckboxControl(); $control = new AphrontFormCheckboxControl();
break; break;
case self::TYPE_DATE:
$control = new AphrontFormDateControl();
$control->setUser($this->getUser());
$control->setValue(time());
break;
default: default:
$label = $this->getLabel(); $label = $this->getLabel();
throw new ManiphestAuxiliaryFieldTypeException( throw new ManiphestAuxiliaryFieldTypeException(
@ -99,15 +105,24 @@ class ManiphestAuxiliaryFieldDefaultSpecification
break; break;
} }
if ($type == self::TYPE_BOOL) { switch ($type) {
$control->addCheckbox( case self::TYPE_BOOL:
'auxiliary['.$this->getAuxiliaryKey().']', $control->addCheckbox(
1, 'auxiliary['.$this->getAuxiliaryKey().']',
$this->getCheckboxLabel(), 1,
(bool)$this->getValue()); $this->getCheckboxLabel(),
} else { (bool)$this->getValue());
$control->setValue($this->getValue()); break;
$control->setName('auxiliary['.$this->getAuxiliaryKey().']'); case self::TYPE_DATE:
if ($this->getValue()) {
$control->setValue($this->getValue());
}
$control->setName('auxiliary_date_'.$this->getAuxiliaryKey());
break;
default:
$control->setValue($this->getValue());
$control->setName('auxiliary['.$this->getAuxiliaryKey().']');
break;
} }
$control->setLabel($this->getLabel()); $control->setLabel($this->getLabel());
@ -117,9 +132,18 @@ class ManiphestAuxiliaryFieldDefaultSpecification
return $control; return $control;
} }
public function setValueFromRequest($request) { public function setValueFromRequest(AphrontRequest $request) {
$aux_post_values = $request->getArr('auxiliary'); switch ($this->getFieldType()) {
return $this->setValue(idx($aux_post_values, $this->getAuxiliaryKey(), '')); case self::TYPE_DATE:
$control = $this->renderControl();
$value = $control->readValueFromRequest($request);
break;
default:
$aux_post_values = $request->getArr('auxiliary');
$value = idx($aux_post_values, $this->getAuxiliaryKey(), '');
break;
}
return $this->setValue($value);
} }
public function getValueForStorage() { public function getValueForStorage() {
@ -135,8 +159,9 @@ class ManiphestAuxiliaryFieldDefaultSpecification
case self::TYPE_INT: case self::TYPE_INT:
if (!is_numeric($this->getValue())) { if (!is_numeric($this->getValue())) {
throw new ManiphestAuxiliaryFieldValidationException( throw new ManiphestAuxiliaryFieldValidationException(
$this->getLabel().' must be an integer value.' pht(
); '%s must be an integer value.',
$this->getLabel()));
} }
break; break;
case self::TYPE_BOOL: case self::TYPE_BOOL:
@ -145,6 +170,14 @@ class ManiphestAuxiliaryFieldDefaultSpecification
return true; return true;
case self::TYPE_SELECT: case self::TYPE_SELECT:
return true; return true;
case self::TYPE_DATE:
if ($this->getValue() <= 0) {
throw new ManiphestAuxiliaryFieldValidationException(
pht(
'%s must be a valid date.',
$this->getLabel()));
}
break;
} }
} }
@ -159,11 +192,13 @@ class ManiphestAuxiliaryFieldDefaultSpecification
case self::TYPE_SELECT: case self::TYPE_SELECT:
$display = idx($this->getSelectOptions(), $this->getValue()); $display = idx($this->getSelectOptions(), $this->getValue());
return $display; return $display;
case self::TYPE_DATE:
$display = phabricator_datetime($this->getValue(), $this->getUser());
return $display;
} }
return parent::renderForDetailView(); return parent::renderForDetailView();
} }
public function renderTransactionDescription( public function renderTransactionDescription(
ManiphestTransaction $transaction, ManiphestTransaction $transaction,
$target) { $target) {
@ -190,6 +225,16 @@ class ManiphestAuxiliaryFieldDefaultSpecification
"from '{$old_display}' to '{$new_display}'"; "from '{$old_display}' to '{$new_display}'";
} }
break; break;
case self::TYPE_DATE:
$new_display = phabricator_datetime($new, $this->getUser());
if ($old === null) {
$desc = "set field '{$label}' to '{$new_display}'";
} else {
$old_display = phabricator_datetime($old, $this->getUser());
$desc = "changed field '{$label}' ".
"from '{$old_display}' to '{$new_display}'";
}
break;
default: default:
if (!strlen($old)) { if (!strlen($old)) {
if (!strlen($new)) { if (!strlen($new)) {

View file

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