mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-22 21:40:55 +01:00
Merge profile "About" into main profile and simplify some custom field stuff
Summary: Ref T1703. Drive "user since" with a custom field and make the other fields render into a property list. Users can make their profiles a little more personal/obnoxious now. Also delete a bunch of code. Test Plan: {F49415} Reviewers: chad, btrahan Reviewed By: chad CC: aran Maniphest Tasks: T1703 Differential Revision: https://secure.phabricator.com/D6401
This commit is contained in:
parent
c20b7540c9
commit
b92fe7dbda
13 changed files with 197 additions and 106 deletions
|
@ -1616,6 +1616,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorUserRealNameField' => 'applications/people/customfield/PhabricatorUserRealNameField.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',
|
||||
'PhabricatorUserStatusInvalidEpochException' => 'applications/people/exception/PhabricatorUserStatusInvalidEpochException.php',
|
||||
'PhabricatorUserStatusOverlapException' => 'applications/people/exception/PhabricatorUserStatusOverlapException.php',
|
||||
|
@ -3568,6 +3569,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorUserRealNameField' => 'PhabricatorUserCustomField',
|
||||
'PhabricatorUserSSHKey' => 'PhabricatorUserDAO',
|
||||
'PhabricatorUserSearchIndexer' => 'PhabricatorSearchDocumentIndexer',
|
||||
'PhabricatorUserSinceField' => 'PhabricatorUserCustomField',
|
||||
'PhabricatorUserStatus' => 'PhabricatorUserDAO',
|
||||
'PhabricatorUserStatusInvalidEpochException' => 'Exception',
|
||||
'PhabricatorUserStatusOverlapException' => 'Exception',
|
||||
|
|
|
@ -16,6 +16,7 @@ final class PhabricatorUserConfigOptions
|
|||
$default = array(
|
||||
id(new PhabricatorUserRealNameField())->getFieldKey() => true,
|
||||
id(new PhabricatorUserTitleField())->getFieldKey() => true,
|
||||
id(new PhabricatorUserSinceField())->getFieldKey() => true,
|
||||
id(new PhabricatorUserBlurbField())->getFieldKey() => true,
|
||||
);
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ final class PhabricatorPeopleProfileController
|
|||
|
||||
private $username;
|
||||
private $page;
|
||||
private $profileUser;
|
||||
|
||||
public function shouldRequireAdmin() {
|
||||
// Default for people app is true
|
||||
|
@ -18,10 +17,6 @@ final class PhabricatorPeopleProfileController
|
|||
$this->page = idx($data, 'page');
|
||||
}
|
||||
|
||||
public function getProfileUser() {
|
||||
return $this->profileUser;
|
||||
}
|
||||
|
||||
private function getMainFilters($username) {
|
||||
return array(
|
||||
array(
|
||||
|
@ -29,11 +24,6 @@ final class PhabricatorPeopleProfileController
|
|||
'name' => pht('Feed'),
|
||||
'href' => '/p/'.$username.'/feed/'
|
||||
),
|
||||
array(
|
||||
'key' => 'about',
|
||||
'name' => pht('About'),
|
||||
'href' => '/p/'.$username.'/about/'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -48,8 +38,6 @@ final class PhabricatorPeopleProfileController
|
|||
return new Aphront404Response();
|
||||
}
|
||||
|
||||
$this->profileUser = $user;
|
||||
|
||||
require_celerity_resource('phabricator-profile-css');
|
||||
|
||||
$profile = $user->loadUserProfile();
|
||||
|
@ -76,16 +64,7 @@ final class PhabricatorPeopleProfileController
|
|||
|
||||
$this->page = $nav->selectFilter($this->page, 'feed');
|
||||
|
||||
switch ($this->page) {
|
||||
case 'feed':
|
||||
$content = $this->renderUserFeed($user);
|
||||
break;
|
||||
case 'about':
|
||||
$content = $this->renderBasicInformation($user, $profile);
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Unknown page '{$this->page}'!");
|
||||
}
|
||||
$content = $this->renderUserFeed($user);
|
||||
|
||||
$picture = $user->loadProfileImageURI();
|
||||
|
||||
|
@ -133,8 +112,11 @@ final class PhabricatorPeopleProfileController
|
|||
->setHref($this->getApplicationURI('edit/'.$user->getID().'/')));
|
||||
}
|
||||
|
||||
$properties = $this->buildPropertyView($user);
|
||||
|
||||
$nav->appendChild($header);
|
||||
$nav->appendChild($actions);
|
||||
$nav->appendChild($properties);
|
||||
$nav->appendChild($content);
|
||||
|
||||
return $this->buildApplicationPage(
|
||||
|
@ -146,55 +128,24 @@ final class PhabricatorPeopleProfileController
|
|||
));
|
||||
}
|
||||
|
||||
private function renderBasicInformation($user, $profile) {
|
||||
|
||||
$blurb = nonempty(
|
||||
$profile->getBlurb(),
|
||||
'//'.pht('Nothing is known about this rare specimen.').'//');
|
||||
|
||||
private function buildPropertyView(PhabricatorUser $user) {
|
||||
$viewer = $this->getRequest()->getUser();
|
||||
|
||||
$engine = PhabricatorMarkupEngine::newProfileMarkupEngine();
|
||||
$engine->setConfig('viewer', $viewer);
|
||||
$blurb = $engine->markupText($blurb);
|
||||
$view = id(new PhabricatorPropertyListView())
|
||||
->setUser($viewer)
|
||||
->setObject($user);
|
||||
|
||||
$content = hsprintf(
|
||||
'<div class="phabricator-profile-info-group profile-wrap-responsive">
|
||||
<h1 class="phabricator-profile-info-header">%s</h1>
|
||||
<div class="phabricator-profile-info-pane">
|
||||
<table class="phabricator-profile-info-table">
|
||||
<tr>
|
||||
<th>%s</th>
|
||||
<td>%s</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>%s</th>
|
||||
<td>%s</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>'.
|
||||
'<div class="phabricator-profile-info-group profile-wrap-responsive">
|
||||
<h1 class="phabricator-profile-info-header">%s</h1>
|
||||
<div class="phabricator-profile-info-pane">
|
||||
<table class="phabricator-profile-info-table">
|
||||
<tr>
|
||||
<th>%s</th>
|
||||
<td>%s</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>',
|
||||
pht('Basic Information'),
|
||||
pht('PHID'),
|
||||
$user->getPHID(),
|
||||
pht('User Since'),
|
||||
phabricator_datetime($user->getDateCreated(), $viewer),
|
||||
pht('Flavor Text'),
|
||||
pht('Blurb'),
|
||||
$blurb);
|
||||
$fields = PhabricatorCustomField::getObjectFields(
|
||||
$user,
|
||||
PhabricatorCustomField::ROLE_VIEW);
|
||||
|
||||
return $content;
|
||||
foreach ($fields as $field) {
|
||||
$field->setViewer($viewer);
|
||||
}
|
||||
|
||||
$view->applyCustomFields($fields);
|
||||
|
||||
return $view;
|
||||
}
|
||||
|
||||
private function renderUserFeed(PhabricatorUser $user) {
|
||||
|
|
|
@ -34,7 +34,7 @@ final class PhabricatorPeopleProfileEditController
|
|||
|
||||
$fields = PhabricatorCustomField::getObjectFields(
|
||||
$user,
|
||||
PhabricatorUserCustomFieldInterface::ROLE_EDIT);
|
||||
PhabricatorCustomField::ROLE_EDIT);
|
||||
|
||||
if ($request->isFormPost()) {
|
||||
$xactions = array();
|
||||
|
|
|
@ -17,7 +17,15 @@ final class PhabricatorUserBlurbField
|
|||
return pht('Short blurb about the user.');
|
||||
}
|
||||
|
||||
public function canDisableField() {
|
||||
public function shouldAppearInApplicationTransactions() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function shouldAppearInEditView() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function shouldAppearInPropertyView() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -49,4 +57,23 @@ final class PhabricatorUserBlurbField
|
|||
->setLabel($this->getFieldName());
|
||||
}
|
||||
|
||||
public function renderPropertyViewLabel() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function renderPropertyViewValue() {
|
||||
$blurb = $this->getObject()->loadUserProfile()->getBlurb();
|
||||
if (!strlen($blurb)) {
|
||||
return null;
|
||||
}
|
||||
return PhabricatorMarkupEngine::renderOneObject(
|
||||
id(new PhabricatorMarkupOneOff())->setContent($blurb),
|
||||
'default',
|
||||
$this->getViewer());
|
||||
}
|
||||
|
||||
public function getStyleForPropertyView() {
|
||||
return 'block';
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,28 +5,4 @@ abstract class PhabricatorUserCustomField
|
|||
implements PhabricatorUserCustomFieldInterface {
|
||||
|
||||
|
||||
public function shouldEnableForRole($role) {
|
||||
switch ($role) {
|
||||
case PhabricatorUserCustomFieldInterface::ROLE_EDIT:
|
||||
return $this->shouldAppearOnProfileEdit();
|
||||
}
|
||||
return parent::shouldEnableForRole($role);
|
||||
}
|
||||
|
||||
public function shouldAppearOnProfileEdit() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/* -( PhabricatorCustomField )--------------------------------------------- */
|
||||
|
||||
|
||||
public function canDisableField() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function shouldAppearInApplicationTransactions() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,8 +2,5 @@
|
|||
|
||||
interface PhabricatorUserCustomFieldInterface {
|
||||
|
||||
const ROLE_EDIT = 'user.edit';
|
||||
|
||||
public function shouldAppearOnProfileEdit();
|
||||
|
||||
}
|
||||
|
|
|
@ -17,6 +17,18 @@ final class PhabricatorUserRealNameField
|
|||
return pht('Stores the real name of the user, like "Abraham Lincoln".');
|
||||
}
|
||||
|
||||
public function canDisableField() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function shouldAppearInApplicationTransactions() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function shouldAppearInEditView() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function didSetObject(PhabricatorCustomFieldInterface $object) {
|
||||
$this->value = $object->getRealName();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorUserSinceField
|
||||
extends PhabricatorUserCustomField {
|
||||
|
||||
private $value;
|
||||
|
||||
public function getFieldKey() {
|
||||
return 'user:since';
|
||||
}
|
||||
|
||||
public function getFieldName() {
|
||||
return pht('User Since');
|
||||
}
|
||||
|
||||
public function getFieldDescription() {
|
||||
return pht('Shows user join date.');
|
||||
}
|
||||
|
||||
public function shouldAppearInPropertyView() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function renderPropertyViewValue() {
|
||||
return phabricator_datetime(
|
||||
$this->getObject()->getDateCreated(),
|
||||
$this->getViewer());
|
||||
}
|
||||
|
||||
}
|
|
@ -17,6 +17,18 @@ final class PhabricatorUserTitleField
|
|||
return pht('User title, like "CEO" or "Assistant to the Manager".');
|
||||
}
|
||||
|
||||
public function canDisableField() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function shouldAppearInApplicationTransactions() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function shouldAppearInEditView() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function didSetObject(PhabricatorCustomFieldInterface $object) {
|
||||
$this->value = $object->loadUserProfile()->getTitle();
|
||||
}
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
* @task storage Field Storage
|
||||
* @task appsearch Integration with ApplicationSearch
|
||||
* @task appxaction Integration with ApplicationTransactions
|
||||
* @task edit Integration with edit views
|
||||
* @task view Integration with property views
|
||||
* @task list Integration with list views
|
||||
*/
|
||||
abstract class PhabricatorCustomField {
|
||||
|
||||
|
@ -17,6 +20,9 @@ abstract class PhabricatorCustomField {
|
|||
const ROLE_APPLICATIONSEARCH = 'ApplicationSearch';
|
||||
const ROLE_STORAGE = 'storage';
|
||||
const ROLE_DEFAULT = 'default';
|
||||
const ROLE_EDIT = 'edit';
|
||||
const ROLE_VIEW = 'view';
|
||||
const ROLE_LIST = 'list';
|
||||
|
||||
|
||||
/* -( Building Applications with Custom Fields )--------------------------- */
|
||||
|
@ -219,6 +225,12 @@ abstract class PhabricatorCustomField {
|
|||
return $this->shouldAppearInApplicationSearch();
|
||||
case self::ROLE_STORAGE:
|
||||
return ($this->getStorageKey() !== null);
|
||||
case self::ROLE_EDIT:
|
||||
return $this->shouldAppearInEditView();
|
||||
case self::ROLE_VIEW:
|
||||
return $this->shouldAppearInPropertyView();
|
||||
case self::ROLE_LIST:
|
||||
return $this->shouldAppearInListView();
|
||||
case self::ROLE_DEFAULT:
|
||||
return true;
|
||||
default:
|
||||
|
@ -605,7 +617,7 @@ abstract class PhabricatorCustomField {
|
|||
/**
|
||||
* @task edit
|
||||
*/
|
||||
public function shouldAppearOnEditView() {
|
||||
public function shouldAppearInEditView() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -626,4 +638,59 @@ abstract class PhabricatorCustomField {
|
|||
}
|
||||
|
||||
|
||||
/* -( Property View )------------------------------------------------------ */
|
||||
|
||||
|
||||
/**
|
||||
* @task view
|
||||
*/
|
||||
public function shouldAppearInPropertyView() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @task view
|
||||
*/
|
||||
public function renderPropertyViewLabel() {
|
||||
return $this->getFieldName();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @task view
|
||||
*/
|
||||
public function renderPropertyViewValue() {
|
||||
throw new PhabricatorCustomFieldImplementationIncompleteException($this);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @task view
|
||||
*/
|
||||
public function getStyleForPropertyView() {
|
||||
return 'property';
|
||||
}
|
||||
|
||||
|
||||
/* -( List View )---------------------------------------------------------- */
|
||||
|
||||
|
||||
/**
|
||||
* @task list
|
||||
*/
|
||||
public function shouldAppearInListView() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @task list
|
||||
*/
|
||||
public function renderOnListItem(PhabricatorObjectItemView $view) {
|
||||
throw new PhabricatorCustomFieldImplementationIncompleteException($this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -346,15 +346,6 @@ final class PhabricatorMarkupEngine {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* @task engine
|
||||
*/
|
||||
public static function newProfileMarkupEngine() {
|
||||
return self::newMarkupEngine(array(
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @task engine
|
||||
*/
|
||||
|
|
|
@ -81,7 +81,32 @@ final class PhabricatorPropertyListView extends AphrontView {
|
|||
$this->invokedWillRenderEvent = true;
|
||||
}
|
||||
|
||||
public function applyCustomFields(array $fields) {
|
||||
assert_instances_of($fields, 'PhabricatorCustomField');
|
||||
|
||||
foreach ($fields as $field) {
|
||||
$label = $field->renderPropertyViewLabel();
|
||||
$value = $field->renderPropertyViewValue();
|
||||
if ($value !== null) {
|
||||
switch ($field->getStyleForPropertyView()) {
|
||||
case 'property':
|
||||
$this->addProperty($label, $value);
|
||||
break;
|
||||
case 'block':
|
||||
$this->invokeWillRenderEvent();
|
||||
if ($label !== null) {
|
||||
$this->addSectionHeader($label);
|
||||
}
|
||||
$this->addTextContent($value);
|
||||
break;
|
||||
default:
|
||||
throw new Exception(
|
||||
"Unknown field property view style; valid styles are ".
|
||||
"'block' and 'property'.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function render() {
|
||||
$this->invokeWillRenderEvent();
|
||||
|
|
Loading…
Reference in a new issue