1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-19 21:32:43 +01:00

Modernize "macro" typeahead datasource

Summary: Ref T4420. Make this modern.

Test Plan:
  - Used typeahead in remarkup comment area to select macro "derpdog".

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T4420

Differential Revision: https://secure.phabricator.com/D9875
This commit is contained in:
epriestley 2014-07-10 16:18:15 -07:00
parent 34628002fd
commit a2caea13d6
6 changed files with 46 additions and 19 deletions

View file

@ -1719,6 +1719,7 @@ phutil_register_library_map(array(
'PhabricatorMacroCommentController' => 'applications/macro/controller/PhabricatorMacroCommentController.php', 'PhabricatorMacroCommentController' => 'applications/macro/controller/PhabricatorMacroCommentController.php',
'PhabricatorMacroConfigOptions' => 'applications/macro/config/PhabricatorMacroConfigOptions.php', 'PhabricatorMacroConfigOptions' => 'applications/macro/config/PhabricatorMacroConfigOptions.php',
'PhabricatorMacroController' => 'applications/macro/controller/PhabricatorMacroController.php', 'PhabricatorMacroController' => 'applications/macro/controller/PhabricatorMacroController.php',
'PhabricatorMacroDatasource' => 'applications/macro/typeahead/PhabricatorMacroDatasource.php',
'PhabricatorMacroDisableController' => 'applications/macro/controller/PhabricatorMacroDisableController.php', 'PhabricatorMacroDisableController' => 'applications/macro/controller/PhabricatorMacroDisableController.php',
'PhabricatorMacroEditController' => 'applications/macro/controller/PhabricatorMacroEditController.php', 'PhabricatorMacroEditController' => 'applications/macro/controller/PhabricatorMacroEditController.php',
'PhabricatorMacroEditor' => 'applications/macro/editor/PhabricatorMacroEditor.php', 'PhabricatorMacroEditor' => 'applications/macro/editor/PhabricatorMacroEditor.php',
@ -4565,6 +4566,7 @@ phutil_register_library_map(array(
'PhabricatorMacroCommentController' => 'PhabricatorMacroController', 'PhabricatorMacroCommentController' => 'PhabricatorMacroController',
'PhabricatorMacroConfigOptions' => 'PhabricatorApplicationConfigOptions', 'PhabricatorMacroConfigOptions' => 'PhabricatorApplicationConfigOptions',
'PhabricatorMacroController' => 'PhabricatorController', 'PhabricatorMacroController' => 'PhabricatorController',
'PhabricatorMacroDatasource' => 'PhabricatorTypeaheadDatasource',
'PhabricatorMacroDisableController' => 'PhabricatorMacroController', 'PhabricatorMacroDisableController' => 'PhabricatorMacroController',
'PhabricatorMacroEditController' => 'PhabricatorMacroController', 'PhabricatorMacroEditController' => 'PhabricatorMacroController',
'PhabricatorMacroEditor' => 'PhabricatorApplicationTransactionEditor', 'PhabricatorMacroEditor' => 'PhabricatorApplicationTransactionEditor',

View file

@ -50,7 +50,7 @@ final class PhabricatorMacroMemeDialogController
->setLabel(pht('Macro')) ->setLabel(pht('Macro'))
->setName('macro') ->setName('macro')
->setLimit(1) ->setLimit(1)
->setDatasource('/typeahead/common/macros/') ->setDatasource(new PhabricatorMacroDatasource())
->setError($e_macro)) ->setError($e_macro))
->appendChild( ->appendChild(
id(new AphrontFormTextControl()) id(new AphrontFormTextControl())

View file

@ -12,6 +12,10 @@ final class PhabricatorMacroPHIDTypeMacro extends PhabricatorPHIDType {
return pht('Image Macro'); return pht('Image Macro');
} }
public function getTypeIcon() {
return 'fa-meh-o';
}
public function newObject() { public function newObject() {
return new PhabricatorFileImageMacro(); return new PhabricatorFileImageMacro();
} }

View file

@ -0,0 +1,35 @@
<?php
final class PhabricatorMacroDatasource
extends PhabricatorTypeaheadDatasource {
public function getPlaceholderText() {
return pht('Type a macro name...');
}
public function getDatasourceApplicationClass() {
return 'PhabricatorApplicationMacro';
}
public function loadResults() {
$viewer = $this->getViewer();
$raw_query = $this->getRawQuery();
$results = array();
$macros = id(new PhabricatorMacroQuery())
->setViewer($viewer)
->withStatus(PhabricatorMacroQuery::STATUS_ACTIVE)
->execute();
foreach ($macros as $macro) {
$results[] = id(new PhabricatorTypeaheadResult())
->setPHID($macro->getPHID())
->setName($macro->getName())
->setIcon('fa-meh-o bluegrey');
}
return $results;
}
}

View file

@ -13,6 +13,10 @@ final class PhabricatorRepositoryPHIDTypeRepository
return pht('Repository'); return pht('Repository');
} }
public function getTypeIcon() {
return 'fa-database';
}
public function newObject() { public function newObject() {
return new PhabricatorRepository(); return new PhabricatorRepository();
} }
@ -40,7 +44,6 @@ final class PhabricatorRepositoryPHIDTypeRepository
$handle->setName($monogram); $handle->setName($monogram);
$handle->setFullName("{$monogram} {$name}"); $handle->setFullName("{$monogram} {$name}");
$handle->setURI("/diffusion/{$callsign}/"); $handle->setURI("/diffusion/{$callsign}/");
$handle->setIcon('fa-database');
} }
} }

View file

@ -34,7 +34,6 @@ final class PhabricatorTypeaheadCommonDatasourceController
$need_jump_objects = false; $need_jump_objects = false;
$need_build_plans = false; $need_build_plans = false;
$need_task_priority = false; $need_task_priority = false;
$need_macros = false;
$need_legalpad_documents = false; $need_legalpad_documents = false;
switch ($this->type) { switch ($this->type) {
case 'mainsearch': case 'mainsearch':
@ -89,9 +88,6 @@ final class PhabricatorTypeaheadCommonDatasourceController
case 'taskpriority': case 'taskpriority':
$need_task_priority = true; $need_task_priority = true;
break; break;
case 'macros':
$need_macros = true;
break;
case 'legalpaddocuments': case 'legalpaddocuments':
$need_legalpad_documents = true; $need_legalpad_documents = true;
break; break;
@ -243,19 +239,6 @@ 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_legalpad_documents) { if ($need_legalpad_documents) {
$documents = id(new LegalpadDocumentQuery()) $documents = id(new LegalpadDocumentQuery())
->setViewer($viewer) ->setViewer($viewer)