1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-18 18:51:12 +01:00

Make typeahead datasources default to PHID type icons

Summary:
Ref T4420. If a datasource does not specify an icon explicitly, check if the PHID type has a default, and use that.

This leaves us with only Projects and some special stuff setting explicit icons, and reduces code duplication.

Test Plan: Used typeahead to find all affected object types.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T4420

Differential Revision: https://secure.phabricator.com/D9894
This commit is contained in:
epriestley 2014-07-17 15:49:11 -07:00
parent 7f0fb63c44
commit b8d604acaf
9 changed files with 40 additions and 9 deletions

View file

@ -25,8 +25,7 @@ final class DiffusionRepositoryDatasource
->setName($repo->getMonogram().' '.$repo->getName())
->setURI('/diffusion/'.$repo->getCallsign().'/')
->setPHID($repo->getPHID())
->setPriorityString($repo->getMonogram())
->setIcon('fa-database bluegrey');
->setPriorityString($repo->getMonogram());
}
return $results;

View file

@ -23,7 +23,6 @@ final class LegalpadDocumentDatasource
foreach ($documents as $document) {
$results[] = id(new PhabricatorTypeaheadResult())
->setPHID($document->getPHID())
->setIcon('fa-file-text-o')
->setName($document->getMonogram().' '.$document->getTitle());
}

View file

@ -25,8 +25,7 @@ final class PhabricatorMacroDatasource
foreach ($macros as $macro) {
$results[] = id(new PhabricatorTypeaheadResult())
->setPHID($macro->getPHID())
->setName($macro->getName())
->setIcon('fa-meh-o bluegrey');
->setName($macro->getName());
}
return $results;

View file

@ -12,6 +12,10 @@ final class PhabricatorMailingListPHIDTypeList extends PhabricatorPHIDType {
return pht('Mailing List');
}
public function getTypeIcon() {
return 'fa-envelope-o';
}
public function newObject() {
return new PhabricatorMetaMTAMailingList();
}

View file

@ -12,6 +12,10 @@ final class PhabricatorOwnersPHIDTypePackage extends PhabricatorPHIDType {
return pht('Owners Package');
}
public function getTypeIcon() {
return 'fa-list-alt';
}
public function newObject() {
return new PhabricatorOwnersPackage();
}

View file

@ -23,7 +23,6 @@ final class PhabricatorOwnersPackageDatasource
foreach ($packages as $package) {
$results[] = id(new PhabricatorTypeaheadResult())
->setIcon('fa-list-alt bluegrey')
->setName($package->getName())
->setURI('/owners/package/'.$package->getID().'/')
->setPHID($package->getPHID());

View file

@ -104,7 +104,6 @@ final class PhabricatorPeopleDatasource
->setURI('/p/'.$user->getUsername())
->setPHID($user->getPHID())
->setPriorityString($user->getUsername())
->setIcon('fa-user bluegrey')
->setPriorityType('user')
->setClosed($closed);

View file

@ -32,7 +32,7 @@ final class PhabricatorProjectDatasource
->setDisplayType('Project')
->setURI('/tag/'.$proj->getPrimarySlug().'/')
->setPHID($proj->getPHID())
->setIcon($proj->getIcon())
->setIcon($proj->getIcon().' bluegrey')
->setPriorityType('proj')
->setClosed($closed);

View file

@ -79,7 +79,7 @@ final class PhabricatorTypeaheadResult {
$this->displayType,
$this->imageURI ? (string)$this->imageURI : null,
$this->priorityType,
$this->icon,
($this->icon === null) ? $this->getDefaultIcon() : $this->icon,
$this->closed,
$this->imageSprite ? (string)$this->imageSprite : null,
);
@ -89,4 +89,32 @@ final class PhabricatorTypeaheadResult {
return $data;
}
/**
* If the datasource did not specify an icon explicitly, try to select a
* default based on PHID type.
*/
private function getDefaultIcon() {
static $icon_map;
if ($icon_map === null) {
$types = PhabricatorPHIDType::getAllTypes();
$map = array();
foreach ($types as $type) {
$icon = $type->getTypeIcon();
if ($icon !== null) {
$map[$type->getTypeConstant()] = "{$icon} bluegrey";
}
}
$icon_map = $map;
}
$phid_type = phid_get_type($this->phid);
if (isset($icon_map[$phid_type])) {
return $icon_map[$phid_type];
}
return null;
}
}