1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-21 04:50:55 +01:00

Implement Maniphest auxiliary field 'default' key

Summary: Fixes T404. Ref T2575. Allows default to be set for any field. Date defaults are interpreted by `strtotime()`. Other defaults are interpreted as expected.

Test Plan:
  - Created a string custom field with default value "Orange".
  - Created a date custom field with a fixed default value (my birthday).
  - Created a date custom field with a relative default value ("today 4:59 PM").
  - Created/edited tasks with these fields, verified everything behaved sensibly.

Reviewers: hach-que, btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T404, T2575

Differential Revision: https://secure.phabricator.com/D5282
This commit is contained in:
epriestley 2013-03-07 17:23:30 -08:00
parent ba4649679c
commit 3f56ca681f
5 changed files with 33 additions and 6 deletions

View file

@ -67,6 +67,7 @@ phutil_register_library_map(array(
'AphrontMiniPanelView' => 'view/layout/AphrontMiniPanelView.php', 'AphrontMiniPanelView' => 'view/layout/AphrontMiniPanelView.php',
'AphrontMoreView' => 'view/layout/AphrontMoreView.php', 'AphrontMoreView' => 'view/layout/AphrontMoreView.php',
'AphrontMySQLDatabaseConnectionTestCase' => 'infrastructure/storage/__tests__/AphrontMySQLDatabaseConnectionTestCase.php', 'AphrontMySQLDatabaseConnectionTestCase' => 'infrastructure/storage/__tests__/AphrontMySQLDatabaseConnectionTestCase.php',
'AphrontNoteView' => 'view/widget/AphrontNoteView.php',
'AphrontNullView' => 'view/AphrontNullView.php', 'AphrontNullView' => 'view/AphrontNullView.php',
'AphrontPHPHTTPSink' => 'aphront/sink/AphrontPHPHTTPSink.php', 'AphrontPHPHTTPSink' => 'aphront/sink/AphrontPHPHTTPSink.php',
'AphrontPageView' => 'view/page/AphrontPageView.php', 'AphrontPageView' => 'view/page/AphrontPageView.php',
@ -1054,6 +1055,7 @@ phutil_register_library_map(array(
'PhabricatorMustVerifyEmailController' => 'applications/auth/controller/PhabricatorMustVerifyEmailController.php', 'PhabricatorMustVerifyEmailController' => 'applications/auth/controller/PhabricatorMustVerifyEmailController.php',
'PhabricatorMySQLConfigOptions' => 'applications/config/option/PhabricatorMySQLConfigOptions.php', 'PhabricatorMySQLConfigOptions' => 'applications/config/option/PhabricatorMySQLConfigOptions.php',
'PhabricatorMySQLFileStorageEngine' => 'applications/files/engine/PhabricatorMySQLFileStorageEngine.php', 'PhabricatorMySQLFileStorageEngine' => 'applications/files/engine/PhabricatorMySQLFileStorageEngine.php',
'PhabricatorNoteExample' => 'applications/uiexample/examples/PhabricatorNoteExample.php',
'PhabricatorNotificationBuilder' => 'applications/notification/builder/PhabricatorNotificationBuilder.php', 'PhabricatorNotificationBuilder' => 'applications/notification/builder/PhabricatorNotificationBuilder.php',
'PhabricatorNotificationClearController' => 'applications/notification/controller/PhabricatorNotificationClearController.php', 'PhabricatorNotificationClearController' => 'applications/notification/controller/PhabricatorNotificationClearController.php',
'PhabricatorNotificationConfigOptions' => 'applications/config/option/PhabricatorNotificationConfigOptions.php', 'PhabricatorNotificationConfigOptions' => 'applications/config/option/PhabricatorNotificationConfigOptions.php',
@ -1628,6 +1630,7 @@ phutil_register_library_map(array(
'AphrontMiniPanelView' => 'AphrontView', 'AphrontMiniPanelView' => 'AphrontView',
'AphrontMoreView' => 'AphrontView', 'AphrontMoreView' => 'AphrontView',
'AphrontMySQLDatabaseConnectionTestCase' => 'PhabricatorTestCase', 'AphrontMySQLDatabaseConnectionTestCase' => 'PhabricatorTestCase',
'AphrontNoteView' => 'AphrontView',
'AphrontNullView' => 'AphrontView', 'AphrontNullView' => 'AphrontView',
'AphrontPHPHTTPSink' => 'AphrontHTTPSink', 'AphrontPHPHTTPSink' => 'AphrontHTTPSink',
'AphrontPageView' => 'AphrontView', 'AphrontPageView' => 'AphrontView',
@ -2550,6 +2553,7 @@ phutil_register_library_map(array(
'PhabricatorMustVerifyEmailController' => 'PhabricatorAuthController', 'PhabricatorMustVerifyEmailController' => 'PhabricatorAuthController',
'PhabricatorMySQLConfigOptions' => 'PhabricatorApplicationConfigOptions', 'PhabricatorMySQLConfigOptions' => 'PhabricatorApplicationConfigOptions',
'PhabricatorMySQLFileStorageEngine' => 'PhabricatorFileStorageEngine', 'PhabricatorMySQLFileStorageEngine' => 'PhabricatorFileStorageEngine',
'PhabricatorNoteExample' => 'PhabricatorUIExample',
'PhabricatorNotificationClearController' => 'PhabricatorNotificationController', 'PhabricatorNotificationClearController' => 'PhabricatorNotificationController',
'PhabricatorNotificationConfigOptions' => 'PhabricatorApplicationConfigOptions', 'PhabricatorNotificationConfigOptions' => 'PhabricatorApplicationConfigOptions',
'PhabricatorNotificationController' => 'PhabricatorController', 'PhabricatorNotificationController' => 'PhabricatorController',

View file

@ -96,7 +96,6 @@ class ManiphestAuxiliaryFieldDefaultSpecification
case self::TYPE_DATE: case self::TYPE_DATE:
$control = new AphrontFormDateControl(); $control = new AphrontFormDateControl();
$control->setUser($this->getUser()); $control->setUser($this->getUser());
$control->setValue(time());
break; break;
default: default:
$label = $this->getLabel(); $label = $this->getLabel();
@ -114,9 +113,7 @@ class ManiphestAuxiliaryFieldDefaultSpecification
(bool)$this->getValue()); (bool)$this->getValue());
break; break;
case self::TYPE_DATE: case self::TYPE_DATE:
if ($this->getValue()) {
$control->setValue($this->getValue()); $control->setValue($this->getValue());
}
$control->setName('auxiliary_date_'.$this->getAuxiliaryKey()); $control->setName('auxiliary_date_'.$this->getAuxiliaryKey());
break; break;
default: default:
@ -181,6 +178,21 @@ class ManiphestAuxiliaryFieldDefaultSpecification
} }
} }
public function setDefaultValue($value) {
switch ($this->getFieldType()) {
case self::TYPE_DATE:
$value = strtotime($value);
if ($value <= 0) {
$value = time();
}
$this->setValue($value);
break;
default:
$this->setValue((string)$value);
break;
}
}
public function renderForDetailView() { public function renderForDetailView() {
switch ($this->getFieldType()) { switch ($this->getFieldType()) {
case self::TYPE_BOOL: case self::TYPE_BOOL:

View file

@ -26,6 +26,9 @@ final class ManiphestDefaultTaskExtensions
} }
$spec->setShouldCopyWhenCreatingSimilarTask(idx($info, 'copy')); $spec->setShouldCopyWhenCreatingSimilarTask(idx($info, 'copy'));
$spec->setDefaultValue(idx($info, 'default'));
$specs[] = $spec; $specs[] = $spec;
} }

View file

@ -24,13 +24,19 @@ abstract class ManiphestTaskExtensions {
} }
$task->loadAndAttachAuxiliaryAttributes(); $task->loadAndAttachAuxiliaryAttributes();
foreach ($aux_fields as $aux) { foreach ($aux_fields as $aux) {
$aux->setUser($viewer); $aux->setUser($viewer);
$aux->setTask($task); $aux->setTask($task);
// If we're creating a new task, we don't bother loading any stored data.
// This allows any defaults configured by the Extensions object to
// survive.
if ($task->getID()) {
$key = $aux->getAuxiliaryKey(); $key = $aux->getAuxiliaryKey();
$aux->setValueFromStorage($task->getAuxiliaryAttribute($key)); $aux->setValueFromStorage($task->getAuxiliaryAttribute($key));
} }
}
return $aux_fields; return $aux_fields;
} }

View file

@ -54,6 +54,8 @@ the field. These options are available:
show next to the checkbox. show next to the checkbox.
- **checkbox-value**: If type is set to **bool**, the value to show on - **checkbox-value**: If type is set to **bool**, the value to show on
the detail view when the checkbox is selected. the detail view when the checkbox is selected.
- **default**: Default field value. For **date**, you can use a string like
`"July 4, 1990"`, `"5PM today"`, or any other valid input to `strtotime()`.
- **copy**: When a user creates a task, the UI gives them an option to - **copy**: When a user creates a task, the UI gives them an option to
"Create Another Similar Task". Some fields from the original task are copied "Create Another Similar Task". Some fields from the original task are copied
into the new task, while others are not; by default, fields are not copied. into the new task, while others are not; by default, fields are not copied.