<?php

final class HeraldRuleDatasource
  extends PhabricatorTypeaheadDatasource {

  public function getPlaceholderText() {
    return pht('Type a Herald rule name...');
  }

  public function getBrowseTitle() {
    return pht('Browse Herald Rules');
  }

  public function getDatasourceApplicationClass() {
    return 'PhabricatorHeraldApplication';
  }

  public function loadResults() {
    $viewer = $this->getViewer();
    $raw_query = $this->getRawQuery();

    $rules = id(new HeraldRuleQuery())
      ->setViewer($viewer)
      ->withDatasourceQuery($raw_query)
      ->execute();

    $handles = id(new PhabricatorHandleQuery())
      ->setViewer($viewer)
      ->withPHIDs(mpull($rules, 'getPHID'))
      ->execute();

    $results = array();
    foreach ($rules as $rule) {
      $handle = $handles[$rule->getPHID()];

      $result = id(new PhabricatorTypeaheadResult())
        ->setName($handle->getFullName())
        ->setPHID($handle->getPHID());

      if ($rule->getIsDisabled()) {
        $result->setClosed(pht('Archived'));
      }

      $results[] = $result;
    }

    return $results;
  }
}

<?php

final class HeraldRuleDatasource
  extends PhabricatorTypeaheadDatasource {

  public function getPlaceholderText() {
    return pht('Type a Herald rule name...');
  }

  public function getBrowseTitle() {
    return pht('Browse Herald Rules');
  }

  public function getDatasourceApplicationClass() {
    return 'PhabricatorHeraldApplication';
  }

  public function loadResults() {
    $viewer = $this->getViewer();
    $raw_query = $this->getRawQuery();

    $query = id(new HeraldRuleQuery())
      ->setViewer($viewer);

    if (preg_match('/^[hH]\d+\z/', $raw_query)) {
      $id = trim($raw_query, 'hH');
      $id = (int)$id;
      $query->withIDs(array($id));
    } else {
      $query->withDatasourceQuery($raw_query);
    }

    $rules = $query->execute();

    $handles = id(new PhabricatorHandleQuery())
      ->setViewer($viewer)
      ->withPHIDs(mpull($rules, 'getPHID'))
      ->execute();

    $results = array();
    foreach ($rules as $rule) {
      $handle = $handles[$rule->getPHID()];

      $result = id(new PhabricatorTypeaheadResult())
        ->setName($handle->getFullName())
        ->setPHID($handle->getPHID());

      if ($rule->getIsDisabled()) {
        $result->setClosed(pht('Archived'));
      }

      $results[] = $result;
    }

    return $results;
  }
}

Support querying Herald rules by monogram in typeahead datsources
Support querying Herald rules by monogram in typeahead datsources

Summary:
Depends on D19556. See PHI765. Ref T13164. Currently, if you type `H1` in this datasource, it isn't smart enough to pull up the right object.

Add support for querying by monogram. This is similar to existing support in Owners packages, etc.

Test Plan: Typed `H1` in the new push log filter, got the right object as a result in the typeahead.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13164

Differential Revision: https://secure.phabricator.com/D19557
