1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-25 23:10:57 +01:00

Split up settings into "Date and Time Settings" and everything else.

Summary: Ref T8176, Split up settings into "Date and Time Settings" and everything else.

Test Plan: Open /settings, Account Settings should now have two tabs: "Account" and "Date and Time"

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: Korvin, epriestley

Maniphest Tasks: T8176

Differential Revision: https://secure.phabricator.com/D12881
This commit is contained in:
lkassianik 2015-05-16 17:21:37 -07:00
parent 72a896f772
commit dbac658025
3 changed files with 95 additions and 46 deletions

View file

@ -1742,6 +1742,7 @@ phutil_register_library_map(array(
'PhabricatorDataCacheSpec' => 'applications/cache/spec/PhabricatorDataCacheSpec.php', 'PhabricatorDataCacheSpec' => 'applications/cache/spec/PhabricatorDataCacheSpec.php',
'PhabricatorDataNotAttachedException' => 'infrastructure/storage/lisk/PhabricatorDataNotAttachedException.php', 'PhabricatorDataNotAttachedException' => 'infrastructure/storage/lisk/PhabricatorDataNotAttachedException.php',
'PhabricatorDatabaseSetupCheck' => 'applications/config/check/PhabricatorDatabaseSetupCheck.php', 'PhabricatorDatabaseSetupCheck' => 'applications/config/check/PhabricatorDatabaseSetupCheck.php',
'PhabricatorDateTimeSettingsPanel' => 'applications/settings/panel/PhabricatorDateTimeSettingsPanel.php',
'PhabricatorDebugController' => 'applications/system/controller/PhabricatorDebugController.php', 'PhabricatorDebugController' => 'applications/system/controller/PhabricatorDebugController.php',
'PhabricatorDefaultSearchEngineSelector' => 'applications/search/selector/PhabricatorDefaultSearchEngineSelector.php', 'PhabricatorDefaultSearchEngineSelector' => 'applications/search/selector/PhabricatorDefaultSearchEngineSelector.php',
'PhabricatorDestructibleInterface' => 'applications/system/interface/PhabricatorDestructibleInterface.php', 'PhabricatorDestructibleInterface' => 'applications/system/interface/PhabricatorDestructibleInterface.php',
@ -5134,6 +5135,7 @@ phutil_register_library_map(array(
'PhabricatorDataCacheSpec' => 'PhabricatorCacheSpec', 'PhabricatorDataCacheSpec' => 'PhabricatorCacheSpec',
'PhabricatorDataNotAttachedException' => 'Exception', 'PhabricatorDataNotAttachedException' => 'Exception',
'PhabricatorDatabaseSetupCheck' => 'PhabricatorSetupCheck', 'PhabricatorDatabaseSetupCheck' => 'PhabricatorSetupCheck',
'PhabricatorDateTimeSettingsPanel' => 'PhabricatorSettingsPanel',
'PhabricatorDebugController' => 'PhabricatorController', 'PhabricatorDebugController' => 'PhabricatorController',
'PhabricatorDefaultSearchEngineSelector' => 'PhabricatorSearchEngineSelector', 'PhabricatorDefaultSearchEngineSelector' => 'PhabricatorSearchEngineSelector',
'PhabricatorDestructionEngine' => 'Phobject', 'PhabricatorDestructionEngine' => 'Phobject',

View file

@ -18,18 +18,8 @@ final class PhabricatorAccountSettingsPanel extends PhabricatorSettingsPanel {
$user = $request->getUser(); $user = $request->getUser();
$username = $user->getUsername(); $username = $user->getUsername();
$pref_time = PhabricatorUserPreferences::PREFERENCE_TIME_FORMAT;
$preferences = $user->loadPreferences();
$errors = array(); $errors = array();
if ($request->isFormPost()) { if ($request->isFormPost()) {
$new_timezone = $request->getStr('timezone');
if (in_array($new_timezone, DateTimeZone::listIdentifiers(), true)) {
$user->setTimezoneIdentifier($new_timezone);
} else {
$errors[] = pht('The selected timezone is not a valid timezone.');
}
$sex = $request->getStr('sex'); $sex = $request->getStr('sex');
$sexes = array(PhutilPerson::SEX_MALE, PhutilPerson::SEX_FEMALE); $sexes = array(PhutilPerson::SEX_MALE, PhutilPerson::SEX_FEMALE);
if (in_array($sex, $sexes)) { if (in_array($sex, $sexes)) {
@ -41,19 +31,13 @@ final class PhabricatorAccountSettingsPanel extends PhabricatorSettingsPanel {
// Checked in runtime. // Checked in runtime.
$user->setTranslation($request->getStr('translation')); $user->setTranslation($request->getStr('translation'));
$preferences->setPreference($pref_time, $request->getStr($pref_time));
if (!$errors) { if (!$errors) {
$preferences->save();
$user->save(); $user->save();
return id(new AphrontRedirectResponse()) return id(new AphrontRedirectResponse())
->setURI($this->getPanelURI('?saved=true')); ->setURI($this->getPanelURI('?saved=true'));
} }
} }
$timezone_ids = DateTimeZone::listIdentifiers();
$timezone_id_map = array_fuse($timezone_ids);
$label_unknown = pht('%s updated their profile', $username); $label_unknown = pht('%s updated their profile', $username);
$label_her = pht('%s updated her profile', $username); $label_her = pht('%s updated her profile', $username);
$label_his = pht('%s updated his profile', $username); $label_his = pht('%s updated his profile', $username);
@ -93,10 +77,10 @@ final class PhabricatorAccountSettingsPanel extends PhabricatorSettingsPanel {
->setUser($user) ->setUser($user)
->appendChild( ->appendChild(
id(new AphrontFormSelectControl()) id(new AphrontFormSelectControl())
->setLabel(pht('Timezone')) ->setOptions($translations)
->setName('timezone') ->setLabel(pht('Translation'))
->setOptions($timezone_id_map) ->setName('translation')
->setValue($user->getTimezoneIdentifier())) ->setValue($user->getTranslation()))
->appendRemarkupInstructions(pht('**Choose the pronoun you prefer:**')) ->appendRemarkupInstructions(pht('**Choose the pronoun you prefer:**'))
->appendChild( ->appendChild(
id(new AphrontFormSelectControl()) id(new AphrontFormSelectControl())
@ -104,32 +88,6 @@ final class PhabricatorAccountSettingsPanel extends PhabricatorSettingsPanel {
->setLabel(pht('Pronoun')) ->setLabel(pht('Pronoun'))
->setName('sex') ->setName('sex')
->setValue($user->getSex())) ->setValue($user->getSex()))
->appendChild(
id(new AphrontFormSelectControl())
->setOptions($translations)
->setLabel(pht('Translation'))
->setName('translation')
->setValue($user->getTranslation()))
->appendRemarkupInstructions(
pht(
"**Custom Date and Time Formats**\n\n".
"You can specify custom formats which will be used when ".
"rendering dates and times of day. Examples:\n\n".
"| Format | Example | Notes |\n".
"| ------ | -------- | ----- |\n".
"| `g:i A` | 2:34 PM | Default 12-hour time. |\n".
"| `G.i a` | 02.34 pm | Alternate 12-hour time. |\n".
"| `H:i` | 14:34 | 24-hour time. |\n".
"\n\n".
"You can find a [[%s | full reference in the PHP manual]].",
'http://www.php.net/manual/en/function.date.php'))
->appendChild(
id(new AphrontFormTextControl())
->setLabel(pht('Time-of-Day Format'))
->setName($pref_time)
->setCaption(
pht('Format used when rendering a time of day.'))
->setValue($preferences->getPreference($pref_time)))
->appendChild( ->appendChild(
id(new AphrontFormSubmitControl()) id(new AphrontFormSubmitControl())
->setValue(pht('Save Account Settings'))); ->setValue(pht('Save Account Settings')));

View file

@ -0,0 +1,89 @@
<?php
final class PhabricatorDateTimeSettingsPanel extends PhabricatorSettingsPanel {
public function getPanelKey() {
return 'datetime';
}
public function getPanelName() {
return pht('Date and Time');
}
public function getPanelGroup() {
return pht('Account Information');
}
public function processRequest(AphrontRequest $request) {
$user = $request->getUser();
$username = $user->getUsername();
$pref_time = PhabricatorUserPreferences::PREFERENCE_TIME_FORMAT;
$preferences = $user->loadPreferences();
$errors = array();
if ($request->isFormPost()) {
$new_timezone = $request->getStr('timezone');
if (in_array($new_timezone, DateTimeZone::listIdentifiers(), true)) {
$user->setTimezoneIdentifier($new_timezone);
} else {
$errors[] = pht('The selected timezone is not a valid timezone.');
}
$preferences->setPreference($pref_time, $request->getStr($pref_time));
if (!$errors) {
$preferences->save();
$user->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()))
->appendRemarkupInstructions(
pht(
"**Custom Date and Time Formats**\n\n".
"You can specify custom formats which will be used when ".
"rendering dates and times of day. Examples:\n\n".
"| Format | Example | Notes |\n".
"| ------ | -------- | ----- |\n".
"| `g:i A` | 2:34 PM | Default 12-hour time. |\n".
"| `G.i a` | 02.34 pm | Alternate 12-hour time. |\n".
"| `H:i` | 14:34 | 24-hour time. |\n".
"\n\n".
"You can find a [[%s | full reference in the PHP manual]].",
'http://www.php.net/manual/en/function.date.php'))
->appendChild(
id(new AphrontFormTextControl())
->setLabel(pht('Time-of-Day Format'))
->setName($pref_time)
->setCaption(
pht('Format used when rendering a time of day.'))
->setValue($preferences->getPreference($pref_time)))
->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,
);
}
}