1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 14:00:56 +01:00

Choose default project image by icon

Summary: Builds out a map for icon->image in Projects, selects the icon's image as the default project image if there is no custom image chosen by the user.

Test Plan: Select various icons, see image change. Test choose picture, pick a new image.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Differential Revision: https://secure.phabricator.com/D18174
This commit is contained in:
Chad Little 2017-07-09 11:15:46 -07:00
parent 39e5da7ea7
commit 250aaabd64
6 changed files with 68 additions and 41 deletions

View file

@ -56,4 +56,20 @@ final class PhabricatorFilesOnDiskBuiltinFile
return $map;
}
public function getProjectBuiltinFiles() {
$root = dirname(phutil_get_library_root('phabricator'));
$root = $root.'/resources/builtin/projects/';
$map = array();
$list = id(new FileFinder($root))
->withType('f')
->withFollowSymlinks(true)
->find();
foreach ($list as $file) {
$map[$file] = $root.$file;
}
return $map;
}
}

View file

@ -34,6 +34,8 @@ a dictionary, which may contain these keys:
- `key` //Required string.// Internal key identifying the icon.
- `name` //Required string.// Human-readable icon name.
- `icon` //Required string.// Specifies which actual icon image to use.
- `image` //Optional string.// Selects a default image. Select an image from
`resources/builtins/projects/`.
- `default` //Optional bool.// Selects a default icon. Exactly one icon must
be selected as the default.
- `disabled` //Optional bool.// If true, this icon will no longer be

View file

@ -98,7 +98,10 @@ final class PhabricatorProjectEditPictureController
$form = id(new PHUIFormLayoutView())
->setUser($viewer);
$default_image = PhabricatorFile::loadBuiltin($viewer, 'project.png');
$builtin = PhabricatorProjectIconSet::getIconImage(
$project->getIcon());
$default_image = PhabricatorFile::loadBuiltin($this->getViewer(),
'projects/'.$builtin);
$images = array();

View file

@ -296,10 +296,6 @@ final class PhabricatorProjectTransactionEditor
}
}
if ($this->getIsNewObject()) {
$this->setDefaultProfilePicture($object);
}
// TODO: We should dump an informational transaction onto the parent
// project to show that we created the sub-thing.
@ -457,34 +453,6 @@ final class PhabricatorProjectTransactionEditor
return $results;
}
private function setDefaultProfilePicture(PhabricatorProject $project) {
if ($project->isMilestone()) {
return;
}
$compose_color = $project->getDisplayIconComposeColor();
$compose_icon = $project->getDisplayIconComposeIcon();
$builtin = id(new PhabricatorFilesComposeIconBuiltinFile())
->setColor($compose_color)
->setIcon($compose_icon);
$data = $builtin->loadBuiltinFileData();
$file = PhabricatorFile::newFromFileData(
$data,
array(
'name' => $builtin->getBuiltinDisplayName(),
'profile' => true,
'canCDN' => true,
));
$project
->setProfileImagePHID($file->getPHID())
->save();
}
protected function shouldApplyHeraldRules(
PhabricatorLiskDAO $object,
array $xactions) {

View file

@ -18,87 +18,104 @@ final class PhabricatorProjectIconSet
'icon' => 'fa-briefcase',
'name' => pht('Project'),
'default' => true,
'image' => 'v3/briefcase.png',
),
array(
'key' => 'tag',
'icon' => 'fa-tags',
'name' => pht('Tag'),
'image' => 'v3/tag.png',
),
array(
'key' => 'policy',
'icon' => 'fa-lock',
'name' => pht('Policy'),
'image' => 'v3/lock.png',
),
array(
'key' => 'group',
'icon' => 'fa-users',
'name' => pht('Group'),
'image' => 'v3/people.png',
),
array(
'key' => 'folder',
'icon' => 'fa-folder',
'name' => pht('Folder'),
'image' => 'v3/folder.png',
),
array(
'key' => 'timeline',
'icon' => 'fa-calendar',
'name' => pht('Timeline'),
'image' => 'v3/calendar.png',
),
array(
'key' => 'goal',
'icon' => 'fa-flag-checkered',
'name' => pht('Goal'),
'image' => 'v3/flag.png',
),
array(
'key' => 'release',
'icon' => 'fa-truck',
'name' => pht('Release'),
'image' => 'v3/truck.png',
),
array(
'key' => 'bugs',
'icon' => 'fa-bug',
'name' => pht('Bugs'),
'image' => 'v3/bug.png',
),
array(
'key' => 'cleanup',
'icon' => 'fa-trash-o',
'name' => pht('Cleanup'),
'image' => 'v3/trash.png',
),
array(
'key' => 'umbrella',
'icon' => 'fa-umbrella',
'name' => pht('Umbrella'),
'image' => 'v3/umbrella.png',
),
array(
'key' => 'communication',
'icon' => 'fa-envelope',
'name' => pht('Communication'),
'image' => 'v3/mail.png',
),
array(
'key' => 'organization',
'icon' => 'fa-building',
'name' => pht('Organization'),
'image' => 'v3/organization.png',
),
array(
'key' => 'infrastructure',
'icon' => 'fa-cloud',
'name' => pht('Infrastructure'),
'image' => 'v3/cloud.png',
),
array(
'key' => 'account',
'icon' => 'fa-credit-card',
'name' => pht('Account'),
'image' => 'v3/creditcard.png',
),
array(
'key' => 'experimental',
'icon' => 'fa-flask',
'name' => pht('Experimental'),
'image' => 'v3/experimental.png',
),
array(
'key' => 'milestone',
'icon' => 'fa-map-marker',
'name' => pht('Milestone'),
'special' => self::SPECIAL_MILESTONE,
'image' => 'v3/marker.png',
),
);
}
@ -149,6 +166,11 @@ final class PhabricatorProjectIconSet
return idx($spec, 'name', null);
}
public static function getIconImage($key) {
$spec = self::getIconSpec($key);
return idx($spec, 'image', 'v3/briefcase.png');
}
private static function getIconSpec($key) {
$icons = self::getIconSpecifications();
foreach ($icons as $icon) {
@ -190,6 +212,7 @@ final class PhabricatorProjectIconSet
'key' => 'string',
'name' => 'string',
'icon' => 'string',
'image' => 'optional string',
'special' => 'optional string',
'disabled' => 'optional bool',
'default' => 'optional bool',
@ -239,6 +262,25 @@ final class PhabricatorProjectIconSet
$is_disabled = idx($value, 'disabled');
if (idx($value, 'image')) {
$builtin = idx($value, 'image');
$builtin_map = id(new PhabricatorFilesOnDiskBuiltinFile())
->getProjectBuiltinFiles();
$builtin_map = array_flip($builtin_map);
$root = dirname(phutil_get_library_root('phabricator'));
$image = $root.'/resources/builtin/projects/'.$builtin;
if (!array_key_exists($image, $builtin_map)) {
throw new Exception(
pht(
'The project image ("%s") specified for ("%s") '.
'was not found in the folder "resources/builtin/projects/".',
$builtin,
$key));
}
}
if (idx($value, 'default')) {
if ($default === null) {
if ($is_disabled) {

View file

@ -358,8 +358,6 @@ final class PhabricatorProjectQuery
protected function didFilterPage(array $projects) {
if ($this->needImages) {
$default = null;
$file_phids = mpull($projects, 'getProfileImagePHID');
$file_phids = array_filter($file_phids);
if ($file_phids) {
@ -376,12 +374,10 @@ final class PhabricatorProjectQuery
foreach ($projects as $project) {
$file = idx($files, $project->getProfileImagePHID());
if (!$file) {
if (!$default) {
$default = PhabricatorFile::loadBuiltin(
$this->getViewer(),
'project.png');
}
$file = $default;
$builtin = PhabricatorProjectIconSet::getIconImage(
$project->getIcon());
$file = PhabricatorFile::loadBuiltin($this->getViewer(),
'projects/'.$builtin);
}
$project->attachProfileImageFile($file);
}