1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-01 18:30:59 +01:00

Turn the macro selector into a tokenizer

Summary: Ref T3562. Here's the 10 minute "value" option.

Test Plan: See screenshots.

Reviewers: chad, btrahan

Reviewed By: chad

CC: aran

Maniphest Tasks: T3562

Differential Revision: https://secure.phabricator.com/D7658
This commit is contained in:
epriestley 2013-11-25 19:22:06 -08:00
parent 325c8853c9
commit 6985c71117
3 changed files with 26 additions and 6 deletions

View file

@ -7,20 +7,20 @@ final class PhabricatorMacroMemeDialogController
$request = $this->getRequest(); $request = $this->getRequest();
$user = $request->getUser(); $user = $request->getUser();
$name = $request->getStr('macro'); $phid = head($request->getArr('macro'));
$above = $request->getStr('above'); $above = $request->getStr('above');
$below = $request->getStr('below'); $below = $request->getStr('below');
$e_macro = true; $e_macro = true;
$errors = array(); $errors = array();
if ($request->isDialogFormPost()) { if ($request->isDialogFormPost()) {
if (!$name) { if (!$phid) {
$e_macro = pht('Required'); $e_macro = pht('Required');
$errors[] = pht('Macro name is required.'); $errors[] = pht('Macro name is required.');
} else { } else {
$macro = id(new PhabricatorMacroQuery()) $macro = id(new PhabricatorMacroQuery())
->setViewer($user) ->setViewer($user)
->withNames(array($name)) ->withPHIDs(array($phid))
->executeOne(); ->executeOne();
if (!$macro) { if (!$macro) {
$e_macro = pht('Invalid'); $e_macro = pht('Invalid');
@ -31,7 +31,7 @@ final class PhabricatorMacroMemeDialogController
if (!$errors) { if (!$errors) {
$options = new PhutilSimpleOptions(); $options = new PhutilSimpleOptions();
$data = array( $data = array(
'src' => $name, 'src' => $macro->getName(),
'above' => $above, 'above' => $above,
'below' => $below, 'below' => $below,
); );
@ -46,10 +46,11 @@ final class PhabricatorMacroMemeDialogController
$view = id(new PHUIFormLayoutView()) $view = id(new PHUIFormLayoutView())
->appendChild( ->appendChild(
id(new AphrontFormTextControl()) id(new AphrontFormTokenizerControl())
->setLabel(pht('Macro')) ->setLabel(pht('Macro'))
->setName('macro') ->setName('macro')
->setValue($name) ->setLimit(1)
->setDatasource('/typeahead/common/macros/')
->setError($e_macro)) ->setError($e_macro))
->appendChild( ->appendChild(
id(new AphrontFormTextControl()) id(new AphrontFormTextControl())

View file

@ -36,6 +36,7 @@ final class PhabricatorTypeaheadCommonDatasourceController
$need_symbols = false; $need_symbols = false;
$need_jump_objects = false; $need_jump_objects = false;
$need_build_plans = false; $need_build_plans = false;
$need_macros = false;
switch ($this->type) { switch ($this->type) {
case 'mainsearch': case 'mainsearch':
$need_users = true; $need_users = true;
@ -97,6 +98,9 @@ final class PhabricatorTypeaheadCommonDatasourceController
case 'buildplans': case 'buildplans':
$need_build_plans = true; $need_build_plans = true;
break; break;
case 'macros':
$need_macros = true;
break;
} }
$results = array(); $results = array();
@ -113,6 +117,7 @@ final class PhabricatorTypeaheadCommonDatasourceController
->setPHID(ManiphestTaskOwner::PROJECT_NO_PROJECT); ->setPHID(ManiphestTaskOwner::PROJECT_NO_PROJECT);
} }
if ($need_users) { if ($need_users) {
$columns = array( $columns = array(
'isSystemAgent', 'isSystemAgent',
@ -234,6 +239,19 @@ final class PhabricatorTypeaheadCommonDatasourceController
} }
} }
if ($need_macros) {
$macros = id(new PhabricatorMacroQuery())
->setViewer($viewer)
->withStatus(PhabricatorMacroQuery::STATUS_ACTIVE)
->execute();
$macros = mpull($macros, 'getName', 'getPHID');
foreach ($macros as $phid => $name) {
$results[] = id(new PhabricatorTypeaheadResult())
->setPHID($phid)
->setName($name);
}
}
if ($need_projs) { if ($need_projs) {
$projs = id(new PhabricatorProjectQuery()) $projs = id(new PhabricatorProjectQuery())
->setViewer($viewer) ->setViewer($viewer)

View file

@ -97,6 +97,7 @@ final class AphrontFormTokenizerControl extends AphrontFormControl {
'packages' => pht('Type a package name...'), 'packages' => pht('Type a package name...'),
'arcanistproject' => pht('Type an arc project name...'), 'arcanistproject' => pht('Type an arc project name...'),
'accountsorprojects' => pht('Type a user or project name...'), 'accountsorprojects' => pht('Type a user or project name...'),
'macros' => pht('Type a macro name...'),
); );
return idx($map, $request); return idx($map, $request);