From 4e7798464435440957774dbdab9ad399f6eb98f4 Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 10 Jul 2014 16:18:48 -0700 Subject: [PATCH] Modernize "legalpad" typeahead datasource Summary: Ref T4420. Modernize legalpad. Test Plan: - Used typeahead in Herald rules. - Used typeahead in Policy dialog. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T4420 Differential Revision: https://secure.phabricator.com/D9876 --- src/__phutil_library_map__.php | 2 ++ .../controller/HeraldRuleController.php | 31 +++++++++-------- .../PhabricatorLegalpadPHIDTypeDocument.php | 7 ++-- .../typeahead/LegalpadDocumentDatasource.php | 33 +++++++++++++++++++ ...PhabricatorPolicyRuleLegalpadSignature.php | 6 ++-- ...torTypeaheadCommonDatasourceController.php | 16 --------- 6 files changed, 62 insertions(+), 33 deletions(-) create mode 100644 src/applications/legalpad/typeahead/LegalpadDocumentDatasource.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 360cfbbf80..d499bfb27a 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -864,6 +864,7 @@ phutil_register_library_map(array( 'LegalpadDocument' => 'applications/legalpad/storage/LegalpadDocument.php', 'LegalpadDocumentBody' => 'applications/legalpad/storage/LegalpadDocumentBody.php', 'LegalpadDocumentCommentController' => 'applications/legalpad/controller/LegalpadDocumentCommentController.php', + 'LegalpadDocumentDatasource' => 'applications/legalpad/typeahead/LegalpadDocumentDatasource.php', 'LegalpadDocumentDoneController' => 'applications/legalpad/controller/LegalpadDocumentDoneController.php', 'LegalpadDocumentEditController' => 'applications/legalpad/controller/LegalpadDocumentEditController.php', 'LegalpadDocumentEditor' => 'applications/legalpad/editor/LegalpadDocumentEditor.php', @@ -3629,6 +3630,7 @@ phutil_register_library_map(array( 1 => 'PhabricatorMarkupInterface', ), 'LegalpadDocumentCommentController' => 'LegalpadController', + 'LegalpadDocumentDatasource' => 'PhabricatorTypeaheadDatasource', 'LegalpadDocumentDoneController' => 'LegalpadController', 'LegalpadDocumentEditController' => 'LegalpadController', 'LegalpadDocumentEditor' => 'PhabricatorApplicationTransactionEditor', diff --git a/src/applications/herald/controller/HeraldRuleController.php b/src/applications/herald/controller/HeraldRuleController.php index e538dd3f2a..ae184ab1f3 100644 --- a/src/applications/herald/controller/HeraldRuleController.php +++ b/src/applications/herald/controller/HeraldRuleController.php @@ -588,20 +588,25 @@ final class HeraldRuleController extends HeraldController { $template = new AphrontTokenizerTemplateView(); $template = $template->render(); + $sources = array( + 'repository' => new DiffusionRepositoryDatasource(), + 'legaldocuments' => new LegalpadDocumentDatasource(), + ); + + $sources = mpull($sources, 'getDatasourceURI'); + $sources += array( + 'email' => '/typeahead/common/mailable/', + 'user' => '/typeahead/common/accounts/', + 'package' => '/typeahead/common/packages/', + 'project' => '/typeahead/common/projects/', + 'userorproject' => '/typeahead/common/accountsorprojects/', + 'buildplan' => '/typeahead/common/buildplans/', + 'taskpriority' => '/typeahead/common/taskpriority/', + 'arcanistprojects' => '/typeahead/common/arcanistprojects/', + ); + return array( - 'source' => array( - 'email' => '/typeahead/common/mailable/', - 'user' => '/typeahead/common/accounts/', - 'repository' => - id(new DiffusionRepositoryDatasource())->getDatasourceURI(), - 'package' => '/typeahead/common/packages/', - 'project' => '/typeahead/common/projects/', - 'userorproject' => '/typeahead/common/accountsorprojects/', - 'buildplan' => '/typeahead/common/buildplans/', - 'taskpriority' => '/typeahead/common/taskpriority/', - 'arcanistprojects' => '/typeahead/common/arcanistprojects/', - 'legaldocuments' => '/typeahead/common/legalpaddocuments/', - ), + 'source' => $sources, 'username' => $this->getRequest()->getUser()->getUserName(), 'icons' => mpull($handles, 'getTypeIcon', 'getPHID'), 'markup' => $template, diff --git a/src/applications/legalpad/phid/PhabricatorLegalpadPHIDTypeDocument.php b/src/applications/legalpad/phid/PhabricatorLegalpadPHIDTypeDocument.php index c854392875..58cdc582fc 100644 --- a/src/applications/legalpad/phid/PhabricatorLegalpadPHIDTypeDocument.php +++ b/src/applications/legalpad/phid/PhabricatorLegalpadPHIDTypeDocument.php @@ -12,6 +12,10 @@ final class PhabricatorLegalpadPHIDTypeDocument extends PhabricatorPHIDType { return pht('Legalpad Document'); } + public function getTypeIcon() { + return 'fa-file-text-o'; + } + public function newObject() { return new LegalpadDocument(); } @@ -33,8 +37,7 @@ final class PhabricatorLegalpadPHIDTypeDocument extends PhabricatorPHIDType { foreach ($handles as $phid => $handle) { $document = $objects[$phid]; $name = $document->getDocumentBody()->getTitle(); - $handle->setName($name); - $handle->setFullName($document->getMonogram().' '.$name); + $handle->setName($document->getMonogram().' '.$name); $handle->setURI('/'.$document->getMonogram()); } } diff --git a/src/applications/legalpad/typeahead/LegalpadDocumentDatasource.php b/src/applications/legalpad/typeahead/LegalpadDocumentDatasource.php new file mode 100644 index 0000000000..e266dca640 --- /dev/null +++ b/src/applications/legalpad/typeahead/LegalpadDocumentDatasource.php @@ -0,0 +1,33 @@ +getViewer(); + $raw_query = $this->getRawQuery(); + + $results = array(); + + $documents = id(new LegalpadDocumentQuery()) + ->setViewer($viewer) + ->execute(); + foreach ($documents as $document) { + $results[] = id(new PhabricatorTypeaheadResult()) + ->setPHID($document->getPHID()) + ->setIcon('fa-file-text-o') + ->setName($document->getMonogram().' '.$document->getTitle()); + } + + return $results; + } + +} diff --git a/src/applications/policy/rule/PhabricatorPolicyRuleLegalpadSignature.php b/src/applications/policy/rule/PhabricatorPolicyRuleLegalpadSignature.php index 4c41b94ac9..b07c50d935 100644 --- a/src/applications/policy/rule/PhabricatorPolicyRuleLegalpadSignature.php +++ b/src/applications/policy/rule/PhabricatorPolicyRuleLegalpadSignature.php @@ -40,10 +40,12 @@ final class PhabricatorPolicyRuleLegalpadSignature } public function getValueControlTemplate() { + $datasource = new LegalpadDocumentDatasource(); + return array( 'markup' => new AphrontTokenizerTemplateView(), - 'uri' => '/typeahead/common/legalpaddocuments/', - 'placeholder' => pht('Type a document title...'), + 'uri' => $datasource->getDatasourceURI(), + 'placeholder' => $datasource->getPlaceholderText(), ); } diff --git a/src/applications/typeahead/controller/PhabricatorTypeaheadCommonDatasourceController.php b/src/applications/typeahead/controller/PhabricatorTypeaheadCommonDatasourceController.php index 171500ef6f..aa6512f547 100644 --- a/src/applications/typeahead/controller/PhabricatorTypeaheadCommonDatasourceController.php +++ b/src/applications/typeahead/controller/PhabricatorTypeaheadCommonDatasourceController.php @@ -34,7 +34,6 @@ final class PhabricatorTypeaheadCommonDatasourceController $need_jump_objects = false; $need_build_plans = false; $need_task_priority = false; - $need_legalpad_documents = false; switch ($this->type) { case 'mainsearch': $need_users = true; @@ -88,9 +87,6 @@ final class PhabricatorTypeaheadCommonDatasourceController case 'taskpriority': $need_task_priority = true; break; - case 'legalpaddocuments': - $need_legalpad_documents = true; - break; } $results = array(); @@ -239,18 +235,6 @@ final class PhabricatorTypeaheadCommonDatasourceController } } - if ($need_legalpad_documents) { - $documents = id(new LegalpadDocumentQuery()) - ->setViewer($viewer) - ->execute(); - foreach ($documents as $document) { - $results[] = id(new PhabricatorTypeaheadResult()) - ->setPHID($document->getPHID()) - ->setIcon('fa-file-text-o') - ->setName($document->getMonogram().' '.$document->getTitle()); - } - } - if ($need_projs) { $projs = id(new PhabricatorProjectQuery()) ->setViewer($viewer)