From 0d162e15f649801e5e95107b5dc714bbdcce8b9c Mon Sep 17 00:00:00 2001 From: vrana Date: Tue, 17 Jul 2012 17:13:03 -0700 Subject: [PATCH] Make Diffusion view sticky Summary: Blame can be slow. Test Plan: Viewed a file with no preference, saw blame. Changed view, saw it. Viewed a file, saw the changed view. Viewed a file as raw document. Reviewers: Two9A, epriestley Reviewed By: epriestley CC: aran, epriestley, Korvin, btrahan Maniphest Tasks: T1278 Differential Revision: https://secure.phabricator.com/D3000 --- .../DiffusionBrowseFileController.php | 34 ++++++++++++------- .../storage/PhabricatorUserPreferences.php | 2 ++ 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/applications/diffusion/controller/DiffusionBrowseFileController.php b/src/applications/diffusion/controller/DiffusionBrowseFileController.php index 8ac7b2e5cc..ed31b2191d 100644 --- a/src/applications/diffusion/controller/DiffusionBrowseFileController.php +++ b/src/applications/diffusion/controller/DiffusionBrowseFileController.php @@ -31,11 +31,20 @@ final class DiffusionBrowseFileController extends DiffusionController { } $path = $drequest->getPath(); + $selected = $request->getStr('view'); - // If requested without a view, assume that blame is required (see T1278). + $preferences = $request->getUser()->loadPreferences(); if (!$selected) { - $selected = 'blame'; + $selected = $preferences->getPreference( + PhabricatorUserPreferences::PREFERENCE_DIFFUSION_VIEW, + 'highlighted'); + } else if ($request->isFormPost() && $selected != 'raw') { + $preferences->setPreference( + PhabricatorUserPreferences::PREFERENCE_DIFFUSION_VIEW, + $selected); + $preferences->save(); } + $needs_blame = ($selected == 'blame' || $selected == 'plainblame'); $file_query = DiffusionFileContentQuery::newFromDiffusionRequest( @@ -60,7 +69,7 @@ final class DiffusionBrowseFileController extends DiffusionController { require_celerity_resource('diffusion-source-css'); if ($this->corpusType == 'text') { - $view_select_panel = $this->renderViewSelectPanel(); + $view_select_panel = $this->renderViewSelectPanel($selected); } else { $view_select_panel = null; } @@ -217,17 +226,17 @@ final class DiffusionBrowseFileController extends DiffusionController { return $corpus; } - private function renderViewSelectPanel() { + private function renderViewSelectPanel($selected) { $request = $this->getRequest(); $select = AphrontFormSelectControl::renderSelectTag( - $request->getStr('view'), + $selected, array( - 'blame' => 'View as Highlighted Text with Blame', 'highlighted' => 'View as Highlighted Text', - 'plainblame' => 'View as Plain Text with Blame', + 'blame' => 'View as Highlighted Text with Blame', 'plain' => 'View as Plain Text', + 'plainblame' => 'View as Plain Text with Blame', 'raw' => 'View as raw document', ), array( @@ -235,11 +244,11 @@ final class DiffusionBrowseFileController extends DiffusionController { )); $view_select_panel = new AphrontPanelView(); - $view_select_form = phutil_render_tag( - 'form', + $view_select_form = phabricator_render_form( + $request->getUser(), array( - 'action' => $request->getRequestURI(), - 'method' => 'get', + 'action' => $request->getRequestURI()->alter('view', null), + 'method' => 'post', 'class' => 'diffusion-browse-type-form', ), $select. @@ -420,10 +429,9 @@ final class DiffusionBrowseFileController extends DiffusionController { 'action' => 'browse', 'line' => $line['line'], 'stable' => true, + 'params' => array('view' => $selected), )); - $line_href->setQueryParams($request->getRequestURI()->getQueryParams()); - $blame = array(); if ($line['color']) { $color = $line['color']; diff --git a/src/applications/people/storage/PhabricatorUserPreferences.php b/src/applications/people/storage/PhabricatorUserPreferences.php index c1512a0a00..d569d8929a 100644 --- a/src/applications/people/storage/PhabricatorUserPreferences.php +++ b/src/applications/people/storage/PhabricatorUserPreferences.php @@ -30,6 +30,8 @@ final class PhabricatorUserPreferences extends PhabricatorUserDAO { const PREFERENCE_SEARCHBAR_JUMP = 'searchbar-jump'; const PREFERENCE_SEARCH_SHORTCUT = 'search-shortcut'; + const PREFERENCE_DIFFUSION_VIEW = 'diffusion-view'; + protected $userPHID; protected $preferences = array();