From 715233fb611569b86f8fd4d8339a7e514c749d69 Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 16 Jul 2015 14:12:44 -0700 Subject: [PATCH] Fully modularize Herald field values Summary: Ref T8726. This gets rid of all the `VALUE_*` constants and lets Fields provide arbitrary typeaheads without upstream/JS changes. Test Plan: Used all tokenizers. Used "Another Herald Rule". Grepped for all removed constants. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T8726 Differential Revision: https://secure.phabricator.com/D13616 --- resources/celerity/map.php | 22 ++--- src/__phutil_library_map__.php | 2 + .../DifferentialDiffAuthorHeraldField.php | 4 +- ...ferentialDiffAuthorProjectsHeraldField.php | 10 +-- .../DifferentialDiffRepositoryHeraldField.php | 10 +-- ...ntialDiffRepositoryProjectsHeraldField.php | 10 +-- .../DifferentialRevisionAuthorHeraldField.php | 4 +- ...ntialRevisionAuthorProjectsHeraldField.php | 10 +-- ...DifferentialRevisionPackageHeraldField.php | 10 +-- ...rentialRevisionPackageOwnerHeraldField.php | 10 +-- ...ferentialRevisionRepositoryHeraldField.php | 10 +-- ...lRevisionRepositoryProjectsHeraldField.php | 10 +-- ...fferentialRevisionReviewersHeraldField.php | 10 +-- .../DiffusionCommitAuthorHeraldField.php | 10 +-- .../DiffusionCommitAutocloseHeraldField.php | 2 +- .../DiffusionCommitCommitterHeraldField.php | 10 +-- ...DiffusionCommitPackageAuditHeraldField.php | 10 +-- .../DiffusionCommitPackageHeraldField.php | 10 +-- ...DiffusionCommitPackageOwnerHeraldField.php | 10 +-- .../DiffusionCommitRepositoryHeraldField.php | 4 +- ...ionCommitRepositoryProjectsHeraldField.php | 10 +-- .../DiffusionCommitReviewerHeraldField.php | 10 +-- ...sionCommitRevisionReviewersHeraldField.php | 10 +-- ...onCommitRevisionSubscribersHeraldField.php | 10 +-- ...usionPreCommitContentAuthorHeraldField.php | 10 +-- ...onPreCommitContentCommitterHeraldField.php | 10 +-- ...usionPreCommitContentPusherHeraldField.php | 4 +- ...CommitContentPusherProjectsHeraldField.php | 11 +-- ...nPreCommitContentRepositoryHeraldField.php | 4 +- ...itContentRepositoryProjectsHeraldField.php | 10 +-- ...mitContentRevisionReviewersHeraldField.php | 10 +-- ...tContentRevisionSubscribersHeraldField.php | 10 +-- ...DiffusionPreCommitRefPusherHeraldField.php | 4 +- ...nPreCommitRefPusherProjectsHeraldField.php | 11 +-- ...usionPreCommitRefRepositoryHeraldField.php | 4 +- ...CommitRefRepositoryProjectsHeraldField.php | 10 +-- .../herald/adapter/HeraldAdapter.php | 50 ++++++------ .../controller/HeraldRuleController.php | 37 ++------- .../herald/field/HeraldAlwaysField.php | 2 +- .../herald/field/HeraldAnotherRuleField.php | 7 +- src/applications/herald/field/HeraldField.php | 21 ++++- .../herald/value/HeraldEmptyFieldValue.php | 2 +- .../herald/value/HeraldFieldValue.php | 14 +++- .../herald/value/HeraldSelectFieldValue.php | 2 +- .../herald/value/HeraldTextFieldValue.php | 2 +- .../value/HeraldTokenizerFieldValue.php | 60 ++++++++++++++ .../ManiphestTaskAssigneeHeraldField.php | 10 +-- .../herald/ManiphestTaskAuthorHeraldField.php | 4 +- .../ManiphestTaskPriorityHeraldField.php | 4 +- .../herald/ManiphestTaskStatusHeraldField.php | 4 +- ...atorMetaMTAApplicationEmailHeraldField.php | 10 +-- .../herald/PholioMockAuthorHeraldField.php | 4 +- .../PhrictionDocumentAuthorHeraldField.php | 4 +- .../project/herald/HeraldProjectsField.php | 10 +-- .../spaces/herald/HeraldSpaceField.php | 4 +- .../herald/HeraldSubscribersField.php | 10 +-- .../PhabricatorStandardCustomFieldUsers.php | 4 +- .../js/application/herald/HeraldRuleEditor.js | 81 +++++-------------- 58 files changed, 261 insertions(+), 401 deletions(-) create mode 100644 src/applications/herald/value/HeraldTokenizerFieldValue.php diff --git a/resources/celerity/map.php b/resources/celerity/map.php index 8379ef7071..23c3ef8d92 100644 --- a/resources/celerity/map.php +++ b/resources/celerity/map.php @@ -382,7 +382,7 @@ return array( 'rsrc/js/application/doorkeeper/behavior-doorkeeper-tag.js' => 'e5822781', 'rsrc/js/application/files/behavior-icon-composer.js' => '8ef9ab58', 'rsrc/js/application/files/behavior-launch-icon-composer.js' => '48086888', - 'rsrc/js/application/herald/HeraldRuleEditor.js' => '797e4876', + 'rsrc/js/application/herald/HeraldRuleEditor.js' => '6c2dffcc', 'rsrc/js/application/herald/PathTypeahead.js' => 'f7fc67ec', 'rsrc/js/application/herald/herald-rule-editor.js' => '7ebaeed3', 'rsrc/js/application/maniphest/behavior-batch-editor.js' => '782ab6e7', @@ -538,7 +538,7 @@ return array( 'global-drag-and-drop-css' => '697324ad', 'harbormaster-css' => '49d64eb4', 'herald-css' => '826075fa', - 'herald-rule-editor' => '797e4876', + 'herald-rule-editor' => '6c2dffcc', 'herald-test-css' => '778b008e', 'inline-comment-summary-css' => '51efda3a', 'javelin-aphlict' => '5359e785', @@ -1338,6 +1338,15 @@ return array( 'javelin-install', 'javelin-util', ), + '6c2dffcc' => array( + 'multirow-row-manager', + 'javelin-install', + 'javelin-util', + 'javelin-dom', + 'javelin-stratcom', + 'javelin-json', + 'phabricator-prefab', + ), '6c53634d' => array( 'javelin-install', 'javelin-event', @@ -1416,15 +1425,6 @@ return array( 'javelin-behavior', 'javelin-quicksand', ), - '797e4876' => array( - 'multirow-row-manager', - 'javelin-install', - 'javelin-util', - 'javelin-dom', - 'javelin-stratcom', - 'javelin-json', - 'phabricator-prefab', - ), '7a68dda3' => array( 'owners-path-editor', 'javelin-behavior', diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 021cdc319a..c0227fe055 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1057,6 +1057,7 @@ phutil_register_library_map(array( 'HeraldSubscribersField' => 'applications/subscriptions/herald/HeraldSubscribersField.php', 'HeraldTestConsoleController' => 'applications/herald/controller/HeraldTestConsoleController.php', 'HeraldTextFieldValue' => 'applications/herald/value/HeraldTextFieldValue.php', + 'HeraldTokenizerFieldValue' => 'applications/herald/value/HeraldTokenizerFieldValue.php', 'HeraldTransactionQuery' => 'applications/herald/query/HeraldTransactionQuery.php', 'HeraldTranscript' => 'applications/herald/storage/transcript/HeraldTranscript.php', 'HeraldTranscriptController' => 'applications/herald/controller/HeraldTranscriptController.php', @@ -4664,6 +4665,7 @@ phutil_register_library_map(array( 'HeraldSubscribersField' => 'HeraldField', 'HeraldTestConsoleController' => 'HeraldController', 'HeraldTextFieldValue' => 'HeraldFieldValue', + 'HeraldTokenizerFieldValue' => 'HeraldFieldValue', 'HeraldTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 'HeraldTranscript' => array( 'HeraldDAO', diff --git a/src/applications/differential/herald/DifferentialDiffAuthorHeraldField.php b/src/applications/differential/herald/DifferentialDiffAuthorHeraldField.php index b1f081fc4f..a6c909dc7c 100644 --- a/src/applications/differential/herald/DifferentialDiffAuthorHeraldField.php +++ b/src/applications/differential/herald/DifferentialDiffAuthorHeraldField.php @@ -17,8 +17,8 @@ final class DifferentialDiffAuthorHeraldField return self::STANDARD_PHID; } - public function getHeraldFieldValueType($condition) { - return HeraldAdapter::VALUE_USER; + protected function getDatasource() { + return new PhabricatorPeopleDatasource(); } } diff --git a/src/applications/differential/herald/DifferentialDiffAuthorProjectsHeraldField.php b/src/applications/differential/herald/DifferentialDiffAuthorProjectsHeraldField.php index 5f170ece31..bec1e2a66c 100644 --- a/src/applications/differential/herald/DifferentialDiffAuthorProjectsHeraldField.php +++ b/src/applications/differential/herald/DifferentialDiffAuthorProjectsHeraldField.php @@ -19,14 +19,8 @@ final class DifferentialDiffAuthorProjectsHeraldField return self::STANDARD_PHID_LIST; } - public function getHeraldFieldValueType($condition) { - switch ($condition) { - case HeraldAdapter::CONDITION_EXISTS: - case HeraldAdapter::CONDITION_NOT_EXISTS: - return HeraldAdapter::VALUE_NONE; - default: - return HeraldAdapter::VALUE_PROJECT; - } + protected function getDatasource() { + return new PhabricatorProjectOrUserDatasource(); } } diff --git a/src/applications/differential/herald/DifferentialDiffRepositoryHeraldField.php b/src/applications/differential/herald/DifferentialDiffRepositoryHeraldField.php index 38fc552d66..19257deff2 100644 --- a/src/applications/differential/herald/DifferentialDiffRepositoryHeraldField.php +++ b/src/applications/differential/herald/DifferentialDiffRepositoryHeraldField.php @@ -23,14 +23,8 @@ final class DifferentialDiffRepositoryHeraldField return self::STANDARD_PHID_NULLABLE; } - public function getHeraldFieldValueType($condition) { - switch ($condition) { - case HeraldAdapter::CONDITION_EXISTS: - case HeraldAdapter::CONDITION_NOT_EXISTS: - return HeraldAdapter::VALUE_NONE; - default: - return HeraldAdapter::VALUE_REPOSITORY; - } + protected function getDatasource() { + return new DiffusionRepositoryDatasource(); } } diff --git a/src/applications/differential/herald/DifferentialDiffRepositoryProjectsHeraldField.php b/src/applications/differential/herald/DifferentialDiffRepositoryProjectsHeraldField.php index 2fac95641d..38f55691a7 100644 --- a/src/applications/differential/herald/DifferentialDiffRepositoryProjectsHeraldField.php +++ b/src/applications/differential/herald/DifferentialDiffRepositoryProjectsHeraldField.php @@ -24,14 +24,8 @@ final class DifferentialDiffRepositoryProjectsHeraldField return self::STANDARD_PHID_LIST; } - public function getHeraldFieldValueType($condition) { - switch ($condition) { - case HeraldAdapter::CONDITION_EXISTS: - case HeraldAdapter::CONDITION_NOT_EXISTS: - return HeraldAdapter::VALUE_NONE; - default: - return HeraldAdapter::VALUE_PROJECT; - } + protected function getDatasource() { + return new PhabricatorProjectDatasource(); } } diff --git a/src/applications/differential/herald/DifferentialRevisionAuthorHeraldField.php b/src/applications/differential/herald/DifferentialRevisionAuthorHeraldField.php index b2f119cc6c..245c5ae794 100644 --- a/src/applications/differential/herald/DifferentialRevisionAuthorHeraldField.php +++ b/src/applications/differential/herald/DifferentialRevisionAuthorHeraldField.php @@ -17,8 +17,8 @@ final class DifferentialRevisionAuthorHeraldField return self::STANDARD_PHID; } - public function getHeraldFieldValueType($condition) { - return HeraldAdapter::VALUE_USER; + protected function getDatasource() { + return new PhabricatorPeopleDatasource(); } } diff --git a/src/applications/differential/herald/DifferentialRevisionAuthorProjectsHeraldField.php b/src/applications/differential/herald/DifferentialRevisionAuthorProjectsHeraldField.php index d02a7c296b..cb916fcf3d 100644 --- a/src/applications/differential/herald/DifferentialRevisionAuthorProjectsHeraldField.php +++ b/src/applications/differential/herald/DifferentialRevisionAuthorProjectsHeraldField.php @@ -19,14 +19,8 @@ final class DifferentialRevisionAuthorProjectsHeraldField return self::STANDARD_PHID_LIST; } - public function getHeraldFieldValueType($condition) { - switch ($condition) { - case HeraldAdapter::CONDITION_EXISTS: - case HeraldAdapter::CONDITION_NOT_EXISTS: - return HeraldAdapter::VALUE_NONE; - default: - return HeraldAdapter::VALUE_PROJECT; - } + protected function getDatasource() { + return new PhabricatorProjectDatasource(); } } diff --git a/src/applications/differential/herald/DifferentialRevisionPackageHeraldField.php b/src/applications/differential/herald/DifferentialRevisionPackageHeraldField.php index e788d9e612..e1ece2e231 100644 --- a/src/applications/differential/herald/DifferentialRevisionPackageHeraldField.php +++ b/src/applications/differential/herald/DifferentialRevisionPackageHeraldField.php @@ -18,14 +18,8 @@ final class DifferentialRevisionPackageHeraldField return self::STANDARD_PHID_LIST; } - public function getHeraldFieldValueType($condition) { - switch ($condition) { - case HeraldAdapter::CONDITION_EXISTS: - case HeraldAdapter::CONDITION_NOT_EXISTS: - return HeraldAdapter::VALUE_NONE; - default: - return HeraldAdapter::VALUE_OWNERS_PACKAGE; - } + protected function getDatasource() { + return new PhabricatorOwnersPackageDatasource(); } } diff --git a/src/applications/differential/herald/DifferentialRevisionPackageOwnerHeraldField.php b/src/applications/differential/herald/DifferentialRevisionPackageOwnerHeraldField.php index ef8b7b2899..5bfe3322d8 100644 --- a/src/applications/differential/herald/DifferentialRevisionPackageOwnerHeraldField.php +++ b/src/applications/differential/herald/DifferentialRevisionPackageOwnerHeraldField.php @@ -23,14 +23,8 @@ final class DifferentialRevisionPackageOwnerHeraldField return self::STANDARD_PHID_LIST; } - public function getHeraldFieldValueType($condition) { - switch ($condition) { - case HeraldAdapter::CONDITION_EXISTS: - case HeraldAdapter::CONDITION_NOT_EXISTS: - return HeraldAdapter::VALUE_NONE; - default: - return HeraldAdapter::VALUE_USER_OR_PROJECT; - } + protected function getDatasource() { + return new PhabricatorProjectOrUserDatasource(); } } diff --git a/src/applications/differential/herald/DifferentialRevisionRepositoryHeraldField.php b/src/applications/differential/herald/DifferentialRevisionRepositoryHeraldField.php index 561d0ff15b..c138c51e22 100644 --- a/src/applications/differential/herald/DifferentialRevisionRepositoryHeraldField.php +++ b/src/applications/differential/herald/DifferentialRevisionRepositoryHeraldField.php @@ -23,14 +23,8 @@ final class DifferentialRevisionRepositoryHeraldField return self::STANDARD_PHID_NULLABLE; } - public function getHeraldFieldValueType($condition) { - switch ($condition) { - case HeraldAdapter::CONDITION_EXISTS: - case HeraldAdapter::CONDITION_NOT_EXISTS: - return HeraldAdapter::VALUE_NONE; - default: - return HeraldAdapter::VALUE_REPOSITORY; - } + protected function getDatasource() { + return new DiffusionRepositoryDatasource(); } } diff --git a/src/applications/differential/herald/DifferentialRevisionRepositoryProjectsHeraldField.php b/src/applications/differential/herald/DifferentialRevisionRepositoryProjectsHeraldField.php index bdf8ecd8c5..4310463ef5 100644 --- a/src/applications/differential/herald/DifferentialRevisionRepositoryProjectsHeraldField.php +++ b/src/applications/differential/herald/DifferentialRevisionRepositoryProjectsHeraldField.php @@ -24,14 +24,8 @@ final class DifferentialRevisionRepositoryProjectsHeraldField return self::STANDARD_PHID_LIST; } - public function getHeraldFieldValueType($condition) { - switch ($condition) { - case HeraldAdapter::CONDITION_EXISTS: - case HeraldAdapter::CONDITION_NOT_EXISTS: - return HeraldAdapter::VALUE_NONE; - default: - return HeraldAdapter::VALUE_PROJECT; - } + protected function getDatasource() { + return new PhabricatorProjectDatasource(); } } diff --git a/src/applications/differential/herald/DifferentialRevisionReviewersHeraldField.php b/src/applications/differential/herald/DifferentialRevisionReviewersHeraldField.php index e8ca0f4109..773c2aa8ec 100644 --- a/src/applications/differential/herald/DifferentialRevisionReviewersHeraldField.php +++ b/src/applications/differential/herald/DifferentialRevisionReviewersHeraldField.php @@ -17,14 +17,8 @@ final class DifferentialRevisionReviewersHeraldField return self::STANDARD_PHID_LIST; } - public function getHeraldFieldValueType($condition) { - switch ($condition) { - case HeraldAdapter::CONDITION_EXISTS: - case HeraldAdapter::CONDITION_NOT_EXISTS: - return HeraldAdapter::VALUE_NONE; - default: - return HeraldAdapter::VALUE_USER_OR_PROJECT; - } + protected function getDatasource() { + return new PhabricatorProjectOrUserDatasource(); } } diff --git a/src/applications/diffusion/herald/DiffusionCommitAuthorHeraldField.php b/src/applications/diffusion/herald/DiffusionCommitAuthorHeraldField.php index 1547253d40..ba1b636684 100644 --- a/src/applications/diffusion/herald/DiffusionCommitAuthorHeraldField.php +++ b/src/applications/diffusion/herald/DiffusionCommitAuthorHeraldField.php @@ -17,14 +17,8 @@ final class DiffusionCommitAuthorHeraldField return self::STANDARD_PHID_NULLABLE; } - public function getHeraldFieldValueType($condition) { - switch ($condition) { - case HeraldAdapter::CONDITION_EXISTS: - case HeraldAdapter::CONDITION_NOT_EXISTS: - return HeraldAdapter::VALUE_NONE; - default: - return HeraldAdapter::VALUE_USER; - } + protected function getDatasource() { + return new PhabricatorPeopleDatasource(); } } diff --git a/src/applications/diffusion/herald/DiffusionCommitAutocloseHeraldField.php b/src/applications/diffusion/herald/DiffusionCommitAutocloseHeraldField.php index f54b24c7d5..674b023582 100644 --- a/src/applications/diffusion/herald/DiffusionCommitAutocloseHeraldField.php +++ b/src/applications/diffusion/herald/DiffusionCommitAutocloseHeraldField.php @@ -20,7 +20,7 @@ final class DiffusionCommitAutocloseHeraldField } public function getHeraldFieldValueType($condition) { - return HeraldAdapter::VALUE_NONE; + return new HeraldEmptyFieldValue(); } } diff --git a/src/applications/diffusion/herald/DiffusionCommitCommitterHeraldField.php b/src/applications/diffusion/herald/DiffusionCommitCommitterHeraldField.php index 06fbc6c9c5..825648c46c 100644 --- a/src/applications/diffusion/herald/DiffusionCommitCommitterHeraldField.php +++ b/src/applications/diffusion/herald/DiffusionCommitCommitterHeraldField.php @@ -17,14 +17,8 @@ final class DiffusionCommitCommitterHeraldField return self::STANDARD_PHID_NULLABLE; } - public function getHeraldFieldValueType($condition) { - switch ($condition) { - case HeraldAdapter::CONDITION_EXISTS: - case HeraldAdapter::CONDITION_NOT_EXISTS: - return HeraldAdapter::VALUE_NONE; - default: - return HeraldAdapter::VALUE_USER; - } + protected function getDatasource() { + return new PhabricatorPeopleDatasource(); } } diff --git a/src/applications/diffusion/herald/DiffusionCommitPackageAuditHeraldField.php b/src/applications/diffusion/herald/DiffusionCommitPackageAuditHeraldField.php index ce1d19a699..c5c803cd69 100644 --- a/src/applications/diffusion/herald/DiffusionCommitPackageAuditHeraldField.php +++ b/src/applications/diffusion/herald/DiffusionCommitPackageAuditHeraldField.php @@ -22,14 +22,8 @@ final class DiffusionCommitPackageAuditHeraldField return self::STANDARD_PHID_LIST; } - public function getHeraldFieldValueType($condition) { - switch ($condition) { - case HeraldAdapter::CONDITION_EXISTS: - case HeraldAdapter::CONDITION_NOT_EXISTS: - return HeraldAdapter::VALUE_NONE; - default: - return HeraldAdapter::VALUE_OWNERS_PACKAGE; - } + protected function getDatasource() { + return new PhabricatorOwnersPackageDatasource(); } } diff --git a/src/applications/diffusion/herald/DiffusionCommitPackageHeraldField.php b/src/applications/diffusion/herald/DiffusionCommitPackageHeraldField.php index 01f117ef3d..08e2fdee6d 100644 --- a/src/applications/diffusion/herald/DiffusionCommitPackageHeraldField.php +++ b/src/applications/diffusion/herald/DiffusionCommitPackageHeraldField.php @@ -18,14 +18,8 @@ final class DiffusionCommitPackageHeraldField return self::STANDARD_PHID_LIST; } - public function getHeraldFieldValueType($condition) { - switch ($condition) { - case HeraldAdapter::CONDITION_EXISTS: - case HeraldAdapter::CONDITION_NOT_EXISTS: - return HeraldAdapter::VALUE_NONE; - default: - return HeraldAdapter::VALUE_OWNERS_PACKAGE; - } + protected function getDatasource() { + return new PhabricatorOwnersPackageDatasource(); } } diff --git a/src/applications/diffusion/herald/DiffusionCommitPackageOwnerHeraldField.php b/src/applications/diffusion/herald/DiffusionCommitPackageOwnerHeraldField.php index bd98aec032..c4dd341ee2 100644 --- a/src/applications/diffusion/herald/DiffusionCommitPackageOwnerHeraldField.php +++ b/src/applications/diffusion/herald/DiffusionCommitPackageOwnerHeraldField.php @@ -24,14 +24,8 @@ final class DiffusionCommitPackageOwnerHeraldField return self::STANDARD_PHID_LIST; } - public function getHeraldFieldValueType($condition) { - switch ($condition) { - case HeraldAdapter::CONDITION_EXISTS: - case HeraldAdapter::CONDITION_NOT_EXISTS: - return HeraldAdapter::VALUE_NONE; - default: - return HeraldAdapter::VALUE_USER_OR_PROJECT; - } + protected function getDatasource() { + return new PhabricatorProjectOrUserDatasource(); } } diff --git a/src/applications/diffusion/herald/DiffusionCommitRepositoryHeraldField.php b/src/applications/diffusion/herald/DiffusionCommitRepositoryHeraldField.php index 88da8c7403..2c835c6d8a 100644 --- a/src/applications/diffusion/herald/DiffusionCommitRepositoryHeraldField.php +++ b/src/applications/diffusion/herald/DiffusionCommitRepositoryHeraldField.php @@ -17,8 +17,8 @@ final class DiffusionCommitRepositoryHeraldField return self::STANDARD_PHID; } - public function getHeraldFieldValueType($condition) { - return HeraldAdapter::VALUE_REPOSITORY; + protected function getDatasource() { + return new DiffusionRepositoryDatasource(); } } diff --git a/src/applications/diffusion/herald/DiffusionCommitRepositoryProjectsHeraldField.php b/src/applications/diffusion/herald/DiffusionCommitRepositoryProjectsHeraldField.php index 7f71d063ee..a12022f74d 100644 --- a/src/applications/diffusion/herald/DiffusionCommitRepositoryProjectsHeraldField.php +++ b/src/applications/diffusion/herald/DiffusionCommitRepositoryProjectsHeraldField.php @@ -19,14 +19,8 @@ final class DiffusionCommitRepositoryProjectsHeraldField return self::STANDARD_PHID_LIST; } - public function getHeraldFieldValueType($condition) { - switch ($condition) { - case HeraldAdapter::CONDITION_EXISTS: - case HeraldAdapter::CONDITION_NOT_EXISTS: - return HeraldAdapter::VALUE_NONE; - default: - return HeraldAdapter::VALUE_PROJECT; - } + protected function getDatasource() { + return new PhabricatorProjectDatasource(); } } diff --git a/src/applications/diffusion/herald/DiffusionCommitReviewerHeraldField.php b/src/applications/diffusion/herald/DiffusionCommitReviewerHeraldField.php index 2f67070f52..2a09eff83e 100644 --- a/src/applications/diffusion/herald/DiffusionCommitReviewerHeraldField.php +++ b/src/applications/diffusion/herald/DiffusionCommitReviewerHeraldField.php @@ -17,14 +17,8 @@ final class DiffusionCommitReviewerHeraldField return self::STANDARD_PHID_NULLABLE; } - public function getHeraldFieldValueType($condition) { - switch ($condition) { - case HeraldAdapter::CONDITION_EXISTS: - case HeraldAdapter::CONDITION_NOT_EXISTS: - return HeraldAdapter::VALUE_NONE; - default: - return HeraldAdapter::VALUE_USER; - } + protected function getDatasource() { + return new PhabricatorPeopleDatasource(); } } diff --git a/src/applications/diffusion/herald/DiffusionCommitRevisionReviewersHeraldField.php b/src/applications/diffusion/herald/DiffusionCommitRevisionReviewersHeraldField.php index f9febc72cd..91103a78fd 100644 --- a/src/applications/diffusion/herald/DiffusionCommitRevisionReviewersHeraldField.php +++ b/src/applications/diffusion/herald/DiffusionCommitRevisionReviewersHeraldField.php @@ -23,14 +23,8 @@ final class DiffusionCommitRevisionReviewersHeraldField return self::STANDARD_PHID_LIST; } - public function getHeraldFieldValueType($condition) { - switch ($condition) { - case HeraldAdapter::CONDITION_EXISTS: - case HeraldAdapter::CONDITION_NOT_EXISTS: - return HeraldAdapter::VALUE_NONE; - default: - return HeraldAdapter::VALUE_USER_OR_PROJECT; - } + protected function getDatasource() { + return new PhabricatorProjectOrUserDatasource(); } } diff --git a/src/applications/diffusion/herald/DiffusionCommitRevisionSubscribersHeraldField.php b/src/applications/diffusion/herald/DiffusionCommitRevisionSubscribersHeraldField.php index 1d235c9a3d..e873e6e74a 100644 --- a/src/applications/diffusion/herald/DiffusionCommitRevisionSubscribersHeraldField.php +++ b/src/applications/diffusion/herald/DiffusionCommitRevisionSubscribersHeraldField.php @@ -24,14 +24,8 @@ final class DiffusionCommitRevisionSubscribersHeraldField return self::STANDARD_PHID_LIST; } - public function getHeraldFieldValueType($condition) { - switch ($condition) { - case HeraldAdapter::CONDITION_EXISTS: - case HeraldAdapter::CONDITION_NOT_EXISTS: - return HeraldAdapter::VALUE_NONE; - default: - return HeraldAdapter::VALUE_USER_OR_PROJECT; - } + protected function getDatasource() { + return new PhabricatorProjectOrUserDatasource(); } } diff --git a/src/applications/diffusion/herald/DiffusionPreCommitContentAuthorHeraldField.php b/src/applications/diffusion/herald/DiffusionPreCommitContentAuthorHeraldField.php index ae9c725e9b..4fb390d474 100644 --- a/src/applications/diffusion/herald/DiffusionPreCommitContentAuthorHeraldField.php +++ b/src/applications/diffusion/herald/DiffusionPreCommitContentAuthorHeraldField.php @@ -17,14 +17,8 @@ final class DiffusionPreCommitContentAuthorHeraldField return self::STANDARD_PHID_NULLABLE; } - public function getHeraldFieldValueType($condition) { - switch ($condition) { - case HeraldAdapter::CONDITION_EXISTS: - case HeraldAdapter::CONDITION_NOT_EXISTS: - return HeraldAdapter::VALUE_NONE; - default: - return HeraldAdapter::VALUE_USER; - } + protected function getDatasource() { + return new PhabricatorPeopleDatasource(); } } diff --git a/src/applications/diffusion/herald/DiffusionPreCommitContentCommitterHeraldField.php b/src/applications/diffusion/herald/DiffusionPreCommitContentCommitterHeraldField.php index 8682c9895f..cab8cbc6ae 100644 --- a/src/applications/diffusion/herald/DiffusionPreCommitContentCommitterHeraldField.php +++ b/src/applications/diffusion/herald/DiffusionPreCommitContentCommitterHeraldField.php @@ -17,14 +17,8 @@ final class DiffusionPreCommitContentCommitterHeraldField return self::STANDARD_PHID_NULLABLE; } - public function getHeraldFieldValueType($condition) { - switch ($condition) { - case HeraldAdapter::CONDITION_EXISTS: - case HeraldAdapter::CONDITION_NOT_EXISTS: - return HeraldAdapter::VALUE_NONE; - default: - return HeraldAdapter::VALUE_USER; - } + protected function getDatasource() { + return new PhabricatorPeopleDatasource(); } } diff --git a/src/applications/diffusion/herald/DiffusionPreCommitContentPusherHeraldField.php b/src/applications/diffusion/herald/DiffusionPreCommitContentPusherHeraldField.php index ec61cd3efb..50163dd019 100644 --- a/src/applications/diffusion/herald/DiffusionPreCommitContentPusherHeraldField.php +++ b/src/applications/diffusion/herald/DiffusionPreCommitContentPusherHeraldField.php @@ -17,8 +17,8 @@ final class DiffusionPreCommitContentPusherHeraldField return HeraldField::STANDARD_PHID; } - public function getHeraldFieldValueType($condition) { - return HeraldAdapter::VALUE_USER; + protected function getDatasource() { + return new PhabricatorPeopleDatasource(); } } diff --git a/src/applications/diffusion/herald/DiffusionPreCommitContentPusherProjectsHeraldField.php b/src/applications/diffusion/herald/DiffusionPreCommitContentPusherProjectsHeraldField.php index 78f5500312..6a8c79c108 100644 --- a/src/applications/diffusion/herald/DiffusionPreCommitContentPusherProjectsHeraldField.php +++ b/src/applications/diffusion/herald/DiffusionPreCommitContentPusherProjectsHeraldField.php @@ -19,13 +19,8 @@ final class DiffusionPreCommitContentPusherProjectsHeraldField return HeraldField::STANDARD_PHID_LIST; } - public function getHeraldFieldValueType($condition) { - switch ($condition) { - case HeraldAdapter::CONDITION_EXISTS: - case HeraldAdapter::CONDITION_NOT_EXISTS: - return HeraldAdapter::VALUE_NONE; - default: - return HeraldAdapter::VALUE_PROJECT; - } + protected function getDatasource() { + return new PhabricatorProjectDatasource(); } + } diff --git a/src/applications/diffusion/herald/DiffusionPreCommitContentRepositoryHeraldField.php b/src/applications/diffusion/herald/DiffusionPreCommitContentRepositoryHeraldField.php index 66352b4743..d0113acfa1 100644 --- a/src/applications/diffusion/herald/DiffusionPreCommitContentRepositoryHeraldField.php +++ b/src/applications/diffusion/herald/DiffusionPreCommitContentRepositoryHeraldField.php @@ -17,8 +17,8 @@ final class DiffusionPreCommitContentRepositoryHeraldField return HeraldField::STANDARD_PHID; } - public function getHeraldFieldValueType($condition) { - return HeraldAdapter::VALUE_REPOSITORY; + protected function getDatasource() { + return new DiffusionRepositoryDatasource(); } } diff --git a/src/applications/diffusion/herald/DiffusionPreCommitContentRepositoryProjectsHeraldField.php b/src/applications/diffusion/herald/DiffusionPreCommitContentRepositoryProjectsHeraldField.php index 4e9d9977ad..d7ad1474e2 100644 --- a/src/applications/diffusion/herald/DiffusionPreCommitContentRepositoryProjectsHeraldField.php +++ b/src/applications/diffusion/herald/DiffusionPreCommitContentRepositoryProjectsHeraldField.php @@ -19,14 +19,8 @@ final class DiffusionPreCommitContentRepositoryProjectsHeraldField return HeraldField::STANDARD_PHID_LIST; } - public function getHeraldFieldValueType($condition) { - switch ($condition) { - case HeraldAdapter::CONDITION_EXISTS: - case HeraldAdapter::CONDITION_NOT_EXISTS: - return HeraldAdapter::VALUE_NONE; - default: - return HeraldAdapter::VALUE_PROJECT; - } + protected function getDatasource() { + return new PhabricatorProjectDatasource(); } } diff --git a/src/applications/diffusion/herald/DiffusionPreCommitContentRevisionReviewersHeraldField.php b/src/applications/diffusion/herald/DiffusionPreCommitContentRevisionReviewersHeraldField.php index 7fc9a0e910..bc494d22ba 100644 --- a/src/applications/diffusion/herald/DiffusionPreCommitContentRevisionReviewersHeraldField.php +++ b/src/applications/diffusion/herald/DiffusionPreCommitContentRevisionReviewersHeraldField.php @@ -23,14 +23,8 @@ final class DiffusionPreCommitContentRevisionReviewersHeraldField return self::STANDARD_PHID_LIST; } - public function getHeraldFieldValueType($condition) { - switch ($condition) { - case HeraldAdapter::CONDITION_EXISTS: - case HeraldAdapter::CONDITION_NOT_EXISTS: - return HeraldAdapter::VALUE_NONE; - default: - return HeraldAdapter::VALUE_USER_OR_PROJECT; - } + protected function getDatasource() { + return new PhabricatorProjectOrUserDatasource(); } } diff --git a/src/applications/diffusion/herald/DiffusionPreCommitContentRevisionSubscribersHeraldField.php b/src/applications/diffusion/herald/DiffusionPreCommitContentRevisionSubscribersHeraldField.php index 711b88e372..b32757485a 100644 --- a/src/applications/diffusion/herald/DiffusionPreCommitContentRevisionSubscribersHeraldField.php +++ b/src/applications/diffusion/herald/DiffusionPreCommitContentRevisionSubscribersHeraldField.php @@ -24,14 +24,8 @@ final class DiffusionPreCommitContentRevisionSubscribersHeraldField return self::STANDARD_PHID_LIST; } - public function getHeraldFieldValueType($condition) { - switch ($condition) { - case HeraldAdapter::CONDITION_EXISTS: - case HeraldAdapter::CONDITION_NOT_EXISTS: - return HeraldAdapter::VALUE_NONE; - default: - return HeraldAdapter::VALUE_USER_OR_PROJECT; - } + protected function getDatasource() { + return new PhabricatorProjectOrUserDatasource(); } } diff --git a/src/applications/diffusion/herald/DiffusionPreCommitRefPusherHeraldField.php b/src/applications/diffusion/herald/DiffusionPreCommitRefPusherHeraldField.php index dae97328a9..59796de602 100644 --- a/src/applications/diffusion/herald/DiffusionPreCommitRefPusherHeraldField.php +++ b/src/applications/diffusion/herald/DiffusionPreCommitRefPusherHeraldField.php @@ -17,8 +17,8 @@ final class DiffusionPreCommitRefPusherHeraldField return HeraldField::STANDARD_PHID; } - public function getHeraldFieldValueType($condition) { - return HeraldAdapter::VALUE_USER; + protected function getDatasource() { + return new PhabricatorPeopleDatasource(); } } diff --git a/src/applications/diffusion/herald/DiffusionPreCommitRefPusherProjectsHeraldField.php b/src/applications/diffusion/herald/DiffusionPreCommitRefPusherProjectsHeraldField.php index b71e672c7f..6fff0a3570 100644 --- a/src/applications/diffusion/herald/DiffusionPreCommitRefPusherProjectsHeraldField.php +++ b/src/applications/diffusion/herald/DiffusionPreCommitRefPusherProjectsHeraldField.php @@ -19,13 +19,8 @@ final class DiffusionPreCommitRefPusherProjectsHeraldField return HeraldField::STANDARD_PHID_LIST; } - public function getHeraldFieldValueType($condition) { - switch ($condition) { - case HeraldAdapter::CONDITION_EXISTS: - case HeraldAdapter::CONDITION_NOT_EXISTS: - return HeraldAdapter::VALUE_NONE; - default: - return HeraldAdapter::VALUE_PROJECT; - } + protected function getDatasource() { + return new PhabricatorProjectDatasource(); } + } diff --git a/src/applications/diffusion/herald/DiffusionPreCommitRefRepositoryHeraldField.php b/src/applications/diffusion/herald/DiffusionPreCommitRefRepositoryHeraldField.php index e3c27890fa..6077259d8d 100644 --- a/src/applications/diffusion/herald/DiffusionPreCommitRefRepositoryHeraldField.php +++ b/src/applications/diffusion/herald/DiffusionPreCommitRefRepositoryHeraldField.php @@ -17,8 +17,8 @@ final class DiffusionPreCommitRefRepositoryHeraldField return HeraldField::STANDARD_PHID; } - public function getHeraldFieldValueType($condition) { - return HeraldAdapter::VALUE_REPOSITORY; + protected function getDatasource() { + return new DiffusionRepositoryDatasource(); } } diff --git a/src/applications/diffusion/herald/DiffusionPreCommitRefRepositoryProjectsHeraldField.php b/src/applications/diffusion/herald/DiffusionPreCommitRefRepositoryProjectsHeraldField.php index e5a90180b6..df262524f2 100644 --- a/src/applications/diffusion/herald/DiffusionPreCommitRefRepositoryProjectsHeraldField.php +++ b/src/applications/diffusion/herald/DiffusionPreCommitRefRepositoryProjectsHeraldField.php @@ -19,14 +19,8 @@ final class DiffusionPreCommitRefRepositoryProjectsHeraldField return HeraldField::STANDARD_PHID_LIST; } - public function getHeraldFieldValueType($condition) { - switch ($condition) { - case HeraldAdapter::CONDITION_EXISTS: - case HeraldAdapter::CONDITION_NOT_EXISTS: - return HeraldAdapter::VALUE_NONE; - default: - return HeraldAdapter::VALUE_PROJECT; - } + protected function getDatasource() { + return new PhabricatorProjectDatasource(); } } diff --git a/src/applications/herald/adapter/HeraldAdapter.php b/src/applications/herald/adapter/HeraldAdapter.php index 708a51b828..99cf108b3b 100644 --- a/src/applications/herald/adapter/HeraldAdapter.php +++ b/src/applications/herald/adapter/HeraldAdapter.php @@ -41,21 +41,6 @@ abstract class HeraldAdapter extends Phobject { const ACTION_BLOCK = 'block'; const ACTION_REQUIRE_SIGNATURE = 'signature'; - const VALUE_NONE = 'none'; - const VALUE_EMAIL = 'email'; - const VALUE_USER = 'user'; - const VALUE_RULE = 'rule'; - const VALUE_REPOSITORY = 'repository'; - const VALUE_OWNERS_PACKAGE = 'package'; - const VALUE_PROJECT = 'project'; - const VALUE_USER_OR_PROJECT = 'userorproject'; - const VALUE_BUILD_PLAN = 'buildplan'; - const VALUE_TASK_PRIORITY = 'taskpriority'; - const VALUE_TASK_STATUS = 'taskstatus'; - const VALUE_LEGAL_DOCUMENTS = 'legaldocuments'; - const VALUE_APPLICATION_EMAIL = 'applicationemail'; - const VALUE_SPACE = 'space'; - private $contentSource; private $isNewObject; private $applicationEmail; @@ -761,36 +746,43 @@ abstract class HeraldAdapter extends Phobject { case self::ACTION_ASSIGN_TASK: case self::ACTION_ADD_REVIEWERS: case self::ACTION_ADD_BLOCKING_REVIEWERS: - return self::VALUE_NONE; + return new HeraldEmptyFieldValue(); case self::ACTION_FLAG: return $this->buildFlagColorFieldValue(); case self::ACTION_ADD_PROJECTS: case self::ACTION_REMOVE_PROJECTS: - return self::VALUE_PROJECT; + return $this->buildTokenizerFieldValue( + new PhabricatorProjectDatasource()); } } else { switch ($action) { case self::ACTION_ADD_CC: case self::ACTION_REMOVE_CC: case self::ACTION_EMAIL: - return self::VALUE_EMAIL; + return $this->buildTokenizerFieldValue( + new PhabricatorMetaMTAMailableDatasource()); case self::ACTION_NOTHING: - return self::VALUE_NONE; + return new HeraldEmptyFieldValue(); case self::ACTION_ADD_PROJECTS: case self::ACTION_REMOVE_PROJECTS: - return self::VALUE_PROJECT; + return $this->buildTokenizerFieldValue( + new PhabricatorProjectDatasource()); case self::ACTION_FLAG: return $this->buildFlagColorFieldValue(); case self::ACTION_ASSIGN_TASK: - return self::VALUE_USER; + return $this->buildTokenizerFieldValue( + new PhabricatorPeopleDatasource()); case self::ACTION_AUDIT: case self::ACTION_ADD_REVIEWERS: case self::ACTION_ADD_BLOCKING_REVIEWERS: - return self::VALUE_USER_OR_PROJECT; + return $this->buildTokenizerFieldValue( + new PhabricatorProjectOrUserDatasource()); case self::ACTION_APPLY_BUILD_PLANS: - return self::VALUE_BUILD_PLAN; + return $this->buildTokenizerFieldValue( + new HarbormasterBuildPlanDatasource()); case self::ACTION_REQUIRE_SIGNATURE: - return self::VALUE_LEGAL_DOCUMENTS; + return $this->buildTokenizerFieldValue( + new LegalpadDocumentDatasource()); case self::ACTION_BLOCK: return new HeraldTextFieldValue(); } @@ -811,6 +803,16 @@ abstract class HeraldAdapter extends Phobject { ->setDefault(PhabricatorFlagColor::COLOR_BLUE); } + private function buildTokenizerFieldValue( + PhabricatorTypeaheadDatasource $datasource) { + + $key = 'action.'.get_class($datasource); + + return id(new HeraldTokenizerFieldValue()) + ->setKey($key) + ->setDatasource($datasource); + } + /* -( Repetition )--------------------------------------------------------- */ diff --git a/src/applications/herald/controller/HeraldRuleController.php b/src/applications/herald/controller/HeraldRuleController.php index 09e5c2fbfa..bc1aab18c3 100644 --- a/src/applications/herald/controller/HeraldRuleController.php +++ b/src/applications/herald/controller/HeraldRuleController.php @@ -458,6 +458,8 @@ final class HeraldRuleController extends HeraldController { $condition); if ($value_key instanceof HeraldFieldValue) { + $value_key->setViewer($this->getViewer()); + $spec = $value_key->getControlSpecificationDictionary(); $value_key = $value_key->getFieldValueKey(); $config_info['valueMap'][$value_key] = $spec; @@ -479,6 +481,8 @@ final class HeraldRuleController extends HeraldController { } if ($value_key instanceof HeraldFieldValue) { + $value_key->setViewer($this->getViewer()); + $spec = $value_key->getControlSpecificationDictionary(); $value_key = $value_key->getFieldValueKey(); $config_info['valueMap'][$value_key] = $spec; @@ -493,7 +497,7 @@ final class HeraldRuleController extends HeraldController { 'root' => 'herald-rule-edit-form', 'conditions' => (object)$serial_conditions, 'actions' => (object)$serial_actions, - 'template' => $this->buildTokenizerTemplates($handles) + array( + 'template' => $this->buildTokenizerTemplates() + array( 'rules' => $all_rules, ), 'info' => $config_info, @@ -576,39 +580,10 @@ final class HeraldRuleController extends HeraldController { } - protected function buildTokenizerTemplates(array $handles) { + protected function buildTokenizerTemplates() { $template = new AphrontTokenizerTemplateView(); $template = $template->render(); - - $sources = array( - 'repository' => new DiffusionRepositoryDatasource(), - 'legaldocuments' => new LegalpadDocumentDatasource(), - 'taskpriority' => new ManiphestTaskPriorityDatasource(), - 'taskstatus' => new ManiphestTaskStatusDatasource(), - 'buildplan' => new HarbormasterBuildPlanDatasource(), - 'package' => new PhabricatorOwnersPackageDatasource(), - 'project' => new PhabricatorProjectDatasource(), - 'user' => new PhabricatorPeopleDatasource(), - 'email' => new PhabricatorMetaMTAMailableDatasource(), - 'userorproject' => new PhabricatorProjectOrUserDatasource(), - 'applicationemail' => new PhabricatorMetaMTAApplicationEmailDatasource(), - 'space' => new PhabricatorSpacesNamespaceDatasource(), - ); - - foreach ($sources as $key => $source) { - $source->setViewer($this->getViewer()); - - $sources[$key] = array( - 'uri' => $source->getDatasourceURI(), - 'placeholder' => $source->getPlaceholderText(), - 'browseURI' => $source->getBrowseURI(), - ); - } - return array( - 'source' => $sources, - 'username' => $this->getRequest()->getUser()->getUserName(), - 'icons' => mpull($handles, 'getTypeIcon', 'getPHID'), 'markup' => $template, ); } diff --git a/src/applications/herald/field/HeraldAlwaysField.php b/src/applications/herald/field/HeraldAlwaysField.php index f52c9a0fc8..41d23d7816 100644 --- a/src/applications/herald/field/HeraldAlwaysField.php +++ b/src/applications/herald/field/HeraldAlwaysField.php @@ -19,7 +19,7 @@ final class HeraldAlwaysField extends HeraldField { } public function getHeraldFieldValueType($condition) { - return HeraldAdapter::VALUE_NONE; + return new HeraldEmptyFieldValue(); } public function supportsObject($object) { diff --git a/src/applications/herald/field/HeraldAnotherRuleField.php b/src/applications/herald/field/HeraldAnotherRuleField.php index add80f36e1..3b5635e332 100644 --- a/src/applications/herald/field/HeraldAnotherRuleField.php +++ b/src/applications/herald/field/HeraldAnotherRuleField.php @@ -24,8 +24,11 @@ final class HeraldAnotherRuleField extends HeraldField { } public function getHeraldFieldValueType($condition) { - return HeraldAdapter::VALUE_RULE; + // NOTE: This is a bit magical because we don't currently have a reasonable + // way to populate it from here. + return id(new HeraldSelectFieldValue()) + ->setKey(self::FIELDCONST) + ->setOptions(array()); } - } diff --git a/src/applications/herald/field/HeraldField.php b/src/applications/herald/field/HeraldField.php index c78d925fcb..e5362cdb22 100644 --- a/src/applications/herald/field/HeraldField.php +++ b/src/applications/herald/field/HeraldField.php @@ -20,6 +20,10 @@ abstract class HeraldField extends Phobject { throw new PhutilMethodNotImplementedException(); } + protected function getDatasource() { + throw new PhutilMethodNotImplementedException(); + } + public function getHeraldFieldConditions() { $standard_type = $this->getHeraldFieldStandardType(); switch ($standard_type) { @@ -91,6 +95,20 @@ abstract class HeraldField extends Phobject { case self::STANDARD_TEXT_LIST: case self::STANDARD_TEXT_MAP: return new HeraldTextFieldValue(); + case self::STANDARD_PHID: + case self::STANDARD_PHID_NULLABLE: + case self::STANDARD_PHID_LIST: + switch ($condition) { + case HeraldAdapter::CONDITION_EXISTS: + case HeraldAdapter::CONDITION_NOT_EXISTS: + return new HeraldEmptyFieldValue(); + default: + return id(new HeraldTokenizerFieldValue()) + ->setKey($this->getHeraldFieldName()) + ->setDatasource($this->getDatasource()); + } + break; + } throw new Exception( @@ -113,7 +131,8 @@ abstract class HeraldField extends Phobject { $value_type = $this->getHeraldFieldValueType($condition); if ($value_type instanceof HeraldFieldValue) { - return $value_type->renderValue($viewer, $value); + $value_type->setViewer($viewer); + return $value_type->renderFieldValue($value); } // TODO: While this is less of a mess than it used to be, it would still diff --git a/src/applications/herald/value/HeraldEmptyFieldValue.php b/src/applications/herald/value/HeraldEmptyFieldValue.php index 565bf69006..1f2899ea8a 100644 --- a/src/applications/herald/value/HeraldEmptyFieldValue.php +++ b/src/applications/herald/value/HeraldEmptyFieldValue.php @@ -11,7 +11,7 @@ final class HeraldEmptyFieldValue return self::CONTROL_NONE; } - public function renderValue(PhabricatorUser $viewer, $value) { + public function renderFieldValue($value) { return null; } diff --git a/src/applications/herald/value/HeraldFieldValue.php b/src/applications/herald/value/HeraldFieldValue.php index 915ebbe0f9..b7d4984687 100644 --- a/src/applications/herald/value/HeraldFieldValue.php +++ b/src/applications/herald/value/HeraldFieldValue.php @@ -2,6 +2,8 @@ abstract class HeraldFieldValue extends Phobject { + private $viewer; + const CONTROL_NONE = 'herald.control.none'; const CONTROL_TEXT = 'herald.control.text'; const CONTROL_SELECT = 'herald.control.select'; @@ -9,10 +11,20 @@ abstract class HeraldFieldValue extends Phobject { abstract public function getFieldValueKey(); abstract public function getControlType(); - abstract public function renderValue(PhabricatorUser $viewer, $value); + abstract public function renderFieldValue($value); + + public function setViewer(PhabricatorUser $viewer) { + $this->viewer = $viewer; + return $this; + } + + public function getViewer() { + return $this->viewer; + } final public function getControlSpecificationDictionary() { return array( + 'key' => $this->getFieldValueKey(), 'control' => $this->getControlType(), 'template' => $this->getControlTemplate(), ); diff --git a/src/applications/herald/value/HeraldSelectFieldValue.php b/src/applications/herald/value/HeraldSelectFieldValue.php index ac0706082e..90e8d37dab 100644 --- a/src/applications/herald/value/HeraldSelectFieldValue.php +++ b/src/applications/herald/value/HeraldSelectFieldValue.php @@ -56,7 +56,7 @@ final class HeraldSelectFieldValue ); } - public function renderValue(PhabricatorUser $viewer, $value) { + public function renderFieldValue($value) { $options = $this->getOptions(); return idx($options, $value, $value); } diff --git a/src/applications/herald/value/HeraldTextFieldValue.php b/src/applications/herald/value/HeraldTextFieldValue.php index 8cf3308184..e88b8e9db6 100644 --- a/src/applications/herald/value/HeraldTextFieldValue.php +++ b/src/applications/herald/value/HeraldTextFieldValue.php @@ -12,7 +12,7 @@ final class HeraldTextFieldValue } - public function renderValue(PhabricatorUser $viewer, $value) { + public function renderFieldValue($value) { return $value; } diff --git a/src/applications/herald/value/HeraldTokenizerFieldValue.php b/src/applications/herald/value/HeraldTokenizerFieldValue.php new file mode 100644 index 0000000000..ef349eecb8 --- /dev/null +++ b/src/applications/herald/value/HeraldTokenizerFieldValue.php @@ -0,0 +1,60 @@ +key = $key; + return $this; + } + + public function getKey() { + return $this->key; + } + + public function setDatasource(PhabricatorTypeaheadDatasource $datasource) { + $this->datasource = $datasource; + return $this; + } + + public function getDatasource() { + return $this->datasource; + } + + public function getFieldValueKey() { + if ($this->getKey() === null) { + throw new PhutilInvalidStateException('setKey'); + } + return 'tokenizer.'.$this->getKey(); + } + + public function getControlType() { + return self::CONTROL_TOKENIZER; + } + + protected function getControlTemplate() { + if ($this->getDatasource() === null) { + throw new PhutilInvalidStateException('setDatasource'); + } + + $datasource = $this->getDatasource(); + $datasource->setViewer($this->getViewer()); + + return array( + 'tokenizer' => array( + 'datasourceURI' => $datasource->getDatasourceURI(), + 'browseURI' => $datasource->getBrowseURI(), + 'placeholder' => $datasource->getPlaceholderText(), + ), + ); + } + + public function renderFieldValue($value) { + $viewer = $this->getViewer(); + return $viewer->renderHandleList((array)$value)->setAsInline(true); + } + +} diff --git a/src/applications/maniphest/herald/ManiphestTaskAssigneeHeraldField.php b/src/applications/maniphest/herald/ManiphestTaskAssigneeHeraldField.php index f42feda951..bf65236e59 100644 --- a/src/applications/maniphest/herald/ManiphestTaskAssigneeHeraldField.php +++ b/src/applications/maniphest/herald/ManiphestTaskAssigneeHeraldField.php @@ -17,14 +17,8 @@ final class ManiphestTaskAssigneeHeraldField return self::STANDARD_PHID_NULLABLE; } - public function getHeraldFieldValueType($condition) { - switch ($condition) { - case HeraldAdapter::CONDITION_EXISTS: - case HeraldAdapter::CONDITION_NOT_EXISTS: - return HeraldAdapter::VALUE_NONE; - default: - return HeraldAdapter::VALUE_USER; - } + protected function getDatasource() { + return new PhabricatorPeopleDatasource(); } } diff --git a/src/applications/maniphest/herald/ManiphestTaskAuthorHeraldField.php b/src/applications/maniphest/herald/ManiphestTaskAuthorHeraldField.php index e44aba8e4d..1103ac5832 100644 --- a/src/applications/maniphest/herald/ManiphestTaskAuthorHeraldField.php +++ b/src/applications/maniphest/herald/ManiphestTaskAuthorHeraldField.php @@ -17,8 +17,8 @@ final class ManiphestTaskAuthorHeraldField return self::STANDARD_PHID; } - public function getHeraldFieldValueType($condition) { - return HeraldAdapter::VALUE_USER; + protected function getDatasource() { + return new PhabricatorPeopleDatasource(); } } diff --git a/src/applications/maniphest/herald/ManiphestTaskPriorityHeraldField.php b/src/applications/maniphest/herald/ManiphestTaskPriorityHeraldField.php index 403cc5669e..0bca2af61d 100644 --- a/src/applications/maniphest/herald/ManiphestTaskPriorityHeraldField.php +++ b/src/applications/maniphest/herald/ManiphestTaskPriorityHeraldField.php @@ -17,8 +17,8 @@ final class ManiphestTaskPriorityHeraldField return self::STANDARD_PHID; } - public function getHeraldFieldValueType($condition) { - return HeraldAdapter::VALUE_TASK_PRIORITY; + protected function getDatasource() { + return new ManiphestTaskPriorityDatasource(); } public function renderConditionValue( diff --git a/src/applications/maniphest/herald/ManiphestTaskStatusHeraldField.php b/src/applications/maniphest/herald/ManiphestTaskStatusHeraldField.php index caadbd644c..b2166de557 100644 --- a/src/applications/maniphest/herald/ManiphestTaskStatusHeraldField.php +++ b/src/applications/maniphest/herald/ManiphestTaskStatusHeraldField.php @@ -17,8 +17,8 @@ final class ManiphestTaskStatusHeraldField return self::STANDARD_PHID; } - public function getHeraldFieldValueType($condition) { - return HeraldAdapter::VALUE_TASK_STATUS; + protected function getDatasource() { + return new ManiphestTaskStatusDatasource(); } public function renderConditionValue( diff --git a/src/applications/metamta/herald/PhabricatorMetaMTAApplicationEmailHeraldField.php b/src/applications/metamta/herald/PhabricatorMetaMTAApplicationEmailHeraldField.php index 9133442f54..e5b3f8bca1 100644 --- a/src/applications/metamta/herald/PhabricatorMetaMTAApplicationEmailHeraldField.php +++ b/src/applications/metamta/herald/PhabricatorMetaMTAApplicationEmailHeraldField.php @@ -28,14 +28,8 @@ final class PhabricatorMetaMTAApplicationEmailHeraldField return self::STANDARD_PHID_LIST; } - public function getHeraldFieldValueType($condition) { - switch ($condition) { - case HeraldAdapter::CONDITION_EXISTS: - case HeraldAdapter::CONDITION_NOT_EXISTS: - return HeraldAdapter::VALUE_NONE; - default: - return HeraldAdapter::VALUE_APPLICATION_EMAIL; - } + protected function getDatasource() { + return new PhabricatorMetaMTAApplicationEmailDatasource(); } } diff --git a/src/applications/pholio/herald/PholioMockAuthorHeraldField.php b/src/applications/pholio/herald/PholioMockAuthorHeraldField.php index a7bf6fabf5..87461b32f9 100644 --- a/src/applications/pholio/herald/PholioMockAuthorHeraldField.php +++ b/src/applications/pholio/herald/PholioMockAuthorHeraldField.php @@ -17,8 +17,8 @@ final class PholioMockAuthorHeraldField return self::STANDARD_PHID; } - public function getHeraldFieldValueType($condition) { - return HeraldAdapter::VALUE_USER; + protected function getDatasource() { + return new PhabricatorPeopleDatasource(); } } diff --git a/src/applications/phriction/herald/PhrictionDocumentAuthorHeraldField.php b/src/applications/phriction/herald/PhrictionDocumentAuthorHeraldField.php index dd3aedb475..c2d28db29d 100644 --- a/src/applications/phriction/herald/PhrictionDocumentAuthorHeraldField.php +++ b/src/applications/phriction/herald/PhrictionDocumentAuthorHeraldField.php @@ -17,8 +17,8 @@ final class PhrictionDocumentAuthorHeraldField return self::STANDARD_PHID; } - public function getHeraldFieldValueType($condition) { - return HeraldAdapter::VALUE_USER; + protected function getDatasource() { + return new PhabricatorPeopleDatasource(); } } diff --git a/src/applications/project/herald/HeraldProjectsField.php b/src/applications/project/herald/HeraldProjectsField.php index d7e77f3476..ec55e78c41 100644 --- a/src/applications/project/herald/HeraldProjectsField.php +++ b/src/applications/project/herald/HeraldProjectsField.php @@ -22,14 +22,8 @@ final class HeraldProjectsField extends HeraldField { return self::STANDARD_PHID_LIST; } - public function getHeraldFieldValueType($condition) { - switch ($condition) { - case HeraldAdapter::CONDITION_EXISTS: - case HeraldAdapter::CONDITION_NOT_EXISTS: - return HeraldAdapter::VALUE_NONE; - default: - return HeraldAdapter::VALUE_PROJECT; - } + protected function getDatasource() { + return new PhabricatorProjectDatasource(); } } diff --git a/src/applications/spaces/herald/HeraldSpaceField.php b/src/applications/spaces/herald/HeraldSpaceField.php index 75314c15c0..27aca63a3d 100644 --- a/src/applications/spaces/herald/HeraldSpaceField.php +++ b/src/applications/spaces/herald/HeraldSpaceField.php @@ -20,8 +20,8 @@ final class HeraldSpaceField extends HeraldField { return self::STANDARD_PHID; } - public function getHeraldFieldValueType($condition) { - return HeraldAdapter::VALUE_SPACE; + protected function getDatasource() { + return new PhabricatorSpacesNamespaceDatasource(); } } diff --git a/src/applications/subscriptions/herald/HeraldSubscribersField.php b/src/applications/subscriptions/herald/HeraldSubscribersField.php index 4d653bfd52..d28add999f 100644 --- a/src/applications/subscriptions/herald/HeraldSubscribersField.php +++ b/src/applications/subscriptions/herald/HeraldSubscribersField.php @@ -21,14 +21,8 @@ final class HeraldSubscribersField extends HeraldField { return self::STANDARD_PHID_LIST; } - public function getHeraldFieldValueType($condition) { - switch ($condition) { - case HeraldAdapter::CONDITION_EXISTS: - case HeraldAdapter::CONDITION_NOT_EXISTS: - return HeraldAdapter::VALUE_NONE; - default: - return HeraldAdapter::VALUE_USER_OR_PROJECT; - } + protected function getDatasource() { + return new PhabricatorProjectOrUserDatasource(); } } diff --git a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldUsers.php b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldUsers.php index 87dc7f830c..7efe873a1d 100644 --- a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldUsers.php +++ b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldUsers.php @@ -41,7 +41,9 @@ final class PhabricatorStandardCustomFieldUsers } public function getHeraldFieldValueType($condition) { - return HeraldAdapter::VALUE_USER; + return id(new HeraldTokenizerFieldValue()) + ->setKey('custom.'.$this->getFieldKey()) + ->setDatasource(new PhabricatorPeopleDatasource()); } } diff --git a/webroot/rsrc/js/application/herald/HeraldRuleEditor.js b/webroot/rsrc/js/application/herald/HeraldRuleEditor.js index 525d82fe0d..4a4e2a97e0 100644 --- a/webroot/rsrc/js/application/herald/HeraldRuleEditor.js +++ b/webroot/rsrc/js/application/herald/HeraldRuleEditor.js @@ -200,7 +200,9 @@ JX.install('HeraldRuleEditor', { return node; }, - _buildStandardInput: function(spec) { + _buildInput : function(type) { + var spec = this._config.info.valueMap[type]; + var input; var get_fn; var set_fn; @@ -216,7 +218,18 @@ JX.install('HeraldRuleEditor', { set_fn = function(v) { input.value = v; }; break; case 'herald.control.select': - input = this._renderSelect(spec.template.options); + var options; + + // NOTE: This is a hacky special case for "Another Herald Rule", + // which we don't currently generate normal options for. + + if (spec.key == 'select.rule') { + options = this._config.template.rules; + } else { + options = spec.template.options; + } + + input = this._renderSelect(options); get_fn = function() { return input.value; }; set_fn = function(v) { input.value = v; }; if (spec.template.default) { @@ -224,7 +237,7 @@ JX.install('HeraldRuleEditor', { } break; case 'herald.control.tokenizer': - var tokenizer = this._newTokenizer(spec.template.tokenizer, true); + var tokenizer = this._newTokenizer(spec.template.tokenizer); input = tokenizer[0]; get_fn = tokenizer[1]; set_fn = tokenizer[2]; @@ -237,48 +250,6 @@ JX.install('HeraldRuleEditor', { return [input, get_fn, set_fn]; }, - _buildInput : function(type) { - if (this._config.info.valueMap[type]) { - return this._buildStandardInput(this._config.info.valueMap[type]); - } - - var input; - var get_fn; - var set_fn; - switch (type) { - case 'rule': - input = this._renderSelect(this._config.template.rules); - get_fn = function() { return input.value; }; - set_fn = function(v) { input.value = v; }; - break; - case 'email': - case 'user': - case 'repository': - case 'tag': - case 'package': - case 'project': - case 'userorproject': - case 'buildplan': - case 'taskpriority': - case 'taskstatus': - case 'legaldocuments': - case 'applicationemail': - case 'space': - var tokenizer = this._newTokenizer(type); - input = tokenizer[0]; - get_fn = tokenizer[1]; - set_fn = tokenizer[2]; - break; - default: - input = JX.$N('input', {type: 'text'}); - get_fn = function() { return input.value; }; - set_fn = function(v) { input.value = v; }; - break; - } - - return [input, get_fn, set_fn]; - }, - _renderValueInputForRow : function(row_id) { var cond = this._config.conditions[row_id]; var type = this._config.info.values[cond[0]][cond[1]]; @@ -303,20 +274,12 @@ JX.install('HeraldRuleEditor', { return node; }, - _newTokenizer : function(type, is_config) { - var tokenizerConfig; - - if (is_config) { - tokenizerConfig = type; - } else { - tokenizerConfig = { - src : this._config.template.source[type].uri, - placeholder: this._config.template.source[type].placeholder, - browseURI: this._config.template.source[type].browseURI, - icons : this._config.template.icons, - username : this._config.username - }; - } + _newTokenizer : function(spec) { + var tokenizerConfig = { + src: spec.datasourceURI, + placeholder: spec.placeholder, + browseURI: spec.browseURI + }; var build = JX.Prefab.newTokenizerFromTemplate( this._config.template.markup,