mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +01:00
Convert "Account" and "Date and Time" settings to EditEngine
Summary: Ref T4103. This pretty much replaces these panels in-place with similar looking ones that go through EditEngine. This has a few rough edges but they're pretty minor and/or hard to hit (for example, when editing another user's settings, the crumbs have a redundant link in them). Test Plan: - Edited my own settings. - Edited a bot user's settings. - Tried to edit another user's settings (failed). {F1674465} Reviewers: chad Reviewed By: chad Maniphest Tasks: T4103 Differential Revision: https://secure.phabricator.com/D16017
This commit is contained in:
parent
67482fd19d
commit
2f936094d8
16 changed files with 370 additions and 327 deletions
|
@ -2372,6 +2372,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorEditEngineQuery' => 'applications/transactions/query/PhabricatorEditEngineQuery.php',
|
||||
'PhabricatorEditEngineSearchEngine' => 'applications/transactions/query/PhabricatorEditEngineSearchEngine.php',
|
||||
'PhabricatorEditEngineSelectCommentAction' => 'applications/transactions/commentaction/PhabricatorEditEngineSelectCommentAction.php',
|
||||
'PhabricatorEditEngineSettingsPanel' => 'applications/settings/panel/PhabricatorEditEngineSettingsPanel.php',
|
||||
'PhabricatorEditEngineTokenizerCommentAction' => 'applications/transactions/commentaction/PhabricatorEditEngineTokenizerCommentAction.php',
|
||||
'PhabricatorEditField' => 'applications/transactions/editfield/PhabricatorEditField.php',
|
||||
'PhabricatorEditPage' => 'applications/transactions/editengine/PhabricatorEditPage.php',
|
||||
|
@ -6167,7 +6168,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorAccessLog' => 'Phobject',
|
||||
'PhabricatorAccessLogConfigOptions' => 'PhabricatorApplicationConfigOptions',
|
||||
'PhabricatorAccessibilitySetting' => 'PhabricatorSelectSetting',
|
||||
'PhabricatorAccountSettingsPanel' => 'PhabricatorSettingsPanel',
|
||||
'PhabricatorAccountSettingsPanel' => 'PhabricatorEditEngineSettingsPanel',
|
||||
'PhabricatorActionListView' => 'AphrontView',
|
||||
'PhabricatorActionView' => 'AphrontView',
|
||||
'PhabricatorActivitySettingsPanel' => 'PhabricatorSettingsPanel',
|
||||
|
@ -6863,7 +6864,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorDatasourceEditField' => 'PhabricatorTokenizerEditField',
|
||||
'PhabricatorDatasourceEditType' => 'PhabricatorPHIDListEditType',
|
||||
'PhabricatorDateFormatSetting' => 'PhabricatorSelectSetting',
|
||||
'PhabricatorDateTimeSettingsPanel' => 'PhabricatorSettingsPanel',
|
||||
'PhabricatorDateTimeSettingsPanel' => 'PhabricatorEditEngineSettingsPanel',
|
||||
'PhabricatorDebugController' => 'PhabricatorController',
|
||||
'PhabricatorDefaultRequestExceptionHandler' => 'PhabricatorRequestExceptionHandler',
|
||||
'PhabricatorDefaultSyntaxStyle' => 'PhabricatorSyntaxStyle',
|
||||
|
@ -6942,6 +6943,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorEditEngineQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
'PhabricatorEditEngineSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||
'PhabricatorEditEngineSelectCommentAction' => 'PhabricatorEditEngineCommentAction',
|
||||
'PhabricatorEditEngineSettingsPanel' => 'PhabricatorSettingsPanel',
|
||||
'PhabricatorEditEngineTokenizerCommentAction' => 'PhabricatorEditEngineCommentAction',
|
||||
'PhabricatorEditField' => 'Phobject',
|
||||
'PhabricatorEditPage' => 'Phobject',
|
||||
|
|
|
@ -29,7 +29,10 @@ final class PhabricatorSettingsApplication extends PhabricatorApplication {
|
|||
public function getRoutes() {
|
||||
return array(
|
||||
'/settings/' => array(
|
||||
'(?:(?P<id>\d+)/)?(?:panel/(?P<key>[^/]+)/)?'
|
||||
'(?:(?P<id>\d+)/)?'.
|
||||
'(?:panel/(?P<pageKey>(?P<key>[^/]+))/'.
|
||||
'(?:(?P<formSaved>saved)/)?'.
|
||||
')?'
|
||||
=> 'PhabricatorSettingsMainController',
|
||||
'adjust/' => 'PhabricatorSettingsAdjustController',
|
||||
'timezone/(?P<offset>[^/]+)/'
|
||||
|
|
|
@ -10,8 +10,14 @@ final class PhabricatorSettingsMainController
|
|||
}
|
||||
|
||||
private function isSelf() {
|
||||
$user = $this->getUser();
|
||||
if (!$user) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$user_phid = $user->getPHID();
|
||||
|
||||
$viewer_phid = $this->getViewer()->getPHID();
|
||||
$user_phid = $this->getUser()->getPHID();
|
||||
return ($viewer_phid == $user_phid);
|
||||
}
|
||||
|
||||
|
@ -45,21 +51,19 @@ final class PhabricatorSettingsMainController
|
|||
|
||||
$key = $nav->selectFilter($key, head($panels)->getPanelKey());
|
||||
|
||||
$panel = $panels[$key];
|
||||
$panel->setUser($this->getUser());
|
||||
$panel->setViewer($viewer);
|
||||
$panel = $panels[$key]
|
||||
->setUser($this->getUser())
|
||||
->setViewer($viewer)
|
||||
->setController($this)
|
||||
->setNavigation($nav);
|
||||
|
||||
$response = $panel->processRequest($request);
|
||||
if ($response instanceof AphrontResponse) {
|
||||
if (($response instanceof AphrontResponse) ||
|
||||
($response instanceof AphrontResponseProducerInterface)) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$crumbs = $this->buildApplicationCrumbs();
|
||||
if (!$this->isSelf()) {
|
||||
$crumbs->addTextCrumb(
|
||||
$this->getUser()->getUsername(),
|
||||
'/p/'.$this->getUser()->getUsername().'/');
|
||||
}
|
||||
$crumbs->addTextCrumb($panel->getPanelName());
|
||||
|
||||
$title = $panel->getPanelName();
|
||||
|
@ -76,11 +80,7 @@ final class PhabricatorSettingsMainController
|
|||
}
|
||||
|
||||
private function buildPanels() {
|
||||
$panels = id(new PhutilClassMapQuery())
|
||||
->setAncestorClass('PhabricatorSettingsPanel')
|
||||
->setExpandMethod('buildPanels')
|
||||
->setUniqueMethod('getPanelKey')
|
||||
->execute();
|
||||
$panels = PhabricatorSettingsPanel::getAllPanels();
|
||||
|
||||
$result = array();
|
||||
foreach ($panels as $key => $panel) {
|
||||
|
@ -107,8 +107,6 @@ final class PhabricatorSettingsMainController
|
|||
$result[$key] = $panel;
|
||||
}
|
||||
|
||||
$result = msort($result, 'getPanelSortKey');
|
||||
|
||||
if (!$result) {
|
||||
throw new Exception(pht('No settings panels are available.'));
|
||||
}
|
||||
|
@ -145,4 +143,16 @@ final class PhabricatorSettingsMainController
|
|||
return $this->renderSideNav($panels)->getMenu();
|
||||
}
|
||||
|
||||
protected function buildApplicationCrumbs() {
|
||||
$crumbs = parent::buildApplicationCrumbs();
|
||||
|
||||
$user = $this->getUser();
|
||||
if (!$this->isSelf() && $user) {
|
||||
$username = $user->getUsername();
|
||||
$crumbs->addTextCrumb($username, "/p/{$username}/");
|
||||
}
|
||||
|
||||
return $crumbs;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,6 +5,27 @@ final class PhabricatorSettingsEditEngine
|
|||
|
||||
const ENGINECONST = 'settings.settings';
|
||||
|
||||
private $isSelfEdit;
|
||||
private $profileURI;
|
||||
|
||||
public function setIsSelfEdit($is_self_edit) {
|
||||
$this->isSelfEdit = $is_self_edit;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getIsSelfEdit() {
|
||||
return $this->isSelfEdit;
|
||||
}
|
||||
|
||||
public function setProfileURI($profile_uri) {
|
||||
$this->profileURI = $profile_uri;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getProfileURI() {
|
||||
return $this->profileURI;
|
||||
}
|
||||
|
||||
public function isEngineConfigurable() {
|
||||
return false;
|
||||
}
|
||||
|
@ -54,6 +75,12 @@ final class PhabricatorSettingsEditEngine
|
|||
}
|
||||
|
||||
protected function getObjectName() {
|
||||
$page = $this->getSelectedPage();
|
||||
|
||||
if ($page) {
|
||||
return $page->getLabel();
|
||||
}
|
||||
|
||||
return pht('Settings');
|
||||
}
|
||||
|
||||
|
@ -74,6 +101,62 @@ final class PhabricatorSettingsEditEngine
|
|||
return PhabricatorPolicies::POLICY_ADMIN;
|
||||
}
|
||||
|
||||
public function getEffectiveObjectEditCancelURI($object) {
|
||||
if ($this->getIsSelfEdit()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($this->getProfileURI()) {
|
||||
return $this->getProfileURI();
|
||||
}
|
||||
|
||||
return parent::getEffectiveObjectEditCancelURI($object);
|
||||
}
|
||||
|
||||
protected function newPages($object) {
|
||||
$viewer = $this->getViewer();
|
||||
$user = $object->getUser();
|
||||
|
||||
$panels = PhabricatorSettingsPanel::getAllPanels();
|
||||
|
||||
foreach ($panels as $key => $panel) {
|
||||
if (!($panel instanceof PhabricatorEditEngineSettingsPanel)) {
|
||||
unset($panels[$key]);
|
||||
continue;
|
||||
}
|
||||
|
||||
$panel->setViewer($viewer);
|
||||
if ($user) {
|
||||
$panel->setUser($user);
|
||||
}
|
||||
}
|
||||
|
||||
$pages = array();
|
||||
$uris = array();
|
||||
foreach ($panels as $key => $panel) {
|
||||
$uris[$key] = $panel->getPanelURI();
|
||||
|
||||
$page = $panel->newEditEnginePage();
|
||||
if (!$page) {
|
||||
continue;
|
||||
}
|
||||
$pages[] = $page;
|
||||
}
|
||||
|
||||
$more_pages = array(
|
||||
id(new PhabricatorEditPage())
|
||||
->setKey('extra')
|
||||
->setLabel(pht('Extra Settings'))
|
||||
->setIsDefault(true),
|
||||
);
|
||||
|
||||
foreach ($more_pages as $page) {
|
||||
$pages[] = $page;
|
||||
}
|
||||
|
||||
return $pages;
|
||||
}
|
||||
|
||||
protected function buildCustomEditFields($object) {
|
||||
$viewer = $this->getViewer();
|
||||
$settings = PhabricatorSetting::getAllEnabledSettings($viewer);
|
||||
|
@ -84,6 +167,8 @@ final class PhabricatorSettingsEditEngine
|
|||
$settings[$key] = $setting;
|
||||
}
|
||||
|
||||
$settings = msortv($settings, 'getSettingOrderVector');
|
||||
|
||||
$fields = array();
|
||||
foreach ($settings as $setting) {
|
||||
foreach ($setting->newCustomEditFields($object) as $field) {
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorAccountSettingsPanel extends PhabricatorSettingsPanel {
|
||||
final class PhabricatorAccountSettingsPanel
|
||||
extends PhabricatorEditEngineSettingsPanel {
|
||||
|
||||
public function getPanelKey() {
|
||||
return 'account';
|
||||
}
|
||||
const PANELKEY = 'account';
|
||||
|
||||
public function getPanelName() {
|
||||
return pht('Account');
|
||||
|
@ -18,162 +17,4 @@ final class PhabricatorAccountSettingsPanel extends PhabricatorSettingsPanel {
|
|||
return true;
|
||||
}
|
||||
|
||||
public function processRequest(AphrontRequest $request) {
|
||||
$viewer = $this->getViewer();
|
||||
$user = $this->getUser();
|
||||
$username = $user->getUsername();
|
||||
|
||||
$preferences = $user->loadPreferences();
|
||||
|
||||
$errors = array();
|
||||
if ($request->isFormPost()) {
|
||||
$sex = $request->getStr('sex');
|
||||
$sexes = array(PhutilPerson::SEX_MALE, PhutilPerson::SEX_FEMALE);
|
||||
if (in_array($sex, $sexes)) {
|
||||
$new_value = $sex;
|
||||
} else {
|
||||
$new_value = null;
|
||||
}
|
||||
|
||||
$preferences->setPreference(
|
||||
PhabricatorPronounSetting::SETTINGKEY,
|
||||
$new_value);
|
||||
|
||||
$preferences->setPreference(
|
||||
PhabricatorTranslationSetting::SETTINGKEY,
|
||||
$request->getStr('translation'));
|
||||
|
||||
if (!$errors) {
|
||||
$preferences->save();
|
||||
|
||||
return id(new AphrontRedirectResponse())
|
||||
->setURI($this->getPanelURI('?saved=true'));
|
||||
}
|
||||
}
|
||||
|
||||
$label_unknown = pht('%s updated their profile', $username);
|
||||
$label_her = pht('%s updated her profile', $username);
|
||||
$label_his = pht('%s updated his profile', $username);
|
||||
|
||||
$sexes = array(
|
||||
PhutilPerson::SEX_UNKNOWN => $label_unknown,
|
||||
PhutilPerson::SEX_MALE => $label_his,
|
||||
PhutilPerson::SEX_FEMALE => $label_her,
|
||||
);
|
||||
|
||||
$translations = $this->getTranslationOptions();
|
||||
|
||||
$form = new AphrontFormView();
|
||||
$form
|
||||
->setUser($viewer)
|
||||
->appendChild(
|
||||
id(new AphrontFormSelectControl())
|
||||
->setOptions($translations)
|
||||
->setLabel(pht('Translation'))
|
||||
->setName('translation')
|
||||
->setValue($user->getTranslation()))
|
||||
->appendRemarkupInstructions(pht('**Choose the pronoun you prefer:**'))
|
||||
->appendChild(
|
||||
id(new AphrontFormSelectControl())
|
||||
->setOptions($sexes)
|
||||
->setLabel(pht('Pronoun'))
|
||||
->setName('sex')
|
||||
->setValue($user->getSex()))
|
||||
->appendChild(
|
||||
id(new AphrontFormSubmitControl())
|
||||
->setValue(pht('Save Account Settings')));
|
||||
|
||||
$form_box = id(new PHUIObjectBoxView())
|
||||
->setHeaderText(pht('Account Settings'))
|
||||
->setFormSaved($request->getStr('saved'))
|
||||
->setFormErrors($errors)
|
||||
->setForm($form);
|
||||
|
||||
return array(
|
||||
$form_box,
|
||||
);
|
||||
}
|
||||
|
||||
private function getTranslationOptions() {
|
||||
$is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');
|
||||
$locales = PhutilLocale::loadAllLocales();
|
||||
|
||||
$group_labels = array(
|
||||
'normal' => pht('Translations'),
|
||||
'limited' => pht('Limited Translations'),
|
||||
'silly' => pht('Silly Translations'),
|
||||
'test' => pht('Developer/Test Translations'),
|
||||
);
|
||||
|
||||
$groups = array_fill_keys(array_keys($group_labels), array());
|
||||
|
||||
$translations = array();
|
||||
foreach ($locales as $locale) {
|
||||
$code = $locale->getLocaleCode();
|
||||
|
||||
// Get the locale's localized name if it's available. For example,
|
||||
// "Deutsch" instead of "German". This helps users who do not speak the
|
||||
// current language to find the correct setting.
|
||||
$raw_scope = PhabricatorEnv::beginScopedLocale($code);
|
||||
$name = $locale->getLocaleName();
|
||||
unset($raw_scope);
|
||||
|
||||
if ($locale->isSillyLocale()) {
|
||||
if ($is_serious) {
|
||||
// Omit silly locales on serious business installs.
|
||||
continue;
|
||||
}
|
||||
$groups['silly'][$code] = $name;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($locale->isTestLocale()) {
|
||||
$groups['test'][$code] = $name;
|
||||
continue;
|
||||
}
|
||||
|
||||
$strings = PhutilTranslation::getTranslationMapForLocale($code);
|
||||
$size = count($strings);
|
||||
|
||||
// If a translation is English, assume it can fall back to the default
|
||||
// strings and don't caveat its completeness.
|
||||
$is_english = (substr($code, 0, 3) == 'en_');
|
||||
|
||||
// Arbitrarily pick some number of available strings to promote a
|
||||
// translation out of the "limited" group. The major goal is just to
|
||||
// keep locales with very few strings out of the main group, so users
|
||||
// aren't surprised if a locale has no upstream translations available.
|
||||
if ($size > 512 || $is_english) {
|
||||
$type = 'normal';
|
||||
} else {
|
||||
$type = 'limited';
|
||||
}
|
||||
|
||||
$groups[$type][$code] = $name;
|
||||
}
|
||||
|
||||
// TODO: Select a default properly.
|
||||
$default = 'en_US';
|
||||
|
||||
$results = array();
|
||||
foreach ($groups as $key => $group) {
|
||||
$label = $group_labels[$key];
|
||||
if (!$group) {
|
||||
continue;
|
||||
}
|
||||
|
||||
asort($group);
|
||||
|
||||
if ($key == 'normal') {
|
||||
$group = array(
|
||||
'' => pht('Server Default: %s', $locales[$default]->getLocaleName()),
|
||||
) + $group;
|
||||
}
|
||||
|
||||
$results[$label] = $group;
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorDateTimeSettingsPanel extends PhabricatorSettingsPanel {
|
||||
final class PhabricatorDateTimeSettingsPanel
|
||||
extends PhabricatorEditEngineSettingsPanel {
|
||||
|
||||
public function getPanelKey() {
|
||||
return 'datetime';
|
||||
}
|
||||
const PANELKEY = 'datetime';
|
||||
|
||||
public function getPanelName() {
|
||||
return pht('Date and Time');
|
||||
|
@ -14,112 +13,8 @@ final class PhabricatorDateTimeSettingsPanel extends PhabricatorSettingsPanel {
|
|||
return pht('Account Information');
|
||||
}
|
||||
|
||||
public function processRequest(AphrontRequest $request) {
|
||||
$user = $request->getUser();
|
||||
$username = $user->getUsername();
|
||||
|
||||
$pref_timezone = PhabricatorTimezoneSetting::SETTINGKEY;
|
||||
$pref_time = PhabricatorUserPreferences::PREFERENCE_TIME_FORMAT;
|
||||
$pref_date = PhabricatorUserPreferences::PREFERENCE_DATE_FORMAT;
|
||||
$pref_week_start = PhabricatorUserPreferences::PREFERENCE_WEEK_START_DAY;
|
||||
$pref_ignore = PhabricatorTimezoneIgnoreOffsetSetting::SETTINGKEY;
|
||||
$preferences = $user->loadPreferences();
|
||||
|
||||
$errors = array();
|
||||
if ($request->isFormPost()) {
|
||||
$new_timezone = $request->getStr('timezone');
|
||||
if (!in_array($new_timezone, DateTimeZone::listIdentifiers(), true)) {
|
||||
$errors[] = pht('The selected timezone is not a valid timezone.');
|
||||
}
|
||||
|
||||
$preferences
|
||||
->setPreference($pref_timezone, $new_timezone)
|
||||
->setPreference(
|
||||
$pref_time,
|
||||
$request->getStr($pref_time))
|
||||
->setPreference(
|
||||
$pref_date,
|
||||
$request->getStr($pref_date))
|
||||
->setPreference(
|
||||
$pref_week_start,
|
||||
$request->getStr($pref_week_start))
|
||||
->setPreference($pref_ignore, null);
|
||||
|
||||
if (!$errors) {
|
||||
$preferences->save();
|
||||
|
||||
return id(new AphrontRedirectResponse())
|
||||
->setURI($this->getPanelURI('?saved=true'));
|
||||
}
|
||||
}
|
||||
|
||||
$timezone_ids = DateTimeZone::listIdentifiers();
|
||||
$timezone_id_map = array_fuse($timezone_ids);
|
||||
|
||||
$form = new AphrontFormView();
|
||||
$form
|
||||
->setUser($user)
|
||||
->appendChild(
|
||||
id(new AphrontFormSelectControl())
|
||||
->setLabel(pht('Timezone'))
|
||||
->setName('timezone')
|
||||
->setOptions($timezone_id_map)
|
||||
->setValue($user->getTimezoneIdentifier()))
|
||||
->appendChild(
|
||||
id(new AphrontFormSelectControl())
|
||||
->setLabel(pht('Time-of-Day Format'))
|
||||
->setName($pref_time)
|
||||
->setOptions(array(
|
||||
'g:i A' => pht('12-hour (2:34 PM)'),
|
||||
'H:i' => pht('24-hour (14:34)'),
|
||||
))
|
||||
->setCaption(
|
||||
pht('Format used when rendering a time of day.'))
|
||||
->setValue($preferences->getPreference($pref_time)))
|
||||
->appendChild(
|
||||
id(new AphrontFormSelectControl())
|
||||
->setLabel(pht('Date Format'))
|
||||
->setName($pref_date)
|
||||
->setOptions(array(
|
||||
'Y-m-d' => pht('ISO 8601 (2000-02-28)'),
|
||||
'n/j/Y' => pht('US (2/28/2000)'),
|
||||
'd-m-Y' => pht('European (28-02-2000)'),
|
||||
))
|
||||
->setCaption(
|
||||
pht('Format used when rendering a date.'))
|
||||
->setValue($preferences->getPreference($pref_date)))
|
||||
->appendChild(
|
||||
id(new AphrontFormSelectControl())
|
||||
->setLabel(pht('Week Starts On'))
|
||||
->setOptions($this->getWeekDays())
|
||||
->setName($pref_week_start)
|
||||
->setCaption(
|
||||
pht('Calendar weeks will start with this day.'))
|
||||
->setValue($preferences->getPreference($pref_week_start, 0)))
|
||||
->appendChild(
|
||||
id(new AphrontFormSubmitControl())
|
||||
->setValue(pht('Save Account Settings')));
|
||||
|
||||
$form_box = id(new PHUIObjectBoxView())
|
||||
->setHeaderText(pht('Date and Time Settings'))
|
||||
->setFormSaved($request->getStr('saved'))
|
||||
->setFormErrors($errors)
|
||||
->setForm($form);
|
||||
|
||||
return array(
|
||||
$form_box,
|
||||
);
|
||||
public function isEditableByAdministrators() {
|
||||
return true;
|
||||
}
|
||||
|
||||
private function getWeekDays() {
|
||||
return array(
|
||||
pht('Sunday'),
|
||||
pht('Monday'),
|
||||
pht('Tuesday'),
|
||||
pht('Wednesday'),
|
||||
pht('Thursday'),
|
||||
pht('Friday'),
|
||||
pht('Saturday'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
|
||||
abstract class PhabricatorEditEngineSettingsPanel
|
||||
extends PhabricatorSettingsPanel {
|
||||
|
||||
final public function processRequest(AphrontRequest $request) {
|
||||
$viewer = $this->getViewer();
|
||||
$user = $this->getUser();
|
||||
|
||||
if ($user->getPHID() === $viewer->getPHID()) {
|
||||
$is_self = true;
|
||||
} else {
|
||||
$is_self = false;
|
||||
}
|
||||
|
||||
if ($user->getPHID()) {
|
||||
$profile_uri = '/people/manage/'.$user->getID().'/';
|
||||
} else {
|
||||
$profile_uri = null;
|
||||
}
|
||||
|
||||
$engine = id(new PhabricatorSettingsEditEngine())
|
||||
->setController($this->getController())
|
||||
->setNavigation($this->getNavigation())
|
||||
->setHideHeader(true)
|
||||
->setIsSelfEdit($is_self)
|
||||
->setProfileURI($profile_uri);
|
||||
|
||||
$preferences = $user->loadPreferences();
|
||||
|
||||
PhabricatorPolicyFilter::requireCapability(
|
||||
$viewer,
|
||||
$preferences,
|
||||
PhabricatorPolicyCapability::CAN_EDIT);
|
||||
|
||||
$engine->setTargetObject($preferences);
|
||||
|
||||
return $engine->buildResponse();
|
||||
}
|
||||
|
||||
final public function newEditEnginePage() {
|
||||
$field_keys = $this->getPanelSettingsKeys();
|
||||
if (!$field_keys) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$key = $this->getPanelKey();
|
||||
$label = $this->getPanelName();
|
||||
$panel_uri = $this->getPanelURI().'saved/';
|
||||
|
||||
return id(new PhabricatorEditPage())
|
||||
->setKey($key)
|
||||
->setLabel($label)
|
||||
->setViewURI($panel_uri)
|
||||
->setFieldKeys($field_keys);
|
||||
}
|
||||
|
||||
final public function getPanelSettingsKeys() {
|
||||
$viewer = $this->getViewer();
|
||||
$settings = PhabricatorSetting::getAllEnabledSettings($viewer);
|
||||
|
||||
$this_key = $this->getPanelKey();
|
||||
|
||||
$panel_settings = array();
|
||||
foreach ($settings as $setting) {
|
||||
if ($setting->getSettingPanelKey() == $this_key) {
|
||||
$panel_settings[] = $setting;
|
||||
}
|
||||
}
|
||||
|
||||
return mpull($panel_settings, 'getSettingKey');
|
||||
}
|
||||
|
||||
}
|
|
@ -17,9 +17,10 @@ abstract class PhabricatorSettingsPanel extends Phobject {
|
|||
|
||||
private $user;
|
||||
private $viewer;
|
||||
private $controller;
|
||||
private $navigation;
|
||||
private $overrideURI;
|
||||
|
||||
|
||||
public function setUser(PhabricatorUser $user) {
|
||||
$this->user = $user;
|
||||
return $this;
|
||||
|
@ -43,6 +44,32 @@ abstract class PhabricatorSettingsPanel extends Phobject {
|
|||
return $this;
|
||||
}
|
||||
|
||||
final public function setController(PhabricatorController $controller) {
|
||||
$this->controller = $controller;
|
||||
return $this;
|
||||
}
|
||||
|
||||
final public function getController() {
|
||||
return $this->controller;
|
||||
}
|
||||
|
||||
final public function setNavigation(AphrontSideNavFilterView $navigation) {
|
||||
$this->navigation = $navigation;
|
||||
return $this;
|
||||
}
|
||||
|
||||
final public function getNavigation() {
|
||||
return $this->navigation;
|
||||
}
|
||||
|
||||
final public static function getAllPanels() {
|
||||
return id(new PhutilClassMapQuery())
|
||||
->setAncestorClass(__CLASS__)
|
||||
->setUniqueMethod('getPanelKey')
|
||||
->setSortMethod('getPanelSortKey')
|
||||
->execute();
|
||||
}
|
||||
|
||||
|
||||
/* -( Panel Configuration )------------------------------------------------ */
|
||||
|
||||
|
@ -54,7 +81,9 @@ abstract class PhabricatorSettingsPanel extends Phobject {
|
|||
* @return string Unique panel identifier (used in URIs).
|
||||
* @task config
|
||||
*/
|
||||
abstract public function getPanelKey();
|
||||
public function getPanelKey() {
|
||||
return $this->getPhobjectClassConstant('PANELKEY');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -95,23 +124,6 @@ abstract class PhabricatorSettingsPanel extends Phobject {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* You can use this callback to generate multiple similar panels which all
|
||||
* share the same implementation. For example, OAuth providers each have a
|
||||
* separate panel, but the implementation for each panel is the same.
|
||||
*
|
||||
* To generate multiple panels, build them here and return a list. By default,
|
||||
* the current panel (`$this`) is returned alone. For most panels, this
|
||||
* is the right implementation.
|
||||
*
|
||||
* @return list<PhabricatorSettingsPanel> Zero or more panels.
|
||||
* @task config
|
||||
*/
|
||||
public function buildPanels() {
|
||||
return array($this);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return true if this panel is available to administrators while editing
|
||||
* system agent accounts.
|
||||
|
|
|
@ -13,6 +13,14 @@ final class PhabricatorDateFormatSetting
|
|||
return pht('Date Format');
|
||||
}
|
||||
|
||||
public function getSettingPanelKey() {
|
||||
return PhabricatorDateTimeSettingsPanel::PANELKEY;
|
||||
}
|
||||
|
||||
protected function getSettingOrder() {
|
||||
return 200;
|
||||
}
|
||||
|
||||
protected function getControlInstructions() {
|
||||
return pht(
|
||||
'Select the format you prefer for editing dates.');
|
||||
|
|
|
@ -9,6 +9,14 @@ final class PhabricatorPronounSetting
|
|||
return pht('Pronoun');
|
||||
}
|
||||
|
||||
public function getSettingPanelKey() {
|
||||
return PhabricatorAccountSettingsPanel::PANELKEY;
|
||||
}
|
||||
|
||||
protected function getSettingOrder() {
|
||||
return 200;
|
||||
}
|
||||
|
||||
protected function getControlInstructions() {
|
||||
return pht('Choose the pronoun you prefer.');
|
||||
}
|
||||
|
@ -18,6 +26,9 @@ final class PhabricatorPronounSetting
|
|||
}
|
||||
|
||||
protected function getSelectOptions() {
|
||||
// TODO: When editing another user's settings as an administrator, this
|
||||
// is not the best username: the user's username would be better.
|
||||
|
||||
$viewer = $this->getViewer();
|
||||
$username = $viewer->getUsername();
|
||||
|
||||
|
|
|
@ -15,6 +15,20 @@ abstract class PhabricatorSetting extends Phobject {
|
|||
|
||||
abstract public function getSettingName();
|
||||
|
||||
public function getSettingPanelKey() {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function getSettingOrder() {
|
||||
return 1000;
|
||||
}
|
||||
|
||||
public function getSettingOrderVector() {
|
||||
return id(new PhutilSortVector())
|
||||
->addInt($this->getSettingOrder())
|
||||
->addString($this->getSettingName());
|
||||
}
|
||||
|
||||
protected function getControlInstructions() {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -12,6 +12,14 @@ final class PhabricatorTimeFormatSetting
|
|||
return pht('Time Format');
|
||||
}
|
||||
|
||||
public function getSettingPanelKey() {
|
||||
return PhabricatorDateTimeSettingsPanel::PANELKEY;
|
||||
}
|
||||
|
||||
protected function getSettingOrder() {
|
||||
return 300;
|
||||
}
|
||||
|
||||
protected function getControlInstructions() {
|
||||
return pht(
|
||||
'Select the format you prefer for editing and displaying time.');
|
||||
|
|
|
@ -9,6 +9,18 @@ final class PhabricatorTimezoneSetting
|
|||
return pht('Timezone');
|
||||
}
|
||||
|
||||
public function getSettingPanelKey() {
|
||||
return PhabricatorDateTimeSettingsPanel::PANELKEY;
|
||||
}
|
||||
|
||||
protected function getSettingOrder() {
|
||||
return 100;
|
||||
}
|
||||
|
||||
protected function getControlInstructions() {
|
||||
return pht('Select your local timezone.');
|
||||
}
|
||||
|
||||
public function getSettingDefaultValue() {
|
||||
return date_default_timezone_get();
|
||||
}
|
||||
|
|
|
@ -9,10 +9,23 @@ final class PhabricatorTranslationSetting
|
|||
return pht('Translation');
|
||||
}
|
||||
|
||||
public function getSettingPanelKey() {
|
||||
return PhabricatorAccountSettingsPanel::PANELKEY;
|
||||
}
|
||||
|
||||
protected function getSettingOrder() {
|
||||
return 100;
|
||||
}
|
||||
|
||||
public function getSettingDefaultValue() {
|
||||
return 'en_US';
|
||||
}
|
||||
|
||||
protected function getControlInstructions() {
|
||||
return pht(
|
||||
'Choose which language you would like the Phabricator UI to use.');
|
||||
}
|
||||
|
||||
protected function getSelectOptionGroups() {
|
||||
$is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');
|
||||
$locales = PhutilLocale::loadAllLocales();
|
||||
|
|
|
@ -9,6 +9,14 @@ final class PhabricatorWeekStartDaySetting
|
|||
return pht('Week Starts On');
|
||||
}
|
||||
|
||||
public function getSettingPanelKey() {
|
||||
return PhabricatorDateTimeSettingsPanel::PANELKEY;
|
||||
}
|
||||
|
||||
protected function getSettingOrder() {
|
||||
return 400;
|
||||
}
|
||||
|
||||
protected function getControlInstructions() {
|
||||
return pht(
|
||||
'Choose which day a calendar week should begin on.');
|
||||
|
|
|
@ -26,6 +26,8 @@ abstract class PhabricatorEditEngine
|
|||
private $targetObject;
|
||||
private $page;
|
||||
private $pages;
|
||||
private $navigation;
|
||||
private $hideHeader;
|
||||
|
||||
final public function setViewer(PhabricatorUser $viewer) {
|
||||
$this->viewer = $viewer;
|
||||
|
@ -80,6 +82,24 @@ abstract class PhabricatorEditEngine
|
|||
return $this->targetObject;
|
||||
}
|
||||
|
||||
public function setNavigation(AphrontSideNavFilterView $navigation) {
|
||||
$this->navigation = $navigation;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getNavigation() {
|
||||
return $this->navigation;
|
||||
}
|
||||
|
||||
public function setHideHeader($hide_header) {
|
||||
$this->hideHeader = $hide_header;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getHideHeader() {
|
||||
return $this->hideHeader;
|
||||
}
|
||||
|
||||
|
||||
/* -( Managing Fields )---------------------------------------------------- */
|
||||
|
||||
|
@ -1090,17 +1110,22 @@ abstract class PhabricatorEditEngine
|
|||
->addSubmitButton($submit_button);
|
||||
}
|
||||
|
||||
$header = id(new PHUIHeaderView())
|
||||
->setHeader($header_text)
|
||||
->setHeaderIcon($header_icon);
|
||||
$crumbs = $this->buildCrumbs($object, $final = true);
|
||||
|
||||
if ($this->getHideHeader()) {
|
||||
$header = null;
|
||||
$crumbs->setBorder(false);
|
||||
} else {
|
||||
$header = id(new PHUIHeaderView())
|
||||
->setHeader($header_text)
|
||||
->setHeaderIcon($header_icon);
|
||||
$crumbs->setBorder(true);
|
||||
}
|
||||
|
||||
if ($action_button) {
|
||||
$header->addActionLink($action_button);
|
||||
}
|
||||
|
||||
$crumbs = $this->buildCrumbs($object, $final = true);
|
||||
$crumbs->setBorder(true);
|
||||
|
||||
$box = id(new PHUIObjectBoxView())
|
||||
->setUser($viewer)
|
||||
->setHeaderText($this->getObjectName())
|
||||
|
@ -1108,12 +1133,30 @@ abstract class PhabricatorEditEngine
|
|||
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
|
||||
->appendChild($form);
|
||||
|
||||
$view = id(new PHUITwoColumnView())
|
||||
->setHeader($header)
|
||||
->setFooter(array(
|
||||
$box,
|
||||
$previews,
|
||||
));
|
||||
// This is fairly questionable, but in use by Settings.
|
||||
if ($request->getURIData('formSaved')) {
|
||||
$box->setFormSaved(true);
|
||||
}
|
||||
|
||||
$content = array(
|
||||
$box,
|
||||
$previews,
|
||||
);
|
||||
|
||||
$view = new PHUITwoColumnView();
|
||||
|
||||
if ($header) {
|
||||
$view->setHeader($header);
|
||||
}
|
||||
|
||||
$navigation = $this->getNavigation();
|
||||
if ($navigation) {
|
||||
$view
|
||||
->setNavigation($navigation)
|
||||
->setMainColumn($content);
|
||||
} else {
|
||||
$view->setFooter($content);
|
||||
}
|
||||
|
||||
return $controller->newPage()
|
||||
->setTitle($header_text)
|
||||
|
@ -1155,10 +1198,14 @@ abstract class PhabricatorEditEngine
|
|||
}
|
||||
|
||||
if (!$request->isAjax()) {
|
||||
$form->appendControl(
|
||||
id(new AphrontFormSubmitControl())
|
||||
->addCancelButton($cancel_uri)
|
||||
->setValue($submit_button));
|
||||
$buttons = id(new AphrontFormSubmitControl())
|
||||
->setValue($submit_button);
|
||||
|
||||
if ($cancel_uri) {
|
||||
$buttons->addCancelButton($cancel_uri);
|
||||
}
|
||||
|
||||
$form->appendControl($buttons);
|
||||
}
|
||||
|
||||
return $form;
|
||||
|
|
Loading…
Reference in a new issue