1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-18 21:02:41 +01:00

Convert some loadPreferences() to getUserSetting()

Summary:
Ref T4103. This doesn't get everything, but takes care of most of the easy stuff.

The tricky-ish bit here is that I need to move timezones, pronouns and translations to proper settings. I expect to pursue that next.

Test Plan:
- Grepped for `loadPreferences` to identify callsites.
- Changed start-of-week setting, loaded Calendar, saw correct start.
- Visited welcome page, read "Adjust Settings" point.
- Loaded Conpherence -- I changed behavior here slightly (switching threads drops the title glyph) but it wasn't consistent to start with and this seems like a good thing to push to the next version of Conpherence.
- Enabled Filetree, toggled in Differential.
- Disabled Filetree, no longer visible in Differential.
- Changed "Unified Diffs" preference to "Small Screens" vs "Always".
- Toggled filetree in Diffusion.
- Edited a task, saw sensible projects in policy dropdown.
- Viewed user profile, uncollapsed/collapsed side nav, reloaded page, sticky'd.
- Toggled "monospaced textareas", used a comment box, got appropriate fonts.
- Toggled durable column.
- Disabled title glyphs.
- Changed monospaced font to 18px/36px impact.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T4103

Differential Revision: https://secure.phabricator.com/D16004
This commit is contained in:
epriestley 2016-06-01 13:59:08 -07:00
parent 9180f429eb
commit edfc6a6934
14 changed files with 62 additions and 84 deletions

View file

@ -74,35 +74,9 @@ foreach ($applications as $application) {
/* -( User preferences )--------------------------------------------------- */ /* -( User preferences )--------------------------------------------------- */
echo pht('Migrating user preferences...')."\n";
$table = new PhabricatorUserPreferences();
$conn_w = $table->establishConnection('w');
$pref_pinned = PhabricatorUserPreferences::PREFERENCE_APP_PINNED;
foreach (new LiskMigrationIterator(new PhabricatorUser()) as $user) { // This originally migrated pinned applications in user preferences, but was
$user_preferences = $user->loadPreferences(); // removed to simplify preference changes after about 22 months.
$old_pinned_apps = $user_preferences->getPreference($pref_pinned);
$new_pinned_apps = array();
if (!$old_pinned_apps) {
continue;
}
foreach ($old_pinned_apps as $pinned_app) {
$new_pinned_apps[] = idx($map, $pinned_app, $pinned_app);
}
$user_preferences
->setPreference($pref_pinned, $new_pinned_apps);
queryfx(
$conn_w,
'UPDATE %T SET preferences = %s WHERE id = %d',
$user_preferences->getTableName(),
json_encode($user_preferences->getPreferences()),
$user_preferences->getID());
}
/* -( Dashboard installs )------------------------------------------------- */ /* -( Dashboard installs )------------------------------------------------- */

View file

@ -151,10 +151,9 @@ final class PhabricatorCalendarEventSearchEngine
$display_start = $start_day->format('U'); $display_start = $start_day->format('U');
$display_end = $next->format('U'); $display_end = $next->format('U');
$preferences = $viewer->loadPreferences(); $start_of_week = $viewer->getUserSetting(
$pref_week_day = PhabricatorUserPreferences::PREFERENCE_WEEK_START_DAY; PhabricatorWeekStartDaySetting::SETTINGKEY);
$start_of_week = $preferences->getPreference($pref_week_day, 0);
$end_of_week = ($start_of_week + 6) % 7; $end_of_week = ($start_of_week + 6) % 7;
$first_of_month = $start_day->format('w'); $first_of_month = $start_day->format('w');

View file

@ -141,8 +141,14 @@ final class PhabricatorConfigWelcomeController
$content); $content);
$settings_href = PhabricatorEnv::getURI('/settings/'); $settings_href = PhabricatorEnv::getURI('/settings/');
$prefs = $viewer->loadPreferences()->getPreferences();
$have_settings = !empty($prefs); $preferences = id(new PhabricatorUserPreferencesQuery())
->setViewer($viewer)
->withUsers(array($viewer))
->executeOne();
$have_settings = ($preferences && $preferences->getPreferences());
if ($have_settings) { if ($have_settings) {
$content = pht( $content = pht(
"=== Adjust Account Settings ===\n\n". "=== Adjust Account Settings ===\n\n".

View file

@ -72,14 +72,6 @@ final class ConpherenceThreadListView extends AphrontView {
$epoch = $data['epoch']; $epoch = $data['epoch'];
$image = $data['image']; $image = $data['image'];
$dom_id = $thread->getPHID().'-nav-item'; $dom_id = $thread->getPHID().'-nav-item';
$glyph_pref = PhabricatorUserPreferences::PREFERENCE_TITLES;
$preferences = $user->loadPreferences();
if ($preferences->getPreference($glyph_pref) == 'glyph') {
$glyph = id(new PhabricatorConpherenceApplication())
->getTitleGlyph().' ';
} else {
$glyph = null;
}
return id(new ConpherenceMenuItemView()) return id(new ConpherenceMenuItemView())
->setUser($user) ->setUser($user)
@ -93,7 +85,7 @@ final class ConpherenceThreadListView extends AphrontView {
->addSigil('conpherence-menu-click') ->addSigil('conpherence-menu-click')
->setMetadata( ->setMetadata(
array( array(
'title' => $glyph.$data['title'], 'title' => $data['title'],
'id' => $dom_id, 'id' => $dom_id,
'threadID' => $thread->getID(), 'threadID' => $thread->getID(),
)); ));

View file

@ -375,18 +375,19 @@ final class DifferentialRevisionViewController extends DifferentialController {
$crumbs->addTextCrumb($object_id, '/'.$object_id); $crumbs->addTextCrumb($object_id, '/'.$object_id);
$crumbs->setBorder(true); $crumbs->setBorder(true);
$prefs = $viewer->loadPreferences(); $filetree_on = $viewer->compareUserSetting(
$pref_filetree = PhabricatorUserPreferences::PREFERENCE_DIFF_FILETREE; PhabricatorShowFiletreeSetting::SETTINGKEY,
PhabricatorShowFiletreeSetting::VALUE_ENABLE_FILETREE);
$nav = null; $nav = null;
if ($prefs->getPreference($pref_filetree)) { if ($filetree_on) {
$collapsed = $prefs->getPreference( $collapsed_key = PhabricatorUserPreferences::PREFERENCE_NAV_COLLAPSED;
PhabricatorUserPreferences::PREFERENCE_NAV_COLLAPSED, $collapsed_value = $viewer->getUserSetting($collapsed_key);
false);
$nav = id(new DifferentialChangesetFileTreeSideNavBuilder()) $nav = id(new DifferentialChangesetFileTreeSideNavBuilder())
->setTitle('D'.$revision->getID()) ->setTitle('D'.$revision->getID())
->setBaseURI(new PhutilURI('/D'.$revision->getID())) ->setBaseURI(new PhutilURI('/D'.$revision->getID()))
->setCollapsed((bool)$collapsed) ->setCollapsed((bool)$collapsed_value)
->build($changesets); ->build($changesets);
} }

View file

@ -150,11 +150,14 @@ final class DifferentialChangesetParser extends Phobject {
} }
public static function getDefaultRendererForViewer(PhabricatorUser $viewer) { public static function getDefaultRendererForViewer(PhabricatorUser $viewer) {
$prefs = $viewer->loadPreferences(); $is_unified = $viewer->compareUserSetting(
$pref_unified = PhabricatorUserPreferences::PREFERENCE_DIFF_UNIFIED; PhabricatorUnifiedDiffsSetting::SETTINGKEY,
if ($prefs->getPreference($pref_unified) == 'unified') { PhabricatorUnifiedDiffsSetting::VALUE_ALWAYS_UNIFIED);
if ($is_unified) {
return '1up'; return '1up';
} }
return null; return null;
} }

View file

@ -175,9 +175,10 @@ final class DifferentialInlineCommentQuery
$viewer = $this->getViewer(); $viewer = $this->getViewer();
$pref = $viewer->loadPreferences()->getPreference( $no_ghosts = $viewer->compareUserSetting(
PhabricatorUserPreferences::PREFERENCE_DIFF_GHOSTS); PhabricatorOlderInlinesSetting::SETTINGKEY,
if ($pref == 'disabled') { PhabricatorOlderInlinesSetting::VALUE_GHOST_INLINES_DISABLED);
if ($no_ghosts) {
return $inlines; return $inlines;
} }

View file

@ -325,14 +325,15 @@ final class DiffusionCommitController extends DiffusionController {
$add_comment = $this->renderAddCommentPanel($commit, $audit_requests); $add_comment = $this->renderAddCommentPanel($commit, $audit_requests);
$prefs = $viewer->loadPreferences(); $filetree_on = $viewer->compareUserSetting(
$pref_filetree = PhabricatorUserPreferences::PREFERENCE_DIFF_FILETREE; PhabricatorShowFiletreeSetting::SETTINGKEY,
PhabricatorShowFiletreeSetting::VALUE_ENABLE_FILETREE);
$pref_collapse = PhabricatorUserPreferences::PREFERENCE_NAV_COLLAPSED; $pref_collapse = PhabricatorUserPreferences::PREFERENCE_NAV_COLLAPSED;
$show_filetree = $prefs->getPreference($pref_filetree); $collapsed = $viewer->getUserSetting($pref_collapse);
$collapsed = $prefs->getPreference($pref_collapse);
$nav = null; $nav = null;
if ($show_changesets && $show_filetree) { if ($show_changesets && $filetree_on) {
$nav = id(new DifferentialChangesetFileTreeSideNavBuilder()) $nav = id(new DifferentialChangesetFileTreeSideNavBuilder())
->setTitle($commit->getDisplayName()) ->setTitle($commit->getDisplayName())
->setBaseURI(new PhutilURI($commit->getURI())) ->setBaseURI(new PhutilURI($commit->getURI()))

View file

@ -506,6 +506,11 @@ final class PhabricatorUser
return null; return null;
} }
public function compareUserSetting($key, $value) {
$actual = $this->getUserSetting($key);
return ($actual == $value);
}
public function loadPreferences() { public function loadPreferences() {
if ($this->preferences) { if ($this->preferences) {
return $this->preferences; return $this->preferences;

View file

@ -201,8 +201,7 @@ final class PhabricatorPolicyQuery
$default_limit = 5; $default_limit = 5;
// If possible, show the user's 10 most recently used projects. // If possible, show the user's 10 most recently used projects.
$preferences = $viewer->loadPreferences(); $favorites = $viewer->getUserSetting($pref_key);
$favorites = $preferences->getPreference($pref_key);
if (!is_array($favorites)) { if (!is_array($favorites)) {
$favorites = array(); $favorites = array();
} }

View file

@ -385,8 +385,7 @@ abstract class PhabricatorProfilePanelEngine extends Phobject {
$collapse_key = $collapse_key =
PhabricatorUserPreferences::PREFERENCE_PROFILE_MENU_COLLAPSED; PhabricatorUserPreferences::PREFERENCE_PROFILE_MENU_COLLAPSED;
$preferences = $viewer->loadPreferences(); $is_collapsed = $viewer->getUserSetting($collapse_key);
$is_collapsed = $preferences->getPreference($collapse_key, false);
if ($is_collapsed) { if ($is_collapsed) {
$nav->addClass('phui-profile-menu-collapsed'); $nav->addClass('phui-profile-menu-collapsed');

View file

@ -260,15 +260,14 @@ final class PhabricatorRemarkupControl extends AphrontFormTextAreaControl {
), ),
$buttons); $buttons);
$monospaced_textareas = null; $use_monospaced = $viewer->compareUserSetting(
$monospaced_textareas_class = null; PhabricatorMonospacedTextareasSetting::SETTINGKEY,
PhabricatorMonospacedTextareasSetting::VALUE_TEXT_MONOSPACED);
$monospaced_textareas = $viewer if ($use_monospaced) {
->loadPreferences()
->getPreference(
PhabricatorUserPreferences::PREFERENCE_MONOSPACED_TEXTAREAS);
if ($monospaced_textareas == 'enabled') {
$monospaced_textareas_class = 'PhabricatorMonospaced'; $monospaced_textareas_class = 'PhabricatorMonospaced';
} else {
$monospaced_textareas_class = null;
} }
$this->setCustomClass( $this->setCustomClass(

View file

@ -133,7 +133,7 @@ final class PhabricatorStandardPageView extends PhabricatorBarePageView
public function getDurableColumnVisible() { public function getDurableColumnVisible() {
$column_key = PhabricatorUserPreferences::PREFERENCE_CONPHERENCE_COLUMN; $column_key = PhabricatorUserPreferences::PREFERENCE_CONPHERENCE_COLUMN;
return (bool)$this->getUserPreference($column_key, 0); return (bool)$this->getUserPreference($column_key, false);
} }
public function addQuicksandConfig(array $config) { public function addQuicksandConfig(array $config) {
@ -164,12 +164,11 @@ final class PhabricatorStandardPageView extends PhabricatorBarePageView
} }
public function getTitle() { public function getTitle() {
$glyph_key = PhabricatorUserPreferences::PREFERENCE_TITLES; $glyph_key = PhabricatorTitleGlyphsSetting::SETTINGKEY;
if ($this->getUserPreference($glyph_key) == 'text') { $glyph_on = PhabricatorTitleGlyphsSetting::VALUE_TITLE_GLYPHS;
$use_glyph = false; $glyph_setting = $this->getUserPreference($glyph_key, $glyph_on);
} else {
$use_glyph = true; $use_glyph = ($glyph_setting == $glyph_on);
}
$title = parent::getTitle(); $title = parent::getTitle();
@ -362,8 +361,8 @@ final class PhabricatorStandardPageView extends PhabricatorBarePageView
if ($request) { if ($request) {
$user = $request->getUser(); $user = $request->getUser();
if ($user) { if ($user) {
$monospaced = $user->loadPreferences()->getPreference( $monospaced = $user->getUserSetting(
PhabricatorUserPreferences::PREFERENCE_MONOSPACED); PhabricatorMonospacedFontSetting::SETTINGKEY);
} }
} }
@ -834,7 +833,7 @@ final class PhabricatorStandardPageView extends PhabricatorBarePageView
return $default; return $default;
} }
return $user->loadPreferences()->getPreference($key, $default); return $user->getUserSetting($key);
} }
public function produceAphrontResponse() { public function produceAphrontResponse() {

View file

@ -574,10 +574,10 @@ final class PHUICalendarMonthView extends AphrontView {
} }
private function getWeekStartAndEnd() { private function getWeekStartAndEnd() {
$preferences = $this->getViewer()->loadPreferences(); $viewer = $this->getViewer();
$pref_week_start = PhabricatorUserPreferences::PREFERENCE_WEEK_START_DAY; $week_key = PhabricatorUserPreferences::PREFERENCE_WEEK_START_DAY;
$week_start = $preferences->getPreference($pref_week_start, 0); $week_start = $viewer->getUserSetting($week_key);
$week_end = ($week_start + 6) % 7; $week_end = ($week_start + 6) % 7;
return array($week_start, $week_end); return array($week_start, $week_end);