Skip to content

Commit 250aaab

Browse files
author
Chad Little
committedJul 9, 2017
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
1 parent 39e5da7 commit 250aaab

6 files changed

+68
-41
lines changed
 

‎src/applications/files/builtin/PhabricatorFilesOnDiskBuiltinFile.php

+16
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,20 @@ private function getAllBuiltinFiles() {
5656
return $map;
5757
}
5858

59+
public function getProjectBuiltinFiles() {
60+
$root = dirname(phutil_get_library_root('phabricator'));
61+
$root = $root.'/resources/builtin/projects/';
62+
63+
$map = array();
64+
$list = id(new FileFinder($root))
65+
->withType('f')
66+
->withFollowSymlinks(true)
67+
->find();
68+
69+
foreach ($list as $file) {
70+
$map[$file] = $root.$file;
71+
}
72+
return $map;
73+
}
74+
5975
}

‎src/applications/project/config/PhabricatorProjectConfigOptions.php

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public function getOptions() {
3434
- `key` //Required string.// Internal key identifying the icon.
3535
- `name` //Required string.// Human-readable icon name.
3636
- `icon` //Required string.// Specifies which actual icon image to use.
37+
- `image` //Optional string.// Selects a default image. Select an image from
38+
`resources/builtins/projects/`.
3739
- `default` //Optional bool.// Selects a default icon. Exactly one icon must
3840
be selected as the default.
3941
- `disabled` //Optional bool.// If true, this icon will no longer be

‎src/applications/project/controller/PhabricatorProjectEditPictureController.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ public function handleRequest(AphrontRequest $request) {
9898
$form = id(new PHUIFormLayoutView())
9999
->setUser($viewer);
100100

101-
$default_image = PhabricatorFile::loadBuiltin($viewer, 'project.png');
101+
$builtin = PhabricatorProjectIconSet::getIconImage(
102+
$project->getIcon());
103+
$default_image = PhabricatorFile::loadBuiltin($this->getViewer(),
104+
'projects/'.$builtin);
102105

103106
$images = array();
104107

‎src/applications/project/editor/PhabricatorProjectTransactionEditor.php

-32
Original file line numberDiff line numberDiff line change
@@ -296,10 +296,6 @@ protected function applyFinalEffects(
296296
}
297297
}
298298

299-
if ($this->getIsNewObject()) {
300-
$this->setDefaultProfilePicture($object);
301-
}
302-
303299
// TODO: We should dump an informational transaction onto the parent
304300
// project to show that we created the sub-thing.
305301

@@ -457,34 +453,6 @@ protected function expandTransactions(
457453
return $results;
458454
}
459455

460-
private function setDefaultProfilePicture(PhabricatorProject $project) {
461-
if ($project->isMilestone()) {
462-
return;
463-
}
464-
465-
$compose_color = $project->getDisplayIconComposeColor();
466-
$compose_icon = $project->getDisplayIconComposeIcon();
467-
468-
$builtin = id(new PhabricatorFilesComposeIconBuiltinFile())
469-
->setColor($compose_color)
470-
->setIcon($compose_icon);
471-
472-
$data = $builtin->loadBuiltinFileData();
473-
474-
$file = PhabricatorFile::newFromFileData(
475-
$data,
476-
array(
477-
'name' => $builtin->getBuiltinDisplayName(),
478-
'profile' => true,
479-
'canCDN' => true,
480-
));
481-
482-
$project
483-
->setProfileImagePHID($file->getPHID())
484-
->save();
485-
}
486-
487-
488456
protected function shouldApplyHeraldRules(
489457
PhabricatorLiskDAO $object,
490458
array $xactions) {

‎src/applications/project/icon/PhabricatorProjectIconSet.php

+42
Original file line numberDiff line numberDiff line change
@@ -18,87 +18,104 @@ public static function getDefaultConfiguration() {
1818
'icon' => 'fa-briefcase',
1919
'name' => pht('Project'),
2020
'default' => true,
21+
'image' => 'v3/briefcase.png',
2122
),
2223
array(
2324
'key' => 'tag',
2425
'icon' => 'fa-tags',
2526
'name' => pht('Tag'),
27+
'image' => 'v3/tag.png',
2628
),
2729
array(
2830
'key' => 'policy',
2931
'icon' => 'fa-lock',
3032
'name' => pht('Policy'),
33+
'image' => 'v3/lock.png',
3134
),
3235
array(
3336
'key' => 'group',
3437
'icon' => 'fa-users',
3538
'name' => pht('Group'),
39+
'image' => 'v3/people.png',
3640
),
3741
array(
3842
'key' => 'folder',
3943
'icon' => 'fa-folder',
4044
'name' => pht('Folder'),
45+
'image' => 'v3/folder.png',
4146
),
4247
array(
4348
'key' => 'timeline',
4449
'icon' => 'fa-calendar',
4550
'name' => pht('Timeline'),
51+
'image' => 'v3/calendar.png',
4652
),
4753
array(
4854
'key' => 'goal',
4955
'icon' => 'fa-flag-checkered',
5056
'name' => pht('Goal'),
57+
'image' => 'v3/flag.png',
5158
),
5259
array(
5360
'key' => 'release',
5461
'icon' => 'fa-truck',
5562
'name' => pht('Release'),
63+
'image' => 'v3/truck.png',
5664
),
5765
array(
5866
'key' => 'bugs',
5967
'icon' => 'fa-bug',
6068
'name' => pht('Bugs'),
69+
'image' => 'v3/bug.png',
6170
),
6271
array(
6372
'key' => 'cleanup',
6473
'icon' => 'fa-trash-o',
6574
'name' => pht('Cleanup'),
75+
'image' => 'v3/trash.png',
6676
),
6777
array(
6878
'key' => 'umbrella',
6979
'icon' => 'fa-umbrella',
7080
'name' => pht('Umbrella'),
81+
'image' => 'v3/umbrella.png',
7182
),
7283
array(
7384
'key' => 'communication',
7485
'icon' => 'fa-envelope',
7586
'name' => pht('Communication'),
87+
'image' => 'v3/mail.png',
7688
),
7789
array(
7890
'key' => 'organization',
7991
'icon' => 'fa-building',
8092
'name' => pht('Organization'),
93+
'image' => 'v3/organization.png',
8194
),
8295
array(
8396
'key' => 'infrastructure',
8497
'icon' => 'fa-cloud',
8598
'name' => pht('Infrastructure'),
99+
'image' => 'v3/cloud.png',
86100
),
87101
array(
88102
'key' => 'account',
89103
'icon' => 'fa-credit-card',
90104
'name' => pht('Account'),
105+
'image' => 'v3/creditcard.png',
91106
),
92107
array(
93108
'key' => 'experimental',
94109
'icon' => 'fa-flask',
95110
'name' => pht('Experimental'),
111+
'image' => 'v3/experimental.png',
96112
),
97113
array(
98114
'key' => 'milestone',
99115
'icon' => 'fa-map-marker',
100116
'name' => pht('Milestone'),
101117
'special' => self::SPECIAL_MILESTONE,
118+
'image' => 'v3/marker.png',
102119
),
103120
);
104121
}
@@ -149,6 +166,11 @@ public static function getIconName($key) {
149166
return idx($spec, 'name', null);
150167
}
151168

169+
public static function getIconImage($key) {
170+
$spec = self::getIconSpec($key);
171+
return idx($spec, 'image', 'v3/briefcase.png');
172+
}
173+
152174
private static function getIconSpec($key) {
153175
$icons = self::getIconSpecifications();
154176
foreach ($icons as $icon) {
@@ -190,6 +212,7 @@ public static function validateConfiguration($config) {
190212
'key' => 'string',
191213
'name' => 'string',
192214
'icon' => 'string',
215+
'image' => 'optional string',
193216
'special' => 'optional string',
194217
'disabled' => 'optional bool',
195218
'default' => 'optional bool',
@@ -239,6 +262,25 @@ public static function validateConfiguration($config) {
239262

240263
$is_disabled = idx($value, 'disabled');
241264

265+
if (idx($value, 'image')) {
266+
$builtin = idx($value, 'image');
267+
$builtin_map = id(new PhabricatorFilesOnDiskBuiltinFile())
268+
->getProjectBuiltinFiles();
269+
$builtin_map = array_flip($builtin_map);
270+
271+
$root = dirname(phutil_get_library_root('phabricator'));
272+
$image = $root.'/resources/builtin/projects/'.$builtin;
273+
274+
if (!array_key_exists($image, $builtin_map)) {
275+
throw new Exception(
276+
pht(
277+
'The project image ("%s") specified for ("%s") '.
278+
'was not found in the folder "resources/builtin/projects/".',
279+
$builtin,
280+
$key));
281+
}
282+
}
283+
242284
if (idx($value, 'default')) {
243285
if ($default === null) {
244286
if ($is_disabled) {

‎src/applications/project/query/PhabricatorProjectQuery.php

+4-8
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,6 @@ protected function willFilterPage(array $projects) {
358358

359359
protected function didFilterPage(array $projects) {
360360
if ($this->needImages) {
361-
$default = null;
362-
363361
$file_phids = mpull($projects, 'getProfileImagePHID');
364362
$file_phids = array_filter($file_phids);
365363
if ($file_phids) {
@@ -376,12 +374,10 @@ protected function didFilterPage(array $projects) {
376374
foreach ($projects as $project) {
377375
$file = idx($files, $project->getProfileImagePHID());
378376
if (!$file) {
379-
if (!$default) {
380-
$default = PhabricatorFile::loadBuiltin(
381-
$this->getViewer(),
382-
'project.png');
383-
}
384-
$file = $default;
377+
$builtin = PhabricatorProjectIconSet::getIconImage(
378+
$project->getIcon());
379+
$file = PhabricatorFile::loadBuiltin($this->getViewer(),
380+
'projects/'.$builtin);
385381
}
386382
$project->attachProfileImageFile($file);
387383
}

0 commit comments

Comments
 (0)
Failed to load comments.