mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-20 20:40:56 +01:00
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
This commit is contained in:
parent
a77ab312f0
commit
a55089e628
7 changed files with 119 additions and 40 deletions
|
@ -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',
|
||||
|
|
|
@ -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,
|
||||
);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorUserRolesField
|
||||
extends PhabricatorUserCustomField {
|
||||
|
||||
private $value;
|
||||
|
||||
public function getFieldKey() {
|
||||
return 'user:roles';
|
||||
}
|
||||
|
||||
public function getFieldName() {
|
||||
return pht('Roles');
|
||||
}
|
||||
|
||||
public function getFieldDescription() {
|
||||
return pht('Shows roles like "Administrator" and "Disabled".');
|
||||
}
|
||||
|
||||
public function shouldAppearInPropertyView() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function renderPropertyViewValue() {
|
||||
$user = $this->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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorUserStatusField
|
||||
extends PhabricatorUserCustomField {
|
||||
|
||||
private $value;
|
||||
|
||||
public function getFieldKey() {
|
||||
return 'user:status';
|
||||
}
|
||||
|
||||
public function getFieldName() {
|
||||
return pht('Status');
|
||||
}
|
||||
|
||||
public function getFieldDescription() {
|
||||
return pht('Shows when a user is away or busy.');
|
||||
}
|
||||
|
||||
public function shouldAppearInPropertyView() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function renderPropertyViewValue() {
|
||||
$user = $this->getObject();
|
||||
$viewer = $this->requireViewer();
|
||||
|
||||
$statuses = id(new PhabricatorUserStatus())
|
||||
->loadCurrentStatuses(array($user->getPHID()));
|
||||
if (!$statuses) {
|
||||
return pht('Available');
|
||||
}
|
||||
|
||||
$status = head($statuses);
|
||||
|
||||
return $status->getTerseSummary($viewer);
|
||||
}
|
||||
|
||||
}
|
|
@ -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'.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue