mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-26 16:52:41 +01:00
Add a "date" standard custom field
Summary: See previous revisions. As maniphest. Test Plan: See screenshots. Reviewers: btrahan Reviewed By: btrahan CC: aran Differential Revision: https://secure.phabricator.com/D7009
This commit is contained in:
parent
726144b995
commit
6115670615
4 changed files with 88 additions and 1 deletions
|
@ -1637,6 +1637,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorSourceCodeView' => 'view/layout/PhabricatorSourceCodeView.php',
|
||||
'PhabricatorStandardCustomField' => 'infrastructure/customfield/standard/PhabricatorStandardCustomField.php',
|
||||
'PhabricatorStandardCustomFieldBool' => 'infrastructure/customfield/standard/PhabricatorStandardCustomFieldBool.php',
|
||||
'PhabricatorStandardCustomFieldDate' => 'infrastructure/customfield/standard/PhabricatorStandardCustomFieldDate.php',
|
||||
'PhabricatorStandardCustomFieldInt' => 'infrastructure/customfield/standard/PhabricatorStandardCustomFieldInt.php',
|
||||
'PhabricatorStandardCustomFieldInterface' => 'infrastructure/customfield/interface/PhabricatorStandardCustomFieldInterface.php',
|
||||
'PhabricatorStandardCustomFieldRemarkup' => 'infrastructure/customfield/standard/PhabricatorStandardCustomFieldRemarkup.php',
|
||||
|
@ -3789,6 +3790,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorSourceCodeView' => 'AphrontView',
|
||||
'PhabricatorStandardCustomField' => 'PhabricatorCustomField',
|
||||
'PhabricatorStandardCustomFieldBool' => 'PhabricatorStandardCustomField',
|
||||
'PhabricatorStandardCustomFieldDate' => 'PhabricatorStandardCustomField',
|
||||
'PhabricatorStandardCustomFieldInt' => 'PhabricatorStandardCustomField',
|
||||
'PhabricatorStandardCustomFieldRemarkup' => 'PhabricatorStandardCustomField',
|
||||
'PhabricatorStandardCustomFieldSelect' => 'PhabricatorStandardCustomField',
|
||||
|
|
|
@ -35,7 +35,9 @@ final class PhabricatorPeopleProfileEditController
|
|||
$field_list = PhabricatorCustomField::getObjectFields(
|
||||
$user,
|
||||
PhabricatorCustomField::ROLE_EDIT);
|
||||
$field_list->readFieldsFromStorage($user);
|
||||
$field_list
|
||||
->setViewer($user)
|
||||
->readFieldsFromStorage($user);
|
||||
|
||||
if ($request->isFormPost()) {
|
||||
$xactions = $field_list->buildFieldTransactionsFromRequest(
|
||||
|
|
|
@ -20,6 +20,13 @@ final class PhabricatorCustomFieldList extends Phobject {
|
|||
return $this->fields;
|
||||
}
|
||||
|
||||
public function setViewer(PhabricatorUser $viewer) {
|
||||
foreach ($this->getFields() as $field) {
|
||||
$field->setViewer($viewer);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read stored values for all fields which support storage.
|
||||
*
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorStandardCustomFieldDate
|
||||
extends PhabricatorStandardCustomField {
|
||||
|
||||
public function getFieldType() {
|
||||
return 'date';
|
||||
}
|
||||
|
||||
public function buildFieldIndexes() {
|
||||
$indexes = array();
|
||||
|
||||
$value = $this->getFieldValue();
|
||||
if (strlen($value)) {
|
||||
$indexes[] = $this->newNumericIndex((int)$value);
|
||||
}
|
||||
|
||||
return $indexes;
|
||||
}
|
||||
|
||||
public function getValueForStorage() {
|
||||
$value = $this->getFieldValue();
|
||||
if (strlen($value)) {
|
||||
return (int)$value;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function setValueFromStorage($value) {
|
||||
if (strlen($value)) {
|
||||
$value = (int)$value;
|
||||
} else {
|
||||
$value = null;
|
||||
}
|
||||
return $this->setFieldValue($value);
|
||||
}
|
||||
|
||||
public function renderEditControl() {
|
||||
return $this->newDateControl();
|
||||
}
|
||||
|
||||
public function readValueFromRequest(AphrontRequest $request) {
|
||||
$control = $this->newDateControl();
|
||||
$control->setUser($request->getUser());
|
||||
$value = $control->readValueFromRequest($request);
|
||||
|
||||
$this->setFieldValue($value);
|
||||
}
|
||||
|
||||
public function renderPropertyViewValue() {
|
||||
$value = $this->getFieldValue();
|
||||
if (!$value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return phabricator_datetime($value, $this->getViewer());
|
||||
}
|
||||
|
||||
private function newDateControl() {
|
||||
$control = id(new AphrontFormDateControl())
|
||||
->setLabel($this->getFieldName())
|
||||
->setName($this->getFieldKey())
|
||||
->setUser($this->getViewer())
|
||||
->setAllowNull(true);
|
||||
|
||||
$control->setValue($this->getFieldValue());
|
||||
|
||||
return $control;
|
||||
}
|
||||
|
||||
// TODO: Support ApplicationSearch for these fields. We build indexes above,
|
||||
// but don't provide a UI for searching. To do so, we need a reasonable date
|
||||
// range control and the ability to add a range constraint.
|
||||
|
||||
}
|
Loading…
Reference in a new issue