Update project profile image composer for new IconSet code

Summary:
Fixes T6856. Fixes T10164.

  - Make the profile image composer code use the underlying icon name instead of the top-level icon key, so it works instead of 404'ing.
  - Change the button to show a preview of the profile icon instead of the text "Use Icon and Color".
  - When creating a new non-milestone project, automatically set the profile image to the icon + color image.

Test Plan:
  - Created several new projects, saw appropriate default icons.
  - Edited projects, saw icon previews.
  - Clicked icon buttons to set icons.
  - Poked around other applications which use builtins (Pholio, user profiles) to look for anything I broke, but everything seemed fine.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T6856, T10164

Differential Revision: https://secure.phabricator.com/D15050
This commit is contained in:
epriestley
2016-01-18 12:58:19 -08:00
parent 155cb1d2c5
commit a9a5991f01
10 changed files with 496 additions and 226 deletions

View File

@@ -6,21 +6,8 @@ final class PhabricatorFileComposeController
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$colors = array(
'red' => pht('Verbillion'),
'orange' => pht('Navel Orange'),
'yellow' => pht('Prim Goldenrod'),
'green' => pht('Lustrous Verdant'),
'blue' => pht('Tropical Deep'),
'sky' => pht('Wide Open Sky'),
'indigo' => pht('Pleated Khaki'),
'violet' => pht('Aged Merlot'),
'pink' => pht('Easter Bunny'),
'charcoal' => pht('Gemstone'),
'backdrop' => pht('Driven Snow'),
);
$manifest = PHUIIconView::getSheetManifest(PHUIIconView::SPRITE_PROJECTS);
$color_map = PhabricatorFilesComposeIconBuiltinFile::getAllColors();
$icon_map = $this->getIconMap();
if ($request->isFormPost()) {
$project_phid = $request->getStr('projectPHID');
@@ -37,36 +24,21 @@ final class PhabricatorFileComposeController
if (!$project) {
return new Aphront404Response();
}
$icon = $project->getIcon();
$color = $project->getColor();
switch ($color) {
case 'grey':
$color = 'charcoal';
break;
case 'checkered':
$color = 'backdrop';
break;
}
} else {
$icon = $request->getStr('icon');
$color = $request->getStr('color');
}
if (!isset($colors[$color]) || !isset($manifest['projects-'.$icon])) {
return new Aphront404Response();
}
$icon = $request->getStr('icon');
$color = $request->getStr('color');
$root = dirname(phutil_get_library_root('phabricator'));
$icon_file = $root.'/resources/sprite/projects_2x/'.$icon.'.png';
$icon_data = Filesystem::readFile($icon_file);
$composer = id(new PhabricatorFilesComposeIconBuiltinFile())
->setIcon($icon)
->setColor($color);
$data = $this->composeImage($color, $icon_data);
$data = $composer->loadBuiltinFileData();
$file = PhabricatorFile::buildFromFileDataOrHash(
$data,
array(
'name' => 'project.png',
'name' => $composer->getBuiltinDisplayName(),
'profile' => true,
'canCDN' => true,
));
@@ -97,14 +69,15 @@ final class PhabricatorFileComposeController
}
}
$value_color = head_key($colors);
$value_icon = head_key($manifest);
$value_icon = substr($value_icon, strlen('projects-'));
$value_color = head_key($color_map);
$value_icon = head_key($icon_map);
require_celerity_resource('people-profile-css');
$buttons = array();
foreach ($colors as $color => $name) {
foreach ($color_map as $color => $info) {
$quip = idx($info, 'quip');
$buttons[] = javelin_tag(
'button',
array(
@@ -113,116 +86,17 @@ final class PhabricatorFileComposeController
'style' => 'margin: 0 8px 8px 0',
'meta' => array(
'color' => $color,
'tip' => $name,
'tip' => $quip,
),
),
id(new PHUIIconView())
->addClass('compose-background-'.$color));
}
$sort_these_first = array(
'projects-fa-briefcase',
'projects-fa-tags',
'projects-fa-folder',
'projects-fa-group',
'projects-fa-bug',
'projects-fa-trash-o',
'projects-fa-calendar',
'projects-fa-flag-checkered',
'projects-fa-envelope',
'projects-fa-truck',
'projects-fa-lock',
'projects-fa-umbrella',
'projects-fa-cloud',
'projects-fa-building',
'projects-fa-credit-card',
'projects-fa-flask',
);
$manifest = array_select_keys(
$manifest,
$sort_these_first)
+ $manifest;
$icons = array();
$icon_quips = array(
'8ball' => pht('Take a Risk'),
'alien' => pht('Foreign Interface'),
'announce' => pht('Louder is Better'),
'art' => pht('Unique Snowflake'),
'award' => pht('Shooting Star'),
'bacon' => pht('Healthy Vegetables'),
'bandaid' => pht('Durable Infrastructure'),
'beer' => pht('Healthy Vegetable Juice'),
'bomb' => pht('Imminent Success'),
'briefcase' => pht('Adventure Pack'),
'bug' => pht('Costumed Egg'),
'calendar' => pht('Everyone Loves Meetings'),
'cloud' => pht('Water Cycle'),
'coffee' => pht('Half-Whip Nonfat Soy Latte'),
'creditcard' => pht('Expense It'),
'death' => pht('Calcium Promotes Bone Health'),
'desktop' => pht('Magical Portal'),
'dropbox' => pht('Cardboard Box'),
'education' => pht('Debt'),
'experimental' => pht('CAUTION: Dangerous Chemicals'),
'facebook' => pht('Popular Social Network'),
'facility' => pht('Pollution Solves Problems'),
'film' => pht('Actual Physical Film'),
'forked' => pht('You Can\'t Eat Soup'),
'games' => pht('Serious Business'),
'ghost' => pht('Haunted'),
'gift' => pht('Surprise!'),
'globe' => pht('Scanner Sweep'),
'golf' => pht('Business Meeting'),
'heart' => pht('Undergoing a Major Surgery'),
'intergalactic' => pht('Jupiter'),
'lock' => pht('Extremely Secret'),
'mail' => pht('Oragami'),
'martini' => pht('Healthy Olive Drink'),
'medical' => pht('Medic!'),
'mobile' => pht('Cellular Telephone'),
'music' => pht("\xE2\x99\xAB"),
'news' => pht('Actual Physical Newspaper'),
'orgchart' => pht('It\'s Good to be King'),
'peoples' => pht('Angel and Devil'),
'piechart' => pht('Actual Physical Pie'),
'poison' => pht('Healthy Bone Juice'),
'putabirdonit' => pht('Put a Bird On It'),
'radiate' => pht('Radiant Beauty'),
'savings' => pht('Oink Oink'),
'search' => pht('Sleuthing'),
'shield' => pht('Royal Crest'),
'speed' => pht('Slow and Steady'),
'sprint' => pht('Fire Exit'),
'star' => pht('The More You Know'),
'storage' => pht('Stack of Pancakes'),
'tablet' => pht('Cellular Telephone For Giants'),
'travel' => pht('Pretty Clearly an Airplane'),
'twitter' => pht('Bird Stencil'),
'warning' => pht('No Caution Required, Everything Looks Safe'),
'whale' => pht('Friendly Walrus'),
'fa-flask' => pht('Experimental'),
'fa-briefcase' => pht('Briefcase'),
'fa-bug' => pht('Bug'),
'fa-building' => pht('Company'),
'fa-calendar' => pht('Deadline'),
'fa-cloud' => pht('The Cloud'),
'fa-credit-card' => pht('Accounting'),
'fa-envelope' => pht('Communication'),
'fa-flag-checkered' => pht('Goal'),
'fa-folder' => pht('Folder'),
'fa-group' => pht('Team'),
'fa-lock' => pht('Policy'),
'fa-tags' => pht('Tag'),
'fa-trash-o' => pht('Garbage'),
'fa-truck' => pht('Release'),
'fa-umbrella' => pht('An Umbrella'),
);
foreach ($manifest as $icon => $spec) {
$icon = substr($icon, strlen('projects-'));
foreach ($icon_map as $icon => $spec) {
$quip = idx($spec, 'quip');
$icons[] = javelin_tag(
'button',
@@ -232,7 +106,7 @@ final class PhabricatorFileComposeController
'style' => 'margin: 0 8px 8px 0',
'meta' => array(
'icon' => $icon,
'tip' => idx($icon_quips, $icon, $icon),
'tip' => $quip,
),
),
id(new PHUIIconView())
@@ -318,23 +192,31 @@ final class PhabricatorFileComposeController
return id(new AphrontDialogResponse())->setDialog($dialog);
}
private function composeImage($color, $icon_data) {
$icon_img = imagecreatefromstring($icon_data);
private function getIconMap() {
$icon_map = PhabricatorFilesComposeIconBuiltinFile::getAllIcons();
$map = id(new CelerityResourceTransformer())
->getCSSVariableMap();
$first = array(
'fa-briefcase',
'fa-tags',
'fa-folder',
'fa-group',
'fa-bug',
'fa-trash-o',
'fa-calendar',
'fa-flag-checkered',
'fa-envelope',
'fa-truck',
'fa-lock',
'fa-umbrella',
'fa-cloud',
'fa-building',
'fa-credit-card',
'fa-flask',
);
$color_string = idx($map, $color, '#ff00ff');
$color_const = hexdec(trim($color_string, '#'));
$icon_map = array_select_keys($icon_map, $first) + $icon_map;
$canvas = imagecreatetruecolor(100, 100);
imagefill($canvas, 0, 0, $color_const);
imagecopy($canvas, $icon_img, 0, 0, 0, 0, 100, 100);
return PhabricatorImageTransformer::saveImageDataInAnyFormat(
$canvas,
'image/png');
return $icon_map;
}
}