From 6ae0a62f9f4822164f0f5684c7431411bf4c09b3 Mon Sep 17 00:00:00 2001 From: Chad Little Date: Thu, 11 Feb 2016 14:55:44 -0800 Subject: [PATCH] New People Hovercards Summary: Mimics the Project Hovercards, more custom UI. Test Plan: Hover over person with and without badges, hover over project. Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin Differential Revision: https://secure.phabricator.com/D15253 --- resources/celerity/map.php | 4 +- src/__phutil_library_map__.php | 6 +- .../PeopleHovercardEngineExtension.php | 66 +------- .../people/view/PhabricatorUserCardView.php | 151 ++++++++++++++++++ ...icatorProjectHovercardEngineExtension.php} | 2 +- .../application/project/project-card-view.css | 7 +- 6 files changed, 169 insertions(+), 67 deletions(-) create mode 100644 src/applications/people/view/PhabricatorUserCardView.php rename src/applications/project/{events/ProjectHovercardEngineExtension.php => engineextension/PhabricatorProjectHovercardEngineExtension.php} (95%) diff --git a/resources/celerity/map.php b/resources/celerity/map.php index 78351f0774..bcdc04d534 100644 --- a/resources/celerity/map.php +++ b/resources/celerity/map.php @@ -93,7 +93,7 @@ return array( 'rsrc/css/application/policy/policy-transaction-detail.css' => '82100a43', 'rsrc/css/application/policy/policy.css' => '957ea14c', 'rsrc/css/application/ponder/ponder-view.css' => '7b0df4da', - 'rsrc/css/application/project/project-card-view.css' => '9c3631e5', + 'rsrc/css/application/project/project-card-view.css' => '9418c97d', 'rsrc/css/application/project/project-view.css' => '4693497c', 'rsrc/css/application/releeph/releeph-core.css' => '9b3c5733', 'rsrc/css/application/releeph/releeph-preview-branch.css' => 'b7a6f4a5', @@ -854,7 +854,7 @@ return array( 'policy-edit-css' => '815c66f7', 'policy-transaction-detail-css' => '82100a43', 'ponder-view-css' => '7b0df4da', - 'project-card-view-css' => '9c3631e5', + 'project-card-view-css' => '9418c97d', 'project-view-css' => '4693497c', 'releeph-core' => '9b3c5733', 'releeph-preview-branch' => 'b7a6f4a5', diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 134e36b2b9..0534da7c3c 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -2904,6 +2904,7 @@ phutil_register_library_map(array( 'PhabricatorProjectHeraldAction' => 'applications/project/herald/PhabricatorProjectHeraldAction.php', 'PhabricatorProjectHeraldAdapter' => 'applications/project/herald/PhabricatorProjectHeraldAdapter.php', 'PhabricatorProjectHeraldFieldGroup' => 'applications/project/herald/PhabricatorProjectHeraldFieldGroup.php', + 'PhabricatorProjectHovercardEngineExtension' => 'applications/project/engineextension/PhabricatorProjectHovercardEngineExtension.php', 'PhabricatorProjectIconSet' => 'applications/project/icon/PhabricatorProjectIconSet.php', 'PhabricatorProjectIconsConfigOptionType' => 'applications/project/config/PhabricatorProjectIconsConfigOptionType.php', 'PhabricatorProjectInterface' => 'applications/project/interface/PhabricatorProjectInterface.php', @@ -3376,6 +3377,7 @@ phutil_register_library_map(array( 'PhabricatorUnsubscribedFromObjectEdgeType' => 'applications/transactions/edges/PhabricatorUnsubscribedFromObjectEdgeType.php', 'PhabricatorUser' => 'applications/people/storage/PhabricatorUser.php', 'PhabricatorUserBlurbField' => 'applications/people/customfield/PhabricatorUserBlurbField.php', + 'PhabricatorUserCardView' => 'applications/people/view/PhabricatorUserCardView.php', 'PhabricatorUserConfigOptions' => 'applications/people/config/PhabricatorUserConfigOptions.php', 'PhabricatorUserConfiguredCustomField' => 'applications/people/customfield/PhabricatorUserConfiguredCustomField.php', 'PhabricatorUserConfiguredCustomFieldStorage' => 'applications/people/storage/PhabricatorUserConfiguredCustomFieldStorage.php', @@ -3828,7 +3830,6 @@ phutil_register_library_map(array( 'ProjectDefaultJoinCapability' => 'applications/project/capability/ProjectDefaultJoinCapability.php', 'ProjectDefaultViewCapability' => 'applications/project/capability/ProjectDefaultViewCapability.php', 'ProjectEditConduitAPIMethod' => 'applications/project/conduit/ProjectEditConduitAPIMethod.php', - 'ProjectHovercardEngineExtension' => 'applications/project/events/ProjectHovercardEngineExtension.php', 'ProjectQueryConduitAPIMethod' => 'applications/project/conduit/ProjectQueryConduitAPIMethod.php', 'ProjectRemarkupRule' => 'applications/project/remarkup/ProjectRemarkupRule.php', 'ProjectRemarkupRuleTestCase' => 'applications/project/remarkup/__tests__/ProjectRemarkupRuleTestCase.php', @@ -7338,6 +7339,7 @@ phutil_register_library_map(array( 'PhabricatorProjectHeraldAction' => 'HeraldAction', 'PhabricatorProjectHeraldAdapter' => 'HeraldAdapter', 'PhabricatorProjectHeraldFieldGroup' => 'HeraldFieldGroup', + 'PhabricatorProjectHovercardEngineExtension' => 'PhabricatorHovercardEngineExtension', 'PhabricatorProjectIconSet' => 'PhabricatorIconSet', 'PhabricatorProjectIconsConfigOptionType' => 'PhabricatorConfigJSONOptionType', 'PhabricatorProjectListController' => 'PhabricatorProjectController', @@ -7887,6 +7889,7 @@ phutil_register_library_map(array( 'PhabricatorFulltextInterface', ), 'PhabricatorUserBlurbField' => 'PhabricatorUserCustomField', + 'PhabricatorUserCardView' => 'AphrontTagView', 'PhabricatorUserConfigOptions' => 'PhabricatorApplicationConfigOptions', 'PhabricatorUserConfiguredCustomField' => array( 'PhabricatorUserCustomField', @@ -8474,7 +8477,6 @@ phutil_register_library_map(array( 'ProjectDefaultJoinCapability' => 'PhabricatorPolicyCapability', 'ProjectDefaultViewCapability' => 'PhabricatorPolicyCapability', 'ProjectEditConduitAPIMethod' => 'PhabricatorEditEngineAPIMethod', - 'ProjectHovercardEngineExtension' => 'PhabricatorHovercardEngineExtension', 'ProjectQueryConduitAPIMethod' => 'ProjectConduitAPIMethod', 'ProjectRemarkupRule' => 'PhabricatorObjectRemarkupRule', 'ProjectRemarkupRuleTestCase' => 'PhabricatorTestCase', diff --git a/src/applications/people/engineextension/PeopleHovercardEngineExtension.php b/src/applications/people/engineextension/PeopleHovercardEngineExtension.php index e986ec87f7..22d63eda8a 100644 --- a/src/applications/people/engineextension/PeopleHovercardEngineExtension.php +++ b/src/applications/people/engineextension/PeopleHovercardEngineExtension.php @@ -25,6 +25,7 @@ final class PeopleHovercardEngineExtension ->setViewer($viewer) ->withPHIDs($phids) ->needAvailability(true) + ->needProfileImage(true) ->needProfile(true) ->needBadges(true) ->execute(); @@ -47,69 +48,12 @@ final class PeopleHovercardEngineExtension return; } - $hovercard->setTitle($user->getUsername()); + $user_card = id(new PhabricatorUserCardView()) + ->setProfile($user) + ->setViewer($viewer); - $profile = $user->getUserProfile(); - $detail = $user->getRealName(); - if ($profile->getTitle()) { - $detail .= ' - '.$profile->getTitle(); - } - $hovercard->setDetail($detail); + $hovercard->appendChild($user_card); - if ($user->getIsDisabled()) { - $hovercard->addField(pht('Account'), pht('Disabled')); - } else if (!$user->isUserActivated()) { - $hovercard->addField(pht('Account'), pht('Not Activated')); - } else if (PhabricatorApplication::isClassInstalledForViewer( - 'PhabricatorCalendarApplication', - $viewer)) { - $hovercard->addField( - pht('Status'), - $user->getAvailabilityDescription($viewer)); - } - - $hovercard->addField( - pht('User Since'), - phabricator_date($user->getDateCreated(), $viewer)); - - if ($profile->getBlurb()) { - $hovercard->addField(pht('Blurb'), - id(new PhutilUTF8StringTruncator()) - ->setMaximumGlyphs(120) - ->truncateString($profile->getBlurb())); - } - - $badges = $this->buildBadges($user, $viewer); - foreach ($badges as $badge) { - $hovercard->addBadge($badge); - } - } - - private function buildBadges( - PhabricatorUser $user, - $viewer) { - - $class = 'PhabricatorBadgesApplication'; - $items = array(); - - if (PhabricatorApplication::isClassInstalledForViewer($class, $viewer)) { - $badge_phids = $user->getBadgePHIDs(); - if ($badge_phids) { - $badges = id(new PhabricatorBadgesQuery()) - ->setViewer($viewer) - ->withPHIDs($badge_phids) - ->withStatuses(array(PhabricatorBadgesBadge::STATUS_ACTIVE)) - ->execute(); - - foreach ($badges as $badge) { - $items[] = id(new PHUIBadgeMiniView()) - ->setIcon($badge->getIcon()) - ->setHeader($badge->getName()) - ->setQuality($badge->getQuality()); - } - } - } - return $items; } } diff --git a/src/applications/people/view/PhabricatorUserCardView.php b/src/applications/people/view/PhabricatorUserCardView.php new file mode 100644 index 0000000000..60ba08c93b --- /dev/null +++ b/src/applications/people/view/PhabricatorUserCardView.php @@ -0,0 +1,151 @@ +profile = $profile; + return $this; + } + + public function setViewer(PhabricatorUser $viewer) { + $this->viewer = $viewer; + return $this; + } + + public function setTag($tag) { + $this->tag = $tag; + return $this; + } + + protected function getTagName() { + if ($this->tag) { + return $this->tag; + } + return 'div'; + } + + protected function getTagAttributes() { + $classes = array(); + $classes[] = 'project-card-view'; + + if ($this->profile->getIsDisabled()) { + $classes[] = 'project-card-grey'; + } else { + $classes[] = 'project-card-blue'; + } + + return array( + 'class' => implode($classes, ' '), + ); + } + + protected function getTagContent() { + + $user = $this->profile; + $profile = $user->loadUserProfile(); + $picture = $user->getProfileImageURI(); + $viewer = $this->viewer; + + require_celerity_resource('project-card-view-css'); + + $profile_icon = PhabricatorPeopleIconSet::getIconIcon($profile->getIcon()); + $profile_title = $profile->getDisplayTitle(); + + $tag = id(new PHUITagView()) + ->setIcon($profile_icon) + ->setName($profile_title) + ->addClass('project-view-header-tag') + ->setType(PHUITagView::TYPE_SHADE); + + $header = id(new PHUIHeaderView()) + ->setHeader(array($user->getFullName(), $tag)) + ->setUser($viewer) + ->setImage($picture); + + $body = array(); + + $body[] = $this->addItem( + pht('User Since'), + phabricator_date($profile->getDateCreated(), $viewer)); + + if (PhabricatorApplication::isClassInstalledForViewer( + 'PhabricatorCalendarApplication', + $viewer)) { + $availability = $user->getAvailabilityDescription($viewer); + $body[] = $this->addItem(pht('Status'), $availability); + } + + $badges = $this->buildBadges($user, $viewer); + if ($badges) { + $badges = id(new PHUIBadgeBoxView()) + ->addItems($badges) + ->setCollapsed(true); + $body[] = phutil_tag( + 'div', + array( + 'class' => 'phui-hovercard-body-item hovercard-badges', + ), + $badges); + } + + $body = phutil_tag( + 'div', + array( + 'class' => 'project-card-body', + ), + $body); + + $card = phutil_tag( + 'div', + array( + 'class' => 'project-card-inner', + ), + array( + $header, + $body, + )); + + return $card; + } + + private function addItem($label, $value) { + $item = array( + phutil_tag('strong', array(), $label), + ': ', + phutil_tag('span', array(), $value), + ); + return phutil_tag_div('project-card-item', $item); + } + + private function buildBadges( + PhabricatorUser $user, + $viewer) { + + $class = 'PhabricatorBadgesApplication'; + $items = array(); + + if (PhabricatorApplication::isClassInstalledForViewer($class, $viewer)) { + $badge_phids = $user->getBadgePHIDs(); + if ($badge_phids) { + $badges = id(new PhabricatorBadgesQuery()) + ->setViewer($viewer) + ->withPHIDs($badge_phids) + ->withStatuses(array(PhabricatorBadgesBadge::STATUS_ACTIVE)) + ->execute(); + + foreach ($badges as $badge) { + $items[] = id(new PHUIBadgeMiniView()) + ->setIcon($badge->getIcon()) + ->setHeader($badge->getName()) + ->setQuality($badge->getQuality()); + } + } + } + return $items; + } + +} diff --git a/src/applications/project/events/ProjectHovercardEngineExtension.php b/src/applications/project/engineextension/PhabricatorProjectHovercardEngineExtension.php similarity index 95% rename from src/applications/project/events/ProjectHovercardEngineExtension.php rename to src/applications/project/engineextension/PhabricatorProjectHovercardEngineExtension.php index deef9a30f8..d2d1f9ab82 100644 --- a/src/applications/project/events/ProjectHovercardEngineExtension.php +++ b/src/applications/project/engineextension/PhabricatorProjectHovercardEngineExtension.php @@ -1,6 +1,6 @@