mirror of
https://we.phorge.it/source/phorge.git
synced 2025-02-13 23:38:34 +01:00
8934dee543
Summary: Fixes T10330. - Anywhere we support "matches regexp", also allow "does not match regexp". Although you can sometimes write a clever negative regexp, these rules are better expressed with "does not match <simple regexp>" anyway, and sometimes no regexp will work. - Always allow "does not contain" when we support "contains". - Fix some JS issues with certain rules affecting custom fields. Test Plan: - Wrote an "Affected files do not match regexp" rule that required every diff to touch "MANUALCHANGELOG.md". - Tried to diff without the file; rejected. - Tried to diff with the file; accepted. - Wrote a bunch of "contains" and "does not contain" rules against text fields and custom fields, then edited tasks to trigger/observe them. - Swapped the editor into custom text, user, remarkup, etc fields, no more JS errors. {F1105172} Reviewers: chad Reviewed By: chad Maniphest Tasks: T10330 Differential Revision: https://secure.phabricator.com/D15254
148 lines
3.6 KiB
PHP
148 lines
3.6 KiB
PHP
<?php
|
|
|
|
final class PhabricatorStandardCustomFieldBool
|
|
extends PhabricatorStandardCustomField {
|
|
|
|
public function getFieldType() {
|
|
return 'bool';
|
|
}
|
|
|
|
public function buildFieldIndexes() {
|
|
$indexes = array();
|
|
|
|
$value = $this->getFieldValue();
|
|
if (strlen($value)) {
|
|
$indexes[] = $this->newNumericIndex((int)$value);
|
|
}
|
|
|
|
return $indexes;
|
|
}
|
|
|
|
public function buildOrderIndex() {
|
|
return $this->newNumericIndex(0);
|
|
}
|
|
|
|
public function readValueFromRequest(AphrontRequest $request) {
|
|
$this->setFieldValue((bool)$request->getBool($this->getFieldKey()));
|
|
}
|
|
|
|
public function getValueForStorage() {
|
|
$value = $this->getFieldValue();
|
|
if ($value !== null) {
|
|
return (int)$value;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public function setValueFromStorage($value) {
|
|
if (strlen($value)) {
|
|
$value = (bool)$value;
|
|
} else {
|
|
$value = null;
|
|
}
|
|
return $this->setFieldValue($value);
|
|
}
|
|
|
|
public function readApplicationSearchValueFromRequest(
|
|
PhabricatorApplicationSearchEngine $engine,
|
|
AphrontRequest $request) {
|
|
|
|
return $request->getStr($this->getFieldKey());
|
|
}
|
|
|
|
public function applyApplicationSearchConstraintToQuery(
|
|
PhabricatorApplicationSearchEngine $engine,
|
|
PhabricatorCursorPagedPolicyAwareQuery $query,
|
|
$value) {
|
|
if ($value == 'require') {
|
|
$query->withApplicationSearchContainsConstraint(
|
|
$this->newNumericIndex(null),
|
|
1);
|
|
}
|
|
}
|
|
|
|
public function appendToApplicationSearchForm(
|
|
PhabricatorApplicationSearchEngine $engine,
|
|
AphrontFormView $form,
|
|
$value) {
|
|
|
|
$form->appendChild(
|
|
id(new AphrontFormSelectControl())
|
|
->setLabel($this->getFieldName())
|
|
->setName($this->getFieldKey())
|
|
->setValue($value)
|
|
->setOptions(
|
|
array(
|
|
'' => $this->getString('search.default', pht('(Any)')),
|
|
'require' => $this->getString('search.require', pht('Require')),
|
|
)));
|
|
}
|
|
|
|
public function renderEditControl(array $handles) {
|
|
return id(new AphrontFormCheckboxControl())
|
|
->setLabel($this->getFieldName())
|
|
->setCaption($this->getCaption())
|
|
->addCheckbox(
|
|
$this->getFieldKey(),
|
|
1,
|
|
$this->getString('edit.checkbox'),
|
|
(bool)$this->getFieldValue());
|
|
}
|
|
|
|
public function renderPropertyViewValue(array $handles) {
|
|
$value = $this->getFieldValue();
|
|
if ($value) {
|
|
return $this->getString('view.yes', pht('Yes'));
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public function getApplicationTransactionTitle(
|
|
PhabricatorApplicationTransaction $xaction) {
|
|
$author_phid = $xaction->getAuthorPHID();
|
|
$old = $xaction->getOldValue();
|
|
$new = $xaction->getNewValue();
|
|
|
|
if ($new) {
|
|
return pht(
|
|
'%s checked %s.',
|
|
$xaction->renderHandleLink($author_phid),
|
|
$this->getFieldName());
|
|
} else {
|
|
return pht(
|
|
'%s unchecked %s.',
|
|
$xaction->renderHandleLink($author_phid),
|
|
$this->getFieldName());
|
|
}
|
|
}
|
|
|
|
public function shouldAppearInHerald() {
|
|
return true;
|
|
}
|
|
|
|
public function getHeraldFieldConditions() {
|
|
return array(
|
|
HeraldAdapter::CONDITION_IS_TRUE,
|
|
HeraldAdapter::CONDITION_IS_FALSE,
|
|
);
|
|
}
|
|
|
|
public function getHeraldFieldStandardType() {
|
|
return HeraldField::STANDARD_BOOL;
|
|
}
|
|
|
|
protected function getHTTPParameterType() {
|
|
return new AphrontBoolHTTPParameterType();
|
|
}
|
|
|
|
protected function newConduitSearchParameterType() {
|
|
return new ConduitBoolParameterType();
|
|
}
|
|
|
|
protected function newConduitEditParameterType() {
|
|
return new ConduitBoolParameterType();
|
|
}
|
|
|
|
}
|