mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-18 03:20:59 +01:00
Allow users to have profile icons
Summary: Ref T10054. This primarily improves aesthetics and consistency for member/wathcher lists in projects. Test Plan: {F1068873} {F1068874} Reviewers: chad Reviewed By: chad Maniphest Tasks: T10054 Differential Revision: https://secure.phabricator.com/D15103
This commit is contained in:
parent
bba14118c7
commit
06aa207960
14 changed files with 249 additions and 8 deletions
2
resources/sql/autopatches/20160124.people.1.icon.sql
Normal file
2
resources/sql/autopatches/20160124.people.1.icon.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE {$NAMESPACE}_user.user_profile
|
||||
ADD icon VARCHAR(32) NOT NULL COLLATE {$COLLATE_TEXT};
|
|
@ -0,0 +1,2 @@
|
|||
UPDATE {$NAMESPACE}_user.user_profile
|
||||
SET icon = 'person' WHERE icon = '';
|
|
@ -2737,6 +2737,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorPeopleEmpowerController' => 'applications/people/controller/PhabricatorPeopleEmpowerController.php',
|
||||
'PhabricatorPeopleExternalPHIDType' => 'applications/people/phid/PhabricatorPeopleExternalPHIDType.php',
|
||||
'PhabricatorPeopleHovercardEngineExtension' => 'applications/people/engineextension/PhabricatorPeopleHovercardEngineExtension.php',
|
||||
'PhabricatorPeopleIconSet' => 'applications/people/icon/PhabricatorPeopleIconSet.php',
|
||||
'PhabricatorPeopleInviteController' => 'applications/people/controller/PhabricatorPeopleInviteController.php',
|
||||
'PhabricatorPeopleInviteListController' => 'applications/people/controller/PhabricatorPeopleInviteListController.php',
|
||||
'PhabricatorPeopleInviteSendController' => 'applications/people/controller/PhabricatorPeopleInviteSendController.php',
|
||||
|
@ -3366,6 +3367,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorUserEmail' => 'applications/people/storage/PhabricatorUserEmail.php',
|
||||
'PhabricatorUserEmailTestCase' => 'applications/people/storage/__tests__/PhabricatorUserEmailTestCase.php',
|
||||
'PhabricatorUserFulltextEngine' => 'applications/people/search/PhabricatorUserFulltextEngine.php',
|
||||
'PhabricatorUserIconField' => 'applications/people/customfield/PhabricatorUserIconField.php',
|
||||
'PhabricatorUserLog' => 'applications/people/storage/PhabricatorUserLog.php',
|
||||
'PhabricatorUserLogView' => 'applications/people/view/PhabricatorUserLogView.php',
|
||||
'PhabricatorUserPHIDResolver' => 'applications/phid/resolver/PhabricatorUserPHIDResolver.php',
|
||||
|
@ -7102,6 +7104,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorPeopleEmpowerController' => 'PhabricatorPeopleController',
|
||||
'PhabricatorPeopleExternalPHIDType' => 'PhabricatorPHIDType',
|
||||
'PhabricatorPeopleHovercardEngineExtension' => 'PhabricatorHovercardEngineExtension',
|
||||
'PhabricatorPeopleIconSet' => 'PhabricatorIconSet',
|
||||
'PhabricatorPeopleInviteController' => 'PhabricatorPeopleController',
|
||||
'PhabricatorPeopleInviteListController' => 'PhabricatorPeopleInviteController',
|
||||
'PhabricatorPeopleInviteSendController' => 'PhabricatorPeopleInviteController',
|
||||
|
@ -7853,6 +7856,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorUserEmail' => 'PhabricatorUserDAO',
|
||||
'PhabricatorUserEmailTestCase' => 'PhabricatorTestCase',
|
||||
'PhabricatorUserFulltextEngine' => 'PhabricatorFulltextEngine',
|
||||
'PhabricatorUserIconField' => 'PhabricatorUserCustomField',
|
||||
'PhabricatorUserLog' => array(
|
||||
'PhabricatorUserDAO',
|
||||
'PhabricatorPolicyInterface',
|
||||
|
|
|
@ -24,6 +24,7 @@ final class PhabricatorUserConfigOptions
|
|||
$default = array(
|
||||
id(new PhabricatorUserRealNameField())->getFieldKey() => true,
|
||||
id(new PhabricatorUserTitleField())->getFieldKey() => true,
|
||||
id(new PhabricatorUserIconField())->getFieldKey() => true,
|
||||
id(new PhabricatorUserSinceField())->getFieldKey() => true,
|
||||
id(new PhabricatorUserRolesField())->getFieldKey() => true,
|
||||
id(new PhabricatorUserStatusField())->getFieldKey() => true,
|
||||
|
|
|
@ -27,9 +27,14 @@ final class PhabricatorPeopleProfileViewController
|
|||
$profile = $user->loadUserProfile();
|
||||
$picture = $user->getProfileImageURI();
|
||||
|
||||
$profile_icon = PhabricatorPeopleIconSet::getIconIcon($profile->getIcon());
|
||||
$profile_icon = id(new PHUIIconView())
|
||||
->setIconFont($profile_icon.' grey');
|
||||
$profile_title = $profile->getDisplayTitle();
|
||||
|
||||
$header = id(new PHUIHeaderView())
|
||||
->setHeader($user->getFullName())
|
||||
->setSubheader($profile->getTitle())
|
||||
->setSubheader(array($profile_icon, $profile_title))
|
||||
->setImage($picture);
|
||||
|
||||
$actions = id(new PhabricatorActionListView())
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorUserIconField
|
||||
extends PhabricatorUserCustomField {
|
||||
|
||||
private $value;
|
||||
|
||||
public function getFieldKey() {
|
||||
return 'user:icon';
|
||||
}
|
||||
|
||||
public function getFieldName() {
|
||||
return pht('Icon');
|
||||
}
|
||||
|
||||
public function getFieldDescription() {
|
||||
return pht('User icon to accompany their title.');
|
||||
}
|
||||
|
||||
public function canDisableField() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function shouldAppearInApplicationTransactions() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function shouldAppearInEditView() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function readValueFromObject(PhabricatorCustomFieldInterface $object) {
|
||||
$this->value = $object->loadUserProfile()->getIcon();
|
||||
}
|
||||
|
||||
public function getOldValueForApplicationTransactions() {
|
||||
return $this->getObject()->loadUserProfile()->getIcon();
|
||||
}
|
||||
|
||||
public function getNewValueForApplicationTransactions() {
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
public function applyApplicationTransactionInternalEffects(
|
||||
PhabricatorApplicationTransaction $xaction) {
|
||||
$this->getObject()->loadUserProfile()->setIcon($xaction->getNewValue());
|
||||
}
|
||||
|
||||
public function readValueFromRequest(AphrontRequest $request) {
|
||||
$this->value = $request->getStr($this->getFieldKey());
|
||||
}
|
||||
|
||||
public function renderEditControl(array $handles) {
|
||||
return id(new PHUIFormIconSetControl())
|
||||
->setName($this->getFieldKey())
|
||||
->setValue($this->value)
|
||||
->setLabel($this->getFieldName())
|
||||
->setIconSet(new PhabricatorPeopleIconSet());
|
||||
}
|
||||
|
||||
}
|
|
@ -54,8 +54,7 @@ final class PhabricatorUserTitleField
|
|||
return id(new AphrontFormTextControl())
|
||||
->setName($this->getFieldKey())
|
||||
->setValue($this->value)
|
||||
->setLabel($this->getFieldName())
|
||||
->setCaption(pht('Serious business title.'));
|
||||
->setLabel($this->getFieldName());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
120
src/applications/people/icon/PhabricatorPeopleIconSet.php
Normal file
120
src/applications/people/icon/PhabricatorPeopleIconSet.php
Normal file
|
@ -0,0 +1,120 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorPeopleIconSet
|
||||
extends PhabricatorIconSet {
|
||||
|
||||
const ICONSETKEY = 'people';
|
||||
|
||||
public function getSelectIconTitleText() {
|
||||
return pht('Choose User Icon');
|
||||
}
|
||||
|
||||
protected function newIcons() {
|
||||
$specifications = self::getIconSpecifications();
|
||||
|
||||
$icons = array();
|
||||
foreach ($specifications as $spec) {
|
||||
$icons[] = id(new PhabricatorIconSetIcon())
|
||||
->setKey($spec['key'])
|
||||
->setIcon($spec['icon'])
|
||||
->setLabel($spec['name']);
|
||||
}
|
||||
|
||||
return $icons;
|
||||
}
|
||||
|
||||
public static function getDefaultIconKey() {
|
||||
$specifications = self::getIconSpecifications();
|
||||
|
||||
foreach ($specifications as $spec) {
|
||||
if (idx($spec, 'default')) {
|
||||
return $spec['key'];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function getIconIcon($key) {
|
||||
$specifications = self::getIconSpecifications();
|
||||
$map = ipull($specifications, 'icon', 'key');
|
||||
return idx($map, $key);
|
||||
}
|
||||
|
||||
public static function getIconName($key) {
|
||||
$specifications = self::getIconSpecifications();
|
||||
$map = ipull($specifications, 'name', 'key');
|
||||
return idx($map, $key);
|
||||
}
|
||||
|
||||
private static function getIconSpecifications() {
|
||||
return self::getDefaultSpecifications();
|
||||
}
|
||||
|
||||
private static function getDefaultSpecifications() {
|
||||
return array(
|
||||
array(
|
||||
'key' => 'person',
|
||||
'icon' => 'fa-user',
|
||||
'name' => pht('User'),
|
||||
'default' => true,
|
||||
),
|
||||
array(
|
||||
'key' => 'engineering',
|
||||
'icon' => 'fa-code',
|
||||
'name' => pht('Engineering'),
|
||||
),
|
||||
array(
|
||||
'key' => 'operations',
|
||||
'icon' => 'fa-space-shuttle',
|
||||
'name' => pht('Operations'),
|
||||
),
|
||||
array(
|
||||
'key' => 'resources',
|
||||
'icon' => 'fa-heart',
|
||||
'name' => pht('Resources'),
|
||||
),
|
||||
array(
|
||||
'key' => 'relationships',
|
||||
'icon' => 'fa-glass',
|
||||
'name' => pht('Relationships'),
|
||||
),
|
||||
array(
|
||||
'key' => 'administration',
|
||||
'icon' => 'fa-fax',
|
||||
'name' => pht('Administration'),
|
||||
),
|
||||
array(
|
||||
'key' => 'security',
|
||||
'icon' => 'fa-shield',
|
||||
'name' => pht('Security'),
|
||||
),
|
||||
array(
|
||||
'key' => 'logistics',
|
||||
'icon' => 'fa-truck',
|
||||
'name' => pht('Logistics'),
|
||||
),
|
||||
array(
|
||||
'key' => 'research',
|
||||
'icon' => 'fa-flask',
|
||||
'name' => pht('Research'),
|
||||
),
|
||||
array(
|
||||
'key' => 'analysis',
|
||||
'icon' => 'fa-bar-chart-o',
|
||||
'name' => pht('Analysis'),
|
||||
),
|
||||
array(
|
||||
'key' => 'executive',
|
||||
'icon' => 'fa-angle-double-up',
|
||||
'name' => pht('Executive'),
|
||||
),
|
||||
array(
|
||||
'key' => 'animal',
|
||||
'icon' => 'fa-paw',
|
||||
'name' => pht('Animal'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -26,6 +26,7 @@ final class PhabricatorPeopleUserPHIDType extends PhabricatorPHIDType {
|
|||
|
||||
return id(new PhabricatorPeopleQuery())
|
||||
->withPHIDs($phids)
|
||||
->needProfile(true)
|
||||
->needProfileImage(true)
|
||||
->needAvailability(true);
|
||||
}
|
||||
|
@ -46,6 +47,15 @@ final class PhabricatorPeopleUserPHIDType extends PhabricatorPHIDType {
|
|||
|
||||
if ($user->getIsMailingList()) {
|
||||
$handle->setIcon('fa-envelope-o');
|
||||
$handle->setSubtitle(pht('Mailing List'));
|
||||
} else {
|
||||
$profile = $user->getUserProfile();
|
||||
$icon_key = $profile->getIcon();
|
||||
$icon_icon = PhabricatorPeopleIconSet::getIconIcon($icon_key);
|
||||
$subtitle = $profile->getDisplayTitle();
|
||||
|
||||
$handle->setIcon($icon_icon);
|
||||
$handle->setSubtitle($subtitle);
|
||||
}
|
||||
|
||||
$availability = null;
|
||||
|
|
|
@ -138,15 +138,16 @@ final class PhabricatorPeopleQuery
|
|||
if ($this->needProfile) {
|
||||
$user_list = mpull($users, null, 'getPHID');
|
||||
$profiles = new PhabricatorUserProfile();
|
||||
$profiles = $profiles->loadAllWhere('userPHID IN (%Ls)',
|
||||
$profiles = $profiles->loadAllWhere(
|
||||
'userPHID IN (%Ls)',
|
||||
array_keys($user_list));
|
||||
|
||||
$profiles = mpull($profiles, null, 'getUserPHID');
|
||||
foreach ($user_list as $user_phid => $user) {
|
||||
$profile = idx($profiles, $user_phid);
|
||||
|
||||
if (!$profile) {
|
||||
$profile = new PhabricatorUserProfile();
|
||||
$profile->setUserPHID($user_phid);
|
||||
$profile = PhabricatorUserProfile::initializeNewProfile($user);
|
||||
}
|
||||
|
||||
$user->attachUserProfile($profile);
|
||||
|
|
|
@ -451,8 +451,7 @@ final class PhabricatorUser
|
|||
$this->getPHID());
|
||||
|
||||
if (!$this->profile) {
|
||||
$profile_dao->setUserPHID($this->getPHID());
|
||||
$this->profile = $profile_dao;
|
||||
$this->profile = PhabricatorUserProfile::initializeNewProfile($this);
|
||||
}
|
||||
|
||||
return $this->profile;
|
||||
|
|
|
@ -6,6 +6,15 @@ final class PhabricatorUserProfile extends PhabricatorUserDAO {
|
|||
protected $title;
|
||||
protected $blurb;
|
||||
protected $profileImagePHID;
|
||||
protected $icon;
|
||||
|
||||
public static function initializeNewProfile(PhabricatorUser $user) {
|
||||
$default_icon = PhabricatorPeopleIconSet::getDefaultIconKey();
|
||||
|
||||
return id(new self())
|
||||
->setUserPHID($user->getPHID())
|
||||
->setIcon($default_icon);
|
||||
}
|
||||
|
||||
protected function getConfiguration() {
|
||||
return array(
|
||||
|
@ -13,6 +22,7 @@ final class PhabricatorUserProfile extends PhabricatorUserDAO {
|
|||
'title' => 'text255',
|
||||
'blurb' => 'text',
|
||||
'profileImagePHID' => 'phid?',
|
||||
'icon' => 'text32',
|
||||
),
|
||||
self::CONFIG_KEY_SCHEMA => array(
|
||||
'userPHID' => array(
|
||||
|
@ -23,4 +33,14 @@ final class PhabricatorUserProfile extends PhabricatorUserDAO {
|
|||
) + parent::getConfiguration();
|
||||
}
|
||||
|
||||
public function getDisplayTitle() {
|
||||
$title = $this->getTitle();
|
||||
if (strlen($title)) {
|
||||
return $title;
|
||||
}
|
||||
|
||||
$icon_key = $this->getIcon();
|
||||
return PhabricatorPeopleIconSet::getIconName($icon_key);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ final class PhabricatorObjectHandle
|
|||
private $complete;
|
||||
private $objectName;
|
||||
private $policyFiltered;
|
||||
private $subtitle;
|
||||
|
||||
public function setIcon($icon) {
|
||||
$this->icon = $icon;
|
||||
|
@ -44,6 +45,15 @@ final class PhabricatorObjectHandle
|
|||
return $this->getTypeIcon();
|
||||
}
|
||||
|
||||
public function setSubtitle($subtitle) {
|
||||
$this->subtitle = $subtitle;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSubtitle() {
|
||||
return $this->subtitle;
|
||||
}
|
||||
|
||||
public function setTagColor($color) {
|
||||
static $colors;
|
||||
if (!$colors) {
|
||||
|
|
|
@ -79,6 +79,13 @@ abstract class PhabricatorProjectUserListView extends AphrontView {
|
|||
->setHref($handle->getURI())
|
||||
->setImageURI($handle->getImageURI());
|
||||
|
||||
$icon = id(new PHUIIconView())
|
||||
->setIconFont($handle->getIcon().' grey');
|
||||
|
||||
$subtitle = $handle->getSubtitle();
|
||||
|
||||
$item->addAttribute(array($icon, ' ', $subtitle));
|
||||
|
||||
if ($can_edit && !$limit) {
|
||||
$remove_uri = $this->getRemoveURI($user_phid);
|
||||
|
||||
|
|
Loading…
Reference in a new issue