1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-02 02:40:58 +01:00

Use radio buttons with explanatory text to select commit rule types

Summary: Ref T4264. Instead of a dropdown, make this step more informative.

Test Plan: {F93928}

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T4264

Differential Revision: https://secure.phabricator.com/D7846
This commit is contained in:
epriestley 2013-12-27 13:16:33 -08:00
parent 79f57cf517
commit f38a565aa5
8 changed files with 96 additions and 8 deletions

View file

@ -31,6 +31,16 @@ final class HeraldPreCommitContentAdapter extends HeraldAdapter {
return pht('Commit Hook: Commit Content');
}
public function getAdapterSortOrder() {
return 2500;
}
public function getAdapterContentDescription() {
return pht(
"React to commits being pushed to hosted repositories.\n".
"Hook rules can block changes.");
}
public function getFieldNameMap() {
return array(
) + parent::getFieldNameMap();

View file

@ -34,6 +34,16 @@ final class HeraldPreCommitRefAdapter extends HeraldAdapter {
return pht('Commit Hook: Branches/Tags/Bookmarks');
}
public function getAdapterSortOrder() {
return 2000;
}
public function getAdapterContentDescription() {
return pht(
"React to branches and tags being pushed to hosted repositories.\n".
"Hook rules can block changes.");
}
public function getFieldNameMap() {
return array(
self::FIELD_REF_TYPE => pht('Ref type'),

View file

@ -136,9 +136,21 @@ abstract class HeraldAdapter {
}
abstract public function getAdapterContentName();
abstract public function getAdapterContentDescription();
abstract public function getAdapterApplicationClass();
abstract public function getObject();
public function getAdapterSortKey() {
return sprintf(
'%08d%s',
$this->getAdapterSortOrder(),
$this->getAdapterContentName());
}
public function getAdapterSortOrder() {
return 1000;
}
/* -( Fields )------------------------------------------------------------- */
@ -814,6 +826,7 @@ abstract class HeraldAdapter {
$adapters = id(new PhutilSymbolLoader())
->setAncestorClass(__CLASS__)
->loadObjects();
$adapters = msort($adapters, 'getAdapterSortKey');
}
return $adapters;
}
@ -846,7 +859,6 @@ abstract class HeraldAdapter {
$map[$type] = $name;
}
asort($map);
return $map;
}

View file

@ -42,6 +42,13 @@ final class HeraldCommitAdapter extends HeraldAdapter {
return pht('Commits');
}
public function getAdapterContentDescription() {
return pht(
"React to new commits appearing in tracked repositories.\n".
"Commit rules can send email, flag commits, trigger audits, ".
"and run build plans.");
}
public function getFieldNameMap() {
return array(
self::FIELD_NEED_AUDIT_FOR_PACKAGE =>

View file

@ -36,6 +36,13 @@ final class HeraldDifferentialRevisionAdapter extends HeraldAdapter {
return pht('Differential Revisions');
}
public function getAdapterContentDescription() {
return pht(
"React to revisions being created or updated.\n".
"Revision rules can send email, flag revisions, add reviewers, ".
"and run build plans.");
}
public function getFields() {
return array_merge(
array(

View file

@ -14,6 +14,11 @@ final class HeraldManiphestTaskAdapter extends HeraldAdapter {
return 'PhabricatorApplicationManiphest';
}
public function getAdapterContentDescription() {
return pht(
'React to tasks being created or updated.');
}
public function setTask(ManiphestTask $task) {
$this->task = $task;
return $this;

View file

@ -12,6 +12,11 @@ final class HeraldPholioMockAdapter extends HeraldAdapter {
return 'PhabricatorApplicationPholio';
}
public function getAdapterContentDescription() {
return pht(
'React to mocks being created or updated.');
}
public function getObject() {
return $this->mock;
}

View file

@ -53,19 +53,21 @@ final class HeraldNewController extends HeraldController {
->setUser($user)
->setAction($this->getApplicationURI('new/'));
$rule_types = $this->renderRuleTypeControl($rule_type_map, $e_rule);
$content_types = $this->renderContentTypeControl(
$content_type_map,
$e_type);
$rule_types = $this->renderRuleTypeControl(
$rule_type_map,
$e_rule);
switch ($step) {
case 0:
default:
$form
->addHiddenInput('step', 1)
->appendChild(
id(new AphrontFormSelectControl())
->setLabel(pht('New Rule for'))
->setName('content_type')
->setValue($request->getStr('content_type'))
->setOptions($content_type_map));
->appendChild($content_types);
$cancel_text = null;
$cancel_uri = $this->getApplicationURI();
break;
@ -73,7 +75,16 @@ final class HeraldNewController extends HeraldController {
$form
->addHiddenInput('content_type', $request->getStr('content_type'))
->addHiddenInput('step', 2)
->appendChild(
id(new AphrontFormStaticControl())
->setLabel(pht('Rule for'))
->setValue(
phutil_tag(
'strong',
array(),
idx($content_type_map, $content_type))))
->appendChild($rule_types);
$cancel_text = pht('Back');
$cancel_uri = id(new PhutilURI('new/'))
->setQueryParams(
@ -112,6 +123,27 @@ final class HeraldNewController extends HeraldController {
));
}
private function renderContentTypeControl(array $content_type_map, $e_type) {
$request = $this->getRequest();
$radio = id(new AphrontFormRadioButtonControl())
->setLabel(pht('New Rule for'))
->setName('content_type')
->setValue($request->getStr('content_type'))
->setError($e_type);
foreach ($content_type_map as $value => $name) {
$adapter = HeraldAdapter::getAdapterForContentType($value);
$radio->addButton(
$value,
$name,
phutil_escape_html_newlines($adapter->getAdapterContentDescription()));
}
return $radio;
}
private function renderRuleTypeControl(array $rule_type_map, $e_rule) {
$request = $this->getRequest();