diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 2b45c3856a..703962b2ae 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -521,6 +521,7 @@ phutil_register_library_map(array( 'DifferentialRevisionAuthorProjectsHeraldField' => 'applications/differential/herald/DifferentialRevisionAuthorProjectsHeraldField.php', 'DifferentialRevisionCloseDetailsController' => 'applications/differential/controller/DifferentialRevisionCloseDetailsController.php', 'DifferentialRevisionCloseTransaction' => 'applications/differential/xaction/DifferentialRevisionCloseTransaction.php', + 'DifferentialRevisionClosedStatusDatasource' => 'applications/differential/typeahead/DifferentialRevisionClosedStatusDatasource.php', 'DifferentialRevisionCommandeerTransaction' => 'applications/differential/xaction/DifferentialRevisionCommandeerTransaction.php', 'DifferentialRevisionContentAddedHeraldField' => 'applications/differential/herald/DifferentialRevisionContentAddedHeraldField.php', 'DifferentialRevisionContentHeraldField' => 'applications/differential/herald/DifferentialRevisionContentHeraldField.php', @@ -548,6 +549,7 @@ phutil_register_library_map(array( 'DifferentialRevisionListController' => 'applications/differential/controller/DifferentialRevisionListController.php', 'DifferentialRevisionListView' => 'applications/differential/view/DifferentialRevisionListView.php', 'DifferentialRevisionMailReceiver' => 'applications/differential/mail/DifferentialRevisionMailReceiver.php', + 'DifferentialRevisionOpenStatusDatasource' => 'applications/differential/typeahead/DifferentialRevisionOpenStatusDatasource.php', 'DifferentialRevisionOperationController' => 'applications/differential/controller/DifferentialRevisionOperationController.php', 'DifferentialRevisionPHIDType' => 'applications/differential/phid/DifferentialRevisionPHIDType.php', 'DifferentialRevisionPackageHeraldField' => 'applications/differential/herald/DifferentialRevisionPackageHeraldField.php', @@ -572,6 +574,8 @@ phutil_register_library_map(array( 'DifferentialRevisionSearchConduitAPIMethod' => 'applications/differential/conduit/DifferentialRevisionSearchConduitAPIMethod.php', 'DifferentialRevisionSearchEngine' => 'applications/differential/query/DifferentialRevisionSearchEngine.php', 'DifferentialRevisionStatus' => 'applications/differential/constants/DifferentialRevisionStatus.php', + 'DifferentialRevisionStatusDatasource' => 'applications/differential/typeahead/DifferentialRevisionStatusDatasource.php', + 'DifferentialRevisionStatusFunctionDatasource' => 'applications/differential/typeahead/DifferentialRevisionStatusFunctionDatasource.php', 'DifferentialRevisionSummaryHeraldField' => 'applications/differential/herald/DifferentialRevisionSummaryHeraldField.php', 'DifferentialRevisionSummaryTransaction' => 'applications/differential/xaction/DifferentialRevisionSummaryTransaction.php', 'DifferentialRevisionTestPlanTransaction' => 'applications/differential/xaction/DifferentialRevisionTestPlanTransaction.php', @@ -5514,6 +5518,7 @@ phutil_register_library_map(array( 'DifferentialRevisionAuthorProjectsHeraldField' => 'DifferentialRevisionHeraldField', 'DifferentialRevisionCloseDetailsController' => 'DifferentialController', 'DifferentialRevisionCloseTransaction' => 'DifferentialRevisionActionTransaction', + 'DifferentialRevisionClosedStatusDatasource' => 'PhabricatorTypeaheadDatasource', 'DifferentialRevisionCommandeerTransaction' => 'DifferentialRevisionActionTransaction', 'DifferentialRevisionContentAddedHeraldField' => 'DifferentialRevisionHeraldField', 'DifferentialRevisionContentHeraldField' => 'DifferentialRevisionHeraldField', @@ -5541,6 +5546,7 @@ phutil_register_library_map(array( 'DifferentialRevisionListController' => 'DifferentialController', 'DifferentialRevisionListView' => 'AphrontView', 'DifferentialRevisionMailReceiver' => 'PhabricatorObjectMailReceiver', + 'DifferentialRevisionOpenStatusDatasource' => 'PhabricatorTypeaheadDatasource', 'DifferentialRevisionOperationController' => 'DifferentialController', 'DifferentialRevisionPHIDType' => 'PhabricatorPHIDType', 'DifferentialRevisionPackageHeraldField' => 'DifferentialRevisionHeraldField', @@ -5565,6 +5571,8 @@ phutil_register_library_map(array( 'DifferentialRevisionSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod', 'DifferentialRevisionSearchEngine' => 'PhabricatorApplicationSearchEngine', 'DifferentialRevisionStatus' => 'Phobject', + 'DifferentialRevisionStatusDatasource' => 'PhabricatorTypeaheadDatasource', + 'DifferentialRevisionStatusFunctionDatasource' => 'PhabricatorTypeaheadCompositeDatasource', 'DifferentialRevisionSummaryHeraldField' => 'DifferentialRevisionHeraldField', 'DifferentialRevisionSummaryTransaction' => 'DifferentialRevisionTransactionType', 'DifferentialRevisionTestPlanTransaction' => 'DifferentialRevisionTransactionType', diff --git a/src/applications/differential/constants/DifferentialRevisionStatus.php b/src/applications/differential/constants/DifferentialRevisionStatus.php index 37b51f1b3b..e5ef7d6a24 100644 --- a/src/applications/differential/constants/DifferentialRevisionStatus.php +++ b/src/applications/differential/constants/DifferentialRevisionStatus.php @@ -93,6 +93,16 @@ final class DifferentialRevisionStatus extends Phobject { return $result; } + public static function getAll() { + $result = array(); + + foreach (self::getMap() as $key => $spec) { + $result[$key] = self::newForStatus($key); + } + + return $result; + } + private static function getMap() { $close_on_accept = PhabricatorEnv::getEnvConfig( 'differential.close-on-accept'); diff --git a/src/applications/differential/typeahead/DifferentialRevisionClosedStatusDatasource.php b/src/applications/differential/typeahead/DifferentialRevisionClosedStatusDatasource.php new file mode 100644 index 0000000000..8487111452 --- /dev/null +++ b/src/applications/differential/typeahead/DifferentialRevisionClosedStatusDatasource.php @@ -0,0 +1,74 @@ + array( + 'name' => pht('Any Closed Status'), + 'summary' => pht('Find results with any closed status.'), + 'description' => pht( + 'This function includes results which have any closed status.'), + ), + ); + } + + public function loadResults() { + $results = array( + $this->buildClosedResult(), + ); + return $this->filterResultsAgainstTokens($results); + } + + protected function evaluateFunction($function, array $argv_list) { + $results = array(); + + $map = DifferentialRevisionStatus::getAll(); + foreach ($argv_list as $argv) { + foreach ($map as $status) { + if ($status->isClosedStatus()) { + $results[] = $status->getKey(); + } + } + } + + return $results; + } + + public function renderFunctionTokens($function, array $argv_list) { + $results = array(); + + foreach ($argv_list as $argv) { + $results[] = PhabricatorTypeaheadTokenView::newFromTypeaheadResult( + $this->buildClosedResult()); + } + + return $results; + } + + private function buildClosedResult() { + $name = pht('Any Closed Status'); + return $this->newFunctionResult() + ->setName($name.' closed') + ->setDisplayName($name) + ->setPHID(self::FUNCTION_TOKEN) + ->setUnique(true) + ->addAttribute(pht('Select any closed status.')); + } + +} diff --git a/src/applications/differential/typeahead/DifferentialRevisionOpenStatusDatasource.php b/src/applications/differential/typeahead/DifferentialRevisionOpenStatusDatasource.php new file mode 100644 index 0000000000..0f00e470c3 --- /dev/null +++ b/src/applications/differential/typeahead/DifferentialRevisionOpenStatusDatasource.php @@ -0,0 +1,74 @@ + array( + 'name' => pht('Any Open Status'), + 'summary' => pht('Find results with any open status.'), + 'description' => pht( + 'This function includes results which have any open status.'), + ), + ); + } + + public function loadResults() { + $results = array( + $this->buildOpenResult(), + ); + return $this->filterResultsAgainstTokens($results); + } + + protected function evaluateFunction($function, array $argv_list) { + $results = array(); + + $map = DifferentialRevisionStatus::getAll(); + foreach ($argv_list as $argv) { + foreach ($map as $status) { + if (!$status->isClosedStatus()) { + $results[] = $status->getKey(); + } + } + } + + return $results; + } + + public function renderFunctionTokens($function, array $argv_list) { + $results = array(); + + foreach ($argv_list as $argv) { + $results[] = PhabricatorTypeaheadTokenView::newFromTypeaheadResult( + $this->buildOpenResult()); + } + + return $results; + } + + private function buildOpenResult() { + $name = pht('Any Open Status'); + return $this->newFunctionResult() + ->setName($name.' open') + ->setDisplayName($name) + ->setPHID(self::FUNCTION_TOKEN) + ->setUnique(true) + ->addAttribute(pht('Select any open status.')); + } + +} diff --git a/src/applications/differential/typeahead/DifferentialRevisionStatusDatasource.php b/src/applications/differential/typeahead/DifferentialRevisionStatusDatasource.php new file mode 100644 index 0000000000..5e240d3c29 --- /dev/null +++ b/src/applications/differential/typeahead/DifferentialRevisionStatusDatasource.php @@ -0,0 +1,52 @@ +buildResults(); + return $this->filterResultsAgainstTokens($results); + } + + + protected function renderSpecialTokens(array $values) { + return $this->renderTokensFromResults($this->buildResults(), $values); + } + + private function buildResults() { + $results = array(); + + $statuses = DifferentialRevisionStatus::getAll(); + foreach ($statuses as $status) { + $key = $status->getKey(); + + $result = id(new PhabricatorTypeaheadResult()) + ->setIcon($status->getIcon()) + ->setPHID($key) + ->setName($status->getDisplayName()); + + if ($status->isClosedStatus()) { + $result->addAttribute(pht('Closed Status')); + } else { + $result->addAttribute(pht('Open Status')); + } + + $results[$key] = $result; + } + + return $results; + } + +} diff --git a/src/applications/differential/typeahead/DifferentialRevisionStatusFunctionDatasource.php b/src/applications/differential/typeahead/DifferentialRevisionStatusFunctionDatasource.php new file mode 100644 index 0000000000..2d4ec38363 --- /dev/null +++ b/src/applications/differential/typeahead/DifferentialRevisionStatusFunctionDatasource.php @@ -0,0 +1,22 @@ +