From a55089e62816793d33a0cd32b2e9bead64949755 Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 10 Jul 2013 12:34:09 -0700 Subject: [PATCH] Move roles and status into properties on profile view Summary: See discussion in D6403. Test Plan: {F49488} Reviewers: chad, btrahan Reviewed By: chad CC: aran Differential Revision: https://secure.phabricator.com/D6409 --- src/__phutil_library_map__.php | 4 ++ .../config/PhabricatorUserConfigOptions.php | 2 + .../PhabricatorPeopleProfileController.php | 35 --------------- .../customfield/PhabricatorUserRolesField.php | 45 +++++++++++++++++++ .../customfield/PhabricatorUserSinceField.php | 8 +++- .../PhabricatorUserStatusField.php | 39 ++++++++++++++++ .../layout/PhabricatorPropertyListView.php | 26 +++++++++-- 7 files changed, 119 insertions(+), 40 deletions(-) create mode 100644 src/applications/people/customfield/PhabricatorUserRolesField.php create mode 100644 src/applications/people/customfield/PhabricatorUserStatusField.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 47ecf785b8..87e10869b9 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1614,10 +1614,12 @@ phutil_register_library_map(array( 'PhabricatorUserProfile' => 'applications/people/storage/PhabricatorUserProfile.php', 'PhabricatorUserProfileEditor' => 'applications/people/editor/PhabricatorUserProfileEditor.php', 'PhabricatorUserRealNameField' => 'applications/people/customfield/PhabricatorUserRealNameField.php', + 'PhabricatorUserRolesField' => 'applications/people/customfield/PhabricatorUserRolesField.php', 'PhabricatorUserSSHKey' => 'applications/settings/storage/PhabricatorUserSSHKey.php', 'PhabricatorUserSearchIndexer' => 'applications/people/search/PhabricatorUserSearchIndexer.php', 'PhabricatorUserSinceField' => 'applications/people/customfield/PhabricatorUserSinceField.php', 'PhabricatorUserStatus' => 'applications/people/storage/PhabricatorUserStatus.php', + 'PhabricatorUserStatusField' => 'applications/people/customfield/PhabricatorUserStatusField.php', 'PhabricatorUserStatusInvalidEpochException' => 'applications/people/exception/PhabricatorUserStatusInvalidEpochException.php', 'PhabricatorUserStatusOverlapException' => 'applications/people/exception/PhabricatorUserStatusOverlapException.php', 'PhabricatorUserTestCase' => 'applications/people/storage/__tests__/PhabricatorUserTestCase.php', @@ -3567,10 +3569,12 @@ phutil_register_library_map(array( 'PhabricatorUserProfile' => 'PhabricatorUserDAO', 'PhabricatorUserProfileEditor' => 'PhabricatorApplicationTransactionEditor', 'PhabricatorUserRealNameField' => 'PhabricatorUserCustomField', + 'PhabricatorUserRolesField' => 'PhabricatorUserCustomField', 'PhabricatorUserSSHKey' => 'PhabricatorUserDAO', 'PhabricatorUserSearchIndexer' => 'PhabricatorSearchDocumentIndexer', 'PhabricatorUserSinceField' => 'PhabricatorUserCustomField', 'PhabricatorUserStatus' => 'PhabricatorUserDAO', + 'PhabricatorUserStatusField' => 'PhabricatorUserCustomField', 'PhabricatorUserStatusInvalidEpochException' => 'Exception', 'PhabricatorUserStatusOverlapException' => 'Exception', 'PhabricatorUserTestCase' => 'PhabricatorTestCase', diff --git a/src/applications/people/config/PhabricatorUserConfigOptions.php b/src/applications/people/config/PhabricatorUserConfigOptions.php index 53a40c341e..41e6f2e88c 100644 --- a/src/applications/people/config/PhabricatorUserConfigOptions.php +++ b/src/applications/people/config/PhabricatorUserConfigOptions.php @@ -17,6 +17,8 @@ final class PhabricatorUserConfigOptions id(new PhabricatorUserRealNameField())->getFieldKey() => true, id(new PhabricatorUserTitleField())->getFieldKey() => true, id(new PhabricatorUserSinceField())->getFieldKey() => true, + id(new PhabricatorUserRolesField())->getFieldKey() => true, + id(new PhabricatorUserStatusField())->getFieldKey() => true, id(new PhabricatorUserBlurbField())->getFieldKey() => true, ); diff --git a/src/applications/people/controller/PhabricatorPeopleProfileController.php b/src/applications/people/controller/PhabricatorPeopleProfileController.php index 090f269a58..9819a60164 100644 --- a/src/applications/people/controller/PhabricatorPeopleProfileController.php +++ b/src/applications/people/controller/PhabricatorPeopleProfileController.php @@ -36,41 +36,6 @@ final class PhabricatorPeopleProfileController ->setSubheader($profile->getTitle()) ->setImage($picture); - if ($user->getIsDisabled()) { - $header->addTag( - id(new PhabricatorTagView()) - ->setType(PhabricatorTagView::TYPE_STATE) - ->setBackgroundColor(PhabricatorTagView::COLOR_GREY) - ->setName(pht('Disabled'))); - } - - if ($user->getIsAdmin()) { - $header->addTag( - id(new PhabricatorTagView()) - ->setType(PhabricatorTagView::TYPE_STATE) - ->setBackgroundColor(PhabricatorTagView::COLOR_RED) - ->setName(pht('Administrator'))); - } - - if ($user->getIsSystemAgent()) { - $header->addTag( - id(new PhabricatorTagView()) - ->setType(PhabricatorTagView::TYPE_STATE) - ->setBackgroundColor(PhabricatorTagView::COLOR_BLUE) - ->setName(pht('Bot'))); - } - - - $statuses = id(new PhabricatorUserStatus()) - ->loadCurrentStatuses(array($user->getPHID())); - if ($statuses) { - $header->addTag( - id(new PhabricatorTagView()) - ->setType(PhabricatorTagView::TYPE_STATE) - ->setBackgroundColor(PhabricatorTagView::COLOR_ORANGE) - ->setName(head($statuses)->getTerseSummary($viewer))); - } - $actions = id(new PhabricatorActionListView()) ->setObject($user) ->setUser($viewer); diff --git a/src/applications/people/customfield/PhabricatorUserRolesField.php b/src/applications/people/customfield/PhabricatorUserRolesField.php new file mode 100644 index 0000000000..dca0b3aaf3 --- /dev/null +++ b/src/applications/people/customfield/PhabricatorUserRolesField.php @@ -0,0 +1,45 @@ +getObject(); + + $roles = array(); + if ($user->getIsAdmin()) { + $roles[] = pht('Administrator'); + } + if ($user->getIsDisabled()) { + $roles[] = pht('Disabled'); + } + if ($user->getIsSystemAgent()) { + $roles[] = pht('Bot'); + } + + if ($roles) { + return implode(', ', $roles); + } + + return null; + } + +} diff --git a/src/applications/people/customfield/PhabricatorUserSinceField.php b/src/applications/people/customfield/PhabricatorUserSinceField.php index 1feaf61eb4..22a39104ef 100644 --- a/src/applications/people/customfield/PhabricatorUserSinceField.php +++ b/src/applications/people/customfield/PhabricatorUserSinceField.php @@ -22,9 +22,15 @@ final class PhabricatorUserSinceField } public function renderPropertyViewValue() { - return phabricator_datetime( + $absolute = phabricator_datetime( $this->getObject()->getDateCreated(), $this->getViewer()); + + $relative = phabricator_format_relative_time_detailed( + time() - $this->getObject()->getDateCreated(), + $levels = 2); + + return hsprintf('%s (%s)', $absolute, $relative); } } diff --git a/src/applications/people/customfield/PhabricatorUserStatusField.php b/src/applications/people/customfield/PhabricatorUserStatusField.php new file mode 100644 index 0000000000..433076d4e6 --- /dev/null +++ b/src/applications/people/customfield/PhabricatorUserStatusField.php @@ -0,0 +1,39 @@ +getObject(); + $viewer = $this->requireViewer(); + + $statuses = id(new PhabricatorUserStatus()) + ->loadCurrentStatuses(array($user->getPHID())); + if (!$statuses) { + return pht('Available'); + } + + $status = head($statuses); + + return $status->getTerseSummary($viewer); + } + +} diff --git a/src/view/layout/PhabricatorPropertyListView.php b/src/view/layout/PhabricatorPropertyListView.php index 137618b8e2..aac5192781 100644 --- a/src/view/layout/PhabricatorPropertyListView.php +++ b/src/view/layout/PhabricatorPropertyListView.php @@ -84,6 +84,28 @@ final class PhabricatorPropertyListView extends AphrontView { public function applyCustomFields(array $fields) { assert_instances_of($fields, 'PhabricatorCustomField'); + // Move all the blocks to the end, regardless of their configuration order, + // because it always looks silly to render a block in the middle of a list + // of properties. + $head = array(); + $tail = array(); + foreach ($fields as $key => $field) { + $style = $field->getStyleForPropertyView(); + switch ($style) { + case 'property': + $head[$key] = $field; + break; + case 'block': + $tail[$key] = $field; + break; + default: + throw new Exception( + "Unknown field property view style '{$style}'; valid styles are ". + "'block' and 'property'."); + } + } + $fields = $head + $tail; + foreach ($fields as $field) { $label = $field->renderPropertyViewLabel(); $value = $field->renderPropertyViewValue(); @@ -99,10 +121,6 @@ final class PhabricatorPropertyListView extends AphrontView { } $this->addTextContent($value); break; - default: - throw new Exception( - "Unknown field property view style; valid styles are ". - "'block' and 'property'."); } } }